OpenIslet

scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py

IIP-0043 / DEC-122 (CAND-034 / EXP-031 — Bucket 1 Closure, Stage S3-R2 Remediated)

script Release v0.8.0 gen-eb955f8266035aba 1008 KB · 76 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_iip0043_wholegraft_gate0v_and_calibration.py · SHA-256: 20706180ed1ed6a2…

    r1_390_cpl10_live = _find_iip33("PASS_R1_390_Staggered_CoupledPlus10OCR_16p5umStandoff_p95_68_2xAdj_nx80")

    fvm_3d = (
        _run_true_3d_fvm_vascular_voxel_replays(openislet_root, r1_rows)
        if run_3d_fvm
        else {"executed": False, "replays": {}}
    )
    live_dispatch_tests = (
        run_nw08_live_dispatch_solver_tests(openislet_root)
        if run_3d_fvm
        else {"executed": False, "total_tests": 0, "passed_tests": 0, "all_passed": True, "tests": []}
    )
    trigger_tests = run_nw08_trigger_and_floor_unit_tests()

    m_vasc_true_plus20 = 1.097 * 1.20  # 1.3164 (+2.6087% whole-slab weighted demand)

    regimes = [
        ("L4_Canonical_1p00x_Baseline", 1.000, 1.000, "Layer-4 canonical basal design point (3.605 pure [2.312 fmol/min/cell] + 0.541 vasc = 4.146 pmol/min/IEQ)"),
        ("L4_Canonical_1p097x_Stimulated", 1.097, 1.097, "Layer-4 canonical chronic stimulated design point (3.955 pure [2.536 fmol/min/cell] + 0.593 vasc = 4.548 pmol/min/IEQ)"),
        ("NW08_External_WholePrep_Basal_Papas_GlycolyticEC", papas_human_ii_pmol_min_ieq / l4_pure_ieq_pmol_min, 0.35, "External whole-prep calibration: Papas 2015 clinical autoislet basal (1.196 pmol/min/IEQ) + glycolytic EC model prior (0.35x L4 vasc)"),
        ("NW08_External_WholePrep_2p2xStim_GlycolyticEC", (papas_human_ii_pmol_min_ieq * 2.2) / l4_pure_ieq_pmol_min, 0.50, "2.2x stimulated external whole-prep scaling (2.631 pmol/min/IEQ) + glycolytic EC model prior (0.50x L4 vasc)"),
        ("NW08_StressSensitivity_SenescentHUVEC_1p3164", 1.097, m_vasc_true_plus20, "Stress sensitivity: stimulated endocrine 1.097x + ~20% higher basal OCR in replicatively senescent HUVEC (m_vasc = 1.3164; Stabenow 2022 Cells Fig. 3A)"),
        ("NW08_Extreme_ActivatedStroma_1p50x_x_StimEndo1p097", 1.097, 1.500, "Extreme stress sensitivity: stimulated endocrine 1.097x + 1.50x vascular stroma (+4.79% weighted slab)"),
    ]

    r1_drop = 35.0 - r1_390_nom_live
    r2_drop = 40.0 - r2_dz_40_live
    r3p_drop = 35.0 - r3p_h180_35_live

    regime_rows = []
    for name, m_endo, m_vasc, desc in regimes:
        m_slab_vs_1p00 = (m_endo + 0.15 * m_vasc) / 1.15
        rel_vs_1p097 = m_slab_vs_1p00 / 1.097
        whole_pmol_min_ieq = l4_whole_1p00_pmol_min * m_slab_vs_1p00
        dp_core_65 = (vmax_islet_mol_cm3_s * m_endo * (32.5e-4 ** 2)) / (6.0 * d_o2_islet * alpha_bunsen_nominal)
        dp_core_100 = (vmax_islet_mol_cm3_s * m_endo * (50.0e-4 ** 2)) / (6.0 * d_o2_islet * alpha_bunsen_nominal)
        r1_face = 35.0 - r1_drop * rel_vs_1p097
        r2_face_40 = 40.0 - r2_drop * rel_vs_1p097
        r3p_face_35 = 35.0 - r3p_drop * rel_vs_1p097
        regime_rows.append({
            "regime": name,
            "description": desc,
            "m_endocrine": round(m_endo, 4),
            "m_vascular": round(m_vasc, 4),
            "slab_ocr_mult_vs_1p00": round(m_slab_vs_1p00, 4),
            "slab_ocr_delta_pct_vs_1p097": round((rel_vs_1p097 - 1.0) * 100.0, 2),
            "whole_prep_ocr_pmol_min_ieq": round(whole_pmol_min_ieq, 4),
            "krogh_core_drop_65um_mmhg": round(dp_core_65, 3),
            "krogh_core_drop_100um_mmhg": round(dp_core_100, 3),
            "route1_390um_bilayer_35mmhg_linearized_screen_mmhg": round(r1_face, 2),
            "route2_140um_designz_40mmhg_linearized_screen_mmhg": round(r2_face_40, 2),
            "route3p_180um_planar_35mmhg_linearized_screen_mmhg": round(r3p_face_35, 2),
            "all_3_nominal_routes_above_15mmhg_gsis_floor": bool(
                _passes_unrounded_15mmhg_floor(r1_face)
                and _passes_unrounded_15mmhg_floor(r2_face_40)
                and _passes_unrounded_15mmhg_floor(r3p_face_35)
            ),
        })

    # Margin + measurement-uncertainty-to-15-mmHg trigger table comparing MATCHED linear screen vs TRUE 3D FVM!
    def _lin_breach_pct(p_bed: float, base_mmhg: float) -> float:
        if base_mmhg <= 15.0:
            return 0.0
        return round(100.0 * (base_mmhg - 15.0) / ((p_bed - base_mmhg) * (0.15 / 1.15)), 2)

    def _lin_at_vasc_target(p_bed: float, base_mmhg: float, base_ocr: float, target_vasc_ocr: float) -> float:
        rel_slab = ((base_ocr + 0.15 * target_vasc_ocr) / 1.15) / base_ocr
        return p_bed - (p_bed - base_mmhg) * rel_slab

    replays_map = fvm_3d.get("replays", {})

    corner_specs = [
        (
            "R1_350um_PurePlus10OCR_Bed35_nx80",
            "R1_350_stress",
            35.0,
            r1_350_p10_live,
            1.2067,
            "verify_iip0033_bilayer_and_resp1.solve_route1_supercell_fixed_pitch",
            "BOTH matched linear screen (14.8027 mmHg) and true 3D FVM (14.8446 mmHg) FAIL at matched m_vasc=1.3164 (+9.09% above 1.2067x). Pre-committed derating: retire compressed 350 um slab in favor of 390 um bilayer via executable evaluate_nw08_measured_ocr_trigger (fires at +1.51% linear / +1.84% two-point 3D slope).",
        ),
        (
            "R1_390um_CoupledPlus10OCR_Bed35_nx80",
            "R1_390_stress",
            35.0,
            r1_390_cpl10_live,
            1.2067,
            "verify_iip0033_bilayer_and_resp1.solve_route1_supercell_fixed_pitch",
            "MESH-SENSITIVE NEAR-FLOOR CORNER (R14-B1 HOLD): at +9.09% (m_vasc=1.3164), native 80x80x78 is 15.0741 mmHg (+0.0741), but predeclared 3-grid refinement (80x80x78: 15.0741 -> 96x96x94: 14.9753 -> 112x112x109: 15.0638 mmHg; conservative interval [14.9629, 15.0864]) straddles 15.0 mmHg and routes to unresolved HOLD (HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR, exit 2). At +20.0% (m_vasc=1.44804), all three grids (14.8489, 14.7492, 14.8373; upper bound 14.8614 < 15.0) decisively FAIL.",
        ),
        (
            "R3P_H180_65um_Bed30_AlphaNom",
            "R3P_30",
            30.0,
            r3p_h180_30_nom_live,
            1.097,
            "verify_iip0034_planar_and_portfolio.solve_planar_route3p_fvm",
            "BOTH linear (14.8297 mmHg) and true 3D FVM (14.9062 mmHg) FAIL at m_vasc=1.3164 (+20% above 1.097x); pre-committed derating action: require qualified bed pO2 >= 35 mmHg or pre-vascularized bed / reduced loading density.",
        ),
        (
            "R3P_H180_65um_Bed30_KRBH_Alpha1p27e9",
            "R3P_30_KRBH",
            30.0,
            r3p_h180_30_krbh_live,
            1.097,
            "verify_iip0034_planar_and_portfolio.solve_planar_route3p_fvm",
            "ALREADY FAILS LIVE at 14.4198 mmHg (and 14.0951 mmHg at m_vasc=1.3164) under physiological KRBH alpha=1.27e-9; disqualified without P_bed >= 35 mmHg or pre-vascularization.",
        ),
        (
            "R3P_H180_VPIO120_Bed35_AlphaNom",
            "R3P_35_VPIO120",
            35.0,
            r3p_h180_35_vpio120_live,
            1.097,
            "verify_iip0034_planar_and_portfolio.solve_planar_route3p_fvm",
            "GENUINE LINEAR-VS-3D REVERSAL: at matched +20% (m_vasc=1.3164 above 1.097x), linearized screen FAILS (14.8656 mmHg) while true 3D FVM PASSES (15.1005 mmHg >= 15.0 unrounded); margin is +0.1005 mmHg so measured OCR+uncertainty reaching floor triggers strict <= 65 um cluster sieving or area expansion.",
        ),
    ]

    marginal_corners = []
    for cid, rkey, p_bed, base_val, base_ocr, op_name, action_txt in corner_specs:
        rep = replays_map.get(rkey, {})
        base_unrounded = float(rep.get("baseline_3d_fvm_face_min_unrounded_mmhg", base_val))
        lin_matched_1p3164 = _lin_at_vasc_target(p_bed, base_unrounded, base_ocr, m_vasc_true_plus20)
        lin_matched_plus20 = _lin_at_vasc_target(p_bed, base_unrounded, base_ocr, base_ocr * 1.20)
        true_3d_val = rep.get("vasc_1p3164_3d_fvm_face_min_mmhg")
        true_3d_unrounded = rep.get("vasc_1p3164_3d_fvm_face_min_unrounded_mmhg")
        lin_pass_1p3164 = _passes_unrounded_15mmhg_floor(lin_matched_1p3164)
        fvm_pass_1p3164 = rep.get("passes_15mmhg_at_vasc_1p3164_3d_fvm_unrounded")
        corner_entry: Dict[str, Any] = {
            "corner_id": cid,
            "replay_key": rkey,
            "route_specific_3d_fvm_operator": op_name,
            "p_bed_mmhg": p_bed,
            "baseline_operator_ocr_mult": base_ocr,
            "live_baseline_min_face_mmhg": round(base_unrounded, 4),
            "baseline_margin_above_15mmhg": round(base_unrounded - 15.0, 4),
            "matched_vasc_1p3164_increment_pct_above_baseline": round(((m_vasc_true_plus20 / base_ocr) - 1.0) * 100.0, 2),
            "matched_linearized_screen_at_vasc_1p3164_mmhg": round(lin_matched_1p3164, 4),
            "matched_linearized_passes_15mmhg_at_vasc_1p3164": lin_pass_1p3164,
            "true_3d_fvm_at_vasc_1p3164_unrounded_mmhg": true_3d_unrounded,
            "true_3d_fvm_at_vasc_1p3164_mmhg": true_3d_val,
            "true_3d_fvm_passes_15mmhg_at_vasc_1p3164_unrounded": fvm_pass_1p3164,
            "genuine_linear_vs_3d_reversal_at_matched_perturbation": (
                bool(lin_pass_1p3164 != fvm_pass_1p3164) if fvm_pass_1p3164 is not None else None
            ),
            "linearized_vascular_ocr_breach_pct": _lin_breach_pct(p_bed, base_unrounded),
            "two_point_linear_extrapolated_3d_breach_pct_not_exact_3d_threshold": rep.get(
                "two_point_linear_extrapolated_breach_pct_not_exact_3d_threshold"
            ),
            "executable_trigger_function": "evaluate_nw08_measured_ocr_trigger",
            "precommitted_derating_action": action_txt,
        }
        if rkey == "R1_390_stress":
            corner_entry["matched_plus20pct_above_1p2067_comparison"] = {
                "target_vasc_ocr_mult": round(base_ocr * 1.20, 5),
                "linearized_min_face_mmhg": round(lin_matched_plus20, 4),
                "linearized_passes_15mmhg": _passes_unrounded_15mmhg_floor(lin_matched_plus20),
                "true_3d_fvm_min_face_unrounded_mmhg": rep.get("matched_plus20pct_3d_fvm_face_min_unrounded_mmhg"),
                "true_3d_fvm_min_face_mmhg": rep.get("matched_plus20pct_3d_fvm_face_min_mmhg"),
                "true_3d_fvm_passes_15mmhg_unrounded": rep.get("passes_15mmhg_at_matched_plus20pct_3d_fvm_unrounded"),
                "linear_and_3d_agree": (
                    bool(_passes_unrounded_15mmhg_floor(lin_matched_plus20) == rep.get("passes_15mmhg_at_matched_plus20pct_3d_fvm_unrounded"))
                    if rep.get("passes_15mmhg_at_matched_plus20pct_3d_fvm_unrounded") is not None
                    else None
                ),
            }
        marginal_corners.append(corner_entry)

    # Explicitly source-typed 5-lineage calibration matrix (zero unbacked donor-level HPAP label;
    # Layer-4 1.000x basal = 2.312 fmol/min/cell vs 1.097x stimulated = 2.536 [~2.54] fmol/min/cell!)
    calibration_table_5lineages = [
        {
            "lineage": "beta",
            "graft_cell_count": GRAFT_COMPOSITION_CELLS["beta"],
            "graft_share_pct": round(100.0 * GRAFT_COMPOSITION_CELLS["beta"] / TOTAL_GRAFT_CELLS, 2),
            "ocr_evidence_source_type": "literature_whole_islet_group_mean_and_layer4_design_upper_envelope",
            "ocr_fmol_min_cell_reference_range": (
                "0.73 - 2.31 basal / 2.54 stimulated (external whole-preparation clinical autoislet basal group mean: "
                "Papas 2015 PMID:26258815 1.144-1.196 pmol/min/IEQ = 0.73-0.77 fmol/min/cell at 10.4 ng DNA/IE & "
                "standard ~6.67 pg diploid DNA/cell; Layer-4 1.000x basal endocrine design point = 2.312 fmol/min/cell; "
                "Layer-4 1.097x stimulated endocrine design point = 2.536 [~2.54] fmol/min/cell; neither is a directly "
                "measured single-cell beta OCR or donor-level HPAP OCR)"
            ),
            "surface_nk_complement_ccby4": "CD46+/CD55+/CD59+ mature (CDC-resistant, ADCC-susceptible: PMID:27787618 Diabetologia); PVR/CD155 & CD276/B7-H3 activating ligands in SC-islet/EP grafts (PMID:41403780 humanized mouse)",
            "antiviral_isg_apoptosis_ccby4": "Immunogold EM localizes CAR-SIV to dense-core insulin secretory granules in human islets (PMID:30074059; observational localization, zero KO/GSIS assays); TYK2-dependent IFN-a/HLA-I (PMID:36289205); IFIH1 rs1990760 IFN-b/l1/l2 (PMID:28000722); adenoviral rat BCL2L1 overexpression rescues rat INS-1E (~40%, slight Ca2+/GSIS reduction) and human EndoC-bH1 (>80%, no GSIS penalty) upstream of mitochondria (PMID:36982731)",
            "ccby4_primary_pmids": ["26258815", "35241836", "37188763", "38956087", "27787618", "41403780", "30074059", "36289205", "28000722", "36982731"],
        },
        {
            "lineage": "alpha",
            "graft_cell_count": GRAFT_COMPOSITION_CELLS["alpha"],
            "graft_share_pct": round(100.0 * GRAFT_COMPOSITION_CELLS["alpha"] / TOTAL_GRAFT_CELLS, 2),
            "ocr_evidence_source_type": "literature_whole_islet_proxy_and_transcriptomic_annotation",
            "ocr_fmol_min_cell_reference_range": "0.60 - 1.50 (assumed modeling range informed by whole-islet OCR & single-cell mitochondrial annotations in PMID:35241836, PMID:38956087; NOT directly measured lineage-specific product OCR)",
            "surface_nk_complement_ccby4": "Endocrine CD46+/CD55+/CD59+ complement regulators (PMID:27787618); SC-islet PVR/CD155 & CD276 context (PMID:41403780)",
            "antiviral_isg_apoptosis_ccby4": "Higher basal/induced STAT1 antiviral clearance in primary rat alpha vs beta cells with separate human islet transcriptomic arm (PMID:26061776); distinct human islet ER/cytokine stress regulons (PMID:38956087); downstream iCasp9/AP20187 escape governed by iCasp9 abundance & XIAP/Caspase-3 ratio in HeLa cells (PMID:35013114; zero islet assays) -> mandates direct empirical Gate 0V-Kill per-lineage verification",
            "ccby4_primary_pmids": ["35241836", "37188763", "38956087", "26061776", "36982731", "35013114", "27787618"],
        },
        {
            "lineage": "delta",
            "graft_cell_count": GRAFT_COMPOSITION_CELLS["delta"],
            "graft_share_pct": round(100.0 * GRAFT_COMPOSITION_CELLS["delta"] / TOTAL_GRAFT_CELLS, 2),
            "ocr_evidence_source_type": "whole_islet_proxy_no_direct_lineage_respirometry",
            "ocr_fmol_min_cell_reference_range": "0.50 - 1.40 (modeling proxy bundled within whole-islet Papas/Balboa OCR; zero direct purified human delta-cell respirometry)",
            "surface_nk_complement_ccby4": "Endocrine CD46+/CD55+/CD59+ (PMID:27787618); SC-islet multi-ome chromatin/transcriptome annotation (PMID:37188763)",
            "antiviral_isg_apoptosis_ccby4": "Distinct ER/cytokine stress regulons in human islets (PMID:38956087); completely unscreened in legacy beta-only Gate 0V",
            "ccby4_primary_pmids": ["35241836", "37188763", "38956087", "27787618"],
        },
        {
            "lineage": "plvap_iec",
            "graft_cell_count": GRAFT_COMPOSITION_CELLS["plvap_iec"],
            "graft_share_pct": round(100.0 * GRAFT_COMPOSITION_CELLS["plvap_iec"] / TOTAL_GRAFT_CELLS, 2),
            "ocr_evidence_source_type": "literature_cultured_huvec_stress_sensitivity_and_model_allowance",
            "ocr_fmol_min_cell_reference_range": "0.15 - 0.55 (model allowance for glycolytic endothelium; cultured replicatively senescent primary HUVECs show ~+20% higher basal OCR in Stabenow 2022 Cells Fig. 3A PMID:35883656 — external stress sensitivity, NOT graft-specific PLVAP+ iEC measurement)",
            "surface_nk_complement_ccby4": "Constitutive CD46/CD55/CD59 + THBD vascular thrombo-protection; PLVAP/ESM1/KDR primary human islet EC identity (factual PMID:39915484); requires >=180k CD47 p10",
            "antiviral_isg_apoptosis_ccby4": "Supports vascular-macrophage crosstalk during CVB4/viral infection in human VMI organoids (PMID:39232561); cultured primary human islet ECs express CAR/DAF and sustain non-lytic CVB4 (factual PMID:17494992)",
            "ccby4_primary_pmids": ["35883656", "37548091", "39232561"],
        },
        {
            "lineage": "pericyte",
            "graft_cell_count": GRAFT_COMPOSITION_CELLS["pericyte"],
            "graft_share_pct": round(100.0 * GRAFT_COMPOSITION_CELLS["pericyte"] / TOTAL_GRAFT_CELLS, 2),
            "ocr_evidence_source_type": "model_engineering_allowance_pending_product_respirometry",
            "ocr_fmol_min_cell_reference_range": "0.15 - 0.50 (engineering model allowance inside Layer-4 15% vascular OCR budget; 3.58% graft share; zero direct human islet pericyte OCR dataset)",
            "surface_nk_complement_ccby4": "NG2+/PDGFRB+ mural markers; vulnerable to myofibroblast conversion & microvascular dysfunction in T1D (factual PMID:37531253, PMID:29514070)",
            "antiviral_isg_apoptosis_ccby4": "Viral spike S1 induces mural ACE2 stripping & capillary constriction in human pancreas slices (factual PMID:39715591); zero prior Gate 0V viral or AP1903 surveillance",
            "ccby4_primary_pmids": ["39232561"],
        },
    ]

    return {
        "layer4_design_constants": {
            "pure_endocrine_vmax_pmol_min_ieq": round(l4_pure_ieq_pmol_min, 6),
            "whole_prep_1p00x_with_15pct_vasc_pmol_min_ieq": round(l4_whole_1p00_pmol_min, 6),
            "whole_prep_1p097x_chronic_pmol_min_ieq": round(l4_whole_1p097_pmol_min, 6),
            "pure_endocrine_1p00x_basal_fmol_min_cell": round(l4_pure_1p00_fmol_min_cell, 4),
            "pure_endocrine_1p097x_stimulated_fmol_min_cell": round(l4_pure_1p097_fmol_min_cell, 4),
            "d_o2_islet_tissue_cm2_s_live_run_layer4": d_o2_islet,
            "d_o2_gel_chronic_cm2_s": d_o2_gel_chronic,
            "papas2015_external_wholeprep_autoislet_id_pmol_min_ieq": round(papas_human_id_pmol_min_ieq, 6),
            "papas2015_external_wholeprep_autoislet_ii_pmol_min_ieq": round(papas_human_ii_pmol_min_ieq, 6),
            "cells_per_ieq_from_10p4ng_papas_and_6p67pg_standard_diploid_dna": round(cells_per_ieq_standard_diploid, 2),
            "l4_conservative_headroom_over_papas_basal_fold": round(l4_pure_ieq_pmol_min / papas_human_ii_pmol_min_ieq, 3),
        },
        "live_fvm_baselines_read_programmatically": {
            "route1_390um_staggered_nominal1p097_nx80_mmhg": round(r1_390_nom_live, 4),
            "route2_designz_140um_40mmhg_chronic1p097_mmhg": round(r2_dz_40_live, 4),
            "route3p_hybrid333_h180_35mmhg_65um_clean_mmhg": round(r3p_h180_35_live, 4),