Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
phase31_counted_matrix_validation.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 """Phase 3.1 counted performance matrix validation (P31-S11-E01).
3 
4 Freezes the full bounded 26-row Phase 3.1 counted performance inventory and
5 one comparable row schema for every counted case.
6 
7 Run with:
8  python benchmarks/density_matrix/performance_evidence/phase31_counted_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.case_selection import (
21  build_phase31_counted_performance_inventory_cases,
22 )
23 from benchmarks.density_matrix.performance_evidence.common import (
24  PERFORMANCE_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
25  performance_evidence_output_dir,
26 )
27 from benchmarks.density_matrix.performance_evidence.records import (
28  build_phase31_decision_summary,
29  build_phase31_counted_performance_records,
30 )
31 from benchmarks.density_matrix.performance_evidence.validation_support import (
32  assemble_record_schema_case_bundle,
33 )
34 from benchmarks.density_matrix.validation_scaffold import (
35  require_bundle_fields,
36  run_case_slice_cli,
37 )
38 
39 SUITE_NAME = "performance_evidence_phase31_counted_matrix"
40 ARTIFACT_FILENAME = "phase31_counted_matrix_bundle.json"
41 DEFAULT_OUTPUT_DIR = performance_evidence_output_dir("phase31_counted_matrix")
42 ARTIFACT_CORE_FIELDS = (
43  "suite_name",
44  "status",
45  "record_schema_version",
46  "software",
47  "selected_candidate",
48  "summary",
49  "cases",
50 )
51 
52 
53 def build_cases() -> list[dict]:
55 
56 
57 def build_artifact_bundle(cases: list[dict]) -> dict:
59  case_ids = [case["case_name"] for case in cases]
60  inventory_ids = [case["case_name"] for case in inventory]
61  decision_summary = build_phase31_decision_summary(cases)
62  primary_rows = sum(case["benchmark_slice"] == "phase31_structured_performance" for case in cases)
63  control_rows = sum(case["benchmark_slice"] == "phase31_control_performance" for case in cases)
64  route_fields_present = all(
65  field in case
66  for case in cases
67  for field in (
68  "channel_native_partition_count",
69  "phase3_routed_partition_count",
70  "channel_native_member_count",
71  "phase3_routed_member_count",
72  "hybrid_partition_route_records",
73  )
74  )
75  baseline_trio_present = all(
76  field in case
77  for case in cases
78  for field in (
79  "sequential_median_runtime_ms",
80  "phase3_fused_median_runtime_ms",
81  "phase31_hybrid_median_runtime_ms",
82  "sequential_median_peak_rss_kb",
83  "phase3_fused_median_peak_rss_kb",
84  "phase31_hybrid_median_peak_rss_kb",
85  )
86  )
87  build_metadata_present = all(
88  field in case
89  for case in cases
90  for field in (
91  "build_policy_id",
92  "build_flavor",
93  "simd_enabled",
94  "tbb_enabled",
95  "thread_count",
96  "counted_claim_build",
97  )
98  )
99  status = (
100  "pass"
101  if len(cases) == 26
102  and case_ids == inventory_ids
103  and len(set(case_ids)) == len(case_ids)
104  and primary_rows == 24
105  and control_rows == 2
106  and route_fields_present
107  and baseline_trio_present
108  and build_metadata_present
109  and decision_summary["inventory_match"]
110  and len(decision_summary["break_even_table"]) == 26
111  and len(decision_summary["justification_map"]) == 26
112  else "fail"
113  )
114  summary = {
115  "total_cases": len(cases),
116  "primary_rows": primary_rows,
117  "control_rows": control_rows,
118  "route_fields_present": route_fields_present,
119  "baseline_trio_present": baseline_trio_present,
120  "build_metadata_present": build_metadata_present,
121  "inventory_match": case_ids == inventory_ids,
122  "decision_rows": decision_summary["total_cases"],
123  "decision_inventory_match": decision_summary["inventory_match"],
124  "phase3_sufficient_rows": decision_summary["phase3_sufficient_rows"],
125  "phase31_justified_rows": decision_summary["phase31_justified_rows"],
126  "phase31_not_justified_yet_rows": decision_summary["phase31_not_justified_yet_rows"],
127  "break_even_table_rows": len(decision_summary["break_even_table"]),
128  "justification_map_rows": len(decision_summary["justification_map"]),
129  }
131  SUITE_NAME,
132  status,
133  summary,
134  cases,
135  )
136  bundle["record_schema_version"] = PERFORMANCE_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION
137  bundle["decision_summary"] = decision_summary
138  require_bundle_fields(bundle, ARTIFACT_CORE_FIELDS, "Phase 3.1 counted matrix bundle")
139  return bundle
140 
141 
142 def main(argv: list[str] | None = None) -> int:
143  return run_case_slice_cli(
144  argv,
145  build_cases=build_cases,
146  build_artifact_bundle=build_artifact_bundle,
147  artifact_filename=ARTIFACT_FILENAME,
148  default_output_dir=DEFAULT_OUTPUT_DIR,
149  description=__doc__ or "",
150  output_dir_help="Directory to write the Phase 3.1 counted matrix bundle into.",
151  quiet_report=lambda b: print(
152  "total_cases={total_cases}, primary_rows={primary_rows}, control_rows={control_rows}, status={status}".format(
153  status=b["status"],
154  **b["summary"],
155  )
156  ),
157  )
158 
159 
160 if __name__ == "__main__":
161  raise SystemExit(main())
def build_phase31_counted_performance_records()