Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
phase31_runtime_classification_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Stage-A Phase 3.1 runtime / fusion classification rollup (six cases).
3 
4 Run with:
5  python benchmarks/density_matrix/correctness_evidence/phase31_runtime_classification_validation.py
6 """
7 
8 from __future__ import annotations
9 
10 from benchmarks.density_matrix.correctness_evidence.common import (
11  CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
12  CORRECTNESS_EVIDENCE_RUNTIME_CLASS_BASELINE,
13  phase31_correctness_evidence_output_dir,
14 )
15 from benchmarks.density_matrix.correctness_evidence.records import (
16  build_phase31_correctness_evidence_positive_records,
17 )
18 from benchmarks.density_matrix.correctness_evidence.validation_support import (
19  assemble_positive_case_bundle,
20 )
21 from benchmarks.density_matrix.validation_scaffold import (
22  require_bundle_fields,
23  run_case_slice_cli,
24 )
25 
26 SUITE_NAME = "correctness_evidence_phase31_runtime_classification"
27 ARTIFACT_FILENAME = "phase31_runtime_classification_bundle.json"
28 DEFAULT_OUTPUT_DIR = phase31_correctness_evidence_output_dir("runtime_classification")
29 ARTIFACT_CORE_FIELDS = (
30  "suite_name",
31  "status",
32  "record_schema_version",
33  "software",
34  "selected_candidate",
35  "summary",
36  "cases",
37 )
38 
39 
40 def build_cases() -> list[dict]:
42 
43 
44 def build_artifact_bundle(cases: list[dict]) -> dict:
45  classification_counts = {
46  "actually_fused": sum(
47  case["runtime_path_classification"] == "actually_fused" for case in cases
48  ),
49  "supported_but_unfused": sum(
50  case["runtime_path_classification"] == "supported_but_unfused" for case in cases
51  ),
52  "deferred_or_unsupported_candidate": sum(
53  case["runtime_path_classification"] == "deferred_or_unsupported_candidate"
54  for case in cases
55  ),
56  CORRECTNESS_EVIDENCE_RUNTIME_CLASS_BASELINE: sum(
57  case["runtime_path_classification"] == CORRECTNESS_EVIDENCE_RUNTIME_CLASS_BASELINE
58  for case in cases
59  ),
60  }
61  status = (
62  "pass"
63  if len(cases) == 6
64  and sum(classification_counts.values()) == len(cases)
65  and all(case["supported_runtime_case"] for case in cases)
66  else "fail"
67  )
68  summary = {
69  "package_kind": "phase31_stage_a_bounded",
70  "total_cases": len(cases),
71  **classification_counts,
72  "actual_fused_cases": sum(case["actual_fused_execution"] for case in cases),
73  }
75  SUITE_NAME,
76  status,
77  summary,
78  cases,
79  record_schema_version=CORRECTNESS_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
80  )
82  bundle, ARTIFACT_CORE_FIELDS, "Phase 3.1 runtime classification bundle"
83  )
84  return bundle
85 
86 
87 def main(argv: list[str] | None = None) -> int:
88  return run_case_slice_cli(
89  argv,
90  build_cases=build_cases,
91  build_artifact_bundle=build_artifact_bundle,
92  artifact_filename=ARTIFACT_FILENAME,
93  default_output_dir=DEFAULT_OUTPUT_DIR,
94  description=__doc__ or "",
95  output_dir_help="Directory to write the Phase 3.1 runtime classification bundle into.",
96  quiet_report=lambda b: print(
97  "total_cases={total_cases}, actually_fused={actually_fused}".format(**b["summary"])
98  ),
99  )
100 
101 
102 if __name__ == "__main__":
103  raise SystemExit(main())
def build_phase31_correctness_evidence_positive_records()
def phase31_correctness_evidence_output_dir