Report Module
The xpyrment.report module contains submodules and components for report.
report
Experimental reporting, lifecycle tracking, and scientific visualization.
This package provides logging, recording, and charting tools to summarize experimental phases. It ensures that setups, runtime quality checks, and analytical inferences are aggregated and presented in standard-compliant, publication-ready formats.
Submodules:
- card: Compiles standard, machine-readable Experiment Cards for metadata cataloging.
- audit: Logs and chains immutable lifecycle events for audit and governance compliance.
- export: Generates high-quality statistical plots (Forest plots, Power curves).
| MODULE | DESCRIPTION |
|---|---|
audit |
Immutable, compliance-ready experimental audit trails. |
card |
Unified, standard-compliant Experiment Cards and meta-ledgers. |
export |
Statistical visualization and plot generation for experimental reports. |
generator |
|
| CLASS | DESCRIPTION |
|---|---|
ExperimentCard |
Consumes metadata, planning state, and calculations to compile a unified report card. |
AuditTrail |
Maintains an immutable, compliance-ready audit trail of experiment phase transition events. |
ExperimentReportGenerator |
Generates premium standalone Markdown and HTML reports from experiment AnalysisResult instances. |
| FUNCTION | DESCRIPTION |
|---|---|
plot_forest |
Generates a horizontal forest plot visualizing relative lift and confidence intervals. |
plot_power_curve |
Plots required sample size per variant across a range of Minimum Detectable Effects (MDE). |
ExperimentCard
ExperimentCard(
experiment_id: str,
plan_spec: dict,
validation_spec: dict,
analysis_summary: dict,
)
Consumes metadata, planning state, and calculations to compile a unified report card.
An Experiment Card (inspired by Model Cards, Mitchell et al. 2019) is the definitive, unified record and metadata registry of an experiment. It acts as a standardized document that records the design, execution, and results of an experiment in a machine-readable format. This makes it possible to search, catalog, and run large-scale meta-analyses across thousands of past experiments (e.g., tracking cumulative lift, estimating p-value distributions, or measuring historical power).
The Experiment Card schema unifies three core lifecycle stages
- Planning & Setup Specification (
plan_spec): mde: Minimum Detectable Effect (relative or absolute).alpha: Nominal Type I error rate (e.g., \(0.05\)).power: Target statistical power (\(1 - \\beta\), e.g., \(0.80\)).target_sample_size: Calculated sample size requirement.metric_registry: Names and types of registered primary, secondary, and guardrail metrics.- Runtime Validation & Diagnostics (
validation_spec): srm_p_value: Pearson Chi-Square goodness-of-fit p-value for sample allocation ratio mismatches.covariate_balance: Standardized Mean Differences (SMDs) confirming unbiased random assignments.- Statistical Analysis Outcomes (
analysis_summary): treatment_effect: Relative and absolute lifts, standard errors, and confidence intervals.p_values: Observed p-values (with any multiple-testing adjustments applied).recommendation: Automated decision outcome (e.g.,"SHIP","NO-SHIP","INCONCLUSIVE").
| ATTRIBUTE | DESCRIPTION |
|---|---|
experiment_id |
Unique tracking identifier for the experiment.
TYPE:
|
plan_spec |
Setup configurations, expected metrics, and calculated power parameters.
TYPE:
|
validation_spec |
Summary of SRM and covariate balance diagnostics.
TYPE:
|
analysis_summary |
Calculated point estimates, confidence intervals, and launch recommendations.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
experiment_id
|
The unique ID of the experiment.
TYPE:
|
plan_spec
|
Setup and design characteristics dictionary.
TYPE:
|
validation_spec
|
Pre-analysis quality check outcomes.
TYPE:
|
analysis_summary
|
Post-analysis statistical summaries.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
to_dict |
Serializes the experiment card metadata to a standard python dictionary. |
to_json |
Dumps the card as a formatted JSON document. |
Source code in src\xpyrment\report\card.py
to_dict
Serializes the experiment card metadata to a standard python dictionary.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
The nested dictionary of card metadata.
TYPE:
|
Source code in src\xpyrment\report\card.py
to_json
Dumps the card as a formatted JSON document.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Indented, pretty-printed JSON string of the complete experiment card ledger.
TYPE:
|
AuditTrail
Maintains an immutable, compliance-ready audit trail of experiment phase transition events.
In enterprise, financial, and clinical environments, maintaining a rigorous record of an experiment's history is critical for governance, auditing, and scientific reproducibility. An audit trail acts as a tamper-evident, chronological log tracking every key lifecycle change, modification to allocation parameters, and analytical peeking event.
Cryptographic Verification and State-Chaining
To satisfy strict regulatory compliance frameworks, the audit log entries are structured as a linear hash chain:
- Each log entry is represented as a state block \(B_k = (t_k, a_k, d_k, h_{k-1})\) where:
- \(t_k\): Coordinated Universal Time (ISO 8601 UTC timestamp).
- \(a_k\): The action or state transition executed (e.g., "ALLOCATION_SHIFT").
- \(d_k\): Detailed parameter changes (e.g., altering treatment allocation from \(10\\%\) to \(50\\%\)).
- \(h_{k-1}\): The SHA-256 cryptographic hash of the preceding block \(B_{k-1}\).
- The hash of the current block \(h_k\) is computed as:
$$
h_k = H(t_k \parallel a_k \parallel d_k \parallel h_{k-1})
$$
where \(\\parallel\) denotes string concatenation, and \(H\) is the SHA-256 secure hash function.
- Because of this chaining, any retroactive modification of historical logs immediately breaks the hash chain,
making the log highly secure and tamper-evident.
| ATTRIBUTE | DESCRIPTION |
|---|---|
experiment_id |
The unique identifier of the experiment under audit.
TYPE:
|
logs |
List of chronological, cryptographically linked log events.
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
experiment_id
|
The unique ID of the target experiment.
TYPE:
|
db_path
|
Optional SQLite database path for tamper-proof persistence.
TYPE:
|
| METHOD | DESCRIPTION |
|---|---|
log_event |
Appends a new event with an active timestamp to the audit trail log. |
verify_integrity |
Verifies the complete cryptographic chain of the audit trail ledger. |
get_logs |
Returns the full list of chronological logs in the audit ledger. |
Source code in src\xpyrment\report\audit.py
log_event
Appends a new event with an active timestamp to the audit trail log.
Calculates timestamps in strict UTC, hashes the event details with the prior block's hash, and appends the entry to the ledger. Optionally attaches RSA/ECDSA digital signatures.
| PARAMETER | DESCRIPTION |
|---|---|
action
|
The action category (e.g.,
TYPE:
|
details
|
Detailed text or JSON payload describing the parameters or user that initiated the change.
TYPE:
|
signature
|
Cryptographic signature of the event hash.
TYPE:
|
public_key
|
Public key string to verify the signature.
TYPE:
|
Source code in src\xpyrment\report\audit.py
verify_integrity
Verifies the complete cryptographic chain of the audit trail ledger.
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the hash chain is fully intact and unmodified, False otherwise.
TYPE:
|
Source code in src\xpyrment\report\audit.py
get_logs
Returns the full list of chronological logs in the audit ledger.
| RETURNS | DESCRIPTION |
|---|---|
List[Dict[str, str]]
|
List[Dict[str, str]]: A list of dictionary objects representing the serialized ledger blocks. |
Source code in src\xpyrment\report\audit.py
ExperimentReportGenerator
ExperimentReportGenerator(
result: AnalysisResult,
experiment_name: str = "A/B Experiment Report",
)
Generates premium standalone Markdown and HTML reports from experiment AnalysisResult instances.
| PARAMETER | DESCRIPTION |
|---|---|
result
|
The completed analysis result object.
TYPE:
|
experiment_name
|
The logical name of the experiment.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If the analysis results are empty or invalid. |
| METHOD | DESCRIPTION |
|---|---|
generate_markdown |
Generates a complete, beautiful GitHub-compatible Markdown summary card. |
generate_html |
Generates a premium, self-contained interactive HTML dashboard of the results. |
save_html |
Saves the beautifully compiled HTML dashboard report to a local file. |
save_markdown |
Saves the GitHub-compatible Markdown summary report to a local file. |
Source code in src\xpyrment\report\generator.py
generate_markdown
Generates a complete, beautiful GitHub-compatible Markdown summary card.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Markdown card representation of the experiment results.
TYPE:
|
Source code in src\xpyrment\report\generator.py
generate_html
Generates a premium, self-contained interactive HTML dashboard of the results.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Portable HTML report page content with embedded modern CSS and layouts.
TYPE:
|
Source code in src\xpyrment\report\generator.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 | |
save_html
Saves the beautifully compiled HTML dashboard report to a local file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Full target file path.
TYPE:
|
Source code in src\xpyrment\report\generator.py
save_markdown
Saves the GitHub-compatible Markdown summary report to a local file.
| PARAMETER | DESCRIPTION |
|---|---|
filepath
|
Full target file path.
TYPE:
|
Source code in src\xpyrment\report\generator.py
plot_forest
plot_forest(
df_raw: DataFrame,
alpha: float = 0.05,
title: str = "A/B Test Results - Relative Lift & 95% CIs",
figsize: tuple = (10, 5),
) -> tuple
Generates a horizontal forest plot visualizing relative lift and confidence intervals.
A Forest Plot is the industrial standard for reviewing multiple metrics simultaneously. It displays each metric's estimated treatment lift along with its surrounding confidence bounds. This allows rapid, visual identification of which metrics experienced significant shifts, whether the shifts are positive or negative, and how much uncertainty surrounds each estimate.
Visual Elements
- Center Dots: Represent the point estimate of the relative lift (\(\\hat{\\theta}\)).
- Horizontal Bars: Represent the \(1 - \\alpha\) confidence interval (\([\\theta_{\\text{lower}}, \\ \\theta_{\\text{upper}}]\)).
- Vertical Reference Line: Placed at \(x = 0\) (represented as a dashed red line) to denote the Null Hypothesis (no effect). If a metric's horizontal bar does not cross this dashed line, the effect is statistically significant.
- Color Coding: Significant shifts (\(p < \\alpha\)) are colored in high-contrast teal, while insignificant shifts are shaded in neutral slate-grey.
| PARAMETER | DESCRIPTION |
|---|---|
df_raw
|
A DataFrame containing the statistical summary. Must include the columns:
-
TYPE:
|
alpha
|
Nominal significance level used to color-code significance. Defaults to 0.05.
TYPE:
|
title
|
Title of the rendered plot. Defaults to
TYPE:
|
figsize
|
Dimensions of the figure canvas. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple
TYPE:
|
Source code in src\xpyrment\report\export.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
plot_power_curve
plot_power_curve(
power_curve_data: Dict[str, ndarray],
title: str = "A/B Test Design - Required Sample Size vs. MDE",
figsize: tuple = (10, 6),
) -> tuple
Plots required sample size per variant across a range of Minimum Detectable Effects (MDE).
Mathematical Relationship and CUPED Savings
Because sample size scales quadratically with the inverse of the MDE: $$ N \propto \frac{1}{\delta^2} $$ small increases in the precision requirements (smaller MDE) trigger massive increases in the required sample size.
If a pre-period covariate is registered, the plot overlays a second curve displaying the required sample size when applying CUPED variance reduction. - Let \(\\rho\) be the correlation coefficient between the pre-period covariate and the post-period outcome. - The required sample size under CUPED (\(N_{\\text{CUPED}}\)) is deflated by a factor of \((1 - \\rho^2)\): $$ N_{\text{CUPED}} = N_{\text{standard}} \times (1 - \rho^2) $$ - The visual shaded gap between the standard curve and the CUPED curve demonstrates the direct sample size savings (and consequently, the timeline savings) gained by utilizing pre-period covariate adjustment.
| PARAMETER | DESCRIPTION |
|---|---|
power_curve_data
|
A dictionary containing:
-
TYPE:
|
title
|
Title of the rendered plot. Defaults to
TYPE:
|
figsize
|
Dimensions of the figure canvas. Defaults to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple
|
A tuple
TYPE:
|
Source code in src\xpyrment\report\export.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |