Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
benchmark_matrix_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Benchmark matrix validation for performance evidence.
3 
4 Freezes the dual-anchor benchmark matrix and representative review-set membership
5 through one stable machine-reviewable surface.
6 
7 Run with:
8  python benchmarks/density_matrix/performance_evidence/benchmark_matrix_validation.py
9 """
10 
11 from __future__ import annotations
12 
13 import sys
14 from pathlib import Path
15 
16 REPO_ROOT = Path(__file__).resolve().parents[3]
17 if str(REPO_ROOT) not in sys.path:
18  sys.path.insert(0, str(REPO_ROOT))
19 
20 from benchmarks.density_matrix.performance_evidence.common import (
21  PERFORMANCE_EVIDENCE_BENCHMARK_SLICE_CONTINUITY,
22  PERFORMANCE_EVIDENCE_BENCHMARK_SLICE_STRUCTURED,
23  performance_evidence_output_dir,
24 )
25 from benchmarks.density_matrix.performance_evidence.case_selection import (
26  build_performance_evidence_inventory_cases,
27 )
28 from benchmarks.density_matrix.performance_evidence.validation_support import (
29  assemble_benchmark_matrix_bundle,
30 )
31 from benchmarks.density_matrix.validation_scaffold import (
32  require_bundle_fields,
33  run_case_slice_cli,
34 )
35 
36 SUITE_NAME = "performance_evidence_benchmark_matrix"
37 ARTIFACT_FILENAME = "benchmark_matrix_bundle.json"
38 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("benchmark_matrix")
39 ARTIFACT_CORE_FIELDS = (
40  "suite_name",
41  "status",
42  "selected_candidate",
43  "software",
44  "summary",
45  "cases",
46 )
47 
48 
49 def build_benchmark_matrix_cases() -> list[dict]:
51 
52 
53 def build_benchmark_matrix_bundle(cases: list[dict]) -> dict:
54  summary = {
55  "total_cases": len(cases),
56  "continuity_cases": sum(
57  case["benchmark_slice"] == PERFORMANCE_EVIDENCE_BENCHMARK_SLICE_CONTINUITY
58  for case in cases
59  ),
60  "structured_cases": sum(
61  case["benchmark_slice"] == PERFORMANCE_EVIDENCE_BENCHMARK_SLICE_STRUCTURED
62  for case in cases
63  ),
64  "representative_review_cases": sum(case["representative_review_case"] for case in cases),
65  "continuity_qbits": sorted(
66  {case["qbit_num"] for case in cases if case["case_kind"] == "continuity"}
67  ),
68  "structured_qbits": sorted(
69  {
70  case["qbit_num"]
71  for case in cases
72  if case["case_kind"] == "structured_family"
73  }
74  ),
75  "structured_seed_count": len(
76  {
77  case["seed"]
78  for case in cases
79  if case["case_kind"] == "structured_family"
80  }
81  ),
82  "noise_patterns": sorted(
83  {
84  case["noise_pattern"]
85  for case in cases
86  if case["noise_pattern"] is not None
87  }
88  ),
89  }
90  bundle = assemble_benchmark_matrix_bundle(SUITE_NAME, "pass", summary, cases)
91  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Benchmark matrix bundle")
92  return bundle
93 
94 
95 def main(argv: list[str] | None = None) -> int:
96  return run_case_slice_cli(
97  argv,
98  build_cases=build_benchmark_matrix_cases,
99  build_artifact_bundle=build_benchmark_matrix_bundle,
100  artifact_filename=ARTIFACT_FILENAME,
101  default_output_dir=DEFAULT_OUTPUT_DIR,
102  description=__doc__ or "",
103  output_dir_help="Directory to write the benchmark matrix bundle into.",
104  quiet_report=lambda b: print(
105  "total_cases={total_cases}, continuity_cases={continuity_cases}, structured_cases={structured_cases}, representative_review_cases={representative_review_cases}".format(
106  **b["summary"]
107  )
108  ),
109  )
110 
111 
112 if __name__ == "__main__":
113  raise SystemExit(main())