pipediag 0.1.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. pipediag-0.1.1/LICENSE +21 -0
  2. pipediag-0.1.1/MANIFEST.in +23 -0
  3. pipediag-0.1.1/PKG-INFO +540 -0
  4. pipediag-0.1.1/README.md +520 -0
  5. pipediag-0.1.1/pipediag.egg-info/PKG-INFO +540 -0
  6. pipediag-0.1.1/pipediag.egg-info/SOURCES.txt +101 -0
  7. pipediag-0.1.1/pipediag.egg-info/dependency_links.txt +1 -0
  8. pipediag-0.1.1/pipediag.egg-info/entry_points.txt +2 -0
  9. pipediag-0.1.1/pipediag.egg-info/requires.txt +9 -0
  10. pipediag-0.1.1/pipediag.egg-info/top_level.txt +2 -0
  11. pipediag-0.1.1/pyproject.toml +49 -0
  12. pipediag-0.1.1/setup.cfg +4 -0
  13. pipediag-0.1.1/src/pipediag/__init__.py +28 -0
  14. pipediag-0.1.1/src/pipediag/acquisition/__init__.py +35 -0
  15. pipediag-0.1.1/src/pipediag/acquisition/dataset.py +0 -0
  16. pipediag-0.1.1/src/pipediag/acquisition/evaluation.py +197 -0
  17. pipediag-0.1.1/src/pipediag/acquisition/model.py +0 -0
  18. pipediag-0.1.1/src/pipediag/acquisition/pipeline.py +0 -0
  19. pipediag-0.1.1/src/pipediag/acquisition/split.py +602 -0
  20. pipediag-0.1.1/src/pipediag/application.py +204 -0
  21. pipediag-0.1.1/src/pipediag/calibration/likelihood_models.json +105 -0
  22. pipediag-0.1.1/src/pipediag/cli.py +100 -0
  23. pipediag-0.1.1/src/pipediag/diagnostics/__init__.py +10 -0
  24. pipediag-0.1.1/src/pipediag/diagnostics/adapters.py +565 -0
  25. pipediag-0.1.1/src/pipediag/diagnostics/bayesian.py +130 -0
  26. pipediag-0.1.1/src/pipediag/diagnostics/bayesian_evidence.py +289 -0
  27. pipediag-0.1.1/src/pipediag/diagnostics/calibrated_registry.py +144 -0
  28. pipediag-0.1.1/src/pipediag/diagnostics/calibration.py +44 -0
  29. pipediag-0.1.1/src/pipediag/diagnostics/calibration_data.py +79 -0
  30. pipediag-0.1.1/src/pipediag/diagnostics/calibration_estimator.py +77 -0
  31. pipediag-0.1.1/src/pipediag/diagnostics/calibration_runner.py +80 -0
  32. pipediag-0.1.1/src/pipediag/diagnostics/diagnostic_engine.py +80 -0
  33. pipediag-0.1.1/src/pipediag/diagnostics/diagnostic_result.py +50 -0
  34. pipediag-0.1.1/src/pipediag/diagnostics/diagnostic_scenario.py +43 -0
  35. pipediag-0.1.1/src/pipediag/diagnostics/distribution_shift.py +445 -0
  36. pipediag-0.1.1/src/pipediag/diagnostics/engine_factory.py +51 -0
  37. pipediag-0.1.1/src/pipediag/diagnostics/evaluation.py +269 -0
  38. pipediag-0.1.1/src/pipediag/diagnostics/evidence.py +42 -0
  39. pipediag-0.1.1/src/pipediag/diagnostics/evidence_group.py +17 -0
  40. pipediag-0.1.1/src/pipediag/diagnostics/evidence_hypothesis_map.py +34 -0
  41. pipediag-0.1.1/src/pipediag/diagnostics/evidence_inference.py +130 -0
  42. pipediag-0.1.1/src/pipediag/diagnostics/evidence_likelihood.py +267 -0
  43. pipediag-0.1.1/src/pipediag/diagnostics/evidence_measurement.py +26 -0
  44. pipediag-0.1.1/src/pipediag/diagnostics/explanation.py +820 -0
  45. pipediag-0.1.1/src/pipediag/diagnostics/explanation_calibration.py +374 -0
  46. pipediag-0.1.1/src/pipediag/diagnostics/generalization.py +208 -0
  47. pipediag-0.1.1/src/pipediag/diagnostics/ground_truth.py +49 -0
  48. pipediag-0.1.1/src/pipediag/diagnostics/hypotheses.py +84 -0
  49. pipediag-0.1.1/src/pipediag/diagnostics/imbalance.py +302 -0
  50. pipediag-0.1.1/src/pipediag/diagnostics/leakage.py +434 -0
  51. pipediag-0.1.1/src/pipediag/diagnostics/likelihood.py +24 -0
  52. pipediag-0.1.1/src/pipediag/diagnostics/likelihood_artifact.py +136 -0
  53. pipediag-0.1.1/src/pipediag/diagnostics/likelihood_builder.py +91 -0
  54. pipediag-0.1.1/src/pipediag/diagnostics/likelihood_estimator.py +99 -0
  55. pipediag-0.1.1/src/pipediag/diagnostics/likelihood_model.py +150 -0
  56. pipediag-0.1.1/src/pipediag/diagnostics/likelihood_registry.py +85 -0
  57. pipediag-0.1.1/src/pipediag/diagnostics/multivariate_likelihood_model.py +194 -0
  58. pipediag-0.1.1/src/pipediag/diagnostics/report.py +170 -0
  59. pipediag-0.1.1/src/pipediag/diagnostics/scenario_result.py +84 -0
  60. pipediag-0.1.1/src/pipediag/diagnostics/scenario_runner.py +52 -0
  61. pipediag-0.1.1/src/pipediag/diagnostics/threshold_evaluation.py +152 -0
  62. pipediag-0.1.1/src/pipediag/diagnostics/threshold_reporting.py +86 -0
  63. pipediag-0.1.1/src/pipediag/diagnostics/uncertainty.py +46 -0
  64. pipediag-0.1.1/src/pipediag/diagnostics/validation.py +69 -0
  65. pipediag-0.1.1/src/pipediag/diagnostics/validation_result.py +78 -0
  66. pipediag-0.1.1/src/pipediag/evidence/__init__.py +35 -0
  67. pipediag-0.1.1/src/pipediag/evidence/collector.py +499 -0
  68. pipediag-0.1.1/src/pipediag/evidence/lineage.py +81 -0
  69. pipediag-0.1.1/src/pipediag/evidence/models.py +35 -0
  70. pipediag-0.1.1/src/pipediag/evidence/registry.py +93 -0
  71. pipediag-0.1.1/src/pipediag/evidence/runtime_provider.py +237 -0
  72. pipediag-0.1.1/src/pipediag/evidence/store.py +45 -0
  73. pipediag-0.1.1/src/pipediag/explanation/__init__.py +0 -0
  74. pipediag-0.1.1/src/pipediag/explanation/generator.py +0 -0
  75. pipediag-0.1.1/src/pipediag/explanation/recommendations.py +0 -0
  76. pipediag-0.1.1/src/pipediag/inference/__init__.py +0 -0
  77. pipediag-0.1.1/src/pipediag/inference/network.py +0 -0
  78. pipediag-0.1.1/src/pipediag/inference/variables.py +0 -0
  79. pipediag-0.1.1/src/pipediag/llm/__init__.py +13 -0
  80. pipediag-0.1.1/src/pipediag/llm/generator.py +64 -0
  81. pipediag-0.1.1/src/pipediag/llm/ollama.py +249 -0
  82. pipediag-0.1.1/src/pipediag/llm/prompt.py +156 -0
  83. pipediag-0.1.1/src/pipediag/llm/validator.py +143 -0
  84. pipediag-0.1.1/src/pipediag/persistence.py +420 -0
  85. pipediag-0.1.1/src/pipediag/result.py +0 -0
  86. pipediag-0.1.1/src/pipediag/runtime/__init__.py +9 -0
  87. pipediag-0.1.1/src/pipediag/runtime/context.py +136 -0
  88. pipediag-0.1.1/src/pipediag/runtime/events.py +30 -0
  89. pipediag-0.1.1/src/pipediag/runtime/instrumentation.py +200 -0
  90. pipediag-0.1.1/src/pipediag/runtime/session.py +89 -0
  91. pipediag-0.1.1/web/__init__.py +0 -0
  92. pipediag-0.1.1/web/backend/__init__.py +0 -0
  93. pipediag-0.1.1/web/backend/evidence.py +23 -0
  94. pipediag-0.1.1/web/backend/integration.py +29 -0
  95. pipediag-0.1.1/web/backend/main.py +352 -0
  96. pipediag-0.1.1/web/backend/run_store.py +65 -0
  97. pipediag-0.1.1/web/backend/schemas.py +99 -0
  98. pipediag-0.1.1/web/backend/serializers.py +230 -0
  99. pipediag-0.1.1/web/backend/service.py +46 -0
  100. pipediag-0.1.1/web/frontend/dist/assets/index-BQS3lKUm.js +37 -0
  101. pipediag-0.1.1/web/frontend/dist/assets/index-xkfZXsN1.css +1 -0
  102. pipediag-0.1.1/web/frontend/dist/favicon.svg +1 -0
  103. pipediag-0.1.1/web/frontend/dist/icons.svg +24 -0
  104. pipediag-0.1.1/web/frontend/dist/index.html +14 -0
pipediag-0.1.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Dathi Likhith
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ include README.md
2
+ include LICENSE
3
+ include pyproject.toml
4
+
5
+ recursive-include src/pipediag *.py
6
+ recursive-include src/pipediag/calibration *.json
7
+ recursive-include web/backend *.py
8
+ recursive-include web/frontend/dist *.html *.svg *.js *.css
9
+
10
+
11
+ exclude *.py[cod]
12
+ global-exclude SOURCES.txt
13
+ recursive-exclude tests *
14
+ recursive-exclude experiments *
15
+ recursive-exclude __pycache__ *
16
+
17
+ prune build
18
+ prune dist
19
+ prune .pytest_cache
20
+ prune .venv
21
+ prune venv
22
+ prune src/pipediag.egg-info
23
+ prune web/frontend/node_modules
@@ -0,0 +1,540 @@
1
+ Metadata-Version: 2.4
2
+ Name: pipediag
3
+ Version: 0.1.1
4
+ Summary: An explainable diagnostic framework for scikit-learn machine learning pipelines
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://github.com/LikhithDathi/PipeDiag
7
+ Project-URL: Repository, https://github.com/LikhithDathi/PipeDiag
8
+ Project-URL: Issues, https://github.com/LikhithDathi/PipeDiag/issues
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+ Requires-Dist: numpy>=2.0
13
+ Requires-Dist: scikit-learn>=1.8
14
+ Provides-Extra: llm
15
+ Requires-Dist: ollama>=0.4; extra == "llm"
16
+ Provides-Extra: web
17
+ Requires-Dist: fastapi>=0.115; extra == "web"
18
+ Requires-Dist: uvicorn[standard]>=0.30; extra == "web"
19
+ Dynamic: license-file
20
+
21
+ # PipeDiag
22
+
23
+ **An explainable diagnostic framework for scikit-learn machine learning pipelines.**
24
+
25
+ PipeDiag observes supported scikit-learn pipeline execution, records runtime events and dataset references, and provides components for evidence-based diagnosis, Bayesian inference, structured explanations, and human-readable reports.
26
+
27
+ The framework separates runtime observation from diagnostic inference so that applications can configure how evidence is collected and how diagnostic results are produced.
28
+
29
+ ## Features
30
+
31
+ - **Runtime instrumentation:** Observe operations performed by supported scikit-learn pipelines.
32
+ - **Execution events:** Record component names, operations, event status, execution duration, dataset references, and event relationships.
33
+ - **Evidence-based diagnosis:** Evaluate diagnostic evidence against calibrated likelihood models.
34
+ - **Bayesian inference:** Produce a posterior distribution over diagnostic hypotheses.
35
+ - **Explainable results:** Build structured explanations and render diagnostic reports.
36
+ - **Configurable architecture:** Supply an evidence provider and diagnostic engine through the application layer.
37
+ - **Packaged calibration data:** Include the default likelihood-model artifact with the Python package.
38
+ - **Optional web dashboard:** Explore diagnostic runs through a locally hosted React dashboard.
39
+ - **Optional LLM integration:** Support Ollama-related explanation workflows through an optional dependency.
40
+
41
+ ## Requirements
42
+
43
+ - Python 3.12 or later
44
+ - NumPy 2.0 or later
45
+ - scikit-learn 1.8 or later
46
+
47
+ ## Installation
48
+
49
+ ### Install from PyPI
50
+
51
+ Install the core PipeDiag package:
52
+
53
+ ```bash
54
+ python -m pip install pipediag
55
+ ```
56
+
57
+ The core installation includes runtime instrumentation, evidence-processing components, calibrated Bayesian diagnosis, explanation generation, and reporting functionality.
58
+
59
+ ### Optional dependencies
60
+
61
+ PipeDiag provides optional integrations that can be installed separately.
62
+
63
+ **Web dashboard:**
64
+
65
+ ```bash
66
+ python -m pip install "pipediag[web]"
67
+ ```
68
+
69
+ Launch the dashboard:
70
+
71
+ ```bash
72
+ pipediag dashboard
73
+ ```
74
+
75
+ The dashboard is available at:
76
+
77
+ ```text
78
+ http://127.0.0.1:8000
79
+ ```
80
+
81
+ To customize the host and port:
82
+
83
+ ```bash
84
+ pipediag dashboard --host 127.0.0.1 --port 8000 --no-browser
85
+ ```
86
+
87
+ The dashboard runs locally and provides access to the PipeDiag backend and React frontend.
88
+
89
+ **Ollama integration:**
90
+
91
+ ```bash
92
+ python -m pip install "pipediag[llm]"
93
+ ```
94
+
95
+ **Install both integrations:**
96
+
97
+ ```bash
98
+ python -m pip install "pipediag[web,llm]"
99
+ ```
100
+
101
+ The `llm` extra installs Ollama-related support. The `web` extra installs FastAPI and Uvicorn. These extras are optional and are not part of the base dependency set.
102
+
103
+ ### Instgit clone https://github.com/LikhithDathi/PipeDiag.git
104
+ cd PipeDiag
105
+ repository and install the package:
106
+
107
+ ```bash
108
+ git clone <REPOSITORY_URL>
109
+ cd pipediag
110
+ python -m pip install .
111
+ ```
112
+
113
+ For development, where source changes should be available without reinstalling:
114
+
115
+ ```bash
116
+ python -m pip install -e .
117
+ ```
118
+
119
+ ### Install from a built wheel
120
+
121
+ If you have downloaded or built a wheel, install it with:
122
+
123
+ ```bash
124
+ python -m pip install pipediag-0.1.0-py3-none-any.whl
125
+ ```
126
+
127
+ Replace the filename with the wheel you have.
128
+
129
+ ## Quick start: end-to-end pipeline diagnosis
130
+
131
+ PipeDiag provides the public `pipediag.start()` API for observing supported scikit-learn pipeline execution and connecting the captured runtime context to a configured diagnostic application.
132
+
133
+ ### 1. Configure the diagnostic application
134
+
135
+ The diagnostic application coordinates evidence acquisition, Bayesian inference, explanation generation, and report rendering.
136
+
137
+ ```python
138
+ from pipediag.application import (
139
+ DiagnosticApplication,
140
+ DiagnosticEvidenceProvider,
141
+ )
142
+
143
+ from pipediag.diagnostics.engine_factory import (
144
+ build_calibrated_diagnostic_engine,
145
+ )
146
+
147
+ from pipediag.evidence.runtime_provider import (
148
+ RuntimeEvidenceProvider,
149
+ )
150
+
151
+ application = DiagnosticApplication(
152
+ evidence_provider=DiagnosticEvidenceProvider(
153
+ RuntimeEvidenceProvider()
154
+ ),
155
+ diagnostic_engine=build_calibrated_diagnostic_engine(),
156
+ )
157
+ ```
158
+
159
+ ### 2. Instrument and execute a pipeline
160
+
161
+ ```python
162
+ import numpy as np
163
+ import pipediag
164
+
165
+ from sklearn.linear_model import LogisticRegression
166
+ from sklearn.model_selection import train_test_split
167
+ from sklearn.pipeline import Pipeline
168
+ from sklearn.preprocessing import StandardScaler
169
+
170
+ X = np.array([
171
+ [1.0, 2.0],
172
+ [2.0, 1.0],
173
+ [3.0, 4.0],
174
+ [4.0, 3.0],
175
+ [5.0, 6.0],
176
+ [6.0, 5.0],
177
+ [7.0, 8.0],
178
+ [8.0, 7.0],
179
+ ])
180
+
181
+ y = np.array([0, 0, 0, 0, 1, 1, 1, 1])
182
+
183
+ X_train, X_test, y_train, y_test = train_test_split(
184
+ X,
185
+ y,
186
+ test_size=0.25,
187
+ random_state=42,
188
+ stratify=y,
189
+ )
190
+
191
+ pipeline = Pipeline([
192
+ ("scaler", StandardScaler()),
193
+ ("classifier", LogisticRegression()),
194
+ ])
195
+
196
+ with pipediag.start(application=application) as run:
197
+ pipeline = run.instrument(pipeline)
198
+
199
+ pipeline.fit(X_train, y_train)
200
+ predictions = pipeline.predict(X_test)
201
+
202
+ result = run.result()
203
+ ```
204
+
205
+ ### 3. Inspect the diagnostic result
206
+
207
+ ```python
208
+ diagnostic = result.diagnostic_result
209
+
210
+ print("Run ID:", run.run_id)
211
+ print("Runtime events:", run.context.event_count())
212
+ print("Predictions:", predictions)
213
+
214
+ print("Posterior:", diagnostic.posterior)
215
+ print("Uncertainty:", diagnostic.uncertainty)
216
+
217
+ print("\nDiagnostic report:")
218
+ print(result.report)
219
+ ```
220
+
221
+ The diagnostic result exposes:
222
+
223
+ - `posterior`: probability distribution over diagnostic hypotheses.
224
+ - `uncertainty`: uncertainty associated with the posterior distribution.
225
+ - `evidence`: evidence groups supplied to the diagnostic engine.
226
+ - `metadata`: contextual information associated with the diagnosis.
227
+
228
+ ### What happens during a run?
229
+
230
+ 1. `pipediag.start()` creates a `DiagnosticRun` and its `RunContext`.
231
+ 2. `run.instrument(pipeline)` instruments the supported pipeline.
232
+ 3. Pipeline operations execute normally while runtime events are recorded.
233
+ 4. `RuntimeEvidenceProvider` acquires execution evidence from the completed runtime context.
234
+ 5. `DiagnosticEvidenceProvider` adapts the acquired evidence into `EvidenceGroup` objects.
235
+ 6. The calibrated diagnostic engine evaluates the evidence and performs Bayesian inference.
236
+ 7. The application builds a structured explanation and renders a diagnostic report.
237
+
238
+ The context manager does not suppress exceptions raised by the user's pipeline.
239
+
240
+ ### Current runtime evidence coverage
241
+
242
+ The current `RuntimeEvidenceProvider` implementation acquires execution evidence (G8) from captured runtime events. It calculates the execution failure rate, total event count, and failed event count.
243
+
244
+ The provider also contains a generalization-evidence helper, but that helper is not currently invoked by `collect()`. Other evidence groups are not automatically acquired by this provider.
245
+
246
+ Consequently, the end-to-end example demonstrates the configured diagnostic workflow using the currently implemented G8 runtime evidence. It should not be interpreted as automatic acquisition of all eight evidence groups.
247
+
248
+ ## Runtime observation versus diagnostic inference
249
+
250
+ PipeDiag separates runtime observation from diagnostic inference. These capabilities can be used independently or combined through the public `DiagnosticRun` API.
251
+
252
+ ### Runtime observation only
253
+
254
+ Use this mode when you want to instrument a pipeline and inspect its execution without performing Bayesian diagnosis.
255
+
256
+ ```python
257
+ with pipediag.start() as run:
258
+ run.instrument(pipeline)
259
+ pipeline.fit(X, y)
260
+ predictions = pipeline.predict(X)
261
+
262
+ events = run.context.get_events()
263
+
264
+ for event in events:
265
+ print(
266
+ event.event_id,
267
+ event.operation,
268
+ event.status,
269
+ event.duration_ms,
270
+ )
271
+ ```
272
+
273
+ This mode does not require a diagnostic application.
274
+
275
+ ### End-to-end diagnosis
276
+
277
+ Use this mode when you want PipeDiag to acquire evidence and produce a diagnostic result.
278
+
279
+ Configure a `DiagnosticApplication` with:
280
+
281
+ - An evidence provider responsible for acquiring diagnostic evidence.
282
+ - A diagnostic engine responsible for Bayesian inference.
283
+
284
+ Pass the configured application to `pipediag.start()` and call `run.result()` after pipeline execution.
285
+
286
+ ```python
287
+ with pipediag.start(application=application) as run:
288
+ run.instrument(pipeline)
289
+ pipeline.fit(X, y)
290
+
291
+ result = run.result()
292
+ ```
293
+
294
+ Alternatively, the application can be supplied directly to `run.result(application=application)`.
295
+
296
+ Calling `run.result()` without a configured application raises a `RuntimeError`.
297
+
298
+ ### Diagnostic result structure
299
+
300
+ The application returns a `DiagnosticRunResult` containing:
301
+
302
+ - `diagnostic_result`: posterior distribution, uncertainty, evidence groups, and metadata.
303
+ - `explanation`: structured diagnostic interpretation.
304
+ - `report`: rendered human-readable report.
305
+
306
+ The posterior represents probabilistic diagnostic support. It should not be interpreted as proof of a causal root cause.
307
+
308
+ ## Building a calibrated diagnostic engine
309
+
310
+ PipeDiag provides a factory for constructing a diagnostic engine from the packaged calibration artifact.
311
+
312
+ ```python
313
+ from pipediag.diagnostics.engine_factory import (
314
+ build_calibrated_diagnostic_engine,
315
+ )
316
+
317
+ engine = build_calibrated_diagnostic_engine()
318
+ ```
319
+
320
+ The default calibration loader looks for the JSON artifact inside the installed package first. It also supports source-tree and shared-data fallback paths.
321
+
322
+ The loader validates the artifact schema, declared model count, required model fields, and duplicate model keys before returning a likelihood-model registry.
323
+
324
+ The calibrated engine can be used by a configured `DiagnosticApplication` or with the lower-level evidence interface when you already have compatible evidence groups.
325
+
326
+ ## Working with diagnostic results
327
+
328
+ The lower-level diagnostic engine accepts evidence groups:
329
+
330
+ ```python
331
+ from pipediag.diagnostics.evidence_group import EvidenceGroup
332
+ from pipediag.diagnostics.engine_factory import (
333
+ build_calibrated_diagnostic_engine,
334
+ )
335
+
336
+ engine = build_calibrated_diagnostic_engine()
337
+
338
+ evidence = [
339
+ EvidenceGroup(
340
+ name="G1",
341
+ value=0.8,
342
+ status="observed",
343
+ )
344
+ ]
345
+
346
+ result = engine.diagnose(evidence)
347
+
348
+ print("Posterior:", result.posterior)
349
+ print("Uncertainty:", result.uncertainty)
350
+ ```
351
+
352
+ This is a minimal API example, not a validated real-world diagnostic scenario. The meaning and validity of evidence values depend on the evidence-generation process and the calibration models. Do not interpret a single synthetic value as proof of a pipeline defect.
353
+
354
+ A diagnostic result includes:
355
+
356
+ - `posterior`: probabilities associated with diagnostic hypotheses.
357
+ - `uncertainty`: the engine's uncertainty measure.
358
+ - `evidence`: the evidence groups supplied to the engine.
359
+ - `metadata`: optional contextual information.
360
+
361
+ The current hypothesis set includes data leakage, generalization failure, distribution shift, class imbalance, data-quality problems, evaluation problems, underfitting, feature-related problems, and pipeline/execution problems.
362
+
363
+ ## Calibration data
364
+
365
+ The package includes a default artifact at:
366
+
367
+ ```text
368
+ pipediag/calibration/likelihood_models.json
369
+ ```
370
+
371
+ The artifact uses schema version 1 and contains calibrated likelihood-model entries for the diagnostic engine.
372
+
373
+ The default loader resolves the artifact from the installed package when available. It also supports fallback locations for source checkouts and shared data installations.
374
+
375
+ If you supply a custom artifact path, ensure that the JSON follows the schema expected by the installed version of PipeDiag.
376
+
377
+ A successful calibration load establishes that the artifact can be parsed and used to construct the registry. It does not, by itself, establish that the resulting probabilities are reliable for every application or dataset. Calibration quality must be assessed against appropriate evaluation scenarios.
378
+
379
+ ## Regenerating calibration artifacts
380
+
381
+ PipeDiag provides a script for regenerating the calibrated likelihood-model artifact.
382
+
383
+ The calibration models are generated using the calibration workflow in `experiments/full_system_validation.py`.
384
+
385
+ To regenerate the artifacts, run the following command from the project root:
386
+
387
+ ```bash
388
+ python scripts/export_calibration.py
389
+ ```
390
+
391
+ The script:
392
+
393
+ 1. Builds the calibrated likelihood-model registry.
394
+ 2. Extracts the likelihood parameters for each model.
395
+ 3. Validates that exactly 11 models have been generated.
396
+ 4. Serializes the models into the versioned JSON artifact format.
397
+ 5. Writes the artifact to both calibration locations.
398
+ 6. Reloads and verifies both generated JSON files.
399
+
400
+ The generated artifacts are stored at:
401
+
402
+ ```text
403
+ artifacts/calibration/likelihood_models.json
404
+ src/pipediag/calibration/likelihood_models.json
405
+ ```
406
+
407
+ The package-level artifact under `src/pipediag/calibration/` is tracked in the repository and included in the Python distribution.
408
+
409
+ The repository-level artifact under `artifacts/calibration/` is a generated development artifact. It is excluded from Git and can be regenerated by running the export script.
410
+
411
+ Both files should remain synchronized when the export script is run. The script updates and verifies both locations automatically.
412
+
413
+ The calibration artifact uses schema version 1 and currently contains 11 likelihood models.
414
+
415
+ Regenerating the artifact does not itself establish the scientific validity of the calibration methodology or its underlying data. Those require separate validation.
416
+
417
+ ## Architecture overview
418
+
419
+ PipeDiag separates runtime observation from inference and presentation.
420
+
421
+ ```text
422
+ Scikit-learn pipeline
423
+ |
424
+ v
425
+ Runtime instrumentation
426
+ |
427
+ v
428
+ RunContext and execution events
429
+ |
430
+ v
431
+ Configured evidence provider
432
+ |
433
+ v
434
+ Evidence groups
435
+ |
436
+ v
437
+ Calibrated diagnostic engine
438
+ |
439
+ v
440
+ Bayesian posterior and uncertainty
441
+ |
442
+ v
443
+ Structured explanation
444
+ |
445
+ v
446
+ Human-readable report
447
+ ```
448
+
449
+ The diagram describes the high-level application workflow. Runtime events are not automatically equivalent to diagnostic evidence; a configured provider is responsible for obtaining and adapting the evidence required by the diagnostic engine.
450
+
451
+ ## Web dashboard
452
+
453
+ PipeDiag includes an optional local web dashboard built with React and powered by a FastAPI backend.
454
+
455
+ Install the web dependencies:
456
+
457
+ ```bash
458
+ python -m pip install "pipediag[web]"
459
+ ```
460
+
461
+ Launch the dashboard:
462
+
463
+ ```bash
464
+ pipediag dashboard
465
+ ```
466
+
467
+ By default, the dashboard is served at:
468
+
469
+ ```text
470
+ http://127.0.0.1:8000
471
+ ```
472
+
473
+ The dashboard provides an interface for exploring diagnostic runs, viewing diagnostic results, and accessing saved run history.
474
+
475
+ The backend exposes API endpoints for health checks, diagnostic runs, and example execution.
476
+
477
+ To stop the dashboard, press `Ctrl+C` in the terminal running the server.
478
+
479
+ The dashboard is optional. Users who only need the Python diagnostic framework do not need to install the web dependencies.
480
+
481
+ ## Development and tests
482
+
483
+ To install the project for development:
484
+
485
+ ```bash
486
+ python -m pip install -e .
487
+ ```
488
+
489
+ Install the optional web dependencies when working on the dashboard:
490
+
491
+ ```bash
492
+ python -m pip install -e ".[web]"
493
+ ```
494
+
495
+ Install the optional LLM dependencies when working on the Ollama integration:
496
+
497
+ ```bash
498
+ python -m pip install -e ".[llm]"
499
+ ```
500
+
501
+ Run the test suite with:
502
+
503
+ ```bash
504
+ python -m pytest -q
505
+ ```
506
+
507
+ Build the distribution artifacts with:
508
+
509
+ ```bash
510
+ python -m pip install build
511
+ python -m build
512
+ ```
513
+
514
+ The wheel and source distribution are written to the `dist/` directory.
515
+
516
+ For release verification, install the built wheel in a fresh virtual environment and check both runtime instrumentation and calibration loading.
517
+
518
+ ## Scope and limitations
519
+
520
+ - Runtime instrumentation targets supported scikit-learn pipelines; it is not a general-purpose Python execution tracer.
521
+ - Runtime events and dataset references provide execution evidence, but they do not independently establish the semantic meaning of every feature or the root cause of a model problem.
522
+ - Full diagnostic inference requires a compatible evidence provider and configured diagnostic engine.
523
+ - The current runtime evidence provider automatically acquires execution evidence (G8); other evidence groups require their own acquisition and integration.
524
+ - Diagnostic outputs depend on the quality, coverage, and applicability of the evidence and calibration models.
525
+ - A confident posterior should not be interpreted as a guarantee of correctness without appropriate empirical validation.
526
+ - Optional integrations may require additional dependencies and their own configuration.
527
+
528
+ ## Project status
529
+
530
+ PipeDiag includes runtime instrumentation, evidence-processing components, calibrated Bayesian diagnosis, explanation and reporting components, and optional integration support.
531
+
532
+ The project is under active development. Before using it in a production decision-making workflow, validate the complete diagnostic process against representative scenarios, verify probability calibration, and document the supported deployment configuration.
533
+
534
+ ## License
535
+
536
+ PipeDiag is released under the MIT License.
537
+
538
+ Copyright (c) 2026 Dathi Likhith.
539
+
540
+ See the [LICENSE](LICENSE) file for details.