OpenIslet

scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py

OpenIslet Wave-6 Round-14 Prospective Candidate W6-C2 (Staged Slot IIP-0047 -> Provisional

script Release v0.8.0 gen-eb955f8266035aba 466 KB · 37 sections

Use this file in any AI chat (paste-only or attachment-capable):

Download as text (.txt) Download section (.txt)

Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0056_route4_omentum_and_exvivo_rest.py · SHA-256: 25e12d578ba80b55…

        "cluster_max_diam_um": 64.5,
        "staggered_bilayer_plane_offset_um": 20.0,
        "bilateral_vascular_perfusion_verified": True,
        "back_to_back_unperfused_stacking": False,
        "scale_mode": "CLINICAL_HUMAN_SCALE",
        "total_implanted_ieq": total_ieq,
        "total_loaded_area_cm2": total_area_cm2,
        "per_leaf_records": leaf_recs,
        "areal_loading_ieq_cm2": 1200.0,
        "bed_face_bot_po2_mmhg": 36.0,
        "bed_face_top_po2_mmhg": 37.0,
        "measured_fibrin_capsule_um": 9.5,
        "measured_worst_face_o2_mmhg": 16.12,
        "measured_worst_core_o2_mmhg": 14.16,
        "measured_lot_ocr_mult": 1.097,
        "route_specific_clean_t50_min": 2.27,
        "route_specific_fibrin_t50_min": 2.73,
        "route_specific_gsis_si": 3.8,
        "porcine_r4o04_zero_bowel_obstruction_torsion_grade3_adhesions": True,
        "porcine_subjects": porcine_subjs,
        **stage1_pathway_fields,
        "invivo_diazoxide_depot_or_credit_claimed": False,
        "r3p06_5day_glycemic_clamp_enabled": True,
        "exvivo_rest_applied": exvivo_rest_applied,
        "exvivo_preconditioning_agents": ["DIAZOXIDE_GMP", "TUDCA_GMP"] if exvivo_rest_applied else [],
        "exvivo_diazoxide_uM": 125.0,
        "exvivo_tudca_uM": 250.0,
        "exvivo_preconditioning_hours": 22.0,
        "h46e01_fccp_max_reserve_pct_ctrl": 91.5,
        "washout_cycles_n": 3,
        "lcms_supernatant_diazoxide_uM": 0.015,
        "lcms_pellet_diazoxide_uM": 0.021,
        "rest_assay_lot_id": eff_lot,
        "rest_challenge_o2_pct": 2.0,
        "rest_two_pulse_gsis_verified": True,
        "rest_pulse1_si_rested": 3.9,
        "rest_pulse1_si_control": 3.7,
        "rest_pulse2_si_rested": 3.7,
        "rest_pulse2_si_control": 3.5,
        "oq018_post_washout_t50_min": 2.33,
        "oq018_post_washout_t50_fold_ctrl": 1.03,
        "oq018_post_washout_gsis_si": 3.8,
        "oq018_post_washout_first_phase_auc_pct_ctrl": 94.0,
        "oq018_post_washout_first_phase_auc_l95_pct_ctrl": 89.0,
        "oq018_post_washout_glucagon_pct_ctrl": 92.0,
        "h46e03_paired_hypoxic_necrosis_reduction_pct": 41.0,
        "rest_endpoint_type": "day14_stimulated_c_peptide",
        "rest_collection_day": 14.0,
        "rest_endpoint_rested_value": 1.92,
        "rest_endpoint_control_value": 1.50,
        "h46e04_day14_cpeptide_or_mass_fold_ctrl": 1.28,
        "h46e04_zero_secretory_delay_verified": True,
    }
    base["current_assay_evidence_record"] = seal_gate33_current_assay_record(base, arm_manifest=arm_manifest)
    return base


def make_mock_authenticated_wetlab_fixture_and_store(
    arm_manifest: Dict[str, Any],
    *,
    arm_key: str = "Y",
    site: str = "R4_OMENTUM_LEAD",
    scope: str = "CLINICAL_PROMOTION",
    exvivo_rest_applied: bool = True,
    lot_id: Optional[str] = None,
    bank_id: Optional[str] = None,
    construct_manifest_sha256: Optional[str] = None,
    upstream_records: Optional[Dict[str, Dict[str, Any]]] = None,
    dec009_primate_free: bool = False,
) -> Tuple[Dict[str, Any], Dict[str, Dict[str, Any]]]:
    """Unit-test helper returning an AUTHENTICATED_ARCHIVED_WETLAB mock payload + matching 4-record sealed trusted store."""
    payload = make_synthetic_valid_gate33_payload(
        arm_manifest,
        arm_key=arm_key,
        site=site,
        scope=scope,
        exvivo_rest_applied=exvivo_rest_applied,
        evidence_tier="AUTHENTICATED_ARCHIVED_WETLAB",
        lot_id=lot_id,
        bank_id=bank_id,
        construct_manifest_sha256=construct_manifest_sha256,
        upstream_records=upstream_records,
        dec009_primate_free=dec009_primate_free,
    )
    store: Dict[str, Dict[str, Any]] = {}
    for rk in (
        "upstream_gate34_record",
        "upstream_gate32_record",
        "upstream_gate0v_record",
        "upstream_gate5_oq012_record",
        "current_assay_evidence_record",
    ):
        rec = payload.get(rk)
        if isinstance(rec, dict) and "record_id" in rec:
            store[rec["record_id"]] = dict(rec)
    return payload, store


def run_gate33_synthetic_adjudicator_self_tests(arm_manifest: Dict[str, Any]) -> Dict[str, Any]:
    """Synthetic self-tests for Gate-35 code correctness (ALL SYNTHETIC_FIXTURE cases return promotion_authorized=False!)."""
    def _resync(p: Dict[str, Any]) -> Dict[str, Any]:
        out = dict(p)
        out["current_assay_evidence_record"] = seal_gate33_current_assay_record(out, arm_manifest=arm_manifest)
        return out

    def _with_leaves(
        base: Dict[str, Any],
        *,
        loading: float,
        bed_bot: float,
        bed_top: float,
        face_o2: float,
        core_o2: float,
        total_ieq: float = 500_000.0,
        thickness_um: float = 120.0,
        d_o2_matrix_m2_s: float = 1.50e-9,
        n_leaves: int = 2,
    ) -> Dict[str, Any]:
        area, leaves = _make_per_leaf_records(
            loading_ieq_cm2=loading,
            total_ieq=total_ieq,
            bed_bot=bed_bot,
            bed_top=bed_top,
            face_o2=face_o2,
            core_o2=core_o2,
            thickness_um=thickness_um,
            d_o2_matrix_m2_s=d_o2_matrix_m2_s,
            n_leaves=n_leaves,
        )
        return _resync({
            **base,
            "areal_loading_ieq_cm2": loading,
            "total_implanted_ieq": total_ieq,
            "total_loaded_area_cm2": area,
            "per_leaf_records": leaves,
            "bed_face_bot_po2_mmhg": bed_bot,
            "bed_face_top_po2_mmhg": bed_top,
            "measured_worst_face_o2_mmhg": face_o2,
            "measured_worst_core_o2_mmhg": core_o2,
        })

    om_d = make_synthetic_valid_gate33_payload(arm_manifest, arm_key="D", site="R4_OMENTUM_LEAD")
    om_d_dec009_pf = make_synthetic_valid_gate33_payload(arm_manifest, arm_key="D", site="R4_OMENTUM_LEAD", dec009_primate_free=True)
    p_t2, n_t2 = _make_subject_cohorts("SYNTH-LOT-Y-001", capsule_um=11.5, retrieval_pct=99.94)
    om_y_t2 = _resync({
        **_with_leaves(
            make_synthetic_valid_gate33_payload(arm_manifest, arm_key="Y", site="R4_OMENTUM_LEAD"),
            loading=1500.0, bed_bot=41.0, bed_top=42.0, face_o2=16.14, core_o2=14.49,
        ),
        "clinical_matrix_id": "GMP_RESORBABLE_FIBRIN",
        "measured_fibrin_capsule_um": 11.5,
        "route_specific_fibrin_t50_min": 2.81,
        "porcine_subjects": p_t2,
        "nhp_subjects": n_t2,
    })
    p_u, n_u = _make_subject_cohorts("SYNTH-LOT-Y-001", capsule_um=12.0, retrieval_pct=99.94)
    om_union_1200 = _resync({
        **_with_leaves(om_y_t2, loading=1200.0, bed_bot=40.0, bed_top=40.0, face_o2=16.14, core_o2=14.49),
        "measured_fibrin_capsule_um": 12.0,
        "porcine_subjects": p_u,
        "nhp_subjects": n_u,
    })
    om_union_1201 = _with_leaves(om_union_1200, loading=1201.0, bed_bot=40.0, bed_top=40.0, face_o2=16.14, core_o2=14.49)

    om_z_no_rest = make_synthetic_valid_gate33_payload(arm_manifest, arm_key="Z", site="R4_OMENTUM_LEAD", exvivo_rest_applied=False)
    sars_y = make_synthetic_valid_gate33_payload(arm_manifest, arm_key="Y", site="R4_SARS_FREE_BACKUP")
    booking_y = make_synthetic_valid_gate33_payload(arm_manifest, arm_key="Y", site="R4_OMENTUM_LEAD", scope="STAGE0_EXPERIMENT_BOOKING")
    for k in (
        "porcine_subjects",
        "nhp_subjects",
        "porcine_r4o04_zero_bowel_obstruction_torsion_grade3_adhesions",
        "porcine_portal_peripheral_insulin_gradient",
        "nhp_r4o05_portal_peripheral_insulin_gradient",
        "nhp_r4o05_post_omentectomy_cpeptide_extinction",
        "dec009_primate_free_pathway",
        "dec009_fda_cber_nhp_exception_authorized",
        "dec009_pillar1_humanized_mouse_efficacy_pass",
        "dec009_pillar2_chandler_loop_50donor_pass",
        "dec009_pillar1_glp_biodistribution_erasure_pass",
        "dec009_post_explant_cpeptide_extinction_verified",
        "rest_endpoint_type",
        "rest_collection_day",
        "rest_endpoint_rested_value",
        "rest_endpoint_control_value",
        "h46e04_day14_cpeptide_or_mass_fold_ctrl",
        "h46e04_zero_secretory_delay_verified",
    ):
        booking_y.pop(k, None)
    booking_y = _resync(booking_y)

    # Positive Round-4/6 surgical-only porcine check (pigs on 0.1 U/kg/d at exact Day-60 boundary MUST PASS!)
    pigs_surgical_day60 = [
        {
            **s,
            "followup_duration_days": 60.0,
            "capsule_sampling_day": 60.0,
            "retrieval_assessment_day": 60.0,
            "insulin_indep_day": 60.0,
            "residual_exogenous_insulin_u_kg_d": 0.1,
        }
        for s in om_d["porcine_subjects"]
    ]
    om_d_pigs_day60_ok = _resync({**om_d, "porcine_subjects": pigs_surgical_day60})

    def _drop_both(base: Dict[str, Any], key: str) -> Dict[str, Any]:
        """Drop a mandatory evidence field from BOTH parent and re-sealed current_assay record (genuine HOLD test)."""
        d = dict(base)
        d.pop(key, None)
        if key not in ("bank_id", "construct_manifest_sha256", "upstream_gate0v_record", "upstream_gate5_oq012_record", "current_assay_evidence_record"):
            d["current_assay_evidence_record"] = seal_gate33_current_assay_record(d, arm_manifest=arm_manifest)
        return d

    def _patch_sync(base: Dict[str, Any], patch: Dict[str, Any]) -> Dict[str, Any]:
        return _resync({**base, **patch})

    def _patch_nhp(base: Dict[str, Any], patch: Dict[str, Any]) -> Dict[str, Any]:
        subjs = [{**s, **patch} for s in base["nhp_subjects"]]
        return _resync({**base, "nhp_subjects": subjs})

    def _patch_nhp_one(base: Dict[str, Any], idx: int, patch: Dict[str, Any], *, drop_keys: Tuple[str, ...] = ()) -> Dict[str, Any]:
        subjs = [dict(s) for s in base["nhp_subjects"]]
        subjs[idx] = {**subjs[idx], **patch}
        for dk in drop_keys:
            subjs[idx].pop(dk, None)
        return _resync({**base, "nhp_subjects": subjs})

    def _patch_porcine(base: Dict[str, Any], patch: Dict[str, Any]) -> Dict[str, Any]:
        subjs = [{**s, **patch} for s in base["porcine_subjects"]]
        return _resync({**base, "porcine_subjects": subjs})

    def _patch_porcine_one(base: Dict[str, Any], idx: int, patch: Dict[str, Any]) -> Dict[str, Any]:
        subjs = [dict(s) for s in base["porcine_subjects"]]
        subjs[idx] = {**subjs[idx], **patch}
        return _resync({**base, "porcine_subjects": subjs})

    def _patch_leaves(base: Dict[str, Any], patch: Dict[str, Any]) -> Dict[str, Any]:
        leaves = [{**lf, **patch} for lf in base["per_leaf_records"]]
        return _resync({**base, "per_leaf_records": leaves})

    def _with_g5(
        base: Dict[str, Any],
        k_surv: int,
        n_test: int,
        u95_reported: Any,
        *,
        f_clon: Any = 0.50,
        eta_det: Any = 0.80,
        n_eff: Any = "AUTO",
        drop_keys: Tuple[str, ...] = (),
    ) -> Dict[str, Any]: