OpenIslet

scripts/verify_wave7_cellgemma_2p24_rebase.py

Wave-7 CellGemma-Islet (IIP-0062 to IIP-0065 / GATE-40 to GATE-43) Pure-CPU

script Release v0.8.0 gen-eb955f8266035aba 1.37 MB · 90 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_wave7_cellgemma_2p24_rebase.py · SHA-256: 5f31a6369f25031d…

    chk("FAIL_DUAL_SWITCH_ORTHOGONAL_NON_INTERFERENCE_UNVERIFIED" in evaluate_gate40_pirfenidone_h4({**g40_ok, "native_switch_evidence": _sign_receipt({**sw_y, "orthogonal_gcv_cid_non_interference": False})})["failures"], "G40_dual_orthog")
    chk("HOLD_GATE0V_KILL_EVIDENCE_MISSING" in evaluate_gate40_pirfenidone_h4({**g40_ok, "gate0v_evidence": None})["holds"], "G40_g0v_missing")
    chk("FAIL_NATIVE_SAFETY_SWITCH_MISMATCH_FOR_PRODUCT" in evaluate_gate40_pirfenidone_h4({**g40_ok, "native_switch_evidence": _sign_receipt({**sw_y, "switch_name": "TBP_ICASP9"})})["failures"], "G40_sw_mismatch")
    chk("HOLD_CANONICAL_BANK_MATERIALIZATION_MISSING" in evaluate_gate40_pirfenidone_h4({**g40_ok, "materialization_evidence": None})["holds"], "G40_mat_missing")
    chk("FAIL_A-0b_COATING_AND_BLANK_VEHICLE_LOT_IDENTICAL" in evaluate_gate40_pirfenidone_h4({**g40_bench, "a0b_evidence": _sign_receipt({**a0b_y, "matched_blank_vehicle_lot_id": coat_a["coating_lot_id"]})})["failures"], "G40_same_coat_veh")
    chk("FAIL_GATE_A0B_WORST_FACE_O2_BELOW_40MMHG" in evaluate_gate40_pirfenidone_h4({**g40_bench, "a0b_evidence": _sign_receipt({**a0b_y, "worst_face_o2_mmhg": 35.0})})["failures"], "G40_a0b_o2")
    chk("FAIL_GATE_A0B_DAY14_VIABILITY_BELOW_90PCT" in evaluate_gate40_pirfenidone_h4({**g40_bench, "a0b_evidence": _sign_receipt({**a0b_y, "day14_viability_pct": 85.0})})["failures"], "G40_a0b_viab")
    chk("FAIL_GATE_A0B_DAY14_SPROUTING_BELOW_90PCT" in evaluate_gate40_pirfenidone_h4({**g40_bench, "a0b_evidence": _sign_receipt({**a0b_y, "day14_sprouting_pct": 84.0})})["failures"], "G40_a0b_spr")
    chk("FAIL_GATE_A2_DAY14_IEC_VCAM1_GT_1P25" in evaluate_gate40_pirfenidone_h4({**g40_ok, "a2_evidence": _sign_receipt({**a2_y, "day14_iec_vcam1_adhesion_fold": 1.45})})["failures"], "G40_a2_vcam")
    chk("FAIL_GATE_A2_WORST_FACE_O2_BELOW_40MMHG" in evaluate_gate40_pirfenidone_h4({**g40_ok, "a2_evidence": _sign_receipt({**a2_y, "worst_face_o2_mmhg": 32.0})})["failures"], "G40_a2_o2")
    chk("FAIL_GATE_A4A_DAY14_VIABILITY_BELOW_90PCT" in evaluate_gate40_pirfenidone_h4({**g40_ok, "a4a_evidence": _sign_receipt({**a4a_y, "day14_viability_pct": 80.0})})["failures"], "G40_a4a_viab")
    chk("FAIL_GATE_A4A_WORST_FACE_O2_BELOW_40MMHG" in evaluate_gate40_pirfenidone_h4({**g40_ok, "a4a_evidence": _sign_receipt({**a4a_y, "worst_face_o2_mmhg": 30.0})})["failures"], "G40_a4a_o2")
    chk("FAIL_GATE_A0A_ENDPOINTS_UNBRACKETED" in evaluate_gate40_pirfenidone_h4({"phase": "ROUTE_FREE_A0A", "a0a_evidence": _sign_receipt({**a0a_ok, "endpoints_bracketed": False})})["failures"], "G40_a0a_unbrack")
    chk("FAIL_GATE_A0A_FU_OUT_OF_DOMAIN" in evaluate_gate40_pirfenidone_h4({"phase": "ROUTE_FREE_A0A", "a0a_evidence": _sign_receipt({**a0a_ok, "fu_measured": 1.2})})["failures"], "G40_a0a_fu")
    chk("FAIL_GATE_A0B_WATER_EQUIV_DIFF_PATH_GT_50UM" in evaluate_gate40_pirfenidone_h4({**g40_bench, "a0b_evidence": _sign_receipt({**a0b_y, "water_equiv_diff_path_um": 65.0})})["failures"], "G40_a0b_wpath")
    chk("FAIL_GATE_A1_DAY14_INTACT_PARENT_BELOW_IC50_U95" in evaluate_gate40_pirfenidone_h4({**g40_ok, "a1_evidence": _sign_receipt({**a1_y, "day14_intact_parent_free_uM": 50.0})})["failures"], "G40_a1_d14_low")
    chk("FAIL_GATE_A1_DAY35_INTACT_PARENT_NOT_EXHAUSTED" in evaluate_gate40_pirfenidone_h4({**g40_ok, "a1_evidence": _sign_receipt({**a1_y, "day35_intact_parent_free_uM": 15.0})})["failures"], "G40_a1_d35_hi")

    # ========================================================================
    # GATE-41 (80 tests: 70 prior + 10 adversarial closures)
    # ========================================================================
    coat_b = _mk_r8_coating("DEUC-R3P")
    bv_b = coat_b["matched_blank_vehicle_lot_id"]
    b0a_s_units = ["SAFE-U1", "SAFE-U2", "SAFE-U3", "SAFE-U4", "SAFE-U5", "SAFE-U6"]
    _b0a_d6 = (-0.38, -0.20, -0.06, 0.06, 0.20, 0.38)
    def _mk_b0a_raw_ratio(pcts: Sequence[float], veh_id: str, base_v: float, *, is_inhib: bool = False) -> dict[str, Any]:
        vehs = [round(base_v * (1.0 + 0.01 * (j - 2.5)), 4) for j in range(len(pcts))]
        if is_inhib:
            trs = [round(vehs[j] * (1.0 - float(pcts[j]) / 100.0), 4) for j in range(len(pcts))]
        else:
            trs = [round(vehs[j] * (float(pcts[j]) / 100.0), 4) for j in range(len(pcts))]
        return {"vehicle_record_id": veh_id, "treated": trs, "vehicle": vehs}

    b0a_s_reps_ok = [
        (lambda _vid, _sp, _nk, _cd, _il: {
            "unit_ids": b0a_s_units,
            "matched_vehicle_record_id": _vid,
            "sprouting_pct": _sp,
            "nkg2a_pct": _nk,
            "cd94_pct": _cd,
            "il10_retention_pct": _il,
            "raw_unit_measurements": {
                "sprouting_pct": _mk_b0a_raw_ratio(_sp, _vid, 400.0),
                "nkg2a_pct": _mk_b0a_raw_ratio(_nk, _vid, 12000.0),
                "cd94_pct": _mk_b0a_raw_ratio(_cd, _vid, 9500.0),
                "il10_retention_pct": _mk_b0a_raw_ratio(_il, _vid, 850.0),
            },
        })(
            f"B0A-VEH-CONC-{idx_b}",
            [round(s + d, 2) for d in _b0a_d6],
            [round(n + d, 2) for d in _b0a_d6],
            [round(c + d, 2) for d in _b0a_d6],
            [round(il + d, 2) for d in _b0a_d6],
        )
        for idx_b, (s, n, c, il) in enumerate(zip(
            [100.0, 99.0, 98.0, 97.0, 95.0, 93.0, 82.0, 65.0],
            [100.0, 99.0, 98.0, 96.0, 94.0, 91.0, 78.0, 60.0],
            [100.0, 99.0, 97.0, 96.0, 94.0, 90.0, 76.0, 58.0],
            [100.0, 98.0, 96.0, 94.0, 90.0, 86.0, 70.0, 50.0],
        ))
    ]
    b0a_e_units = ["EFF-U1", "EFF-U2", "EFF-U3", "EFF-U4", "EFF-U5", "EFF-U6"]
    b0a_eb_grid = [0.0, 24.0, 50.0, 72.0, 86.0, 93.0, 97.0, 98.5]
    b0a_en_grid = [0.0, 23.0, 49.0, 70.0, 85.0, 92.5, 96.5, 98.2]
    b0a_ei_grid = [0.0, 22.0, 48.0, 68.0, 84.0, 92.0, 96.0, 98.0]
    b0a_e_reps_ok = [
        (lambda _vid, _eb, _en, _ei: {
            "unit_ids": b0a_e_units,
            "matched_vehicle_record_id": _vid,
            "beta_cytokine_protection_pct": _eb,
            "nk_cytokine_suppression_pct": _en,
            "iec_ibmir_marker_suppression_pct": _ei,
            "raw_unit_measurements": {
                "beta_cytokine_protection_pct": _mk_b0a_raw_ratio(_eb, _vid, 100.0, is_inhib=True),
                "nk_cytokine_suppression_pct": _mk_b0a_raw_ratio(_en, _vid, 500.0, is_inhib=True),
                "iec_ibmir_marker_suppression_pct": _mk_b0a_raw_ratio(_ei, _vid, 250.0, is_inhib=True),
            },
        })(
            f"B0A-EFF-VEH-CONC-{idx_e}",
            [round(eb_v + d, 2) for d in _b0a_d6],
            [round(en_v + d, 2) for d in _b0a_d6],
            [round(ei_v + d, 2) for d in _b0a_d6],
        )
        for idx_e, (eb_v, en_v, ei_v) in enumerate(zip(b0a_eb_grid, b0a_en_grid, b0a_ei_grid))
    ]
    b0a_an_ok = _sign_receipt({
        "analysis_method": "SIMULTANEOUS_BONFERRONI_GRID_BRACKET_STUDENT_T",
        "efficacy_combination_rule": "CONJUNCTIVE_MAX_EC50_U95_ACROSS_ALL_3_ENDPOINTS",
        "efficacy_endpoints_tested": [
            "beta_cytokine_protection_pct",
            "iec_ibmir_marker_suppression_pct",
            "nk_cytokine_suppression_pct",
        ],
        "efficacy_unit_ids": b0a_e_units,
        "safety_unit_ids": b0a_s_units,
        "raw_efficacy_replicates_sha256": sha256_bytes(canonical_json_bytes(b0a_e_reps_ok)),
        "raw_safety_replicates_sha256": sha256_bytes(canonical_json_bytes(b0a_s_reps_ok)),
        "analysis_record_sha256": "a" * 64,
        "ec50_eff_u95_free_nM": 6.0, "c_safe_max_bench_l95_free_nM": 25.0,
    })
    b0a_ok = _sign_receipt({
        "stage": "B-0a", "verdict": "PASS", "evidence_scope": "route_free",
        "recorded_at_utc": "2026-08-01T08:00:00Z", "endpoints_bracketed": True,
        "analysis_record_sha256": "a" * 64,
        "lloq_parent_by_matrix_nM": {"low_serum_media": 0.05, "human_serum_100pct": 0.05, "whole_blood": 0.05},
        "lloq_bmt_by_matrix_nM": {"low_serum_media": 0.05, "human_serum_100pct": 0.05, "whole_blood": 0.05},
        "fu_parent_by_matrix": {"low_serum_media": 0.85, "human_serum_100pct": 0.14, "whole_blood": 0.11},
        "fu_bmt_by_matrix": {"low_serum_media": 0.86, "human_serum_100pct": 0.15, "whole_blood": 0.12},
        "tested_free_conc_grid_nM": [0.0, 1.0, 3.0, 6.0, 12.0, 25.0, 50.0, 100.0],
        "efficacy_inhibition_pct_grid": list(b0a_ei_grid),
        "efficacy_beta_protection_pct_grid": list(b0a_eb_grid),
        "efficacy_nk_suppression_pct_grid": list(b0a_en_grid),
        "efficacy_iec_ibmir_pct_grid": list(b0a_ei_grid),
        "safety_sprouting_pct_grid": [100.0, 99.0, 98.0, 97.0, 95.0, 93.0, 82.0, 65.0],
        "safety_nkg2a_pct_grid": [100.0, 99.0, 98.0, 96.0, 94.0, 91.0, 78.0, 60.0],
        "safety_cd94_pct_grid": [100.0, 99.0, 97.0, 96.0, 94.0, 90.0, 76.0, 58.0],
        "safety_il10_retention_pct_grid": [100.0, 98.0, 96.0, 94.0, 90.0, 86.0, 70.0, 50.0],
        "safety_replicates_by_conc": b0a_s_reps_ok,
        "efficacy_replicates_by_conc": b0a_e_reps_ok,
        "b0a_analysis_receipt": b0a_an_ok,
        "ec50_eff_u95_free_nM": 6.0, "c_safe_max_bench_l95_free_nM": 25.0,
    })
    def _mk_b0b_pk_model(b0a_sha: str, **ov: Any) -> dict[str, Any]:
        body: dict[str, Any] = {
            "b0a_receipt_sha256": b0a_sha,
            "pk_model_protocol_sha256": "c" * 64,
            "modeled_day1_burst_pct": 14.0,
            "modeled_days0_10_parent_l95_free_nM": 7.2,
            "modeled_days0_21_combined_peak_u95_free_nM": 19.5,
            "modeled_systemic_combined_cmax_u95_total_nM": 0.12,
            "alpha_conc": 0.025, "alpha_fu_parent": 0.0125, "alpha_fu_bmt": 0.0125,
            "used_marginal_u95_sum": False, "lloq_censoring_allocated": True,
        }
        body.update(ov)
        return {**body, "model_receipt_sha256": sha256_bytes(canonical_json_bytes(body))}

    b0b_pk_ok = _mk_b0b_pk_model(b0a_ok["receipt_sha256"])
    b0b_y = _sign_receipt({
        "stage": "B-0b", "verdict": "PASS", "product_id": py, "bank_id": by, "lot_id": ly, "route_id": ry,
        "evidence_scope": "bench_unedited", "recorded_at_utc": "2026-08-05T09:00:00Z",
        "parent_receipt_sha256": b0a_ok["receipt_sha256"], **coat_b,
        "coating_thickness_um": 3.5, "worst_face_o2_mmhg": 44.0,
        "local_ph_min": 7.32, "local_ph_max": 7.40, "mass_balance_margin_verified": True,
        "route_clearance_l_per_day": 6.0, "target_total_conc_nM": 50.0, "active_duration_days": 10.0,
        "loaded_api_mass_mg": 2.0, "usable_recovery_fraction": 0.80,
        "provisional_pk_model_receipt": b0b_pk_ok,
    })
    _b2b_ref_tps = _mk_r8_b2b_replicates()["timepoint_replicate_records"]
    def _mk_b12_ledger(stage_tag: str, tps: Sequence[Mapping[str, Any]] = _b2b_ref_tps, *, assay_matrix: str = "human_serum_100pct", recirc_assay_matrix: str = "human_serum_100pct") -> list[dict[str, Any]]:
        out_lg: list[dict[str, Any]] = []
        for _tr in tps:
            _is_b2 = abs(float(_tr["hour_h"]) - 2.0) <= 1e-6
            if (stage_tag == "B-2" and not _is_b2) or (stage_tag == "B-1" and _is_b2):
                continue
            for _ri_l, _sid_l in enumerate(_tr["source_sample_ids"]):
                _buid_l = str(_tr["biological_unit_ids"][_ri_l]).strip().upper()
                _row_obj = {
                    "sample_id": str(_sid_l).strip().upper(),
                    "hour_h": float(_tr["hour_h"]),
                    "assay_matrix": assay_matrix,
                    "recirc_assay_matrix": recirc_assay_matrix,
                    "biological_unit_id": _buid_l,
                    "local_parent_total_nM": float(_tr["local_parent_total_replicates_nM"][_ri_l]), "local_parent_blq": bool(_tr["local_parent_blq_flags"][_ri_l]),
                    "local_bmt_total_nM": float(_tr["local_bmt_total_replicates_nM"][_ri_l]), "local_bmt_blq": bool(_tr["local_bmt_blq_flags"][_ri_l]),
                    "recirc_bmt_total_nM": float(_tr["recirc_bmt_total_replicates_nM"][_ri_l]), "recirc_bmt_blq": bool(_tr["recirc_bmt_blq_flags"][_ri_l]),
                    "systemic_parent_total_nM": float(_tr["systemic_parent_total_replicates_nM"][_ri_l]), "systemic_parent_blq": bool(_tr["systemic_parent_blq_flags"][_ri_l]),
                    "systemic_bmt_total_nM": float(_tr["systemic_bmt_total_replicates_nM"][_ri_l]), "systemic_bmt_blq": bool(_tr["systemic_bmt_blq_flags"][_ri_l]),
                }
                out_lg.append({
                    "sample_id": _sid_l, "hour_h": float(_tr["hour_h"]), "source_stage": stage_tag,
                    "assay_matrix": assay_matrix, "recirc_assay_matrix": recirc_assay_matrix, "biological_unit_id": _buid_l,
                    "raw_analytical_row_sha256": sha256_bytes(canonical_json_bytes(_row_obj)),
                })
        return out_lg
    b1_ledger_ok = _mk_b12_ledger("B-1")
    b2_ledger_ok = _mk_b12_ledger("B-2")
    b1_y = _sign_receipt({
        "stage": "B-1", "verdict": "PASS", "product_id": py, "bank_id": by, "lot_id": ly, "route_id": ry,
        "evidence_scope": "bench_unedited", "elution_started_at_utc": "2026-08-06T09:00:00Z",
        "recorded_at_utc": "2026-08-28T09:00:00Z", "parent_receipt_sha256": b0b_y["receipt_sha256"], **coat_b,
        "day1_burst_pct": 14.0, "day21_effluent_total_nM": 3.5, "day21_effluent_free_nM": 0.45,
        "day21_depot_depletion_pct": 91.0, "day21_elution_verified": True, "terminal_mass_recovery_pct": 97.0,
        "analytical_sample_ledger": b1_ledger_ok,
    })
    b2_y = _sign_receipt({
        "stage": "B-2", "verdict": "PASS", "product_id": py, "bank_id": by, "lot_id": ly, "route_id": ry,
        "evidence_scope": "bench_unedited", "recorded_at_utc": "2026-09-05T10:00:00Z",
        "parent_receipt_sha256": b1_y["receipt_sha256"], **coat_b,
        "enrolled_donors_n": 6, "excluded_invalid_donors_n": 0, "invalid_donor_exclusion_log": [],
        "donor_records": _mk_r8_b2_donors(),
        "analytical_sample_ledger": b2_ledger_ok,
        "iec_sprouting_pct_ctrl": 95.0, "iec_birc5_viability_pct": 94.0,
        "iec_txnip_fold": 1.10, "iec_ros_fold": 1.05, "iec_cd274_pct_ctrl": 92.0, "iec_hlae_pct_ctrl": 93.0,
        "iec_pgf_pct_ctrl": 91.0, "iec_c3_fold_vs_ctrl": 1.08,
    })
    b2bb_y = _sign_receipt({
        "stage": "B-2b-bench", "verdict": "PASS", "product_id": py, "bank_id": by, "lot_id": ly, "route_id": ry,
        "evidence_scope": "bench_unedited", "recorded_at_utc": "2026-09-12T10:00:00Z",
        "parent_receipt_sha256": b2_y["receipt_sha256"],
        "prerequisite_receipt_sha256s": {"B-1": b1_y["receipt_sha256"], "B-2": b2_y["receipt_sha256"]}, **coat_b,
        "used_marginal_u95_sum": False, "alpha_conc": 0.025, "alpha_fu_parent": 0.0125, "alpha_fu_bmt": 0.0125,
        "u95_joint_peak_free_nM": 20.8, "days0_10_parent_lower_free_nM": 7.0,
        **_mk_r8_b2b_replicates(),
        "c_bmt_local_total_u_alloc_nM": 0.04, "c_bmt_local_free_u_alloc_nM": 0.02,
        "c_bmt_recirc_total_u_alloc_nM": 0.03, "c_bmt_recirc_free_u_alloc_nM": 0.02,
        "censoring_audit_passed": True, "intersample_peak_envelope_justified": True,
        "systemic_exposure_below_cap": True, "mixture_requalified": False,
    })
    mat_y40 = _mk_r8_mat(py, by, ly, "2026-09-15T08:00:00Z")
    b0a_ex_y = _sign_receipt({
        "stage": "B-0a-exact", "verdict": "PASS", "product_id": py, "bank_id": by, "lot_id": ly, "route_id": ry,
        "evidence_scope": "exact_product", "recorded_at_utc": "2026-09-20T09:00:00Z",
        "parent_receipt_sha256": mat_y40["receipt_sha256"],
        "prerequisite_receipt_sha256s": {"B-0a": b0a_ok["receipt_sha256"], "B-2b-bench": b2bb_y["receipt_sha256"], "BANK_MATERIALIZATION": mat_y40["receipt_sha256"]},
        **coat_b,
        "endpoints_bracketed": True, "analysis_record_sha256": "b" * 64,
        "tested_free_conc_grid_nM": [0.0, 5.0, 12.0, 22.0, 45.0, 90.0],
        "cassette_retention_pct_grid": [100.0, 97.0, 94.0, 91.0, 80.0, 62.0],
        "cassette_retention_replicates_by_conc": [
            (lambda _vid, _tech, _blk: {
                "unit_ids": ["B0AEX-BLK-1", "B0AEX-BLK-2", "B0AEX-BLK-3", "B0AEX-BLK-4", "B0AEX-BLK-5"],
                "matched_vehicle_record_id": _vid,
                "technical_replicates_per_unit_pct": _tech,
                "cassette_retention_pct": _blk,
                "raw_unit_measurements": {
                    "vehicle_record_id": _vid,
                    "vehicle_by_unit_tech": [[1000.0, 1005.0, 995.0] for _ in _tech],
                    "treated_by_unit_tech": [
                        [round(vh * pct / 100.0, 4) for vh, pct in zip((1000.0, 1005.0, 995.0), tw)]
                        for tw in _tech
                    ],
                },
            })(
                f"B0AEX-VEH-{int(c_nm)}NM",
                [[round(v + d - 0.1, 2), round(v + d, 2), round(v + d + 0.1, 2)] for d in (-0.4, -0.2, 0.0, 0.2, 0.4)],
                [round(v + d, 2) for d in (-0.4, -0.2, 0.0, 0.2, 0.4)],
            )
            for c_nm, v in zip((0.0, 5.0, 12.0, 22.0, 45.0, 90.0), (100.0, 97.0, 94.0, 91.0, 80.0, 62.0))
        ],
        "c_safe_max_exact_l95_free_nM": 22.0, "exact_cassette_retention_at_csafe_pct": 91.5,
        "hour0_density_at_csafe_by_lineage": _mk_r8_hour0(py),
    })
    sw_y40 = _mk_r8_switch(py, by, ly, ry, mat_y40, "2026-10-08T09:00:00Z", coating_identity=coat_b)
    g0v_y40 = _mk_r8_gate0v(py, by, ly, ry, mat_y40, "2026-10-08T09:30:00Z", coating_identity=coat_b)
    pr_mat_40 = {"BANK_MATERIALIZATION": mat_y40["receipt_sha256"]}
    pr_b2be = {
        "BANK_MATERIALIZATION": mat_y40["receipt_sha256"], "B-0a-exact": b0a_ex_y["receipt_sha256"],
        "B-1": b1_y["receipt_sha256"], "B-2": b2_y["receipt_sha256"],
    }
    pr_all_40 = {