OpenIslet

scripts/verify_iip0055_hygiene_safecell_minifh_orthogonality.py

OpenIslet Wave-6 W6-C1 (Provisional IIP-0055 / DEC-136 / GATE-34 / GY-033;

script Release v0.8.0 gen-eb955f8266035aba 417 KB · 30 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_iip0055_hygiene_safecell_minifh_orthogonality.py · SHA-256: d5b98e2ba1310333…

            "Loci:chr4_CXCL10", "Loci:chr19_AAVS1", "Loci:chr13_CLYBL", "H4:R3P_Planar_FibrinCliff", "H4:65um_SubQ_FBR",
        },
    }

    # Physical-identity token bags (distinguishing v0.8.0 ARM1B bystander + AAVS1 switch on ISLET1_DESIGN_A_V080_REF)
    w6_v090_cand = _build_tokens_from_canonical_manifest(arm_manifest, design_a_variant="V090_TBP_CANDIDATE", include_shared_gp2_sorting=False, token_equality_mode="PHYSICAL_IDENTITY")
    w6_v090_cand_gp2 = _build_tokens_from_canonical_manifest(arm_manifest, design_a_variant="V090_TBP_CANDIDATE", include_shared_gp2_sorting=True, token_equality_mode="PHYSICAL_IDENTITY")
    w6_v080_ref_phys = _build_tokens_from_canonical_manifest(arm_manifest, design_a_variant="V080_REF", include_shared_gp2_sorting=False, token_equality_mode="PHYSICAL_IDENTITY")
    w6_v080_ref_phys_gp2 = _build_tokens_from_canonical_manifest(arm_manifest, design_a_variant="V080_REF", include_shared_gp2_sorting=True, token_equality_mode="PHYSICAL_IDENTITY")
    # Functional-family token bags (grouping CXCL10::SERPINB9+PD-L1 by shared biological effector family)
    w6_v080_ref_fam = _build_tokens_from_canonical_manifest(arm_manifest, design_a_variant="V080_REF", include_shared_gp2_sorting=False, token_equality_mode="FUNCTIONAL_FAMILY")
    w6_v080_ref_fam_gp2 = _build_tokens_from_canonical_manifest(arm_manifest, design_a_variant="V080_REF", include_shared_gp2_sorting=True, token_equality_mode="FUNCTIONAL_FAMILY")

    # Verify strict canonical manifest invariants directly on ALL token sets
    for w6_set in (w6_v090_cand, w6_v080_ref_phys, w6_v080_ref_fam):
        require_cond(not any(t.startswith("Opt:") for t in w6_set["A"]), "Design A must have ZERO optional biologic/drug/rest tokens")
        require_cond(not any("ZeroBiologic" in t for t in w6_set["A"]), "Must NOT count 'zero biologic' as a fake unique token")
        for unhardened in ("A", "B", "X"):
            require_cond("H4:allowed_R4" not in w6_set[unhardened] and "H4:home_R4" not in w6_set[unhardened], f"GY-027(1) violation: {unhardened} on R4")
            require_cond("Safe:CDK1_HSV_TK" not in w6_set[unhardened], f"Manifest mismatch: single-switch {unhardened} has CDK1_HSV_TK")
        require_cond("Safe:CDK1_HSV_TK" not in w6_set["D"], "Manifest mismatch: single-switch D has CDK1_HSV_TK")
        for dual_arm in ("Y", "Z"):
            require_cond("Safe:TBP_iCasp9" in w6_set[dual_arm] and "Safe:CDK1_HSV_TK" in w6_set[dual_arm], f"Manifest mismatch: {dual_arm} missing Dual-FailSafe")
        for arm_id in ("A", "B", "X", "Y", "D", "Z"):
            require_cond("Safe:GY030_5lineage_wholegraft" in w6_set[arm_id], f"GY-030 5-lineage missing on arm {arm_id}")
    require_cond(
        "Safe:AAVS1_iCasp9_v080_ref" in w6_v080_ref_phys["A"]
        and "Loci:chr19_AAVS1_iCasp9_v080_ref" in w6_v080_ref_phys["A"]
        and "H3:CXCL10_SERPINB9_P2A_PDL1_v080_ARM1B_ref" in w6_v080_ref_phys["A"]
        and "H3:CXCL10_SERPINB9_PDL1_SYN6plus_ARM5_v090" not in w6_v080_ref_phys["A"],
        "Physical-identity V080_REF A must retain BOTH AAVS1 switch and v0.8.0 ARM1B bystander cassette",
    )
    require_cond(
        "Safe:TBP_iCasp9" in w6_v090_cand["A"]
        and "Loci:chr6_TBP_iCasp9" in w6_v090_cand["A"]
        and "H3:CXCL10_SERPINB9_PDL1_SYN6plus_ARM5_v090" in w6_v090_cand["A"],
        "Separately versioned V090_TBP_CANDIDATE A must carry TBP switch and ARM5_v0.9.0 bystander repair",
    )

    def jaccard_exact(a: Set[str], b: Set[str]) -> float:
        return (len(a & b) / len(a | b)) if (a | b) else 0.0

    def filter_prefixes(d: Dict[str, Set[str]], prefixes: Tuple[str, ...]) -> Dict[str, Set[str]]:
        return {k: {t for t in v if t.startswith(prefixes)} for k, v in d.items()}

    def pairwise_stats(d: Dict[str, Set[str]]) -> Dict[str, Any]:
        names = list(d.keys())
        pairs_exact: Dict[str, float] = {}
        pairs_disp: Dict[str, float] = {}
        vals_exact: List[float] = []
        for i in range(len(names)):
            for j in range(i + 1, len(names)):
                k = f"{names[i]}_vs_{names[j]}"
                jv = jaccard_exact(d[names[i]], d[names[j]])
                pairs_exact[k] = jv
                pairs_disp[k] = round(jv, 4)
                vals_exact.append(jv)
        mean_ex = sum(vals_exact) / len(vals_exact)
        return {
            "pairs_exact": pairs_exact,
            "pairs": pairs_disp,
            "mean_jaccard_exact": mean_ex,
            "mean_jaccard": round(mean_ex, 4),
            "max_jaccard": round(max(vals_exact), 4),
            "min_jaccard": round(min(vals_exact), 4),
        }

    w5_h23 = pairwise_stats(filter_prefixes(w5_full, ("H2:", "Comp:", "H3:")))
    w6_intrinsic_h23_fam = pairwise_stats(filter_prefixes(w6_v080_ref_fam, ("H2:", "Comp:", "H3:")))
    w6_h23_plus_opt_fam = pairwise_stats(filter_prefixes(w6_v080_ref_fam, ("H2:", "Comp:", "H3:", "Opt:")))
    w6_intrinsic_h23_phys = pairwise_stats(filter_prefixes(w6_v080_ref_phys, ("H2:", "Comp:", "H3:")))
    w6_h23_plus_opt_phys = pairwise_stats(filter_prefixes(w6_v080_ref_phys, ("H2:", "Comp:", "H3:", "Opt:")))
    w6_assigned_7axis_v080_ref_phys = pairwise_stats(filter_prefixes(w6_v080_ref_phys, ("H1:", "H2:", "Comp:", "H3:", "Safe:", "Loci:", "H4:")))
    w6_all_8axis_v080_ref_phys = pairwise_stats(w6_v080_ref_phys)
    w6_all_8axis_v080_ref_phys_gp2 = pairwise_stats(w6_v080_ref_phys_gp2)
    w6_all_8axis_v080_ref_fam = pairwise_stats(w6_v080_ref_fam)
    w6_all_8axis_v080_ref_fam_gp2 = pairwise_stats(w6_v080_ref_fam_gp2)
    w6_all_8axis_v090_cand = pairwise_stats(w6_v090_cand)
    w6_all_8axis_v090_cand_gp2 = pairwise_stats(w6_v090_cand_gp2)

    def _abx_mean(st: Dict[str, Any]) -> Tuple[Dict[str, float], float, float]:
        pe = st["pairs_exact"]
        ex_list = [pe["A_vs_B"], pe["A_vs_X"], pe["B_vs_X"]]
        m_ex = sum(ex_list) / 3.0
        return (
            {"A_vs_B": round(ex_list[0], 4), "A_vs_X": round(ex_list[1], 4), "B_vs_X": round(ex_list[2], 4)},
            m_ex,
            round(m_ex, 4),
        )

    w5_abx_p, mean_inc_w5_ex, mean_inc_w5 = _abx_mean(w5_h23)
    intr_abx_p, mean_inc_w6_intr_ex, mean_inc_w6_intr = _abx_mean(w6_intrinsic_h23_fam)
    opt_abx_p, mean_inc_w6_opt_ex, mean_inc_w6_opt = _abx_mean(w6_h23_plus_opt_fam)
    intr_phys_abx_p, mean_inc_w6_intr_phys_ex, mean_inc_w6_intr_phys = _abx_mean(w6_intrinsic_h23_phys)
    opt_phys_abx_p, mean_inc_w6_opt_phys_ex, mean_inc_w6_opt_phys = _abx_mean(w6_h23_plus_opt_phys)
    v090_8ax_p, mean_v090_8ax_ex, mean_v090_8ax = _abx_mean(w6_all_8axis_v090_cand)
    v090_8ax_gp2_p, mean_v090_8ax_gp2_ex, mean_v090_8ax_gp2 = _abx_mean(w6_all_8axis_v090_cand_gp2)
    v080_phys_8ax_p, mean_v080_phys_8ax_ex, mean_v080_phys_8ax = _abx_mean(w6_all_8axis_v080_ref_phys)
    v080_phys_8ax_gp2_p, mean_v080_phys_8ax_gp2_ex, mean_v080_phys_8ax_gp2 = _abx_mean(w6_all_8axis_v080_ref_phys_gp2)
    v080_fam_8ax_p, mean_v080_fam_8ax_ex, mean_v080_fam_8ax = _abx_mean(w6_all_8axis_v080_ref_fam)
    v080_fam_8ax_gp2_p, mean_v080_fam_8ax_gp2_ex, mean_v080_fam_8ax_gp2 = _abx_mean(w6_all_8axis_v080_ref_fam_gp2)

    rel_red_intr_pct = round((1.0 - mean_inc_w6_intr_ex / mean_inc_w5_ex) * 100.0, 2)
    rel_red_opt_pct = round((1.0 - mean_inc_w6_opt_ex / mean_inc_w5_ex) * 100.0, 2)

    require_cond(mean_inc_w5 == 0.7185, f"Expected W5 ABX H2+H3 mean 0.7185, got {mean_inc_w5}")
    require_cond(mean_inc_w6_intr == 0.3152 and abs(mean_inc_w6_intr_ex - (3 / 11 + 4 / 10 + 3 / 11) / 3.0) < 1e-15, f"Expected canonical W6 functional-family intrinsic ABX mean 0.3152 (0.3151515...), got {mean_inc_w6_intr}")
    require_cond(mean_inc_w6_opt == 0.3181, f"Expected canonical W6 functional-family ABX H2+Comp+H3+Opt mean 0.3181, got {mean_inc_w6_opt}")
    require_cond(mean_inc_w6_intr_phys == 0.2727 and mean_inc_w6_opt_phys == 0.2917, f"Expected physical-identity V080_REF intrinsic/opt 0.2727/0.2917, got {mean_inc_w6_intr_phys}/{mean_inc_w6_opt_phys}")
    require_cond(mean_v090_8ax == 0.4754 and mean_v090_8ax_gp2 == 0.4935, f"Expected V090_TBP_CANDIDATE 8-axis 0.4754->0.4935 with GP2, got {mean_v090_8ax}->{mean_v090_8ax_gp2}")
    require_cond(mean_v080_phys_8ax == 0.3950 and mean_v080_phys_8ax_gp2 == 0.4147, f"Expected V080_REF physical-identity 8-axis 0.3950->0.4147 with GP2, got {mean_v080_phys_8ax}->{mean_v080_phys_8ax_gp2}")
    require_cond(mean_v080_fam_8ax == 0.4103 and mean_v080_fam_8ax_gp2 == 0.4297, f"Expected V080_REF functional-family 8-axis 0.4103->0.4297 with GP2, got {mean_v080_fam_8ax}->{mean_v080_fam_8ax_gp2}")

    # Full transparent audit of EVERY token shared by >= 2 arms across ALL 8 axes (ZERO silent exemptions!)
    token_arms: Dict[str, List[str]] = defaultdict(list)
    for arm in ("A", "B", "X", "Y", "D", "Z"):
        for t in sorted(w6_v080_ref_phys_gp2[arm]):
            token_arms[t].append(arm)
    all_shared_modules = [
        {"token": t, "arm_count": len(arms), "arms": arms}
        for t, arms in sorted(token_arms.items(), key=lambda kv: (-len(kv[1]), kv[0]))
        if len(arms) >= 2
    ]
    unique_specialized_modules = sorted(t for t, arms in token_arms.items() if len(arms) == 1)

    return {
        "derived_strictly_from_canonical_manifest": True,
        "manifest_schema_version": arm_manifest.get("schema_version"),
        "zero_silent_exemptions_verified": True,
        "zero_biologic_fake_token_excluded": True,
        "design_a_zero_additional_biologics_beyond_v080_catalase_hydrogel": True,
        "design_a_contains_preexisting_p04040_catalase_hydrogel": True,
        "design_a_strictly_zero_protein_biologics": False,
        "design_a_preexisting_catalase_hydrogel_exception": arm_manifest["design_a_strict_policy"]["preexisting_hydrogel_enzyme_exception"],
        "design_a_reference_vs_hygiene_candidate_policy": arm_manifest["design_a_strict_policy"]["reference_vs_hygiene_candidate"],
        "gy027_1_r4_compatibility_verified": True,
        "gy030_5lineage_all_6_arms_verified": True,
        "shared_gp2_sorting_process_disclosed": True,
        "token_equality_semantics": {
            "physical_identity_mode": "Token equality denotes identical physical construct version: governed ISLET1_DESIGN_A_V080_REF carries BOTH its v0.8.0 AAVS1 switch (Safe:AAVS1_iCasp9_v080_ref, Loci:chr19_AAVS1_iCasp9_v080_ref) AND its distinct v0.8.0 ARM1B bystander cassette (H3:CXCL10_SERPINB9_P2A_PDL1_v080_ARM1B_ref), whereas ISLET1_DESIGN_A_V090_TBP_CANDIDATE and X/Y/D/Z carry H3:CXCL10_SERPINB9_PDL1_SYN6plus_ARM5_v090 (8-axis V080_REF physical-identity ABX mean = 0.3950 -> 0.4147 with shared GP2).",
            "functional_family_mode": "Token equality groups CXCL10::SERPINB9+PD-L1 constructs by shared biological effector family (H3:CXCL10_SERPINB9_PDL1_family) regardless of v0.8.0 P2A vs v0.9.0 ARM5 repair sequence (intrinsic H2+Comp+H3 ABX mean = 0.3152 [-56.14%]; 8-axis V080_REF functional-family ABX mean = 0.4103 -> 0.4297 with shared GP2).",
        },
        "epistemic_scope_statement": "Pairwise token Jaccard overlap is strictly a structural inventory descriptor, NOT an empirical estimator of cross-arm failure correlation (phi_inc). Neither token Jaccard nor the single-recipient 12-week donor-islet case report (Carlsson et al. 2025, PMID:40757665) identifies true phi_inc; therefore Part F reports exact portfolio sensitivity across phi_inc in {0.25, 0.50, 0.75}. All means are computed on exact unrounded pair fractions before 4-decimal display, with both physical-identity and functional-family token equality reported explicitly.",
        "incumbent_ABX_structural_jaccard_comparison": {
            "wave5_h2_comp_h3_pairs": w5_abx_p,
            "wave5_h2_comp_h3_mean_exact": mean_inc_w5_ex,
            "wave5_h2_comp_h3_mean": mean_inc_w5,
            "wave6_canonical_intrinsic_h2_comp_h3_pairs": intr_abx_p,
            "wave6_canonical_intrinsic_h2_comp_h3_mean_exact": mean_inc_w6_intr_ex,
            "wave6_canonical_intrinsic_h2_comp_h3_mean": mean_inc_w6_intr,
            "relative_reduction_intrinsic_pct": rel_red_intr_pct,
            "wave6_canonical_h2_comp_h3_plus_opt_pairs": opt_abx_p,
            "wave6_canonical_h2_comp_h3_plus_opt_mean_exact": mean_inc_w6_opt_ex,
            "wave6_canonical_h2_comp_h3_plus_opt_mean": mean_inc_w6_opt,
            "relative_reduction_with_opt_pct": rel_red_opt_pct,
            "wave6_canonical_intrinsic_h2_comp_h3_physical_identity_pairs": intr_phys_abx_p,
            "wave6_canonical_intrinsic_h2_comp_h3_physical_identity_mean_exact": mean_inc_w6_intr_phys_ex,
            "wave6_canonical_intrinsic_h2_comp_h3_physical_identity_mean": mean_inc_w6_intr_phys,
            "wave6_canonical_h2_comp_h3_plus_opt_physical_identity_pairs": opt_phys_abx_p,
            "wave6_canonical_h2_comp_h3_plus_opt_physical_identity_mean_exact": mean_inc_w6_opt_phys_ex,
            "wave6_canonical_h2_comp_h3_plus_opt_physical_identity_mean": mean_inc_w6_opt_phys,
            "wave6_canonical_full_8axis_a_v090_tbp_candidate_pairs": v090_8ax_p,
            "wave6_canonical_full_8axis_a_v090_tbp_candidate_mean_exact": mean_v090_8ax_ex,
            "wave6_canonical_full_8axis_a_v090_tbp_candidate_mean": mean_v090_8ax,
            "wave6_canonical_full_8axis_a_v090_tbp_candidate_with_shared_gp2_pairs": v090_8ax_gp2_p,
            "wave6_canonical_full_8axis_a_v090_tbp_candidate_with_shared_gp2_mean_exact": mean_v090_8ax_gp2_ex,
            "wave6_canonical_full_8axis_a_v090_tbp_candidate_with_shared_gp2_mean": mean_v090_8ax_gp2,
            "wave6_canonical_full_8axis_a_v080_ref_physical_identity_pairs": v080_phys_8ax_p,
            "wave6_canonical_full_8axis_a_v080_ref_physical_identity_mean_exact": mean_v080_phys_8ax_ex,
            "wave6_canonical_full_8axis_a_v080_ref_physical_identity_mean": mean_v080_phys_8ax,
            "wave6_canonical_full_8axis_a_v080_ref_physical_identity_with_shared_gp2_pairs": v080_phys_8ax_gp2_p,
            "wave6_canonical_full_8axis_a_v080_ref_physical_identity_with_shared_gp2_mean_exact": mean_v080_phys_8ax_gp2_ex,
            "wave6_canonical_full_8axis_a_v080_ref_physical_identity_with_shared_gp2_mean": mean_v080_phys_8ax_gp2,
            "wave6_canonical_full_8axis_a_v080_ref_functional_family_pairs": v080_fam_8ax_p,
            "wave6_canonical_full_8axis_a_v080_ref_functional_family_mean_exact": mean_v080_fam_8ax_ex,
            "wave6_canonical_full_8axis_a_v080_ref_functional_family_mean": mean_v080_fam_8ax,
            "wave6_canonical_full_8axis_a_v080_ref_functional_family_with_shared_gp2_pairs": v080_fam_8ax_gp2_p,
            "wave6_canonical_full_8axis_a_v080_ref_functional_family_with_shared_gp2_mean_exact": mean_v080_fam_8ax_gp2_ex,
            "wave6_canonical_full_8axis_a_v080_ref_functional_family_with_shared_gp2_mean": mean_v080_fam_8ax_gp2,
            "sensitivity_parameter_note": "Adding shared allogeneic GP2 sorting token moves 8-axis ABX mean from 0.4754 to 0.4935 (ISLET1_DESIGN_A_V090_TBP_CANDIDATE), from 0.3950 to 0.4147 (ISLET1_DESIGN_A_V080_REF physical-identity), and from 0.4103 to 0.4297 (ISLET1_DESIGN_A_V080_REF functional-family); modeled phi_inc = 0.25 vs 0.50 vs 0.75 is reported as an explicit scenario sensitivity (not derived by formula from Jaccard).",
        },
        "wave5_monoculture_h2_comp_h3": w5_h23,
        "wave6_canonical_cell_intrinsic_h2_comp_h3": w6_intrinsic_h23_fam,
        "wave6_canonical_h2_comp_h3_plus_optional_exogenous": w6_h23_plus_opt_fam,
        "wave6_canonical_cell_intrinsic_h2_comp_h3_physical_identity": w6_intrinsic_h23_phys,
        "wave6_canonical_full_7axis_assigned_a_v080_ref_physical_identity": w6_assigned_7axis_v080_ref_phys,
        "wave6_canonical_full_8axis_a_v080_ref_physical_identity": w6_all_8axis_v080_ref_phys,
        "wave6_canonical_full_8axis_a_v080_ref_physical_identity_with_shared_gp2": w6_all_8axis_v080_ref_phys_gp2,
        "wave6_canonical_full_8axis_a_v080_ref_functional_family": w6_all_8axis_v080_ref_fam,
        "wave6_canonical_full_8axis_a_v080_ref_functional_family_with_shared_gp2": w6_all_8axis_v080_ref_fam_gp2,
        "wave6_canonical_full_8axis_a_v090_tbp_candidate": w6_all_8axis_v090_cand,
        "wave6_canonical_full_8axis_a_v090_tbp_candidate_with_shared_gp2": w6_all_8axis_v090_cand_gp2,
        "arm_token_sets_canonical_a_v080_ref_physical_identity_with_gp2": {k: sorted(v) for k, v in w6_v080_ref_phys_gp2.items()},
        "arm_token_sets_canonical_a_v080_ref_functional_family_with_gp2": {k: sorted(v) for k, v in w6_v080_ref_fam_gp2.items()},
        "arm_token_sets_canonical_a_v090_tbp_candidate": {k: sorted(v) for k, v in w6_v090_cand.items()},
        "all_shared_modules_transparent_ledger": all_shared_modules,
        "unique_1_of_6_modules": unique_specialized_modules,
    }


# =============================================================================
# PART F — BIT-EXACT 2^12 / 2^20 / 2^24 PORTFOLIO & EXTERNAL CONTRACT PARITY
# =============================================================================
def biv_bern(p1: float, p2: float, phi: float) -> Dict[Tuple[int, int], float]:
    require_cond(0.0 <= p1 <= 1.0 and 0.0 <= p2 <= 1.0 and 0.0 <= phi <= 1.0, f"Invalid biv_bern inputs: p1={p1}, p2={p2}, phi={phi}")
    p11 = (1.0 - phi) * (p1 * p2) + phi * min(p1, p2)
    raw = {
        (0, 0): 1.0 - p1 - p2 + p11,
        (1, 0): p1 - p11,
        (0, 1): p2 - p11,
        (1, 1): p11,
    }
    out = {}
    for k, v in raw.items():
        require_cond(v >= -1e-12, f"Negative biv_bern mass {k}={v}")
        out[k] = max(0.0, v)
    require_cond(abs(sum(out.values()) - 1.0) < 1e-12, "biv_bern mass sum != 1")
    return out


def frechet_joint(probs: Sequence[float], phi: float) -> List[float]:
    m = len(probs)
    require_cond(0.0 <= phi <= 1.0, f"Invalid phi={phi}")
    for p in probs:
        require_cond(0.0 <= p <= 1.0, f"Invalid marginal p={p}")
    n_states = 1 << m
    d_ind = [0.0] * n_states
    for mask in range(n_states):
        w = 1.0
        for i in range(m):
            w *= probs[i] if (mask & (1 << i)) else (1.0 - probs[i])
        d_ind[mask] = w
    if phi == 0.0:
        return d_ind
    order = sorted(range(m), key=lambda i: probs[i])
    d_pos = [0.0] * n_states
    prev = 0.0
    for idx, i in enumerate(order):
        w = probs[i] - prev
        if w > 0.0:
            d_pos[sum(1 << j for j in order[idx:])] += w
        prev = probs[i]
    d_pos[0] += 1.0 - prev