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