scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py · SHA-256: 33439d619c00fcc3…
#!/usr/bin/env python3
"""Provisional IIP-0058 / DEC-139 / GATE-37 / GY-036 (Round-14 Blueprint Alignment; staged in iip0058/):
Foundry v2.0 Two-Stage Islet-SORT v2.0 + 2025-2026 Maturation Stack (GP2 MCB + ITGA1 Component Sort,
BOTH promotion_authorized=False per live GY-024), Honest hiPSC-Derived 6th Arm (Arm Z-EnSC / E-islet 01;
upstream W6-C1 GATE-34 Dual-FailSafe + live Blueprint Section 7 OQ-012 Gate 5 k=0, n_eff>=299,573,228,
eta>=0.30, U95<=1e-8) + GINS 0.00 pp Reserve, Gate 28-A H1_allo = 88% Bayesian Lock, and Master
Integrated Wave-6 2^20 / 2^24 Portfolio Crosswalk Verifier (W6-C1..W6-C4).
Pure Python standard library ONLY:
- ZERO external dependencies (zero numpy/scipy; exact scale-relative 3x3 Kogbetliantz
Kabsch SVD, exact 75-digit Decimal Bernoulli-Stirling + Lentz CF Clopper-Pearson U95,
and exact pure-stdlib transportation/simplex LP solvers)
- ZERO wetlab_contract.py imports (Zero-LIMS-Touch)
- ZERO assert statements (byte-identical execution under -B and -O -B)
- ZERO network calls at verifier runtime
- Embeds verified RCSB CC0-1.0 atomic coordinate subset for 7P6S, 7P6T, 1PT6 (A/B),
1QC5 (A/B), and ALL 10 NMR conformers of 2M32 (Models 1..10)
- Strict fail-closed external hash-verified verification against wave6_master_contract.json
and release-relative wave6_canonical_arm_manifest.json across EVERY invariant, reachable
scenario, prerequisite-waived counterfactual, sensitivity, sharp H2/H3 transportation LP,
24-state weight-dependence LP, and individual state cell (<1e-12 unrounded exact parity
AND 0.00e+00 4-decimal display parity).
Usage:
PYTHONDONTWRITEBYTECODE=1 python3 -B scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py --standalone
PYTHONDONTWRITEBYTECODE=1 python3 -B scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py --standalone --check --check-portable
PYTHONDONTWRITEBYTECODE=1 python3 -O -B scripts/verify_iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio.py --standalone --check --check-portable
"""
from __future__ import annotations
import argparse
import hashlib
import heapq
import json
import math
import re
import statistics
import sys
import unicodedata
from decimal import Decimal, ROUND_FLOOR, localcontext
from fractions import Fraction
from pathlib import Path
from typing import Any, Callable, FrozenSet, Mapping, Optional, Sequence
sys.dont_write_bytecode = True
SCRIPT_PATH = Path(__file__).resolve()
SCRIPT_DIR = SCRIPT_PATH.parent
PKG_ROOT = SCRIPT_DIR.parent if SCRIPT_DIR.name == "scripts" else SCRIPT_DIR
DEFAULT_RECEIPT_PATH = (
PKG_ROOT / "data" / "extracted" / "iip0058_armz_ensc_isletsort_v2_and_2p24_portfolio_v0.9.0.json"
)
DEFAULT_SIDE_CONTRACT_PATH = (
PKG_ROOT / "data" / "protocols" / "iip0058_armz_ensc_sortv2_portfolio_side_contract_v0.9.0.json"
)
DEFAULT_PROTOCOL_DOC_PATH = (
PKG_ROOT / "docs" / "GATE-37-ARMZ-ENSC-ISLETSORT-V2-AND-2P24-PORTFOLIO-PROTOCOL.md"
)
DEFAULT_GY036_PATH = PKG_ROOT / "data" / "protocols" / "iip0058_gy036_entry.json"
def discover_default_master_contract_path(pkg_root: Optional[Path] = None) -> Path:
"""Discover default wave6_master_contract.json across supported staged & flattened release layouts."""
root = pkg_root if pkg_root is not None else PKG_ROOT
candidates = (
root.parent / "shared" / "wave6_master_contract.json",
root / "data" / "protocols" / "wave6_master_contract.json",
root / "shared" / "wave6_master_contract.json",
)
for cand in candidates:
if cand.is_file():
return cand
return candidates[0]
DEFAULT_MASTER_CONTRACT_PATH = discover_default_master_contract_path()
DEFAULT_CANONICAL_MANIFEST_PATH = DEFAULT_MASTER_CONTRACT_PATH.parent / "wave6_canonical_arm_manifest.json"
EXPECTED_CANONICAL_MANIFEST_SHA256 = "0a051b69687bd791feeaf55e97c07d993e27cdd7c453e6e3b67b599d243a4235"
EXPECTED_CANONICAL_MANIFEST_CANON_SHA256 = "9e84e0b64925f9fdeb9450b364728a4076fa43cf8b46085ba2215722541f0d50"
EXPECTED_MASTER_CONTRACT_SHA256 = "53f90447f1f32213adff883f26d30aa1268f4848e6d3d1d946c03d9c7c8a8b42"
EXPECTED_MASTER_CONTRACT_FILE_SHA256 = "2108aa272bfe657c2767ba0f10961443fa280d5f074a84d5578d42c204fff35a"
EXPECTED_SIDE_CONTRACT_SHA256 = "7e5f523b145a5611d89b4abcaaad52479d3bf29f7f260b287fb6860e80d448b6"
EXPECTED_PROTOCOL_DOC_SHA256 = "bb34386a1ec6ff2aa485bebe9c0cf6583921b6761128742a31eb05ad7a15cf4c"
EXPECTED_GY036_SHA256 = "eaa35e07c8b70b70d6fe452b26d04c404de99dc0fcfac4bf7171df5530584ba4"
GP2_ARCHIVE_REQUIRED_RELEASE_FIELDS: tuple[str, ...] = (
"input_gp2_pos_pct",
"input_total_loaded_cells",
"input_gp2_pos_cells",
"recovered_gp2_pos_cells",
"macs_recovery_denominator_type",
"macs_recovery_eta_pct",
"mature_acinar_cpa1_prss1_ptf1a_pct",
"gpi_post_dissociation_mfi_retention_pct",
"gpi_post_dissociation_mfi",
"gpi_baseline_mfi",
"post_sort_pdx1_nkx61_pct",
"post_sort_pdx1_nkx61_pos_cells",
"post_sort_total_evaluated_cells",
"kd_gp2_nM",
"selectivity_vs_umod_fold",
"challenge_dose_cells",
"teratoma_n",
"teratoma_events",
"teratoma_followup_weeks",
"tumor_host_strain",
"per_animal_exposures",
)
ITGA1_ARCHIVE_REQUIRED_RELEASE_FIELDS: tuple[str, ...] = (
"binder_id",
"assay_lot_id",
"epitope_contact_residues",
"binder_valency",
"capture_temp_C",
"kd_itga1_nM",
"spr_selectivity_vs_itga2_fold",
"spr_selectivity_vs_itga10_fold",
"spr_selectivity_vs_itga11_fold",
"live_cell_ec50_itga1_target_nm",
"live_cell_ec50_itga2_offtarget_nm",
"collagen_midas_inhibition_pct",
"isx9_nkx61_retention_pct",
"pcamkii_retention_pct",
"pfak_y397_fold_vs_vehicle",
"psrc_fold_vs_vehicle",
"integrin_internalization_pct",
"residual_ligand_ng_per_1e6",
"post_sort_tph1_sc_ec_pct",
"alpha_cell_respike_pct",
"oq018_low_glucose_1mM_glucagon_fold",
"oq018_glucagon_auc_l95",
"common_denom_eta_sort_pct",
)
ENSC_ARCHIVE_REQUIRED_RELEASE_FIELDS: tuple[str, ...] = (
"seedline_source",
"baseline_bcor_or_cosmic_tier1_mutations",
"editing_passes",
"mcb_plus_wcb_passage",
"mcb_plus_wcb_pds",
"teratoma_events",
"teratoma_n",
"teratoma_followup_weeks",
"tumor_host_strain",
"tumor_challenge_dose_cells",
"per_animal_teratoma_outcomes",
"perifusion_mode",
"stage7_ins_nkx61_beta_pct",
"stage7_monohormonal_gcg_cpep_neg_alpha_pct",
"stage7_sst_delta_pct",
"stage7_tph1_sc_ec_pct",
"entpd3_mature_beta_pct",
"pulse1_si",
"pulse2_si",
"dynamic_gsis_si",
"stepdown_shutoff_t90_min",
"oq018_low_glucose_1mM_glucagon_fold",
"oq018_glucagon_auc_l95",
"terminal_alk5i_class_exposed",
"terminal_reagents",
)
ENSC_ARCHIVE_ROSTER_CANONICAL_KEY: str = "per_animal_teratoma_outcomes"
ENSC_ARCHIVE_ACCEPTED_STRUCTURED_ROSTER_ALIASES: tuple[str, ...] = (
"per_animal_teratoma_outcomes",
"per_animal_exposures",
"teratoma_animal_outcomes",
)
ENSC_ARCHIVE_RECONCILED_ID_LIST_ONLY_ALIASES: tuple[str, ...] = (
"animal_ids",
"teratoma_animal_ids",
)
ENSC_ARCHIVE_ACCEPTED_TERMINAL_REAGENTS_ALIASES: tuple[str, ...] = (
"terminal_reagents",
"terminal_maturation_small_molecules",
)
ENSC_ROW_DOSE_ALIASES: tuple[str, ...] = (
"challenge_dose_cells",
"dose_cells",
"tumor_challenge_dose_cells",
)
ENSC_ROW_FOLLOWUP_ALIASES: tuple[str, ...] = (
"followup_weeks",
"teratoma_followup_weeks",
)
ENSC_ROW_OUTCOME_ALIASES: tuple[str, ...] = (
"tumor_detected",
"teratoma_detected",
"teratoma_observed",
"tumor_observed",
)
ENSC_ROW_HOST_ALIASES: tuple[str, ...] = (
"host_strain",
"tumor_host_strain",
)
STUDY_TERATOMA_FOLLOWUP_ALIASES: tuple[str, ...] = (
"teratoma_followup_weeks",
"followup_weeks",
"study_followup_weeks",
"teratoma_observation_weeks",
"observation_weeks",
)
STUDY_TERATOMA_DOSE_ALIASES: tuple[str, ...] = (
"challenge_dose_cells",
"tumor_challenge_dose_cells",
"dose_cells",
)
STUDY_TERATOMA_HOST_ALIASES: tuple[str, ...] = (
"tumor_host_strain",
"host_strain",
)
STUDY_TERATOMA_N_ALIASES: tuple[str, ...] = (
"teratoma_n",
"teratoma_n_evaluated",
"teratoma_cohort_n",
)
STUDY_TERATOMA_EVENTS_ALIASES: tuple[str, ...] = (
"teratoma_events",
"teratoma_event_count",
"teratoma_positive_count",
"teratoma_tumors",
)
GINS_ARCHIVE_REQUIRED_RELEASE_FIELDS: tuple[str, ...] = (
"study_id",
"non_integrating_platform_verified",
"vector_copy_number_per_cell",
"process_class",
"vcn_assay_id",
"integrating_lentivirus_used",
"tamoxifen_inducible_fusion_used",
"liraglutide_free_perifusion",
"alpha_coagg_monohormonal_gcg_pct",
"reaggregation_cluster_diameter_um",
"oq018_low_glucose_1mM_glucagon_fold",
"oq018_glucagon_auc_l95",
"stepdown_shutoff_t90_min",
"gastric_mucin_reversion_pct",
"mouse_durability_days",
"nhp_durability_days",
"nhp_n_tested",
"nhp_durability_pass_count",
"polyclonal_donor_count",
"polyclonal_t1d_pbmc_hla_dq_verified",
"polyclonal_donor_survival_pct",
)
GENERATED_DATE = "2026-12-01"
MIN_GATE5_TESTED_CELLS = 1
MIN_GATE5_OQ012_EFFECTIVE_TRIALS = 299_573_228
MIN_GATE5_CLONOGENIC_CELLS = MIN_GATE5_OQ012_EFFECTIVE_TRIALS
MIN_GATE5_SPIKE_IN_ETA = Decimal("0.30")
MAX_GATE5_OQ012_U95 = Decimal("1e-8")
MAX_CLONOGENIC_CELLS = 10**12