1 """Shared noise-support vocabulary and bundle summary helpers.""" 3 from __future__
import annotations
7 SUPPORT_TIER_REQUIRED =
"required" 8 SUPPORT_TIER_OPTIONAL =
"optional" 9 SUPPORT_TIER_DEFERRED =
"deferred" 10 SUPPORT_TIER_UNSUPPORTED =
"unsupported" 12 CASE_PURPOSE_MANDATORY_BASELINE =
"mandatory_baseline" 13 CASE_PURPOSE_OPTIONAL_REGRESSION =
"optional_regression" 14 CASE_PURPOSE_OPTIONAL_STRESS =
"optional_stress" 15 CASE_PURPOSE_OPTIONAL_COMPARISON =
"optional_comparison" 16 CASE_PURPOSE_DEFERRED_SCOPE_GUARD =
"deferred_scope_guard" 17 CASE_PURPOSE_UNSUPPORTED_SCOPE_GUARD =
"unsupported_scope_guard" 19 OPTIONAL_REASON_WHOLE_REGISTER_DEPOLARIZING =
"whole_register_depolarizing_baseline" 20 OPTIONAL_REASON_WORKFLOW_JUSTIFIED_EXTENSION =
"workflow_justified_extension" 22 BOUNDARY_CLASS_MODEL_FAMILY =
"model_family" 23 BOUNDARY_CLASS_SCHEDULE_ELEMENT =
"schedule_element" 24 BOUNDARY_CLASS_CONFIGURATION =
"configuration" 26 DEFERRED_REASON_CORRELATED_MULTI_QUBIT =
"correlated_multi_qubit_noise" 27 DEFERRED_REASON_READOUT =
"readout_noise" 28 DEFERRED_REASON_CALIBRATION_AWARE =
"calibration_aware_noise" 29 DEFERRED_REASON_NON_MARKOVIAN =
"non_markovian_noise" 31 UNSUPPORTED_REASON_DENSITY_NOISE_CHANNEL =
"unsupported_density_noise_channel" 32 UNSUPPORTED_REASON_AFTER_GATE_INDEX_NEGATIVE =
"after_gate_index_negative" 33 UNSUPPORTED_REASON_AFTER_GATE_INDEX_EXCEEDS_GATE_COUNT = (
34 "after_gate_index_exceeds_gate_count" 36 UNSUPPORTED_REASON_TARGET_QBIT_OUT_OF_RANGE =
"target_qbit_out_of_range" 37 UNSUPPORTED_REASON_NOISE_VALUE_OUT_OF_RANGE =
"noise_value_out_of_range" 38 UNSUPPORTED_REASON_NOISE_VALUE_NON_FINITE =
"noise_value_non_finite" 40 DEFERRED_FAMILY_REASONS = (
41 DEFERRED_REASON_CORRELATED_MULTI_QUBIT,
42 DEFERRED_REASON_READOUT,
43 DEFERRED_REASON_CALIBRATION_AWARE,
44 DEFERRED_REASON_NON_MARKOVIAN,
47 UNSUPPORTED_CONFIGURATION_REASONS = (
48 UNSUPPORTED_REASON_DENSITY_NOISE_CHANNEL,
49 UNSUPPORTED_REASON_AFTER_GATE_INDEX_NEGATIVE,
50 UNSUPPORTED_REASON_AFTER_GATE_INDEX_EXCEEDS_GATE_COUNT,
51 UNSUPPORTED_REASON_TARGET_QBIT_OUT_OF_RANGE,
52 UNSUPPORTED_REASON_NOISE_VALUE_OUT_OF_RANGE,
53 UNSUPPORTED_REASON_NOISE_VALUE_NON_FINITE,
56 SUPPORT_TIER_VOCABULARY = (
57 SUPPORT_TIER_REQUIRED,
58 SUPPORT_TIER_OPTIONAL,
59 SUPPORT_TIER_DEFERRED,
60 SUPPORT_TIER_UNSUPPORTED,
66 "support_tier": SUPPORT_TIER_REQUIRED,
67 "case_purpose": CASE_PURPOSE_MANDATORY_BASELINE,
68 "counts_toward_mandatory_baseline":
True,
74 "support_tier": SUPPORT_TIER_OPTIONAL,
75 "case_purpose": case_purpose,
76 "optional_reason": optional_reason,
77 "counts_toward_mandatory_baseline":
False,
84 case_purpose=CASE_PURPOSE_DEFERRED_SCOPE_GUARD,
87 "support_tier": SUPPORT_TIER_DEFERRED,
88 "case_purpose": case_purpose,
89 "deferred_reason": deferred_reason,
90 "counts_toward_mandatory_baseline":
False,
97 case_purpose=CASE_PURPOSE_UNSUPPORTED_SCOPE_GUARD,
100 "support_tier": SUPPORT_TIER_UNSUPPORTED,
101 "case_purpose": case_purpose,
102 "unsupported_scope_reason": unsupported_reason,
103 "counts_toward_mandatory_baseline":
False,
108 match = re.search(
r"Unsupported density-noise channel '([^']+)'", reason)
110 return match.group(1)
115 if not requested_channel:
118 lowered = requested_channel.lower()
119 if "readout" in lowered:
120 return DEFERRED_REASON_READOUT
121 if "correlated" in lowered:
122 return DEFERRED_REASON_CORRELATED_MULTI_QUBIT
123 if "calibration" in lowered:
124 return DEFERRED_REASON_CALIBRATION_AWARE
125 if "non_markovian" in lowered
or "non-markovian" in lowered:
126 return DEFERRED_REASON_NON_MARKOVIAN
127 return UNSUPPORTED_REASON_DENSITY_NOISE_CHANNEL
132 if "Unsupported density-noise channel" in reason:
134 if first_condition
in DEFERRED_FAMILY_REASONS:
136 deferred_reason=first_condition
140 unsupported_reason=UNSUPPORTED_REASON_DENSITY_NOISE_CHANNEL
143 "unsupported_category":
"noise_type",
144 "first_unsupported_condition": first_condition,
145 "noise_boundary_class": BOUNDARY_CLASS_MODEL_FAMILY,
146 "failure_stage":
"python_normalization",
147 "requested_noise_channel": requested_channel,
151 if "after_gate_index must be non-negative" in reason:
153 "unsupported_category":
"noise_insertion",
154 "first_unsupported_condition": UNSUPPORTED_REASON_AFTER_GATE_INDEX_NEGATIVE,
155 "noise_boundary_class": BOUNDARY_CLASS_SCHEDULE_ELEMENT,
156 "failure_stage":
"cxx_noise_spec_validation",
157 "requested_noise_channel":
None,
159 unsupported_reason=UNSUPPORTED_REASON_AFTER_GATE_INDEX_NEGATIVE
163 if "after_gate_index exceeds generated gate count" in reason:
165 "unsupported_category":
"noise_insertion",
166 "first_unsupported_condition": (
167 UNSUPPORTED_REASON_AFTER_GATE_INDEX_EXCEEDS_GATE_COUNT
169 "noise_boundary_class": BOUNDARY_CLASS_SCHEDULE_ELEMENT,
170 "failure_stage":
"density_anchor_preflight",
171 "requested_noise_channel":
None,
173 unsupported_reason=UNSUPPORTED_REASON_AFTER_GATE_INDEX_EXCEEDS_GATE_COUNT
177 if "target_qbit out of range" in reason:
179 "unsupported_category":
"noise_target",
180 "first_unsupported_condition": UNSUPPORTED_REASON_TARGET_QBIT_OUT_OF_RANGE,
181 "noise_boundary_class": BOUNDARY_CLASS_CONFIGURATION,
182 "failure_stage":
"cxx_noise_spec_validation",
183 "requested_noise_channel":
None,
185 unsupported_reason=UNSUPPORTED_REASON_TARGET_QBIT_OUT_OF_RANGE
189 if "noise values must be in [0, 1]" in reason:
191 "unsupported_category":
"noise_value",
192 "first_unsupported_condition": UNSUPPORTED_REASON_NOISE_VALUE_OUT_OF_RANGE,
193 "noise_boundary_class": BOUNDARY_CLASS_CONFIGURATION,
194 "failure_stage":
"cxx_noise_spec_validation",
195 "requested_noise_channel":
None,
197 unsupported_reason=UNSUPPORTED_REASON_NOISE_VALUE_OUT_OF_RANGE
201 if "non-finite value" in reason:
203 "unsupported_category":
"noise_value",
204 "first_unsupported_condition": UNSUPPORTED_REASON_NOISE_VALUE_NON_FINITE,
205 "noise_boundary_class": BOUNDARY_CLASS_CONFIGURATION,
206 "failure_stage":
"python_normalization",
207 "requested_noise_channel":
None,
209 unsupported_reason=UNSUPPORTED_REASON_NOISE_VALUE_NON_FINITE
214 "unsupported_category":
"workflow_execution",
215 "first_unsupported_condition":
"workflow_execution",
216 "noise_boundary_class":
"workflow_execution",
217 "failure_stage":
"workflow_execution",
218 "requested_noise_channel": requested_channel,
220 unsupported_reason=
"workflow_execution" 228 case
for case
in cases
if case.get(
"support_tier") == SUPPORT_TIER_REQUIRED
231 case
for case
in cases
if case.get(
"support_tier") == SUPPORT_TIER_OPTIONAL
234 case
for case
in cases
if case.get(
"support_tier") == SUPPORT_TIER_DEFERRED
236 unsupported_cases = [
237 case
for case
in cases
if case.get(
"support_tier") == SUPPORT_TIER_UNSUPPORTED
240 case
for case
in cases
if case.get(
"counts_toward_mandatory_baseline")
243 required_passed_cases = sum(case.get(
"status") ==
"pass" for case
in required_cases)
244 optional_passed_cases = sum(case.get(
"status") ==
"pass" for case
in optional_cases)
245 mandatory_passed_cases = sum(case.get(
"status") ==
"pass" for case
in mandatory_cases)
247 def _rate(passed, total):
248 return 0.0
if total == 0
else passed / total
251 "required_cases": len(required_cases),
252 "required_passed_cases": required_passed_cases,
253 "required_pass_rate": _rate(required_passed_cases, len(required_cases)),
254 "optional_cases": len(optional_cases),
255 "optional_passed_cases": optional_passed_cases,
256 "optional_pass_rate": _rate(optional_passed_cases, len(optional_cases)),
257 "deferred_cases": len(deferred_cases),
258 "unsupported_cases": len(unsupported_cases),
259 "mandatory_baseline_case_count": len(mandatory_cases),
260 "mandatory_baseline_passed_cases": mandatory_passed_cases,
261 "mandatory_baseline_completed":
bool(mandatory_cases)
262 and mandatory_passed_cases == len(mandatory_cases),
263 "optional_cases_count_toward_mandatory_baseline": sum(
264 case.get(
"counts_toward_mandatory_baseline",
False)
265 for case
in optional_cases
267 "support_tiers_present": sorted(
269 case.get(
"support_tier")
271 if case.get(
"support_tier")
is not None def build_deferred_case_classification(deferred_reason, case_purpose=CASE_PURPOSE_DEFERRED_SCOPE_GUARD)
def _extract_requested_channel
def build_support_tier_summary(cases)
def build_optional_case_classification(case_purpose, optional_reason)
def classify_noise_boundary_reason
def build_unsupported_case_classification(unsupported_reason, case_purpose=CASE_PURPOSE_UNSUPPORTED_SCOPE_GUARD)
def build_required_case_classification()
def _map_requested_channel_to_boundary_reason