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…

NW08_MESH_CONVERGENCE_FORMAL_ORDER_P: float = 2.0
NW08_MESH_CONVERGENCE_MAX_ADMISSIBLE_ORDER_P: float = 2.5
NW08_HOLD_TOKEN_STRADDLES_FLOOR: str = "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR"
NW08_HOLD_TOKEN_UNQUALIFIED_ORDER: str = "HOLD_NW08_MESH_CONVERGENCE_UNQUALIFIED_SLOW_OR_NON_ASYMPTOTIC_ORDER"
NW08_HOLD_TOKEN_INFERENTIAL_REQUIRES_POSITIVE_SE: str = "HOLD_NW08_INFERENTIAL_MODEL_REQUIRES_POSITIVE_SE"

NW08_MESH_STATUS_SINGLE_GRID_POLICY_PASS: str = "SINGLE_GRID_FAR_FROM_FLOOR_POLICY_PASS_ORDER_NOT_EVALUATED"
NW08_MESH_STATUS_SINGLE_GRID_POLICY_FAIL: str = "SINGLE_GRID_FAR_FROM_FLOOR_POLICY_FAIL_ORDER_NOT_EVALUATED"
NW08_MESH_STATUS_TWO_GRID_DIRECT_CROSSING_HOLD: str = "TWO_GRID_DIRECT_FLOOR_CROSSING_HOLD"
NW08_MESH_STATUS_THREE_GRID_ASYMPTOTIC_GCI_QUALIFIED: str = "THREE_GRID_ASYMPTOTIC_GCI_QUALIFIED"
NW08_MESH_STATUS_THREE_GRID_EXACT_ZERO_SPREAD: str = "THREE_GRID_EXACT_ZERO_SPREAD_CONVERGED"
NW08_MESH_STATUS_THREE_GRID_OSCILLATORY_BOUND: str = "THREE_GRID_OSCILLATORY_ASME_VV20_HALF_RANGE_BOUND"
NW08_MESH_STATUS_THREE_GRID_MONOTONE_FALLBACK: str = "THREE_GRID_MONOTONE_NON_ASYMPTOTIC_FALLBACK_ORDER_NOT_QUALIFIED"
NW08_MESH_STATUS_THREE_GRID_UNQUALIFIED_ORDER_HOLD: str = "THREE_GRID_UNQUALIFIED_ORDER_HOLD"
NW08_MESH_STATUS_THREE_GRID_NON_ASYMPTOTIC_HOLD: str = "THREE_GRID_NON_ASYMPTOTIC_STRADDLE_OR_TOWARD_FLOOR_HOLD"
NW08_MESH_STATUS_THREE_GRID_INVALID_HOLD: str = "THREE_GRID_INVALID_OR_NONFINITE_HOLD"

# R10-B1: Canonical 8-route NW-08 geometry allowlist shared by lot-envelope validation and coupled OCR dispatch.
CANONICAL_NW08_ROUTE_IDS = frozenset({
    "R1_390_nominal",
    "R1_350_stress",
    "R1_390_stress",
    "R2_DZ40",
    "R3P_35",
    "R3P_30",
    "R3P_30_KRBH",
    "R3P_35_VPIO120",
})

# R05-M1 + R10-M2 + R15-M2: Public release ledger of the exact 8 indirect/contextual non-certifying
# CEG cross-link edges (`primary_certification_eligible = false`) added under IIP-0043
# (CEG-DELTA V3.3) to pre-existing studies in data/extracted/context_evidence_graph_v1.json,
# carrying independent expected relation, target_gate_or_module, applicability, and cited_outcome_tuples
# fields for verbatim programmatic parity verification.
CEG_DELTA_V33_EIGHT_CROSSLINKS_SPEC: Tuple[Dict[str, Any], ...] = (
    {
        "edge_id": "M0085:L4",
        "queue_id": "M0085",
        "pmid": "37854597",
        "pre_iip0043_study_status": "existing_wave1_ceg_candidate_promoted_to_ring1_in_wave5",
        "pre_iip0043_prior_edge_ids": ["M0085:L1", "M0085:L2", "M0085:L3"],
        "expected_relation": "scoping_qualification",
        "expected_target_gate_or_module": "Gate0V-Geno / NW-18 (selective TYK2 pseudokinase inhibition preserves IFN-gamma while blunting IFN-alpha; EndoC-betaH1 cell line T5)",
        "expected_applicability": "unvalidated_transfer",
        "expected_cited_outcome_tuples": ["M0085:O1", "M0085:O5", "M0085:O6"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): selective TYK2 inhibition in EndoC-betaH1 cell line provides Gate 0V-Geno context.",
    },
    {
        "edge_id": "M0630:L4",
        "queue_id": "M0630",
        "pmid": "35013114",
        "pre_iip0043_study_status": "existing_wave1_ceg_candidate_promoted_to_ring1_in_wave5",
        "pre_iip0043_prior_edge_ids": ["M0630:L1", "M0630:L2", "M0630:L3"],
        "expected_relation": "scoping_qualification",
        "expected_target_gate_or_module": "Gate0V-Kill / NW-18 (HeLa AP20187 mechanism hypothesis showing iCasp9 expression & XIAP/Caspase-3 drive escape; diagnostic probe only)",
        "expected_applicability": "unvalidated_transfer",
        "expected_cited_outcome_tuples": ["M0630:O13", "M0630:O14", "M0630:O15", "M0630:O17"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): HeLa AP20187 iCasp9/XIAP study provides diagnostic kill-variability context for Gate 0V-Kill.",
    },
    {
        "edge_id": "M0458:L3",
        "queue_id": "M0458",
        "pmid": "26258815",
        "pre_iip0043_study_status": "existing_wave1_ceg_candidate_promoted_to_ring1_in_wave5",
        "pre_iip0043_prior_edge_ids": ["M0458:L1", "M0458:L2"],
        "expected_relation": "supports",
        "expected_target_gate_or_module": "Layer 4 / NW-08 (external whole-prep clinical autoislet OCR/DNA group mean from M0458:O4, converted analytically via 10.4 ng DNA/IE)",
        "expected_applicability": "justified_bridge",
        "expected_cited_outcome_tuples": ["M0458:O4"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): whole autologous human islet OCR/DNA group mean provides prior respirometry context for NW-08.",
    },
    {
        "edge_id": "M0184:L4",
        "queue_id": "M0184",
        "pmid": "38956087",
        "pre_iip0043_study_status": "existing_wave1_ceg_candidate_promoted_to_ring1_in_wave5",
        "pre_iip0043_prior_edge_ids": ["M0184:L1", "M0184:L2", "M0184:L3"],
        "expected_relation": "supports",
        "expected_target_gate_or_module": "NW-08 & Gate 0V-Kill (CC-BY-4.0 human beta/alpha/ductal ER and cytokine stress regulon divergence)",
        "expected_applicability": "matched_domain",
        "expected_cited_outcome_tuples": ["M0184:O1", "M0184:O2", "M0184:O3", "M0184:O4"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): human islet ER/cytokine stress-response study provides stress-response context indirect to NW-08 and Gate 0V-Kill.",
    },
    {
        "edge_id": "M0066:L3",
        "queue_id": "M0066",
        "pmid": "41403780",
        "pre_iip0043_study_status": "existing_wave1_ceg_candidate_promoted_to_ring1_in_wave5",
        "pre_iip0043_prior_edge_ids": ["M0066:L1", "M0066:L2"],
        "expected_relation": "supports",
        "expected_target_gate_or_module": "Layer 1/3 & NW-08 (CC-BY-4.0 T3 humanized-mouse calibration of CD155/PVR & CD276/B7-H3 blockade on iPSC/EP grafts)",
        "expected_applicability": "justified_bridge",
        "expected_cited_outcome_tuples": ["M0066:O2", "M0066:O3", "M0066:O5"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): CD155/CD276 humanized-mouse study provides immune-engraftment context indirect to NW-08.",
    },
    {
        "edge_id": "R1_0287:L4",
        "queue_id": "R1_0287",
        "pmid": "39232561",
        "pre_iip0043_study_status": "pre_existing_ring1_and_wave1_ceg_study",
        "pre_iip0043_prior_edge_ids": ["R1_0287:L1", "R1_0287:L2", "R1_0287:L3"],
        "expected_relation": "supports",
        "expected_target_gate_or_module": "Gate0V / NW-18 & NW-08 (CC-BY-4.0 human VMI organoid vascular-macrophage beta-cell pyroptosis anchor)",
        "expected_applicability": "matched_domain",
        "expected_cited_outcome_tuples": ["R1_0287:O10", "R1_0287:O11", "R1_0287:O13"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): human vascularized macrophage-islet organoid study provides model-system context indirect to Gate 0V and NW-08.",
    },
    {
        "edge_id": "R1_0099:L3",
        "queue_id": "R1_0099",
        "pmid": "28000722",
        "pre_iip0043_study_status": "pre_existing_ring1_and_wave1_ceg_study",
        "pre_iip0043_prior_edge_ids": ["R1_0099:L1", "R1_0099:L2"],
        "expected_relation": "scoping_qualification",
        "expected_target_gate_or_module": "Gate0V-Geno / NW-18 (CC-BY-4.0 primary human islet IFIH1 rs1990760 TC vs TT IFN/ISG and 48-h CVB3 genotype contrast)",
        "expected_applicability": "matched_domain",
        "expected_cited_outcome_tuples": ["R1_0099:O11", "R1_0099:O12", "R1_0099:O15", "R1_0099:O16"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): human islet IFIH1 rs1990760 CVB3 genotype contrast provides antiviral genotype context for Gate 0V-Geno.",
    },
    {
        "edge_id": "R1_0095:L4",
        "queue_id": "R1_0095",
        "pmid": "27626039",
        "pre_iip0043_study_status": "pre_existing_ring1_and_wave1_ceg_study",
        "pre_iip0043_prior_edge_ids": ["R1_0095:L1", "R1_0095:L2", "R1_0095:L3"],
        "expected_relation": "scoping_qualification",
        "expected_target_gate_or_module": "Gate0V-Kill / NW-18 (hiPSC iCasp9 escape mechanism via silencing/EF1a methylation/BCL2; T5 cell line)",
        "expected_applicability": "unvalidated_transfer",
        "expected_cited_outcome_tuples": ["R1_0095:O2", "R1_0095:O4", "R1_0095:O7", "R1_0095:O12", "R1_0095:O13"],
        "previous_edge_state": "absent_pre_iip0043",
        "added_edge_status": "added_by_iip0043_scoping_non_certifying",
        "evidence_scope": "indirect_contextual_non_certifying",
        "contextual_scope_note": "Indirect contextual cross-link (primary_certification_eligible=false): hiPSC iCasp9 silencing/BCL2 escape study provides escape-risk context for Gate 0V-Kill.",
    },
)

# Tier-distinct PASS verdict codes carrying explicit tested-vs-inherited scope (B6)
GATE0V_PASS_VERDICTS_BY_TIER: Dict[str, str] = {
    "BANK_QUALIFICATION": "PASS_WHOLEGRAFT_BANK_QUALIFICATION",
    "LOT_RELEASE_SURROGATE": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE",
    "AUTOLOGOUS_D1B_PROCESS_QUAL": "PASS_WHOLEGRAFT_AUTOLOGOUS_PROCESS_QUAL",
}
GATE0V_ALL_PASS_VERDICTS = frozenset(GATE0V_PASS_VERDICTS_BY_TIER.values())

GATE0V_A_REQUIRED_ISG_MARKERS: Tuple[str, ...] = (
    "IFNB1_or_IFNL1_fold",
    "ISG15_fold",
    "MX1_fold",
    "OAS1_fold",
)

STRESS_AP1903_REGIMES: Tuple[str, ...] = (
    "normoxia_baseline",
    "hypoxia_1pct_plus_cytokines",
    "er_stress_tg_or_tm",
    "active_or_persistent_cvb4_infection",
    "active_or_persistent_hcmv_infection",
)

INFECTED_AP1903_REGIMES: Tuple[str, ...] = (
    "active_or_persistent_cvb4_infection",
    "active_or_persistent_hcmv_infection",
)

ALLOWED_ANTIVIRAL_GENOTYPES: Tuple[str, ...] = (
    "TYK2_WT__IFIH1_WT_OR_A946T",
    "TYK2_P1104A_HOM__IFIH1_WT",
    "TYK2_P1104A_HET__IFIH1_WT",
    "TYK2_WT__IFIH1_PROTECTIVE_LOF",
)

EDITED_ANTIVIRAL_GENOTYPES: Tuple[str, ...] = (
    "TYK2_P1104A_HOM__IFIH1_WT",
    "TYK2_P1104A_HET__IFIH1_WT",
    "TYK2_WT__IFIH1_PROTECTIVE_LOF",
)


def _is_public_bundle(openislet_root: Path) -> bool:
    """Detect public-export bundle mode cleanly via `.openislet_public_bundle` marker."""
    return (openislet_root / ".openislet_public_bundle").is_file()

# ---------------------------------------------------------------------------
# Pure Elementary Outward-Directed Taylor Interval Arithmetic (Zero .ln/.exp)
# ---------------------------------------------------------------------------
def _clean_dec_ctx(prec: int = 80, rounding: str = ROUND_CEILING):
    """Fresh Decimal context immune to active-context, DefaultContext, or Inexact traps."""
    return localcontext(
        Context(
            prec=prec,
            rounding=rounding,
            Emin=-999999,
            Emax=999999,
            capitals=1,
            clamp=0,
            flags=[],
            traps=[],
        )
    )


def _to_exact_decimal(val: Any) -> Decimal | None:
    """Strictly convert non-bool int/float/Decimal/str to finite Decimal without binary64 drift."""
    if isinstance(val, bool) or val is None:
        return None
    if isinstance(val, Decimal):
        return Decimal(val) if val.is_finite() else None
    if isinstance(val, int):
        return Decimal(val)
    if isinstance(val, float):
        if not math.isfinite(val):
            return None
        return Decimal(str(val))
    if isinstance(val, str):
        s = val.strip()
        if not s:
            return None
        try:
            with localcontext(
                Context(prec=120, rounding=ROUND_HALF_EVEN, Emax=decimal.MAX_EMAX, Emin=decimal.MIN_EMIN, traps=[])
            ):
                d = Decimal(s)
        except Exception:
            return None
        return d if d.is_finite() else None
    return None


def _to_exact_decimal_nonneg(val: Any) -> Decimal | None: