Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
diagnosis_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Diagnosis-path validation for performance evidence.
3 
4 Verifies that representative cases which do not satisfy the measurable-benefit path
5 remain benchmark-grounded, carry explicit bottleneck reasons, and preserve follow-on
6 branch visibility.
7 
8 Run with:
9  python benchmarks/density_matrix/performance_evidence/diagnosis_validation.py
10 """
11 
12 from __future__ import annotations
13 
14 import sys
15 from pathlib import Path
16 
17 REPO_ROOT = Path(__file__).resolve().parents[3]
18 if str(REPO_ROOT) not in sys.path:
19  sys.path.insert(0, str(REPO_ROOT))
20 
21 from benchmarks.density_matrix.performance_evidence.common import (
22  build_boundary_evidence,
23  performance_evidence_output_dir,
24 )
25 from benchmarks.density_matrix.performance_evidence.records import (
26  build_performance_evidence_benchmark_records,
27 )
28 from benchmarks.density_matrix.performance_evidence.validation_support import (
29  assemble_record_schema_case_bundle,
30 )
31 from benchmarks.density_matrix.validation_scaffold import (
32  require_bundle_fields,
33  run_case_slice_cli,
34 )
35 
36 SUITE_NAME = "performance_evidence_diagnosis"
37 ARTIFACT_FILENAME = "diagnosis_bundle.json"
38 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("diagnosis")
39 ARTIFACT_CORE_FIELDS = (
40  "suite_name",
41  "status",
42  "record_schema_version",
43  "software",
44  "selected_candidate",
45  "summary",
46  "cases",
47 )
48 
49 
50 def build_diagnosis_cases() -> list[dict]:
51  return [
52  case
54  if case["diagnosis_only_case"]
55  ]
56 
57 
58 def build_diagnosis_bundle(cases: list[dict]) -> dict:
59  diagnosis_surface_pass = all(case["diagnosis_reasons"] for case in cases)
60  status = "pass" if diagnosis_surface_pass else "fail"
61  summary = {
62  "total_cases": len(cases),
63  "correctness_evidence_boundary_cases": len(build_boundary_evidence()),
64  "no_real_fused_coverage_cases": sum(
65  "no_real_fused_coverage" in case["diagnosis_reasons"] for case in cases
66  ),
67  "limited_fused_coverage_cases": sum(
68  "limited_fused_coverage_due_to_noise_boundaries" in case["diagnosis_reasons"]
69  for case in cases
70  ),
71  "runtime_slower_cases": sum(
72  "fused_runtime_slower_than_sequential_reference" in case["diagnosis_reasons"]
73  for case in cases
74  ),
75  }
76  bundle = assemble_record_schema_case_bundle(SUITE_NAME, status, summary, cases)
77  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Diagnosis bundle")
78  return bundle
79 
80 
81 def main(argv: list[str] | None = None) -> int:
82  return run_case_slice_cli(
83  argv,
84  build_cases=build_diagnosis_cases,
85  build_artifact_bundle=build_diagnosis_bundle,
86  artifact_filename=ARTIFACT_FILENAME,
87  default_output_dir=DEFAULT_OUTPUT_DIR,
88  description=__doc__ or "",
89  output_dir_help="Directory to write the diagnosis bundle into.",
90  quiet_report=lambda b: print(
91  "total_cases={total_cases}, limited_fused_coverage_cases={limited_fused_coverage_cases}, runtime_slower_cases={runtime_slower_cases}".format(
92  **b["summary"]
93  )
94  ),
95  )
96 
97 
98 if __name__ == "__main__":
99  raise SystemExit(main())
def build_performance_evidence_benchmark_records()