scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py · SHA-256: 25e12d578ba80b55…
(0.62, 0.92, 0.70, 0.70), # D1b stays on R3P (single-switch barred from R4-SARS-Free)
]
sars_classes = ("INC", "INC", "INC", "STAGED_DUAL_SWITCH", "STAGED_SINGLE_SWITCH")
sars_compat = {
"INC": frozenset({"R1", "R2"}),
"STAGED_DUAL_SWITCH": frozenset({"R3P", "R4"}),
"STAGED_SINGLE_SWITCH": frozenset({"R3P"}),
}
r_diag_sars_backup = eval_5arm_2pow20_exact(
"Diag_PrereqWaived_Demoted_R4SARS_Free_DualSwitch_Y_Only", sars_y_only_arms,
c4_univ=0.935, c4_r4=0.86, phi_r4=0.75, two_site_nested_subars=True,
routes=("R1", "R2", "R1", "R4", "R3P"), cell_classes=sars_classes, compat_map=sars_compat, phi_inc=0.50,
)
# Verify locked-selector loophole is CLOSED: assigning A directly to R4 MUST raise RuntimeError!
loophole_blocked = False
try:
eval_5arm_2pow20_exact(
"TEST_ILLEGAL_A_HOME_R4", c2_isol_zero_rest_arms,
c4_univ=0.950, c4_r4=0.870, phi_r4=0.30,
routes=("R4", "R2", "R1", "R3P", "R4"), cell_classes=base_c, compat_map=isol_r4_m, phi_inc=0.50,
)
except RuntimeError:
loophole_blocked = True
require_cond(loophole_blocked, "Locked-selector home-route GY-027(1) guard failed to block Design A on R4")
# Exact unrounded (<1e-12) AND 4-decimal display (0.0) parity against external Round-3 master contract!
max_exact_err = 0.0
max_disp_err = 0.0
for comp, tgt, lbl, h_ref in [
(l0, rs["L0_core_3arm"], "L0_core_3arm", None),
(b_l1, rs["L1_shipped_IIP0035_phi0"], "L1_shipped_IIP0035_phi0", None),
(b_w5, rs["Wave5_L3B_audited_caveated"], "Wave5_L3B_audited_caveated", None),
(b_honest, rs["L1_honest_monoculture_phi_inc_0.50"], "L1_honest_monoculture_phi_inc_0.50", None),
(r_c1_standalone, rs["W6_C1_standalone_over_honest_L1"], "W6_C1_standalone_over_honest_L1", honest_exact),
(r_c2_plus_c1, rs["W6_C2_plus_C1_R4Omentum_zeroRest"], "W6_C2_plus_C1_R4Omentum_zeroRest", honest_exact),
(r_diag_c2_isol_zero, dc["Diag_PrereqWaived_C2_isolated_zeroRest"], "Diag_PrereqWaived_C2_isolated_zeroRest", honest_exact),
(r_diag_c2_c4univ92, dc["Diag_PrereqWaived_C2_c4univ_held_0.92_site_only"], "Diag_PrereqWaived_C2_c4univ_held_0.92_site_only", honest_exact),
(r_diag_c2_prospective_rest, dc["Diag_PrereqWaived_C2_prospective_rest_1p5pp_all_eligible_BXYD"], "Diag_PrereqWaived_C2_prospective_rest_1p5pp_all_eligible_BXYD", honest_exact),
]:
e_ex, e_dp = _check_contract_cell_parity(comp, tgt, lbl, h_ref, exact_tol=1e-12)
max_exact_err = max(max_exact_err, e_ex)
max_disp_err = max(max_disp_err, e_dp)
require_cond(max_exact_err < 1e-12, f"Unrounded master contract parity exceeded 1e-12: {max_exact_err:.3e}")
require_cond(max_disp_err == 0.0, f"Display master contract parity non-zero: {max_disp_err}")
require_cond(r_diag_c2_isol_zero["modular_exact"] > r_diag_sars_backup["modular_exact"], "Lead R4-Omentum must strictly beat demoted R4-SARS-Free backup")
def _with_deltas(d: Dict[str, Any], *, include_delta: bool = False) -> Dict[str, Any]:
out = dict(d)
if include_delta:
d_hon = d["modular_exact"] - honest_exact
d_shp = d["modular_exact"] - b_l1["modular_exact"]
out["delta_vs_honest_l1_exact_pp"] = d_hon
out["delta_vs_honest_l1_pct_pp"] = round(d_hon, 4)
out["delta_vs_shipped_l1_exact_pp"] = d_shp
out["delta_vs_shipped_l1_pct_pp"] = round(d_shp, 4)
return out
cond_c2_given_c1_exact_pp = r_c2_plus_c1["modular_exact"] - c1_standalone_exact
return {
"external_master_contract_verified": True,
"external_master_contract_sha256": contracts["contract_sha256"],
"external_master_contract_file_sha256": contracts["contract_file_sha256"],
"external_arm_manifest_sha256": contracts["manifest_sha256"],
"exact_master_contract_parity_max_abs_err_unrounded": max_exact_err,
"display_master_contract_parity_max_abs_err": max_disp_err,
"exact_parity_lt_1e12": bool(max_exact_err < 1e-12),
"live_odds_credit_today_pp": 0.0,
"rounding_policy": "Both unrounded IEEE-754 float64 (*_exact, verified <1e-12) and 4-decimal display (*_pct, verified ==0.0) values are preserved.",
"c4_r4_route_cap_epistemic_note": "c4_r4 = 0.87 (and c4_univ = 0.95, phi_r4 = 0.30) is an explicit supplied scenario parameter, NOT a statistically identified parameter from small heterogeneous clinical omental cohorts; live OpenIslet odds credit today is +0.00 pp pending Stage-0/1 clearance.",
"h1_allo_locked_pct": 88.0,
"design_a_strictly_invariant_tuple": [0.88, 0.78, 0.57, 0.69],
"home_route_locked_selector_guard_verified": loophole_blocked,
"core_3arm_baseline_invariant": dict(l0),
"reachable_scenarios": {
"L1_shipped_IIP0035_phi0": dict(b_l1),
"Wave5_L3B_audited_caveated": dict(b_w5),
"L1_honest_monoculture_phi_inc_0.50": dict(b_honest),
"W6_C1_standalone_over_honest_L1": {
**_with_deltas(r_c1_standalone, include_delta=True),
"scenario_role": "REACHABLE_W6_C1_STANDALONE_PREREQUISITE_BASELINE",
"released_state_eligible": True,
},
"W6_C2_plus_C1_R4Omentum_zeroRest": {
**_with_deltas(r_c2_plus_c1, include_delta=True),
"conditional_c2_given_c1_exact_pp": cond_c2_given_c1_exact_pp,
"conditional_c2_given_c1_pct_pp": round(cond_c2_given_c1_exact_pp, 4),
"scenario_role": "PRIMARY_REACHABLE_PREREQUISITE_PAIRED_C2_PLUS_C1_ZERO_EXVIVO_REST_CREDIT",
"released_state_eligible": True,
"gy027_1_compliant": True,
"gy014_compliant": True,
"design_a_invariant_verified": True,
},
},
"diagnostic_prerequisite_waived_counterfactuals": {
"scope_warning": "Explicitly disables W6-C1 prerequisites for marginal isolation; carries 0.0% released-state weight and is excluded from reachable qualification comparisons.",
"released_state_weight_pct": 0.0,
"Diag_PrereqWaived_C2_isolated_zeroRest": {
**_with_deltas(r_diag_c2_isol_zero, include_delta=True),
"scenario_role": "DIAGNOSTIC_PREREQ_WAIVED_ISOLATED_C2_ZERO_EXVIVO_REST_CREDIT",
"released_state_eligible": False,
"gy027_1_compliant": True,
"gy014_compliant": True,
"design_a_invariant_verified": True,
},
"Diag_PrereqWaived_C2_c4univ_held_0.92_site_only": {
**_with_deltas(r_diag_c2_c4univ92, include_delta=True),
"scenario_role": "DIAGNOSTIC_PREREQ_WAIVED_C4_UNIV_HELD_0P92_SITE_ONLY",
"released_state_eligible": False,
},
"Diag_PrereqWaived_C2_prospective_rest_1p5pp_all_eligible_BXYD": {
**_with_deltas(r_diag_c2_prospective_rest, include_delta=True),
"scenario_role": "DIAGNOSTIC_PREREQ_WAIVED_PROSPECTIVE_REST_1P5PP_ALL_ELIGIBLE_NON_A_ARMS_BXYD_ZERO_PRIMARY_CREDIT",
"released_state_eligible": False,
"design_a_invariant_verified": True,
},
"Diag_PrereqWaived_Demoted_R4SARS_Free_DualSwitch_Y_Only": {
**_with_deltas(r_diag_sars_backup, include_delta=True),
"scenario_role": "DIAGNOSTIC_PREREQ_WAIVED_DEMOTED_BACKUP_DUAL_FAILSAFE_Y_ONLY_D1B_BARRED",
"released_state_eligible": False,
"advantage_of_isolated_omentum_zeroRest_exact_pp": r_diag_c2_isol_zero["modular_exact"] - r_diag_sars_backup["modular_exact"],
"advantage_of_isolated_omentum_zeroRest_pct_pp": round(r_diag_c2_isol_zero["modular_exact"] - r_diag_sars_backup["modular_exact"], 4),
},
},
}
# =============================================================================
# 7. Strict Fail-Closed, Manifest-Linked Gate-33 Adjudicator (Round-4)
# =============================================================================
ALLOWED_CUFF_COMPONENTS_ALLOWLIST: FrozenSet[str] = frozenset({
"sCR1_v2",
"THBD-M406L",
"CD200-ECD",
"CCL22",
"IL1RN",
"IL18BP",
})
ALLOWED_CLINICAL_MATRICES_OMENTUM: FrozenSet[str] = frozenset({
"GMP_AUTOLOGOUS_PLASMA_THROMBIN",
"GMP_RESORBABLE_FIBRIN",
})
ALLOWED_CLINICAL_MATRICES_SARS_BACKUP: FrozenSet[str] = frozenset({
"BIODEGRADABLE_THIN_PLANAR_CARRIER_SHEET",
})
REQUIRED_EXVIVO_REST_AGENTS: FrozenSet[str] = frozenset({
"DIAZOXIDE_GMP",
"TUDCA_GMP",
})
BANNED_EXVIVO_TOKENS: FrozenSet[str] = frozenset({
"FERROSTATIN_1",
"FER_1",
"ISRIB",
"INVIVO_DIAZOXIDE_DEPOT",
})
# Exact live GY-030 5-lineage whole-graft panel (matched verbatim across C1/C2/C4)
REQUIRED_GY030_LINEAGES: FrozenSet[str] = frozenset({
"alpha",
"beta",
"delta",
"pericyte",
"plvap_iec",
})
ALLOWED_BANK_ORIGINS: FrozenSet[str] = frozenset({
"allogeneic_hiPSC",
"autologous_hiPSC",
"allogeneic_EnSC",
})
ALLOWED_AUTHORITY_SCOPES: FrozenSet[str] = frozenset({
"CLINICAL_LOT_RELEASE",
"BANK_QUALIFICATION_ONLY",
"STAGE_LIMITED_SORT_ONLY",
"COMPONENT_SORT_QUALIFICATION_ONLY",
"WAVE7_RESERVE_ONLY",
"SYNTHETIC_SELF_TEST",
"REJECTED_OR_HELD",
})
ALLOWED_SCALE_MODES: FrozenSet[str] = frozenset({
"CLINICAL_HUMAN_SCALE",
"ANIMAL_PRECLINICAL_SCALE",
})
ALLOWED_REST_ENDPOINT_TYPES: FrozenSet[str] = frozenset({
"day7_beta_mass",
"day14_stimulated_c_peptide",
})
# Unified v2_round4_unified 14-field producer-owned evidence record schema
REQUIRED_UPSTREAM_SCHEMA_V2_STRING_FIELDS: Tuple[str, ...] = (
"record_id",
"gate_source",
"product_id",
"lot_id",
"bank_id",
"bank_origin",
"canonical_arm_manifest_sha256",
"construct_manifest_sha256",
"evidence_tier",
"decision",
"authority_scope",
"archive_sha256",
)
REQUIRED_UPSTREAM_SCHEMA_V2_BOOL_FIELDS: Tuple[str, ...] = (
"bank_qualified",
"promotion_authorized",
)
REQUIRED_UPSTREAM_SCHEMA_V2_ALL_FIELDS: Tuple[str, ...] = (
"record_id",
"gate_source",
"product_id",
"lot_id",
"bank_id",
"bank_origin",
"canonical_arm_manifest_sha256",
"construct_manifest_sha256",
"evidence_tier",
"decision",
"authority_scope",
"bank_qualified",
"promotion_authorized",
"archive_sha256",
)
REQUIRED_PER_LEAF_FIELDS: Tuple[str, ...] = (
"leaf_id",
"loaded_ieq",
"measured_area_cm2",
"measured_thickness_um",
"measured_d_o2_matrix_m2_s",
"measured_face_o2_mmhg",
"measured_core_o2_mmhg",
"bed_face_bot_po2_mmhg",
"bed_face_top_po2_mmhg",
"direct_o2_sensor_coverage_verified",
)
PORCINE_MIN_FOLLOWUP_DAYS: float = 60.0
NHP_MIN_FOLLOWUP_DAYS: float = 90.0
MAX_POST_OMENTECTOMY_CPEP_EXTINCTION_WINDOW_DAYS: float = 14.0
PORCINE_MIN_FOLLOWUP_DAYS_DEC: Decimal = Decimal("60")
NHP_MIN_FOLLOWUP_DAYS_DEC: Decimal = Decimal("90")
MAX_POST_OMENTECTOMY_CPEP_EXTINCTION_WINDOW_DAYS_DEC: Decimal = Decimal("14")
NHP_MAX_INSULIN_INDEP_DAY_DEC: Decimal = Decimal("45")
# Porcine cohort: per-subject SURGICAL SAFETY, measurement dates, typed monitored complications, & retrieval/residual reconciliation (Review C2 #1 / Audit F5 / Audit R5-04)
REQUIRED_PORCINE_SUBJECT_FIELDS: Tuple[str, ...] = (
"subject_id",
"species",
"lot_id",
"followup_duration_days",
"capsule_sampling_day",
"retrieval_assessment_day",