1 from pathlib
import Path
6 REPO_ROOT = Path(__file__).resolve().parents[2]
7 if str(REPO_ROOT)
not in sys.path:
8 sys.path.insert(0, str(REPO_ROOT))
10 from squander.partitioning.noisy_planner
import (
11 PARTITIONED_DENSITY_MODE,
12 build_canonical_planner_surface_from_operation_specs,
13 build_partition_descriptor_set,
14 build_phase3_continuity_partition_descriptor_set,
16 from squander.partitioning
import noisy_runtime
as noisy_runtime_mod
17 from squander.partitioning.noisy_runtime
import (
18 PHASE3_RUNTIME_PATH_BASELINE,
19 PHASE3_RUNTIME_PATH_FUSED_UNITARY_ISLANDS,
20 build_runtime_audit_record,
21 execute_partitioned_density,
25 PHASE3_RUNTIME_DENSITY_TOL,
26 PHASE3_RUNTIME_ENERGY_TOL,
27 build_initial_parameters,
29 execute_partitioned_with_reference,
32 MANDATORY_NOISE_PATTERNS,
33 STRUCTURED_FAMILY_NAMES,
35 build_microcase_descriptor_set,
36 build_structured_descriptor_set,
37 iter_microcase_descriptor_sets,
44 @pytest.mark.parametrize(
"qbit_num", [4, 6])
51 assert result.requested_mode == PARTITIONED_DENSITY_MODE
52 assert result.source_type ==
"generated_hea" 53 assert result.workload_id == f
"phase2_xxz_hea_q{qbit_num}_continuity" 54 assert result.runtime_path == PHASE3_RUNTIME_PATH_BASELINE
55 assert result.requested_runtime_path == PHASE3_RUNTIME_PATH_BASELINE
56 assert result.partition_count > 0
57 assert result.exact_output_present
is True 58 assert result.rho_is_valid
is True 61 @pytest.mark.parametrize(
"qbit_num", [4, 6])
69 hamiltonian, result.density_matrix_numpy()
71 continuity_energy = float(vqe.Optimization_Problem(parameters))
73 assert abs(partitioned_energy_real - continuity_energy) <= PHASE3_RUNTIME_ENERGY_TOL
74 assert abs(partitioned_energy_imag) <= PHASE3_RUNTIME_DENSITY_TOL
82 assert result.requested_mode == PARTITIONED_DENSITY_MODE
83 assert result.source_type ==
"microcase_builder" 84 assert result.workload_id == metadata[
"case_name"]
85 assert result.partition_count > 0
86 assert result.runtime_path == PHASE3_RUNTIME_PATH_BASELINE
87 assert result.requested_runtime_path == PHASE3_RUNTIME_PATH_BASELINE
88 assert result.exact_output_present
is True 93 STRUCTURED_FAMILY_NAMES[0],
94 qbit_num=STRUCTURED_QUBITS[0],
95 noise_pattern=MANDATORY_NOISE_PATTERNS[0],
100 assert result.source_type ==
"structured_family_builder" 101 assert result.partition_count > 0
102 assert result.runtime_path == PHASE3_RUNTIME_PATH_BASELINE
103 assert result.requested_runtime_path == PHASE3_RUNTIME_PATH_BASELINE
104 assert result.rho_is_valid
is True 114 assert audit[
"provenance"][
"source_type"] ==
"generated_hea" 115 assert audit[
"summary"][
"partition_count"] == result.partition_count
116 assert audit[
"summary"][
"descriptor_member_count"] == result.descriptor_member_count
117 assert audit[
"metadata"][
"case_kind"] ==
"continuity" 118 assert audit[
"requested_runtime_path"] == PHASE3_RUNTIME_PATH_BASELINE
119 assert audit[
"qbit_num"] == result.qbit_num
120 assert audit[
"parameter_count"] == result.parameter_count
125 "microcase_4q_partition_boundary_triplet" 129 descriptor_set, parameters
132 assert result.partition_count > 0
133 assert result.remapped_partition_count > 0
134 assert result.parameter_routing_segment_count > 0
135 assert density_metrics[
"frobenius_norm_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
136 assert density_metrics[
"max_abs_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
141 STRUCTURED_FAMILY_NAMES[0],
142 qbit_num=STRUCTURED_QUBITS[0],
143 noise_pattern=MANDATORY_NOISE_PATTERNS[0],
147 descriptor_set, parameters
150 assert result.partition_count > 0
151 assert result.parameter_routing_segment_count > 0
152 assert density_metrics[
"frobenius_norm_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
153 assert density_metrics[
"max_abs_diff"] <= PHASE3_RUNTIME_DENSITY_TOL
157 """allow_fusion upgrades the request to fused path, but singleton unitary segments never fuse.""" 161 workload_id=
"story3_singleton_unitary_segments",
165 "local_depolarizing",
177 assert result.requested_runtime_path == PHASE3_RUNTIME_PATH_FUSED_UNITARY_ISLANDS
178 assert result.runtime_path == PHASE3_RUNTIME_PATH_BASELINE
179 assert not result.actual_fused_execution
185 validated, _ = noisy_runtime_mod.validate_runtime_request(
186 descriptor_set, parameters, runtime_path=noisy_runtime_mod.PHASE3_RUNTIME_PATH_BASELINE
188 partition = validated.partitions[0]
189 rp = noisy_runtime_mod.PHASE3_RUNTIME_PATH_BASELINE
191 circuit_full, ordered_full = noisy_runtime_mod._build_runtime_circuit(
194 qbit_num=validated.qbit_num,
197 noisy_runtime_mod._validate_runtime_operation_alignment(
202 member_sequence_kind=
"descriptor",
203 param_start_policy=
"from_member_attr",
204 param_start_attr=
"local_param_start",
207 segment = partition.members[:3]
208 assert all(validated.canonical_operation_for(m).is_unitary
for m
in segment)
209 circuit_seg, ordered_seg = noisy_runtime_mod._build_runtime_circuit(
212 qbit_num=validated.qbit_num,
215 noisy_runtime_mod._validate_runtime_operation_alignment(
220 member_sequence_kind=
"segment",
221 param_start_policy=
"segment_accumulated",
def test_partitioned_runtime_semantics_boundary_microcase_matches_sequential_reference()
def test_runtime_operation_alignment_descriptor_and_segment_policies()
def build_microcase_descriptor_set
def test_partitioned_runtime_mandatory_structured_case_executes_through_shared_runtime_surface()
def build_phase2_continuity_vqe
def build_runtime_audit_record
def test_partitioned_runtime_semantics_structured_case_matches_sequential_reference()
def execute_partitioned_density
def build_initial_parameters
def test_partitioned_runtime_mandatory_microcases_execute_through_shared_runtime_surface()
def build_partition_descriptor_set
def test_partitioned_runtime_continuity_runtime_audit_record_tracks_provenance()
def test_partitioned_runtime_continuity_energy_matches_existing_density_backend(qbit_num)
def build_phase3_continuity_partition_descriptor_set
def build_canonical_planner_surface_from_operation_specs
def execute_partitioned_with_reference
def test_partitioned_runtime_fusion_requested_path_without_actual_fusion_downgrades_runtime_path()
def test_phase3_partitioned_runtime_continuity_runtime_executes_supported_anchor(qbit_num)
def iter_microcase_descriptor_sets
def build_structured_descriptor_set