Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
phase31_summary_consistency_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Stage-A Phase 3.1 summary consistency vs. the Phase 3.1 correctness package.
3 
4 Run with:
5  python benchmarks/density_matrix/correctness_evidence/phase31_summary_consistency_validation.py
6 """
7 
8 from __future__ import annotations
9 
10 import argparse
11 from pathlib import Path
12 
13 from benchmarks.density_matrix.correctness_evidence.common import (
14  CORRECTNESS_EVIDENCE_PHASE31_SUMMARY_SCHEMA_VERSION,
15  build_correctness_evidence_software_metadata,
16  phase31_correctness_evidence_output_dir,
17  write_artifact_bundle,
18 )
19 from benchmarks.density_matrix.correctness_evidence.phase31_correctness_bundle_validation import (
20  build_artifact_bundle as build_phase31_correctness_package_bundle,
21 )
22 from benchmarks.density_matrix.correctness_evidence.records import counted_supported_case
23 from benchmarks.density_matrix.validation_scaffold import require_bundle_fields
24 
25 SUITE_NAME = "correctness_evidence_phase31_summary_consistency"
26 ARTIFACT_FILENAME = "phase31_summary_consistency_bundle.json"
27 DEFAULT_OUTPUT_DIR = phase31_correctness_evidence_output_dir("summary_consistency")
28 ARTIFACT_CORE_FIELDS = (
29  "suite_name",
30  "status",
31  "schema_version",
32  "software",
33  "selected_candidate",
34  "requirements",
35  "summary",
36  "required_artifacts",
37 )
38 
39 
40 def build_artifact_bundle() -> dict:
41  correctness_package = build_phase31_correctness_package_bundle()
42  cases = correctness_package["cases"]
43  negative_cases = correctness_package["negative_cases"]
44  counted_supported_cases = sum(counted_supported_case(case) for case in cases)
45  summary_consistency_pass = (
46  correctness_package["summary"]["total_cases"] == len(cases)
47  and correctness_package["summary"]["counted_supported_cases"] == counted_supported_cases
48  and correctness_package["summary"]["unsupported_boundary_cases"] == len(negative_cases)
49  )
50  main_correctness_claim_completed = (
51  counted_supported_cases == len(cases)
52  and len(negative_cases) > 0
53  and all(case["status"] == "unsupported" for case in negative_cases)
54  )
55  bundle = {
56  "suite_name": SUITE_NAME,
57  "status": "pass" if summary_consistency_pass else "fail",
58  "schema_version": CORRECTNESS_EVIDENCE_PHASE31_SUMMARY_SCHEMA_VERSION,
60  "selected_candidate": correctness_package["selected_candidate"],
61  "requirements": {
62  "main_claim_rule": (
63  "Only mandatory, complete, supported evidence may close the main "
64  "correctness claim for the Phase 3.1 Stage-A bounded package."
65  ),
66  "boundary_visibility_rule": (
67  "Excluded, unsupported, or deferred evidence must remain visible "
68  "as claim-boundary evidence in downstream summaries."
69  ),
70  },
71  "summary": {
72  "package_kind": "phase31_stage_a_bounded",
73  "summary_consistency_pass": summary_consistency_pass,
74  "main_correctness_claim_completed": main_correctness_claim_completed,
75  "counted_supported_cases": counted_supported_cases,
76  "excluded_supported_cases": len(cases) - counted_supported_cases,
77  "unsupported_boundary_cases": len(negative_cases),
78  "planner_entry_boundary_cases": sum(
79  case["boundary_stage"] == "planner_entry" for case in negative_cases
80  ),
81  "descriptor_generation_boundary_cases": sum(
82  case["boundary_stage"] == "descriptor_generation"
83  for case in negative_cases
84  ),
85  "runtime_stage_boundary_cases": sum(
86  case["boundary_stage"] == "runtime_stage" for case in negative_cases
87  ),
88  },
89  "required_artifacts": [
90  {
91  "artifact_id": "phase31_correctness_package",
92  "suite_name": correctness_package["suite_name"],
93  "status": correctness_package["status"],
94  "schema_version": correctness_package["schema_version"],
95  }
96  ],
97  }
98  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Phase 3.1 summary consistency bundle")
99  return bundle
100 
101 
102 def main(argv: list[str] | None = None) -> int:
103  parser = argparse.ArgumentParser(description=__doc__)
104  parser.add_argument(
105  "--output-dir",
106  type=Path,
107  default=DEFAULT_OUTPUT_DIR,
108  help="Directory to write the Phase 3.1 summary consistency bundle into.",
109  )
110  parser.add_argument(
111  "--quiet",
112  action="store_true",
113  help="Suppress console output.",
114  )
115  args = parser.parse_args(argv)
116 
117  bundle = build_artifact_bundle()
118  output_path = write_artifact_bundle(bundle, args.output_dir, ARTIFACT_FILENAME)
119 
120  if not args.quiet:
121  print(
122  "summary_consistency_pass={summary_consistency_pass}, main_correctness_claim_completed={main_correctness_claim_completed}".format(
123  **bundle["summary"]
124  )
125  )
126  print("Wrote {}".format(output_path))
127 
128  return 0 if bundle["status"] == "pass" else 1
129 
130 
131 if __name__ == "__main__":
132  raise SystemExit(main())
def build_correctness_evidence_software_metadata()
def phase31_correctness_evidence_output_dir
def counted_supported_case