Sequential Quantum Gate Decomposer  v1.9.6
Powerful decomposition of general unitarias into one- and two-qubit gates gates
test_evidence_core.py
Go to the documentation of this file.
1 """Regression tests for shared density-matrix evidence core (Story 1)."""
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.evidence_core import (
13  RUNTIME_CORRECTNESS_BRIDGE_FIELD_NAMES,
14  counted_supported_case,
15 )
16 from benchmarks.density_matrix.correctness_evidence.records import (
17  build_correctness_evidence_positive_records,
18 )
19 from benchmarks.density_matrix.performance_evidence.records import (
20  build_performance_evidence_core_benchmark_records,
21 )
22 
23 # Snapshot: sorted bridge keys must stay stable unless the evidence contract changes intentionally.
24 _EXPECTED_SORTED_BRIDGE_FIELD_NAMES: tuple[str, ...] = (
25  "actual_fused_execution",
26  "continuity_energy_error",
27  "continuity_energy_pass",
28  "continuity_energy_required",
29  "deferred_region_count",
30  "descriptor_member_count",
31  "exact_output_present",
32  "external_frobenius_norm_diff",
33  "external_max_abs_diff",
34  "external_reference_pass",
35  "frobenius_norm_diff",
36  "fused_gate_count",
37  "fused_region_count",
38  "gate_count",
39  "internal_reference_pass",
40  "max_abs_diff",
41  "max_partition_span",
42  "noise_count",
43  "output_integrity_pass",
44  "parameter_routing_segment_count",
45  "partition_count",
46  "partition_member_counts",
47  "peak_rss_kb",
48  "peak_rss_mb",
49  "remapped_partition_count",
50  "rho_is_valid",
51  "rho_is_valid_tol",
52  "runtime_ms",
53  "runtime_path",
54  "supported_runtime_case",
55  "supported_unfused_gate_count",
56  "supported_unfused_region_count",
57  "trace_deviation",
58 )
59 
60 
62  assert tuple(sorted(RUNTIME_CORRECTNESS_BRIDGE_FIELD_NAMES)) == _EXPECTED_SORTED_BRIDGE_FIELD_NAMES
63 
64 
66  correctness_by_workload = {
67  r["workload_id"]: r for r in build_correctness_evidence_positive_records()
68  }
70  if not perf["correctness_evidence_reference_available"]:
71  continue
72  ce = correctness_by_workload[perf["workload_id"]]
73  ce_counted = counted_supported_case(ce)
74  perf_counted = counted_supported_case(perf)
75  assert ce_counted == perf_counted
76  assert perf_counted == perf["counted_supported_benchmark_case"]
77 
78 
80  correctness_by_workload = {
81  r["workload_id"]: r for r in build_correctness_evidence_positive_records()
82  }
84  if not perf["correctness_evidence_reference_available"]:
85  continue
86  ce = correctness_by_workload[perf["workload_id"]]
87  for field in RUNTIME_CORRECTNESS_BRIDGE_FIELD_NAMES:
88  assert perf[field] == ce[field], field
89 
90 
92  base = {
93  "supported_runtime_case": True,
94  "internal_reference_pass": True,
95  "output_integrity_pass": True,
96  "continuity_energy_required": False,
97  "continuity_energy_pass": True,
98  "external_reference_required": False,
99  "external_reference_pass": True,
100  }
101  assert counted_supported_case(base) is True
102 
103  assert counted_supported_case({**base, "supported_runtime_case": False}) is False
104  assert counted_supported_case({**base, "continuity_energy_required": True, "continuity_energy_pass": False}) is False
105  assert counted_supported_case(
106  {**base, "external_reference_required": True, "external_reference_pass": False}
107  ) is False
def build_correctness_evidence_positive_records()
def build_performance_evidence_core_benchmark_records()
def counted_supported_case