OpenIslet

scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py

IIP-0042 / DEC-121 (CAND-033 / EXP-030): Master Exact 2^20 Multi-Layer Portfolio

script Release v0.8.0 gen-eb955f8266035aba 881 KB · 63 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_iip0042_master_multilayer_portfolio_crosswalk.py · SHA-256: 16964a158458b5cf…

#!/usr/bin/env python3
"""
IIP-0042 / DEC-121 (CAND-033 / EXP-030): Master Exact 2^20 Multi-Layer Portfolio
& OpenIslet Foundry Crosswalk Verifier (Stage S3-R3 Round-2 Surgical Closure).

Key S3-R2 Remediations:
  1. Fail-closed CLI parity:
     - `--standalone`: verifies exact 2^20 engine + live IIP-0035 parity (24/24
       scalars exact at shipped 4-dp display precision + unrounded L0 parity
       <= 5e-9 + 4,096-state incumbent law <= 1e-12) without emitting misleading
       verified=False / passed=False cross-track flags.
     - `--cross-track-dir` (or default non-standalone mode): REQUIRES both
       EXP-028 and archived EXP-029 receipts to exist, be non-empty, and pass
       parity <= 1e-12 with positive verified=True, passed=True flags; fails
       closed (non-zero exit) otherwise.
     - Logs sys.version and cross-interpreter numeric tolerance policy (<= 1e-12).
  2. Strict live-eligibility masking of unregistered ROUTE_3B_ACTIVE_IEOG (R3B):
     - Headlines the live-eligible Strict series (no blocked R3B).
     - Masks unregistered R3B in strict live-eligible totals (W_U3 = 57.5945%,
       W_U4 = 56.8730%), segregating parked EXP-029 R3B rows strictly into a
       labeled parked counterfactual sensitivity section.
  3. Locked Policy Option 1 eligibility math & P(XREACT pass) sensitivity:
     - Track-B reset (Day-1 active 0.5 mg/kg MELD-ATG + Day-2 placebo; n=35
       assigned, n=34 safety, 8/34 CRS, 11/34 serum sickness; Design A
       unconditionally excluded from Track-B ATG/lymphodepleting induction)
       is NEVER credited inside the ineligible full-SHIELD
       cocktail branch (yielding +2.5372 pp gross / +0.9986 pp AE-adjusted on
       the legacy comparator at P(XREACT pass)=1.0, plus strict zero-R3B EV),
       swept across P(XREACT pass) in {0.25, 0.50, 0.75, 1.00}.
  4. Legal 0.003 checkerboard mass-transfer stress test:
     - Proves explicitly in code that a legal 0.003 checkerboard coupling
       preserving every hurdle marginal and the full 4,096-state incumbent law
       flips L4-AE slightly negative (-0.0569 pp vs L3B).
  5. Honest Stage-0 Foundry sensitivity block:
     - Reflects v1.2 computational reality (qualitative hosted Tier-2 non-binding
       and ITGA2 paralog inversion flags; zero hosted Tier-2 numerics copied):
       low Stage-0 base-rate priors (p_S1 in {0.03, 0.05, 0.10}), 0 credit for
       Islet-SORT / Islet-GUARD until wet lab, 50% delivery-feasibility /
       PK-clearance discount on 6.77/6.49 kDa miniproteins, reporting honest
       unconditional EV (+0.5 to +2 pp today) while holding live public odds
       strictly at +0.00 pp.
  6. Automated public-prose & Gate 30-TOS-QUARANTINE leak scan:
     - Enforces 0 personal home paths, 0 currency figures, 0 vendor/model
       identifiers, and 0 hosted Tier-2 numeric outputs.

Strictly READ-ONLY with respect to OpenIslet and OpenIslet-Website.
Run with:
  PYTHONDONTWRITEBYTECODE=1 python3 -B scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py --standalone --repo-root . --out /tmp/iip0042_standalone_check.json
  PYTHONDONTWRITEBYTECODE=1 python3 -B scripts/verify_iip0042_master_multilayer_portfolio_crosswalk.py --cross-track-dir <idea-exploration-dir> --repo-root . --out /tmp/iip0042_crosstrack_check.json
"""
from __future__ import annotations

import argparse
from datetime import datetime
from decimal import Decimal, InvalidOperation
import fnmatch
import hashlib
import json
import math
import os
import re
import stat
import sys
from pathlib import Path
from typing import Any

import numpy as np

sys.dont_write_bytecode = True

ART_DIR = Path(__file__).resolve().parent
EXP_ROOT = ART_DIR.parents[1]  # idea-exploration/
INV_ROOT = ART_DIR.parents[2]  # OpenIslet-Investigations/
RECEIPT_PATH = (
    ART_DIR.parent / "data" / "extracted" / "iip0042_master_multilayer_portfolio_crosswalk_v0.8.0.json"
    if ART_DIR.name == "scripts"
    else ART_DIR / "exp030_verification_receipt.json"
)
GENERATED_DATE = "2026-11-28"

ARM_NAMES = ("A", "B", "X", "Y", "D")

# Canonical single-source-of-truth H3 Channel-(a) intervention scenario deltas
# (explicitly labeled as uncited modeling judgment scenarios, not measured exact-product values)
DC3_SHIELD1 = 0.015
DC3_SHIELD_COCKTAIL = 0.035
DC3_RESET_CENTRAL = 0.040
DC3_RESET_CONSERVATIVE = 0.030
DC3_RESET_AE_DOWNSIDE = 0.020

D_SHIELD1_ARMS = {"A": 0.025, "B": 0.025, "X": 0.025, "Y": 0.020, "D": 0.025}
D_SHIELD_COCKTAIL_ARMS_BASE = {"A": 0.055, "B": 0.055, "X": 0.055, "Y": 0.040, "D": 0.055}
D_SHIELD_COCKTAIL_ARMS_POST028 = {"A": 0.055, "B": 0.050, "X": 0.045, "Y": 0.040, "D": 0.055}

# Finite Reset arm deltas — IDENTICAL across L2C, L3A+Reset, SHIELD-Fail+Reset, and L4!
# Design A strictly 0.000 (unconditionally excluded from Track-B ATG/lymphodepleting induction).
D_RESET_ARMS_CENTRAL = {"A": 0.000, "B": 0.060, "X": 0.050, "Y": 0.040, "D": 0.060}
D_RESET_ARMS_CONSERVATIVE = {"A": 0.000, "B": 0.040, "X": 0.030, "Y": 0.020, "D": 0.040}
D_RESET_ARMS_AE_DOWNSIDE = {"A": 0.000, "B": 0.030, "X": 0.020, "Y": 0.020, "D": 0.030}
H4_AE_STEROID_HAIRCUT_NON_A = -0.015  # -1.5 pp H4 drag on {B, X, Y, D} from CRS/SS/steroid-rescue toxicity

# Islet-GUARD (THBD M406L) strictly restricted to R1 CaO2 peroxide arms (A, X) ONLY (enforced in code!)
# Set to 0.000 in Honest Stage-0 Zero-SORT/Zero-GUARD headline sensitivity until wet-lab data exist.
D_GUARD_H3_ARMS = {"A": 0.005, "B": 0.000, "X": 0.005, "Y": 0.000, "D": 0.000}
D_GUARD_H4_ARMS = {"A": 0.010, "B": 0.000, "X": 0.010, "Y": 0.000, "D": 0.000}

# Islet-SORT (CD49a/ITGA1 enrichment) — held at 0.000 in Honest Stage-0 headline sensitivity until wet lab!
D_SORT_H1_D = 0.040
D_SORT_H4_ALL = 0.015

# Delivery-feasibility / PK-clearance discount for 6.77/6.49 kDa miniproteins (conditional on route/formulation/dosing)
MINIPROTEIN_PK_DISCOUNT_FACTOR = 0.50

# Canonical pinned SHA-256 of frozen live IIP-0035 5-arm portfolio fixture (enforced BY DEFAULT in --standalone!)
CANONICAL_SHIPPED_IIP0035_SHA256 = "31320c0e6ac039773c2ca58160f064e8655d1a58b97050a713dfbf00d283ff99"

# Pinned 17-file pre-Wave-5 authorized coordinate structure inventory under data/structures/
# pinned by EXACT SHA-256 digest (RCSB PDB CC0 1.0 + pre-existing AFDB v6 reference structures;
# ZERO Foundry/Tier-2 coordinates in OpenIslet; rejects modified/spoofed files at these paths!)
AUTHORIZED_PRE_WAVE5_PUBLIC_COORDINATE_SHA256: dict[str, str] = {
    "data/structures/1EFX.pdb": "4e432fe894cc6b0390bab6071598f2f95249d5b6f0c4e5a9365c1ca110660fba",
    "data/structures/1IM9.pdb": "4c21ebf9e5ba064ab65569079cb8d10a73b718bdc8c4cd1c298bec7a8e4f0013",
    "data/structures/2WII.pdb": "93dc715a38124883028aea79a1e3a2715c1d82bed06f59e7889e9971f41543eb",
    "data/structures/5O32.pdb": "26b9d9684e7b3fa1757f91a173c8423d583ca6df88eb11d1fa2ecdc059a803d3",
    "data/structures/AF-P10144-F1-model_v6.cif": "6362a677cc62d80b89229ea40a4c3ae81007a631d1c038a2e158541c8d40e9a5",
    "data/structures/AF-P50453-F1-model_v6.cif": "d0b27f7cc8317acd9cd59b76d3080b4019ffd38930dbfddf3bd2560814baf5b9",
    "data/structures/pdb_00001bl4.cif": "ce142b747272c5fd3b7c0b5f5157750277614700bc32492f0eb7cb43056914d5",
    "data/structures/pdb_00001iau.cif": "c1ffdeab80cc9ecaf06c9901c756b0f59259e178a45a4a33ffc949bd01123161",
    "data/structures/pdb_00001jxq.cif": "4b7355537a8a81e90d5397cba398ff425dddc904a7748e3a25a0a9f57d1ff772",
    "data/structures/pdb_00001mhe.cif": "4f1bc39231d6ffb288cf85bb9322d264ceac92d6d427f755339a648e49d6227a",
    "data/structures/pdb_00001nw9.cif": "89edc3aa4833b22c9604872d163e64d53755af6de1c9163204f2244ac1ce5da4",
    "data/structures/pdb_00002jjs.cif": "84672a253e9c982dac16136cb76ae706eeafa2aa390cfdb2355ad68592cac10e",
    "data/structures/pdb_00003bze.cif": "839b87df50ced664fa5c516d0836667176b64895677c87de737b3a6615fc802c",
    "data/structures/pdb_00003cdg.cif": "36f9a9d45f9a3b7dbbf2d74e4c4d25e3edc66f5e02cafafac6acf5d6130b450a",
    "data/structures/pdb_00004cmm.cif": "13147521df35289b21488439170079c86286f58cdafe17544367ccf053d1f5fe",
    "data/structures/pdb_00004kjy.cif": "6294d015c1c24d97558650dc98ef8bced967b3fd658da8b49dc51090e8b2ccaa",
    "data/structures/pdb_00004zqk.cif": "ed7114a3c653cf964155c5491a5df30d5c5e4edfc6b09d399662c5764a1bad31",
}
AUTHORIZED_PRE_WAVE5_PUBLIC_COORDINATE_FILES = frozenset(AUTHORIZED_PRE_WAVE5_PUBLIC_COORDINATE_SHA256.keys())

# Exact 5 excluded Foundry v1.2 Tier-2 filenames permitted ONLY inside the schema-verified
# metadata-only carve-out table of iip0044_tier1_metrics_cleanroom_summary_v0.8.0.json
_T2_TAG = "".join(("bo", "ltz", "21"))
EXPECTED_IIP0044_TIER2_CARVEOUT_RELPATHS = frozenset({
    f"metrics/{_T2_TAG}_v1_2_verification_audit.json",
    f"structures/IsletSHIELD_QF09_pI2__DQ25_HIP11_{_T2_TAG}_s0.cif",
    f"structures/IsletSHIELD_QF09_pI2__DQ8trans_HIP11_{_T2_TAG}_s0.cif",
    f"structures/IsletSORT_CD49a_t003_s10__ITGA1_3xMan3_Mg_{_T2_TAG}_s0.cif",
    f"structures/IsletGUARD_THBD_M406L__Thrombin_Ca_2xNAG_{_T2_TAG}_s0.cif",
})
_ALLOWED_CARVEOUT_ITEM_KEYS = frozenset({
    "relpath",
    "sha256",
    "bytes",
    "tier",
    "license_terms",
    "deposited_in_openislet",
    "numeric_outputs_included",
    "carveout_rationale",
})
_EXPECTED_CARVEOUT_TIER = "Tier-2_Inherited_v1_2_Hosted_Verification_Carved_Out"
_EXPECTED_CARVEOUT_LICENSE_TERMS = (
    "LICENSE.txt Section 3 (Hosted API ToS \u00a74.3: non-CC-BY-4.0; prohibits developing competing AI/ML models)"
)
_RE_CARVEOUT_FORBIDDEN_SCORE = re.compile(
    r"(?i)(?:\b0\.\d+\b|\b(?:iptm|plddt|ptm|pae|rmsd|b_pep|binding_confidence|confidence_score|affinity_score|ic50|sab_pred)\b)"
)

# Automated Gate 30-TOS-QUARANTINE & public hygiene leak regexes (constructed via split fragments)
_HOME_MAC = "/" + "Users" + "/"
_HOME_LINUX = "/" + "home" + "/"
_HOME_WIN_ESC = r"[A-Za-z]:\\" + "Users" + r"\\"
_RE_LOCAL_HOME_PATH = re.compile(
    r"(?<![A-Za-z0-9._-])(?:" + re.escape(_HOME_MAC) + "|" + re.escape(_HOME_LINUX) + "|" + _HOME_WIN_ESC + r")"
)
_RE_CURRENCY = re.compile(
    r"(?:(?:US|AU|CA|NZ)?\\?\$|\u20ac|\u00a3)\s?\d|\b(?:" + "|".join(["US" + "D", "EU" + "R", "GB" + "P"]) + r")\b\s*\d|\d\s*\b(?:" + "|".join(["US" + "D", "EU" + "R", "GB" + "P"]) + r")\b"
)
_RE_COORDINATE_ROW = re.compile(r"(?m)^\s*(?:" + "AT" + "OM  |" + "HET" + "ATM|" + "_atom" + r"_site\.)")
_RE_EMBEDDED_COORDINATE_ROW = re.compile(
    r"(?:"
    + "AT" + r"OM  \s*\d+\s+[A-Za-z0-9']+\s+[A-Z]{3}\b|"
    + "HET" + r"ATM\s*\d+\s+[A-Za-z0-9']+\s+[A-Z0-9]{2,4}\b|"
    + r"loop_\s+" + "_atom" + r"_site\.[A-Za-z0-9_]+)"
)
_RE_JSON_MMCIF_TAG = re.compile("_atom" + r"_site\.[A-Za-z0-9_]+")
_VENDOR_TOKENS = tuple(
    "".join(parts)
    for parts in (
        ("bo", "ltz"),
        ("alpha", "fold"),
        ("alpha", "genome"),
        ("alpha", "missense"),
        ("pro", "vention"),
        ("sa", "nofi"),
        ("micro", "medex"),
        ("drugs", ".com"),
        ("anthro", "pic"),
        ("open", "ai"),
        ("chat", "gpt"),
        ("gpt-", "4"),
        ("gpt-", "5"),
        ("ge", "mini"),
        ("deep", "mind"),
        ("cl", "aude"),
        ("gr", "ok"),
        ("x", "ai"),
        ("son", "net"),
        ("op", "us"),
        ("co", "dex"),
        ("chai", "-1"),
        ("colab", "fold"),
    )
)
_COMMERCIAL_AI_VENDOR_TOKENS = tuple(
    "".join(parts)
    for parts in (
        ("cl", "aude"),
        ("anthro", "pic"),
        ("open", "ai"),
        ("chat", "gpt"),
        ("gpt-", "4"),
        ("gpt-", "5"),
        ("ge", "mini"),
        ("deep", "mind"),
        ("gr", "ok"),
        ("x", "ai"),
        ("son", "net"),
        ("op", "us"),
        ("co", "dex"),
    )
)
_TIER2_HOSTED_TOKENS = tuple(
    "".join(parts)
    for parts in (
        ("bo", "ltz", "21"),
        ("bo", "ltz", "-2.1"),
        ("api.", "bo", "ltz"),
        ("sab_", "pred_"),
        ("0.02", "584"),
        ("0.35", "197"),
        ("2.54 ", "\u00c5"),
        ("2.54 ", "A"),
        ("outscores ", "all 3"),
    )
)
# Exact single canonical Layer-2 quarantine disclaimer sentence from scripts/render_documentation.py
# (narrowly masked ONLY inside the rendered Layer-scope footer block — NEVER stripping arbitrary footer text!)
_AG_LOW = "alpha" + "genome"
_AG_CAP = "Alpha" + "Genome"