Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
calibrated_claim_selection_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Validation: Phase 3 planner-calibration supported-claim selection surface.
3 
4 Selects one supported planner claim from the correctness-gated calibration
5 matrix using an explicit benchmark-grounded rule and keeps the other candidate
6 settings visible as comparison baselines.
7 
8 Run with:
9  python benchmarks/density_matrix/planner_calibration/calibrated_claim_selection_validation.py
10 """
11 
12 from __future__ import annotations
13 
14 import argparse
15 import json
16 import sys
17 from pathlib import Path
18 
19 REPO_ROOT = Path(__file__).resolve().parents[3]
20 if str(REPO_ROOT) not in sys.path:
21  sys.path.insert(0, str(REPO_ROOT))
22 
23 from benchmarks.density_matrix.planner_calibration.claim_selection import (
24  PLANNER_CALIBRATION_CLAIM_SELECTION_SCHEMA_VERSION,
25  PLANNER_CALIBRATION_CLAIM_SELECTION_RULE,
26  PLANNER_CALIBRATION_CLAIM_STATUS_COMPARISON,
27  PLANNER_CALIBRATION_CLAIM_STATUS_SUPPORTED,
28  build_planner_calibration_claim_selection_payload,
29 )
30 from benchmarks.density_matrix.planner_surface.common import build_software_metadata
31 
32 SUITE_NAME = "phase3_planner_calibration_claim_selection"
33 ARTIFACT_FILENAME = "claim_selection_bundle.json"
34 DEFAULT_OUTPUT_DIR = (
35  REPO_ROOT
36  / "benchmarks"
37  / "density_matrix"
38  / "artifacts"
39  / "planner_calibration"
40  / "claim_selection"
41 )
42 ARTIFACT_CORE_FIELDS = (
43  "suite_name",
44  "status",
45  "claim_selection_schema_version",
46  "software",
47  "summary",
48  "candidate_summaries",
49  "cases",
50 )
51 
52 
53 def build_cases() -> list[dict]:
55 
56 
57 def build_artifact_bundle() -> dict:
59  cases = payload["cases"]
60  candidate_summaries = payload["candidate_summaries"]
61  selected_candidate = payload["selected_candidate"]
62  supported_claim_cases = sum(
63  case["claim_status"] == PLANNER_CALIBRATION_CLAIM_STATUS_SUPPORTED for case in cases
64  )
65  comparison_cases = sum(
66  case["claim_status"] == PLANNER_CALIBRATION_CLAIM_STATUS_COMPARISON for case in cases
67  )
68  bundle = {
69  "suite_name": SUITE_NAME,
70  "status": "pass"
71  if supported_claim_cases > 0
72  and comparison_cases > 0
73  and len(candidate_summaries) == 3
74  else "fail",
75  "claim_selection_schema_version": PLANNER_CALIBRATION_CLAIM_SELECTION_SCHEMA_VERSION,
76  "software": build_software_metadata(),
77  "summary": {
78  "total_cases": len(cases),
79  "supported_claim_cases": supported_claim_cases,
80  "comparison_cases": comparison_cases,
81  "selected_candidate_id": selected_candidate["candidate_id"],
82  "claim_selection_rule": PLANNER_CALIBRATION_CLAIM_SELECTION_RULE,
83  },
84  "selected_candidate": selected_candidate,
85  "candidate_summaries": candidate_summaries,
86  "cases": cases,
87  }
88  missing = [field for field in ARTIFACT_CORE_FIELDS if field not in bundle]
89  if missing:
90  raise ValueError(
91  "Calibrated claim-selection bundle missing required fields: {}".format(
92  ", ".join(missing)
93  )
94  )
95  return bundle
96 
97 
98 def write_artifact_bundle(bundle: dict, output_dir: Path = DEFAULT_OUTPUT_DIR) -> Path:
99  output_dir.mkdir(parents=True, exist_ok=True)
100  output_path = output_dir / ARTIFACT_FILENAME
101  output_path.write_text(json.dumps(bundle, indent=2, sort_keys=True) + "\n")
102  return output_path
103 
104 
105 def main(argv: list[str] | None = None) -> int:
106  parser = argparse.ArgumentParser(description=__doc__)
107  parser.add_argument(
108  "--output-dir",
109  type=Path,
110  default=DEFAULT_OUTPUT_DIR,
111  help="Directory to write the calibrated claim-selection bundle into.",
112  )
113  parser.add_argument(
114  "--quiet",
115  action="store_true",
116  help="Suppress per-case console output.",
117  )
118  args = parser.parse_args(argv)
119 
120  bundle = build_artifact_bundle()
121  output_path = write_artifact_bundle(bundle, output_dir=args.output_dir)
122 
123  if not args.quiet:
124  print(
125  "selected_candidate={selected_candidate_id}, rule={claim_selection_rule}".format(
126  **bundle["summary"]
127  )
128  )
129  print("Wrote {}".format(output_path))
130 
131  return 0 if bundle["status"] == "pass" else 1
132 
133 
134 if __name__ == "__main__":
135  raise SystemExit(main())
def build_software_metadata()
def build_planner_calibration_claim_selection_payload()