1 """Kraus-bundle invariant metrics for Phase 3.1 strict microcase correctness records.""" 3 from __future__
import annotations
9 from squander.partitioning.noisy_runtime
import PHASE31_RUNTIME_PATH_CHANNEL_NATIVE
10 from squander.partitioning.noisy_runtime_channel_native
import (
11 _compose_kraus_bundles,
12 _identity_kraus_bundle_for_support_qubit_count,
13 _member_to_kraus_bundle,
15 from squander.partitioning.noisy_runtime_core
import (
16 _build_partition_parameter_vector,
17 _segment_parameter_vector,
19 from squander.partitioning.noisy_types
import NoisyPartitionDescriptorSet
21 _KRAUS_COMPLETENESS_TOL = 1e-10
22 _CHOI_POSITIVITY_FLOOR = -1e-12
26 for partition
in descriptor_set.partitions:
27 if len(partition.local_to_global_qbits) == descriptor_set.qbit_num:
29 return descriptor_set.partitions[0]
33 descriptor_set: NoisyPartitionDescriptorSet,
34 parameters: np.ndarray,
36 """Fused channel-native Kraus bundle for the primary partition (matches pytest substrate).""" 42 runtime_path=PHASE31_RUNTIME_PATH_CHANNEL_NATIVE,
48 runtime_path=PHASE31_RUNTIME_PATH_CHANNEL_NATIVE,
50 local_support = tuple(range(len(partition.local_to_global_qbits)))
56 local_support=local_support,
57 runtime_path=PHASE31_RUNTIME_PATH_CHANNEL_NATIVE,
59 for m
in partition.members
63 descriptor_set=descriptor_set,
64 runtime_path=PHASE31_RUNTIME_PATH_CHANNEL_NATIVE,
70 descriptor_set=descriptor_set,
71 runtime_path=PHASE31_RUNTIME_PATH_CHANNEL_NATIVE,
77 """Scalar completeness / Choi checks aligned with ``_check_kraus_bundle_invariants``.""" 78 _k, d, _ = bundle.shape
79 acc = np.zeros((d, d), dtype=np.complex128)
80 for idx
in range(bundle.shape[0]):
82 acc += kj.conj().T @ kj
83 completeness_residual = float(
84 np.linalg.norm(acc - np.eye(d, dtype=np.complex128), ord=
"fro")
86 choi = np.zeros((d * d, d * d), dtype=np.complex128)
87 for idx
in range(bundle.shape[0]):
88 vec = np.reshape(bundle[idx], (d * d,), order=
"C")
89 choi += np.outer(vec, vec.conj())
90 choi = (choi + choi.conj().T) / 2.0
91 min_eig = float(np.min(np.real(np.linalg.eigvalsh(choi))))
93 "kraus_operator_count":
int(bundle.shape[0]),
94 "support_dimension":
int(d),
95 "completeness_residual_frobenius": completeness_residual,
96 "completeness_tolerance": _KRAUS_COMPLETENESS_TOL,
97 "completeness_pass": completeness_residual <= _KRAUS_COMPLETENESS_TOL,
98 "choi_min_eigenvalue_real": min_eig,
99 "choi_positivity_floor": _CHOI_POSITIVITY_FLOOR,
100 "choi_pass": min_eig >= _CHOI_POSITIVITY_FLOOR,
101 "invariant_slice_pass": (
102 completeness_residual <= _KRAUS_COMPLETENESS_TOL
103 and min_eig >= _CHOI_POSITIVITY_FLOOR
109 descriptor_set: NoisyPartitionDescriptorSet,
110 parameters: np.ndarray,
115 "runtime_path": PHASE31_RUNTIME_PATH_CHANNEL_NATIVE,
116 "representation_primary":
"kraus_bundle",
def _segment_parameter_vector
def measure_kraus_bundle_invariants
def build_strict_microcase_channel_invariants_slice
def _identity_kraus_bundle_for_support_qubit_count
def _build_partition_parameter_vector
def build_fused_kraus_bundle_strict_microcase
def _member_to_kraus_bundle
def _compose_kraus_bundles