1 """Phase 3.1 hybrid whole-workload path: runtime (P31-S07-E01) and counted continuity (P31-S08 + P31-S10). 3 **P31-S07-E01 (runtime / routing):** ``phase31_channel_native_hybrid``, 4 ``execute_partitioned_density_channel_native_hybrid``, partition-level route 5 reasons, unsupported-by-both failure, and structured smoke. 7 **Counted hybrid continuity gates (Task 3):** ``P31-S08-E01`` â 8 ``phase2_xxz_hea_q4_continuity``; ``P31-S10-E01`` â ``phase2_xxz_hea_q6_continuity``. 9 Each asserts full-density exactness vs sequential oracle and a frozen aggregated 10 route summary (partition count, runtime-class counts, route-reason counts). 12 **Correctness package (``P31-S10-E02``):** Stage-A sibling builders and 13 ``phase31_validation_pipeline.py`` emit the bounded six-case package under 14 ``artifacts/correctness_evidence/phase31_stage_a/`` (default Phase 3 pipeline 17 **Still deferred:** counted structured performance matrix (``P31-ADR-010``); 18 default-pipeline Stage-B switch; publication closure. 20 Strict motif-proof tests stay in ``test_partitioned_channel_native_phase31_*slice.py``. 23 from __future__
import annotations
25 from collections
import Counter
26 from pathlib
import Path
28 from typing
import Any
32 REPO_ROOT = Path(__file__).resolve().parents[2]
33 if str(REPO_ROOT)
not in sys.path:
34 sys.path.insert(0, str(REPO_ROOT))
36 from squander.partitioning.noisy_planner
import (
37 build_canonical_planner_surface_from_operation_specs,
38 build_partition_descriptor_set,
39 build_phase3_continuity_partition_descriptor_set,
41 from squander.partitioning.noisy_runtime
import (
42 PHASE31_RUNTIME_PATH_CHANNEL_NATIVE_HYBRID,
43 NoisyRuntimeExecutionResult,
44 execute_partitioned_density_channel_native_hybrid,
45 execute_sequential_density_reference,
47 from squander.partitioning.noisy_validation_errors
import NoisyRuntimeValidationError
50 PHASE3_RUNTIME_DENSITY_TOL,
51 build_density_comparison_metrics,
52 build_initial_parameters,
56 build_phase31_structured_descriptor_set,
60 _FROZEN_HYBRID_ROUTE_REASONS = frozenset(
62 "eligible_channel_native_motif",
63 "pure_unitary_partition",
64 "channel_native_noise_presence",
65 "channel_native_qubit_span",
66 "channel_native_support_surface",
72 _COUNTED_HYBRID_CONTINUITY_Q4_WORKLOAD_ID =
"phase2_xxz_hea_q4_continuity" 73 _EXPECTED_Q4_HYBRID_PARTITION_COUNT = 5
74 _EXPECTED_Q4_RUNTIME_CLASS_COUNTS = {
75 "phase31_channel_native": 2,
76 "phase3_unitary_island_fused": 3,
78 _EXPECTED_Q4_ROUTE_REASON_COUNTS = {
79 "eligible_channel_native_motif": 2,
80 "pure_unitary_partition": 3,
83 _COUNTED_HYBRID_CONTINUITY_Q6_WORKLOAD_ID =
"phase2_xxz_hea_q6_continuity" 84 _EXPECTED_Q6_HYBRID_PARTITION_COUNT = 7
85 _EXPECTED_Q6_RUNTIME_CLASS_COUNTS = {
86 "phase31_channel_native": 2,
87 "phase3_unitary_island_fused": 5,
89 _EXPECTED_Q6_ROUTE_REASON_COUNTS = {
90 "eligible_channel_native_motif": 2,
91 "pure_unitary_partition": 5,
96 result: NoisyRuntimeExecutionResult,
98 """Aggregate hybrid route metadata from ``result.partitions`` (test-local).""" 99 classes = [rec.partition_runtime_class
for rec
in result.partitions]
100 reasons = [rec.partition_route_reason
for rec
in result.partitions]
102 "partition_count": len(result.partitions),
103 "runtime_class_counts": dict(Counter(c
for c
in classes
if c
is not None)),
104 "route_reason_counts": dict(Counter(r
for r
in reasons
if r
is not None)),
114 assert descriptor_set.workload_id == _COUNTED_HYBRID_CONTINUITY_Q4_WORKLOAD_ID
121 assert metrics[
"frobenius_norm_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
122 assert metrics[
"max_abs_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
123 assert hybrid.trace_deviation <= PHASE3_RUNTIME_DENSITY_TOL
124 assert hybrid.rho_is_valid
is True 125 assert hybrid.runtime_path == PHASE31_RUNTIME_PATH_CHANNEL_NATIVE_HYBRID
126 assert hybrid.requested_runtime_path == PHASE31_RUNTIME_PATH_CHANNEL_NATIVE_HYBRID
129 assert summary[
"partition_count"] == _EXPECTED_Q4_HYBRID_PARTITION_COUNT
130 assert summary[
"runtime_class_counts"] == _EXPECTED_Q4_RUNTIME_CLASS_COUNTS
131 assert summary[
"route_reason_counts"] == _EXPECTED_Q4_ROUTE_REASON_COUNTS
133 classes = [rec.partition_runtime_class
for rec
in hybrid.partitions]
134 assert any(c ==
"phase31_channel_native" for c
in classes)
136 c
in (
"phase3_unitary_island_fused",
"phase3_supported_unfused")
for c
in classes
139 reasons = [rec.partition_route_reason
for rec
in hybrid.partitions]
140 assert all(r
in _FROZEN_HYBRID_ROUTE_REASONS
for r
in reasons)
149 assert descriptor_set.workload_id == _COUNTED_HYBRID_CONTINUITY_Q6_WORKLOAD_ID
153 descriptor_set, parameters
158 assert metrics[
"frobenius_norm_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
159 assert metrics[
"max_abs_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
160 assert hybrid.trace_deviation <= PHASE3_RUNTIME_DENSITY_TOL
161 assert hybrid.rho_is_valid
is True 162 assert hybrid.runtime_path == PHASE31_RUNTIME_PATH_CHANNEL_NATIVE_HYBRID
163 assert hybrid.requested_runtime_path == PHASE31_RUNTIME_PATH_CHANNEL_NATIVE_HYBRID
166 assert summary[
"partition_count"] == _EXPECTED_Q6_HYBRID_PARTITION_COUNT
167 assert summary[
"runtime_class_counts"] == _EXPECTED_Q6_RUNTIME_CLASS_COUNTS
168 assert summary[
"route_reason_counts"] == _EXPECTED_Q6_ROUTE_REASON_COUNTS
170 classes = [rec.partition_runtime_class
for rec
in hybrid.partitions]
171 assert any(c ==
"phase31_channel_native" for c
in classes)
173 c
in (
"phase3_unitary_island_fused",
"phase3_supported_unfused")
for c
in classes
176 reasons = [rec.partition_route_reason
for rec
in hybrid.partitions]
177 assert all(r
in _FROZEN_HYBRID_ROUTE_REASONS
for r
in reasons)
186 source_type=
"microcase_builder",
187 workload_id=
"hybrid_negative_rx_relaxed_surface",
197 "name":
"phase_damping",
199 "source_gate_index": 0,
204 strict_phase3_support=
False,
208 with pytest.raises(NoisyRuntimeValidationError)
as excinfo:
210 assert excinfo.value.first_unsupported_condition ==
"gate_name" 218 "phase31_pair_repeat",
220 noise_pattern=
"dense",
228 assert hybrid.runtime_path == PHASE31_RUNTIME_PATH_CHANNEL_NATIVE_HYBRID
229 assert metrics[
"frobenius_norm_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
230 reasons = [rec.partition_route_reason
for rec
in hybrid.partitions]
231 assert all(r
in _FROZEN_HYBRID_ROUTE_REASONS
for r
in reasons)
def test_phase31_s08_e01_counted_hybrid_continuity_q4_matches_sequential_oracle()
def execute_partitioned_density_channel_native_hybrid
def execute_sequential_density_reference
Execute a sequential density reference.
def test_phase31_hybrid_rejects_unsupported_gate_not_routed_quietly()
def build_phase2_continuity_vqe
def test_phase31_s10_e01_counted_hybrid_continuity_q6_matches_sequential_oracle()
def build_initial_parameters
def build_phase31_structured_descriptor_set
def test_phase31_hybrid_structured_pair_repeat_q8_dense_smoke()
def _hybrid_partition_route_summary
def build_partition_descriptor_set
def build_phase3_continuity_partition_descriptor_set
def build_density_comparison_metrics
def build_canonical_planner_surface_from_operation_specs