Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_phase31_counted_matrix_validation.py
Go to the documentation of this file.
1 """Regression tests for the Phase 3.1 counted performance matrix (P31-S11-E01)."""
2 
3 from __future__ import annotations
4 
5 from pathlib import Path
6 import sys
7 
8 REPO_ROOT = Path(__file__).resolve().parents[3]
9 if str(REPO_ROOT) not in sys.path:
10  sys.path.insert(0, str(REPO_ROOT))
11 
12 from benchmarks.density_matrix.performance_evidence.case_selection import (
13  build_phase31_counted_performance_case_contexts,
14  build_phase31_counted_performance_inventory_cases,
15 )
16 from benchmarks.density_matrix.performance_evidence.common import (
17  PERFORMANCE_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION,
18 )
19 from benchmarks.density_matrix.performance_evidence.phase31_counted_matrix_validation import (
20  build_artifact_bundle,
21  build_cases,
22 )
23 from benchmarks.density_matrix.performance_evidence.records import (
24  build_phase31_decision_summary,
25  build_phase31_counted_performance_record,
26 )
27 
28 
31  assert len(inventory) == 26
32  assert sum(case["benchmark_slice"] == "phase31_structured_performance" for case in inventory) == 24
33  assert sum(case["benchmark_slice"] == "phase31_control_performance" for case in inventory) == 2
34  assert all(case["counted_phase31_case"] is True for case in inventory)
35  assert all(case["claim_surface_id"] == "phase31_bounded_mixed_motif_v1" for case in inventory)
36 
37 
40  assert len(contexts) == 26
41  assert sum(ctx.metadata["benchmark_slice"] == "phase31_structured_performance" for ctx in contexts) == 24
42  assert sum(ctx.metadata["benchmark_slice"] == "phase31_control_performance" for ctx in contexts) == 2
43 
44 
48  )
49  assert record["record_schema_version"] == PERFORMANCE_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION
50  assert record["artifact_kind"] == "phase31_counted_performance_matrix_row"
51  assert record["counted_phase31_case"] is True
52  assert record["claim_surface_id"] == "phase31_bounded_mixed_motif_v1"
53  assert record["representation_primary"] == "kraus_bundle"
54  assert record["contains_noise"] is True
55  assert record["runtime_class"] == "phase31_channel_native_hybrid"
56  assert record["build_policy_id"] == "phase31_scalar_only_v1"
57  assert record["build_flavor"] == "scalar"
58  assert record["simd_enabled"] is False
59  assert record["tbb_enabled"] is False
60  assert record["thread_count"] == 1
61  assert record["counted_claim_build"] is True
62  assert record["timing_mode"] == "median_3"
63  assert record["decision_class"] in {
64  "phase3_sufficient",
65  "phase31_justified",
66  "phase31_not_justified_yet",
67  }
68  assert isinstance(record["hybrid_partition_route_records"], list)
69  assert len(record["hybrid_partition_route_records"]) == (
70  record["channel_native_partition_count"] + record["phase3_routed_partition_count"]
71  )
72  for key in (
73  "channel_native_partition_count",
74  "phase3_routed_partition_count",
75  "channel_native_member_count",
76  "phase3_routed_member_count",
77  ):
78  assert key in record
79  assert record[key] >= 0
80  for key in (
81  "sequential_runtime_ms_samples",
82  "phase3_fused_runtime_ms_samples",
83  "phase31_hybrid_runtime_ms_samples",
84  ):
85  assert len(record[key]) == 3
86 
87 
89  cases = build_cases()
90  bundle = build_artifact_bundle(cases)
91  assert bundle["status"] == "pass"
92  assert bundle["record_schema_version"] == PERFORMANCE_EVIDENCE_PHASE31_CASE_SCHEMA_VERSION
93  summary = bundle["summary"]
94  assert summary["total_cases"] == 26
95  assert summary["primary_rows"] == 24
96  assert summary["control_rows"] == 2
97  assert summary["baseline_trio_present"] is True
98  assert summary["route_fields_present"] is True
99  assert summary["build_metadata_present"] is True
100  assert summary["inventory_match"] is True
101  assert summary["decision_rows"] == 26
102  assert summary["decision_inventory_match"] is True
103  assert summary["break_even_table_rows"] == 26
104  assert summary["justification_map_rows"] == 26
105 
106 
108  cases = build_cases()
109  decision_summary = build_phase31_decision_summary(cases)
110  assert decision_summary["total_cases"] == 26
111  assert len(decision_summary["break_even_table"]) == 26
112  assert len(decision_summary["justification_map"]) == 26
113  assert decision_summary["decision_class_counts"]["phase3_sufficient"] >= 0
114  assert decision_summary["decision_class_counts"]["phase31_justified"] >= 0
115  assert decision_summary["decision_class_counts"]["phase31_not_justified_yet"] >= 0
116  assert sorted(
117  entry["case_name"] for entry in decision_summary["break_even_table"]
118  ) == sorted(case["case_name"] for case in cases)
119  assert set(decision_summary["justification_map"]) == {
120  case["case_name"] for case in cases
121  }
def build_artifact_bundle(results)
def build_phase31_counted_performance_record(case_context)