Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
performance_evidence/summary_consistency_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Summary-consistency guardrails for performance evidence.
3 
4 Interprets the shared benchmark package and verifies that downstream rollups,
5 limitation carry-forward, and claim-closure flags stay consistent with the
6 underlying per-case evidence.
7 
8 Run with:
9  python benchmarks/density_matrix/performance_evidence/summary_consistency_validation.py
10 """
11 
12 from __future__ import annotations
13 
14 import argparse
15 import sys
16 from pathlib import Path
17 
18 REPO_ROOT = Path(__file__).resolve().parents[3]
19 if str(REPO_ROOT) not in sys.path:
20  sys.path.insert(0, str(REPO_ROOT))
21 
22 from benchmarks.density_matrix.performance_evidence.benchmark_bundle_validation import (
23  build_performance_evidence_benchmark_package,
24 )
25 from benchmarks.density_matrix.performance_evidence.common import (
26  PERFORMANCE_EVIDENCE_SUMMARY_SCHEMA_VERSION,
27  build_package_software_metadata,
28  performance_evidence_output_dir,
29  write_artifact_bundle,
30 )
31 from benchmarks.density_matrix.validation_scaffold import require_bundle_fields
32 
33 SUITE_NAME = "performance_evidence_summary_consistency"
34 ARTIFACT_FILENAME = "summary_consistency_bundle.json"
35 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("summary_consistency")
36 ARTIFACT_CORE_FIELDS = (
37  "suite_name",
38  "status",
39  "schema_version",
40  "software",
41  "selected_candidate",
42  "requirements",
43  "summary",
44  "required_artifacts",
45 )
46 
47 
50  cases = benchmark_package["cases"]
51  negative_cases = benchmark_package["negative_cases"]
52  counted_supported_cases = sum(case["counted_supported_benchmark_case"] for case in cases)
53  positive_threshold_pass_cases = sum(case["positive_threshold_pass"] for case in cases)
54  diagnosis_only_cases = sum(case["diagnosis_only_case"] for case in cases)
55  excluded_cases = sum(case["benchmark_status"] == "excluded" for case in cases)
56  representative_review_cases = sum(case["representative_review_case"] for case in cases)
57 
58  summary_consistency_pass = (
59  benchmark_package["summary"]["total_cases"] == len(cases)
60  and benchmark_package["summary"]["counted_supported_cases"] == counted_supported_cases
61  and benchmark_package["summary"]["positive_threshold_pass_cases"]
62  == positive_threshold_pass_cases
63  and benchmark_package["summary"]["diagnosis_only_cases"] == diagnosis_only_cases
64  and benchmark_package["summary"]["excluded_cases"] == excluded_cases
65  and benchmark_package["summary"]["representative_review_cases"]
66  == representative_review_cases
67  and benchmark_package["summary"]["correctness_evidence_boundary_cases"] == len(negative_cases)
68  )
69 
70  positive_benchmark_claim_completed = positive_threshold_pass_cases >= 1
71  diagnosis_grounded_closure_completed = (
72  positive_threshold_pass_cases == 0
73  and diagnosis_only_cases >= 1
74  and all(case["diagnosis_reasons"] for case in cases if case["diagnosis_only_case"])
75  and len(negative_cases) > 0
76  )
77  main_benchmark_claim_completed = (
78  positive_benchmark_claim_completed or diagnosis_grounded_closure_completed
79  )
80 
81  bundle = {
82  "suite_name": SUITE_NAME,
83  "status": "pass" if summary_consistency_pass and main_benchmark_claim_completed else "fail",
84  "schema_version": PERFORMANCE_EVIDENCE_SUMMARY_SCHEMA_VERSION,
85  "software": build_package_software_metadata(),
86  "selected_candidate": benchmark_package["selected_candidate"],
87  "requirements": {
88  "positive_claim_rule": (
89  "Only counted representative performance-evidence cases may close a "
90  "positive benchmark claim."
91  ),
92  "diagnosis_rule": (
93  "If no representative case meets the positive threshold, diagnosis-"
94  "only cases must remain benchmark-grounded and visible as explicit "
95  "limitation evidence."
96  ),
97  "boundary_visibility_rule": (
98  "Excluded, unsupported, or deferred evidence must remain visible "
99  "as claim-boundary evidence in downstream summaries."
100  ),
101  },
102  "summary": {
103  "summary_consistency_pass": summary_consistency_pass,
104  "positive_benchmark_claim_completed": positive_benchmark_claim_completed,
105  "diagnosis_grounded_closure_completed": diagnosis_grounded_closure_completed,
106  "main_benchmark_claim_completed": main_benchmark_claim_completed,
107  "counted_supported_cases": counted_supported_cases,
108  "positive_threshold_pass_cases": positive_threshold_pass_cases,
109  "diagnosis_only_cases": diagnosis_only_cases,
110  "excluded_cases": excluded_cases,
111  "representative_review_cases": representative_review_cases,
112  "correctness_evidence_boundary_cases": len(negative_cases),
113  },
114  "required_artifacts": [
115  {
116  "artifact_id": "benchmark_package",
117  "suite_name": benchmark_package["suite_name"],
118  "status": benchmark_package["status"],
119  "schema_version": benchmark_package["schema_version"],
120  }
121  ],
122  }
123  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Summary consistency bundle")
124  return bundle
125 
126 
127 def main(argv: list[str] | None = None) -> int:
128  parser = argparse.ArgumentParser(description=__doc__)
129  parser.add_argument(
130  "--output-dir",
131  type=Path,
132  default=DEFAULT_OUTPUT_DIR,
133  help="Directory to write the summary consistency bundle into.",
134  )
135  parser.add_argument(
136  "--quiet",
137  action="store_true",
138  help="Suppress console output.",
139  )
140  args = parser.parse_args(argv)
141 
143  output_path = write_artifact_bundle(bundle, args.output_dir, ARTIFACT_FILENAME)
144 
145  if not args.quiet:
146  print(
147  "summary_consistency_pass={summary_consistency_pass}, main_benchmark_claim_completed={main_benchmark_claim_completed}".format(
148  **bundle["summary"]
149  )
150  )
151  print("Wrote {}".format(output_path))
152 
153  return 0 if bundle["status"] == "pass" else 1
154 
155 
156 if __name__ == "__main__":
157  raise SystemExit(main())
def build_package_software_metadata()