OpenIslet

scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py

Provisional IIP-0058 / DEC-139 / GATE-37 / GY-036 (Round-14 Blueprint Alignment; staged in iip0058/):

script Release v0.8.0 gen-eb955f8266035aba 837 KB · 62 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_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py · SHA-256: 33439d619c00fcc3…

    *,
    evidence_tier: str = "SYNTHETIC_FIXTURE",
    lot_id: str = "SYN_LOT_GINS_001",
    bank_id: str = "SYN_BANK_GINS_001",
    construct_manifest_sha256: Optional[str] = None,
) -> dict[str, Any]:
    is_wl = evidence_tier == "AUTHENTICATED_ARCHIVED_WETLAB"
    csha = construct_manifest_sha256 or default_lot_construct_manifest_sha256("ISLET1_ARM_Z_GINS_WAVE7_RESERVE", lot_id)
    dec = "PASS_ELIGIBLE_FOR_WAVE7_PROMOTION" if is_wl else "SYNTHETIC_SELF_TEST_PASS"
    scope = "WAVE7_RESERVE_ONLY" if is_wl else "SYNTHETIC_SELF_TEST"
    study_id = "SYN_WAVE7_GINS_STUDY_001"
    vcn_assay_id = "DDPCR_VCN_GY036_001"
    rec = make_signed_evidence_record({
        "record_id": f"REC_GINS_{lot_id}",
        "gate_source": "GATE-37-GINS",
        "product_id": "ISLET1_ARM_Z_GINS_WAVE7_RESERVE",
        "lot_id": lot_id,
        "bank_id": bank_id,
        "bank_origin": "somatic_gastric_reprogrammed",
        "canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
        "construct_manifest_sha256": csha,
        "evidence_tier": evidence_tier,
        "decision": dec,
        "authority_scope": scope,
        "bank_qualified": False,
        "promotion_authorized": False,
        "study_id": study_id,
        "non_integrating_platform_verified": True,
        "vector_copy_number_per_cell": 0.0,
        "process_class": "NON_INTEGRATING_NPM",
        "vcn_assay_id": vcn_assay_id,
        "integrating_lentivirus_used": False,
        "tamoxifen_inducible_fusion_used": False,
        "liraglutide_free_perifusion": True,
        "alpha_coagg_monohormonal_gcg_pct": 27.0,
        "reaggregation_cluster_diameter_um": 95.0,
        "oq018_low_glucose_1mM_glucagon_fold": 2.2,
        "oq018_glucagon_auc_l95": 0.89,
        "stepdown_shutoff_t90_min": 2.5,
        "gastric_mucin_reversion_pct": 2.0,
        "mouse_durability_days": 195.0,
        "nhp_durability_days": 120.0,
        "nhp_n_tested": 3,
        "nhp_durability_pass_count": 3,
        "polyclonal_donor_count": 8,
        "polyclonal_t1d_pbmc_hla_dq_verified": True,
        "polyclonal_donor_survival_pct": 88.0,
    })
    return {
        "evidence_tier": evidence_tier,
        "canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
        "construct_manifest_sha256": csha,
        "product_id": "ISLET1_ARM_Z_GINS_WAVE7_RESERVE",
        "lot_id": lot_id,
        "bank_id": bank_id,
        "study_record_ref": study_id,
        "vcn_assay_id": vcn_assay_id,
        "process_class": "NON_INTEGRATING_NPM",
        "non_integrating_platform_verified": True,
        "vector_copy_number_per_cell": 0.0,
        "integrating_lentivirus_used": False,
        "tamoxifen_inducible_fusion_used": False,
        "liraglutide_free_perifusion": True,
        "alpha_coagg_monohormonal_gcg_pct": 27.0,
        "reaggregation_cluster_diameter_um": 95.0,
        "oq018_low_glucose_1mM_glucagon_fold": 2.2,
        "oq018_glucagon_auc_l95": 0.89,
        "stepdown_shutoff_t90_min": 2.5,
        "gastric_mucin_reversion_pct": 2.0,
        "durability_study_lot_id": lot_id,
        "mouse_durability_days": 195.0,
        "nhp_survival_days": 120.0,
        "nhp_n_tested": 3,
        "nhp_n_durable": 3,
        "polyclonal_donor_study_lot_id": lot_id,
        "polyclonal_t1d_pbmc_donors_n": 8,
        "polyclonal_t1d_pbmc_hla_dq_verified": True,
        "polyclonal_t1d_pbmc_survival_pct": 88.0,
        "study_evidence_record": rec,
    }


def build_trusted_evidence_store_for_fixture(payload: Mapping[str, Any]) -> dict[str, dict[str, Any]]:
    """Build a mock authenticated trusted_evidence_store indexing all upstream & current-assay records in payload."""
    store: dict[str, dict[str, Any]] = {}
    for k in (
        "lot_evidence_record",
        "itga1_live_cell_selectivity_record",
        "dual_failsafe_record",
        "gate0v_5lineage_record",
        "gate5_oq012_record",
        "genomic_qc_record",
        "current_assay_evidence_record",
        "study_evidence_record",
    ):
        rec = payload.get(k)
        if isinstance(rec, dict) and isinstance(rec.get("record_id"), str):
            store[rec["record_id"]] = dict(rec)
    return store


def run_executable_gate35_self_tests(ext_manifest: Optional[Mapping[str, Any]] = None) -> dict[str, Any]:
    """Synthetic fixture self-test suite verifying synthetic isolation & fail-closed adverse/missing probes.

    NOTE: Synthetic software self-tests ONLY — EVERY synthetic fixture MUST return
    promotion_authorized=False (decision='SYNTHETIC_SELF_TEST_PASS').
    """
    # Exact 75-digit Decimal Clopper-Pearson U95 boundary self-checks (Review #3 / Audit R4-02 / Round-14 live OQ-012)
    u95_pass_1e12 = clopper_pearson_u95_decimal(99_983_552, 10**12)
    u95_fail_1e12 = clopper_pearson_u95_decimal(99_983_553, 10**12)
    u95_fail_100k = clopper_pearson_u95_decimal(100_000, 1_005_216_927)
    u95_oq012_min = clopper_pearson_u95_decimal(0, MIN_GATE5_OQ012_EFFECTIVE_TRIALS)
    _require(u95_pass_1e12 <= Decimal("1e-4"), f"99,983,552/10^12 should be <= 1e-4, got {u95_pass_1e12}")
    _require(u95_fail_1e12 > Decimal("1e-4"), f"99,983,553/10^12 should be > 1e-4, got {u95_fail_1e12}")
    _require(u95_fail_100k > Decimal("1e-4"), f"100,000/1,005,216,927 should be > 1e-4, got {u95_fail_100k}")
    _require(u95_oq012_min <= MAX_GATE5_OQ012_U95, f"0/299,573,228 should be <= 1e-8, got {u95_oq012_min}")

    # Underflow-free zero-event U95 self-check at n = 10^17
    u95_1e17 = one_sided_clopper_pearson_u95(0, 10**17)
    _require(abs(u95_1e17 - 2.995732273553991e-17) < 1e-29, f"Underflow in zero-event U95 at 10^17: {u95_1e17!r}")

    # Top-level non-dict structured FAIL across all 4 Gate 35 evaluators
    for fn in (
        evaluate_gate35_sort_gp2,
        evaluate_gate35_sort_itga1_ridge,
        evaluate_gate35_ensc_p19_singlepass,
        evaluate_gate35_gins_oq018_reserve,
    ):
        nd = fn(["not_a_dict"])
        _require(
            isinstance(nd, dict)
            and nd["decision"] == "FAIL"
            and nd["promotion_authorized"] is False
            and "INVALID_TOP_LEVEL_PAYLOAD_MUST_BE_DICT" in nd["failures"],
            f"Non-dict guard failed for {fn.__name__}: {nd}",
        )

    # GP2 synthetic isolation + Round-5 exposure, host, & tumor_detected probes
    gp2_syn = evaluate_gate35_sort_gp2(_sample_valid_gp2_fixture(), canonical_manifest=ext_manifest)
    gp2_bypass = evaluate_gate35_sort_gp2({
        "evidence_tier": "SYNTHETIC_FIXTURE",
        "canonical_arm_manifest_sha256": EXPECTED_CANONICAL_MANIFEST_SHA256,
        "construct_manifest_sha256": default_lot_construct_manifest_sha256("ISLET1_DESIGN_D1B_LEAN_K2", "SYN_AUTO_01"),
        "lot_id": "SYN_AUTO_01",
        "bank_id": "SYN_BANK_AUTO_01",
        "product_id": "ISLET1_DESIGN_D1B_LEAN_K2",
        "starting_cell_origin": "autologous_hiPSC",
        "input_gp2_pos_pct": 12.0,
    }, canonical_manifest=ext_manifest)
    gp2_auto_reject = evaluate_gate35_sort_gp2({
        **_sample_valid_gp2_fixture(), "product_id": "ISLET1_DESIGN_D1B_LEAN_K2",
        "starting_cell_origin": "autologous_hiPSC", "input_gp2_pos_pct": 30.0,
    }, canonical_manifest=ext_manifest)
    gp2_wrong_host = evaluate_gate35_sort_gp2({**_sample_valid_gp2_fixture(), "tumor_host_strain": "C57BL/6"}, canonical_manifest=ext_manifest)
    gp2_zero_dose = evaluate_gate35_sort_gp2({**_sample_valid_gp2_fixture(), "challenge_dose_cells": 0}, canonical_manifest=ext_manifest)
    gp2_count_mismatch = evaluate_gate35_sort_gp2({
        **_sample_valid_gp2_fixture(),
        "input_gp2_pos_pct": 80.0,
        "input_total_loaded_cells": 1_000_000_000,
        "input_gp2_pos_cells": 100_000_000,
        "recovered_gp2_pos_cells": 65_000_000,
    }, canonical_manifest=ext_manifest)
    gp2_missing = evaluate_gate35_sort_gp2({k: v for k, v in _sample_valid_gp2_fixture().items() if k != "teratoma_n"}, canonical_manifest=ext_manifest)
    # Audit R5-02 self-tests: verified archive 0% GPI / 0% purity / 0% recovery MUST FAIL (even with passing caller),
    # and missing required archived field MUST HOLD!
    def _gp2_with_arch_override(overrides: Mapping[str, Any], *, drop_keys: Sequence[str] = ()) -> dict[str, Any]:
        base = _sample_valid_gp2_fixture()
        rec_body = {k: v for k, v in base["lot_evidence_record"].items() if k != "archive_sha256" and k not in drop_keys}
        rec_body.update(overrides)
        base["lot_evidence_record"] = make_signed_evidence_record(rec_body)
        return base

    gp2_arch_zero_gpi = evaluate_gate35_sort_gp2(
        _gp2_with_arch_override({"gpi_post_dissociation_mfi_retention_pct": 0.0, "gpi_post_dissociation_mfi": 0.0}),
        canonical_manifest=ext_manifest,
    )
    gp2_arch_zero_purity = evaluate_gate35_sort_gp2(
        _gp2_with_arch_override({"post_sort_pdx1_nkx61_pct": 0.0, "post_sort_pdx1_nkx61_pos_cells": 0}),
        canonical_manifest=ext_manifest,
    )
    gp2_arch_zero_recovery = evaluate_gate35_sort_gp2(
        _gp2_with_arch_override({"macs_recovery_eta_pct": 0.0, "recovered_gp2_pos_cells": 0}),
        canonical_manifest=ext_manifest,
    )
    gp2_arch_missing_gpi = evaluate_gate35_sort_gp2(
        _gp2_with_arch_override({}, drop_keys=("gpi_post_dissociation_mfi_retention_pct",)),
        canonical_manifest=ext_manifest,
    )
    # Audit R6-04 + R7-04 self-test: 12 whitespace variants & 12 Unicode formatting/confusable variants
    # of ONE animal ID MUST FAIL with verified_distinct_canonical_animals==1 and U95=95.0 (NOT 22.0922%)!
    ws_ids = [
        "M01", " M01", "M01 ", "  M01", "M01  ", " M01 ",
        "\tM01", "M01\t", "\nM01", "M01\n", "m01", "M 01",
    ]
    gp2_ws_base = _sample_valid_gp2_fixture()
    ws_exposures = [
        {**gp2_ws_base["per_animal_exposures"][i], "animal_id": ws_ids[i]}
        for i in range(12)
    ]
    gp2_ws_base["per_animal_exposures"] = ws_exposures
    gp2_ws_rec = {k: v for k, v in gp2_ws_base["lot_evidence_record"].items() if k != "archive_sha256"}
    gp2_ws_rec["per_animal_exposures"] = ws_exposures
    gp2_ws_base["lot_evidence_record"] = make_signed_evidence_record(gp2_ws_rec)
    gp2_ws_single = evaluate_gate35_sort_gp2(gp2_ws_base, canonical_manifest=ext_manifest)

    unicode_fmt_ids = [
        "M01",
        "M\u00ad01",
        "M\u200b01",
        "M\u200c01",
        "M\u200d01",
        "M\u206001",
        "\ufeffM01",
        "M01\ufe0e",
        "\u202aM01\u202c",
        "M01\U000e0001",
        "\uff2d\uff10\uff11",
        "M01\u0301",
    ]
    gp2_uf_base = _sample_valid_gp2_fixture()
    uf_exposures = [
        {**gp2_uf_base["per_animal_exposures"][i], "animal_id": unicode_fmt_ids[i]}
        for i in range(12)
    ]
    gp2_uf_base["per_animal_exposures"] = uf_exposures
    gp2_uf_rec = {k: v for k, v in gp2_uf_base["lot_evidence_record"].items() if k != "archive_sha256"}
    gp2_uf_rec["per_animal_exposures"] = uf_exposures
    gp2_uf_base["lot_evidence_record"] = make_signed_evidence_record(gp2_uf_rec)
    gp2_uf_single = evaluate_gate35_sort_gp2(gp2_uf_base, canonical_manifest=ext_manifest)

    # Audit R8-07 self-test: 12 ASCII punctuation/padding spellings of ONE animal ID MUST collapse to 1 canonical animal
    # and FAIL CLOSED with FAIL_NONUNIQUE_CANONICAL_EQUIVALENCE_ID, verified_distinct_canonical_animals==1, U95==95.0%!
    ascii_punct_12 = [
        "M-01", "M_01", "M.01", "M:01", "M-0-1", "M-001",
        "M.0_1", "M:0-1", "M01", "M0-1", "M0.1", "M0_1",
    ]
    gp2_ap_base = _sample_valid_gp2_fixture()
    ap_exposures = [
        {**gp2_ap_base["per_animal_exposures"][i], "animal_id": ascii_punct_12[i]}
        for i in range(12)
    ]
    gp2_ap_base["per_animal_exposures"] = ap_exposures
    gp2_ap_rec = {k: v for k, v in gp2_ap_base["lot_evidence_record"].items() if k != "archive_sha256"}
    gp2_ap_rec["per_animal_exposures"] = ap_exposures
    gp2_ap_base["lot_evidence_record"] = make_signed_evidence_record(gp2_ap_rec)
    gp2_ap_single = evaluate_gate35_sort_gp2(gp2_ap_base, canonical_manifest=ext_manifest)

    # Audit R6-07 self-test: large finite GPI MFI pair must divide BEFORE scaling and produce strict JSON (zero Infinity)!
    gp2_big_mfi_base = _gp2_with_arch_override({
        "gpi_post_dissociation_mfi": 0.5e307,