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…

        n_req = min_n_for_zero_event_cap(cap_persist, alpha_1p_2way, eta_l, prec=80)["min_n_pass"]
        calibrant_1p_thresholds[f"{rn}_of_{rn}"] = {
            "eta_lower_80d": format(eta_l, "f")[:24],
            "clears_0p80_floor": bool(eta_l >= Decimal("0.80")),
            "min_obs_n_per_lineage": n_req,
            "total_obs_cells_5_lineages": n_req * 5,
        }

    calibrant_3p_thresholds = {}
    for rn in (28, 29, 30, 40, 50):
        eta_l = exact_clopper_pearson_lower_calibrant(rn, rn, alpha_3p_2way, prec=80)
        n_req = min_n_for_zero_event_cap(cap_persist, alpha_3p_2way, eta_l, prec=80)["min_n_pass"]
        calibrant_3p_thresholds[f"{rn}_of_{rn}"] = {
            "eta_lower_80d": format(eta_l, "f")[:24],
            "clears_0p80_floor": bool(eta_l >= Decimal("0.80")),
            "min_obs_n_per_lineage_per_pathogen": n_req,
            "total_obs_cells_5lin_1pathogen": n_req * 5,
            "total_obs_cells_5lin_3pathogens": n_req * 15,
        }

    kill_eta_0p80 = min_n_for_zero_event_cap(cap_kill_esc, alpha_1p_2way, Decimal("0.80"), prec=80)
    eta_kill_24 = exact_clopper_pearson_lower_calibrant(24, 24, alpha_1p_2way, prec=80)
    kill_eta_24 = min_n_for_zero_event_cap(cap_kill_esc, alpha_1p_2way, eta_kill_24, prec=80)
    kill_cond_3log_eta_0p80_indirect = min_n_for_zero_event_cap(Decimal("0.001"), Decimal("0.015"), Decimal("0.80"), prec=80)
    kill_cond_3log_eta_0p80_direct = min_n_for_zero_event_cap(Decimal("0.001"), Decimal("0.020"), Decimal("0.80"), prec=80)
    kill_cond_3log_eta_0p80_legacy_0p005 = min_n_for_zero_event_cap(Decimal("0.001"), alpha_1p_2way, Decimal("0.80"), prec=80)
    with _clean_dec_ctx(80, ROUND_HALF_EVEN):
        w_pericyte = Decimal(GRAFT_COMPOSITION_CELLS["pericyte"]) / Decimal(TOTAL_GRAFT_CELLS)
        weighted_masking_pct = float(w_pericyte * Decimal("1.30"))
    kill_lab_scale_by_sveh = {}
    for sveh_str in ("0.50", "0.25", "0.10"):
        sveh_d = Decimal(sveh_str)
        with _clean_dec_ctx(80, ROUND_FLOOR):
            sveh_eta_prod = sveh_d * Decimal("0.80")
        pericytes_needed = min_n_for_zero_event_cap(
            cap_kill_esc, alpha_1p_2way, sveh_eta_prod, prec=80
        )["min_n_pass"]
        with _clean_dec_ctx(80, ROUND_CEILING):
            organoid_cells_needed = int((Decimal(pericytes_needed) / w_pericyte).to_integral_value(rounding=ROUND_CEILING))
        kill_lab_scale_by_sveh[f"s_veh_{sveh_str}"] = {
            "ratio_bound_method": "exact_component_probability_bonferroni_ratio",
            "min_at_risk_n_eff_per_lineage_at_eta0p80": kill_eta_0p80["min_n_pass"],
            "min_pre_ap1903_pericytes_needed": pericytes_needed,
            "min_assembled_organoid_cells_per_arm": organoid_cells_needed,
            "fits_within_2e7_cells_per_arm": bool(organoid_cells_needed <= 20_000_000),
        }

    decimal_regression = run_decimal_interval_regression_suite()
    adversarial = run_adversarial_contract_tests(openislet_root=openislet_root)
    nw08 = run_nw08_calibration_and_layer4_margin_audit(openislet_root, run_3d_fvm=not args.skip_3d_fvm)
    ceg_and_prot = audit_protected_files_and_ceg_delta(openislet_root, inv_root, args.protected_manifest)
    oq016 = quantify_oq016_and_tail_risk_reduction(openislet_root)

    r4_ok = bool(ceg_and_prot["r4_playbook_sec4120_dec114_and_renderer_compatibility"]["passed"])
    gy030_parity_ok = bool(ceg_and_prot["gy030_graveyard_parity"]["passed"])
    ceg_eight_crosslinks_ok = bool(ceg_and_prot["ceg_delta_v33_eight_crosslinks_ledger"]["all_eight_crosslinks_verified"])
    fvm_ok = bool(args.skip_3d_fvm or nw08["true_3d_fvm_vascular_voxel_1p3164_replays"].get("executed"))
    dispatch_ok = bool(args.skip_3d_fvm or nw08["nw08_live_dispatch_solver_tests"].get("all_passed"))
    nw08_trig_ok = bool(nw08["nw08_trigger_and_floor_unit_tests"]["all_passed"])
    all_ok = bool(
        decimal_regression["all_passed"]
        and adversarial["all_passed"]
        and nw08_trig_ok
        and dispatch_ok
        and ceg_and_prot["protected_files_zero_byte_invariance_ok"]
        and r4_ok
        and gy030_parity_ok
        and ceg_eight_crosslinks_ok
        and fvm_ok
    )

    receipt = {
        "schema_version": "0.8.0-exp031-r17-v20",
        "investigation_id": "EXP-031",
        "candidate_id": "CAND-034",
        "target_iip": "IIP-0043",
        "decision_id": "DEC-122",
        "python_version": sys.version.split()[0],
        "graveyard_guardrail_id": GRAVEYARD_GUARDRAIL_ID,
        "graveyard_card_id": GRAVEYARD_CARD_ID,
        "design_pattern": (
            "Option-2 Zero-LIMS-Touch (R17-B1 mandatory typed sampling-unit reconciliation extended to ALL "
            "release-critical control & recovery counts entering exact Clopper-Pearson or joint directional bounds "
            "[BOTH stressed-arm recovery calibrants spike_calibrant & fragile_infected_spike_calibrant, Day-28 "
            "uninfected negative controls uninfected_ctrl_per_unit_counts, AND BOTH Day-28 recovery calibrants "
            "spike_calibrant_per_unit_counts & fragile_infected_spike_per_unit_counts; 209/209 reconciled partitions "
            "on shipping multi-well bank fixture; missing/mismatched calibrant or neg-ctrl basis routes to HOLD with "
            "exact_directional_confidence_certified=False and all_sampling_units_reconciled=False while strictly "
            "preserving FAIL_HARD_STOP precedence] + R17-B2 provably upper-enclosed 60-digit standard-normal 95th "
            "percentile z_{0.95} = 1.64485362695147271486... [upward IEEE-754 float64 1.6448536269514729; 1 - Phi(z) "
            "< 0.05 strictly, rejecting old under-covering 1.6448536269514722] AND guaranteed upward-rounded IEEE-754 "
            "float64 live 3D FVM vascular OCR multiplier derived directly from exact rational Fraction(ocr_u95_dec) / "
            "Fraction(baseline_ocr_dec) via math.nextafter(..., +inf) with per-voxel upward guarantee [strictly > 1.0 "
            "even on sub-ULP positive SE such as 1.097 + t_{0.95, 5}*1e-20] + R17-M1 direct qualification_scope and "
            "physical_qualification_complete=False emitted on dispatch_and_solve_nw08_measured_ocr return dicts + "
            "R17-M2 3-grid ladder docstrings explicitly qualified with recorded 2-grid direct-crossing early-stop "
            "exception + R16-B1 strict uncertainty_se > 0 enforcement for BOTH inferential NW-08 "
            "OCR models [STUDENT_T_ESTIMATED_SE and KNOWN_SIGMA_NORMAL] before solving -> "
            "HOLD_NW08_INFERENTIAL_MODEL_REQUIRES_POSITIVE_SE [solver_executed=False, release_authorizing=False, "
            "exit 2; ValueError on direct API] while retaining ZERO_UNCERTAINTY_DETERMINISTIC_POINT for SE == 0 "
            "+ R16-M1 provably outward-conservative upper-enclosed Student-t critical values t_{0.95, df} >= exact "
            "across all df >= 1 [including df=1 Cauchy cot(pi/20) and exact 7-dp t_{0.95, 5}=2.0150484] "
            "+ R16-M2 exact arbitrary-precision rational integer floor n_eff = floor(n / deff) via Fraction(n) // "
            "Fraction(deff) eliminating finite-precision Decimal truncation for huge counts [10**80 + 1] "
            "+ R16-M3 explicit mesh_uncertainty_status distinguishing single-grid far-from-floor policy skip "
            "[order_qualified=False, interval_valid=False, SINGLE_GRID_FAR_FROM_FLOOR_POLICY_PASS_ORDER_NOT_EVALUATED], "
            "3-grid monotone non-asymptotic fallback [order_qualified=False, "
            "THREE_GRID_MONOTONE_NON_ASYMPTOTIC_FALLBACK_ORDER_NOT_QUALIFIED], and 3-grid asymptotic GCI qualified "
            "[order_qualified=True, interval_valid=True, THREE_GRID_ASYMPTOTIC_GCI_QUALIFIED] + "
            "R14-B1 + R15-B2 predeclared 3-grid numerical convergence verification policy "
            "inside route-family near-floor bands [R1: 14.88-15.25, R2: 14.75-15.25, R3P: 14.70-15.30 mmHg] using "
            "NASA/Roache GCI [admissible p_obs in [0.5, 2.5], formal cap 2.0, ZERO upward clamping of slow p_obs < 0.5] "
            "and ASME V&V-20 oscillatory half-range bounds [Fs=1.25] routing threshold-straddling cases to "
            "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR and sub-asymptotic/unqualified order cases to "
            "HOLD_NW08_MESH_CONVERGENCE_UNQUALIFIED_SLOW_OR_NON_ASYMPTOTIC_ORDER [interval_valid=False, exit 2] "
            "before any coupled authorization + R15-M2 verbatim 8-edge CEG-DELTA field parity check on relation, "
            "target_gate_or_module, applicability, and cited_outcome_tuples + R14-B2 exact Student-t small-sample "
            "OCR inference [t_{0.95, df}, e.g. t_{0.95, 5}=2.0150484 for n=6 replicates] and required inferential model "
            "provenance rejecting bare undeclared positive SE fail-closed while scoping normal z=1.6448536 "
            "strictly to declared KNOWN_SIGMA_NORMAL models with external calibration provenance + R18-B1/B2 "
            "isolated child Python subprocess native 3D FVM execution strictly bound to openislet_root/scripts "
            "[verifying Path(mod.__file__).resolve().is_relative_to(resolved_root), reporting "
            "resolved_solver_module_origins on live dispatch responses, zero parent sys.path/sys.modules/"
            "layer4 callback mutation for concurrent raw native Layer-4 callers, and sequential cross-root "
            "copy_A -> copy_B module-origin isolation] + R14-B3 process-wide _FVM_SOLVER_LOCK cache "
            "serialization across direct and composite-wrapper interfaces + single canonical strict RFC-8259 JSON decoder enforcing exact-Decimal "
            "preservation on adjudication-boundary keys + nonzero float64 underflow rejection (-1e-400, 1e-400) + "
            "full signed negative-zero rejection (-0, -0.0, '-0', '-0.0') on non-negative parameters + bounded nesting "
            "depth MAX_JSON_NESTING_DEPTH=64 + RecursionError capture + duplicate-key, NaN/Infinity, overflowing-float, "
            "& out-of-float64-range integer rejection across all direct, store, archive, and CLI intake boundaries + "
            "unconditional pre-schema adverse per_unit_counts scanner across all required/supplemental arms and both "
            "single-cell/multi-well classes with zero early returns on malformed rows + single-cell per_unit_counts "
            "rejection + cross-estimand same-unit ID set and within-unit subset inequality reconciliation "
            "(direct_infected_veh_72h <= veh_72h and SAME_72H_ALIQUOT infected_viral_pos_72h <= ap1903_72h) + "
            "reconciled per-estimand sampling-unit basis enforcing independent_biological_units_n >= 6, canonical "
            "independent_sampling_unit_class enum, and ZERO unvalidated numeric deff retention when spec or partitions "
            "fail validation + subtractive prohibition of require_trusted_nw08_ocr_record=True on BANK_QUALIFICATION "
            "enforced identically at direct admission and archive replay + machine-readable qualification_scope and "
            "physical_qualification_complete=False attached directly onto every live PASS response across all tiers + "
            "safe type-checked intake guaranteeing structured HOLD exit 2 + mandatory fail-closed enforcement of "
            "require_trusted_nw08_ocr_record=True on clinical release lots -> HOLD_NW08_REQUIRED_OCR_RECORD_MISSING "
            "when OCR is omitted + standalone unbound --dispatch-nw08-ocr strictly non-authorizing "
            "release_authorizing=False recursively + external --trusted-qualification-store with canonical composite "
            "envelope parity & live dual/composite bank replay across both store layouts + cryptographic & structural "
            "coupled --nw08-ocr-json binding + strict SAME_72H_ALIQUOT count reconciliation + direct infected-vehicle "
            "conditional escape requirement + unclamped [0, +infinity) exact component-probability Bonferroni ratio "
            "bounds strictly certified ONLY at deff == 1.0 under a valid reconciled sampling-unit basis [matching "
            "GY-018/IIP-0044], routing deff > 1.0 to non-authorizing HOLD_CLUSTERED_DEFF_GT_1_REQUIRES_CLUSTER_LEVEL_INFERENCE "
            "+ explicit 0/0 [point=None, flag=None] vs k>0/0 [point=+Infinity] zero-denominator boundary conventions + "
            "0..n 3-state control-HOLD adjudication + canonical product_variant_id reconciliation + true U95 <= 0.15% "
            "negative controls + exact zero-deadband IEEE-754 canonical live 3D FVM dispatch solver + public-bundle "
            "portable verification)"
        ),
        "arithmetic_engine": (
            "Exact Fraction argument reduction + pure elementary (+,-,*,/) outward-directed 80/120-digit "
            "Taylor interval Decimal + dynamic working precision + three-valued exact/interval boundary "
            "adjudication (ZERO Decimal.ln()/exp() reliance; full ambient-context, narrow-exponent, & Inexact-trap immunity)"
        ),
        "graft_5lineage_composition": {
            "composition_scope": "reference_design_fraction_lot_composition_unmeasured",
            "total_cells_per_500k_ieq_graft": TOTAL_GRAFT_CELLS,
            "cells_by_lineage": GRAFT_COMPOSITION_CELLS,
            "non_beta_cell_count": TOTAL_GRAFT_CELLS - GRAFT_COMPOSITION_CELLS["beta"],
            "non_beta_share_pct": round(100.0 * (TOTAL_GRAFT_CELLS - GRAFT_COMPOSITION_CELLS["beta"]) / TOTAL_GRAFT_CELLS, 4),
            "composition_caveat": (
                "48.58% non-beta share is the reference design fraction for the 500k IEQ modeled graft; "
                "actual lot cellular composition remains to be measured experimentally across SC-islet and "
                "native pancreas preparations."
            ),
        },
        "part_a_gate0v_outward_taylor_decimal_bounds": {
            "decimal_interval_regression_suite": decimal_regression,
            "per_lineage_persistence_cap_frac": "0.0005",
            "negative_control_true_u95_cap_pct": "0.15",
            "negative_control_n_min": 20000,
            "legacy_beta_only_alpha_0p05_eta_1p0": legacy_beta_only,
            "five_lineage_1way_bonferroni_alpha_0p01": fwer_5lin_1way,
            "single_pathogen_cvb4_5lin_2way_alpha_0p005": fwer_1pathogen_5lin_2way,
            "full_3pathogen_global_fwer_30tests_alpha_1_over_600": fwer_3pathogen_5lin_2way,
            "spike_calibrant_1pathogen_alpha_0p005": calibrant_1p_thresholds,
            "spike_calibrant_3pathogen_alpha_1_over_600": calibrant_3p_thresholds,
            "gate0v_kill_dual_estimand_sizing": {
                "estimand1_per_total_input_escape_cap": "0.0001",
                "estimand2_conditional_per_pretreat_infected_escape_cap": "0.001",
                "bonferroni_per_estimand_alpha_budgets": {
                    "confidence_statement_type": "DIRECTIONAL_ONE_SIDED_SEPARATE_AT_1_MINUS_ALPHA_SUM",
                    "paired_24h_ratio": {
                        "alpha_veh": "0.025",
                        "alpha_surv": "0.025",
                        "union_bound_sum": "0.050",
                        "confidence_statement_type": "DIRECTIONAL_ONE_SIDED_SEPARATE_AT_1_MINUS_ALPHA_SUM",
                    },
                    "paired_72h_ratio": {
                        "alpha_veh": "0.025",
                        "alpha_surv": "0.025",
                        "union_bound_sum": "0.050",
                        "confidence_statement_type": "DIRECTIONAL_ONE_SIDED_SEPARATE_AT_1_MINUS_ALPHA_SUM",
                    },
                    "estimand1_total_input": {
                        "alpha_veh": "0.025",
                        "alpha_eta": "0.005",
                        "alpha_escape": "0.005",
                        "union_bound_sum": "0.035",
                        "confidence_statement_type": "DIRECTIONAL_ONE_SIDED_UPPER_AT_1_MINUS_ALPHA_SUM",
                    },
                    "estimand2_indirect": {
                        "alpha_veh": "0.015",
                        "alpha_prev": "0.015",
                        "alpha_eta": "0.005",
                        "alpha_escape": "0.015",
                        "union_bound_sum": "0.050",
                        "confidence_statement_type": "DIRECTIONAL_ONE_SIDED_UPPER_AT_1_MINUS_ALPHA_SUM",
                    },
                    "estimand2_direct": {
                        "alpha_inf_veh": "0.025",
                        "alpha_eta": "0.005",
                        "alpha_escape": "0.020",
                        "union_bound_sum": "0.050",
                        "confidence_statement_type": "DIRECTIONAL_ONE_SIDED_UPPER_AT_1_MINUS_ALPHA_SUM",
                    },
                    "coverage_scope_disclosure": (
                        "Each budget certifies >= 95.0% exact directional one-sided confidence across all estimated "
                        "component parameters within an individual lineage x stress-regime estimand STRICTLY AT "
                        "deff == 1.0 UNDER A VALID, RECONCILED PER-ESTIMAND SAMPLING-UNIT BASIS (independent_biological_units_n >= 6, "
                        "canonical independent_sampling_unit_class enum, and verified per-unit counts; matching GY-018 and IIP-0044). "
                        "Missing or invalid clustering_and_independence_spec NEVER defaults deff = 1.0 and sets "
                        "exact_directional_confidence_certified = false (confidence_scope = UNCERTIFIED_MISSING_OR_INVALID_SAMPLING_SPEC). "
                        "For RECONCILED_MULTI_WELL_CELL_ASSAY_WITH_UNIT_PARTITION (6 <= independent_biological_units_n < n), "
                        "certification carries explicit scope CONDITIONAL_ON_EXTERNALLY_VALIDATED_WITHIN_WELL_INDEPENDENCE_DEFF_EQ_1 "
                        "(JSON partition reconciliation verifies accounting against declared biological units but does NOT prove "
                        "physical within-well independence; external assay QA must verify zero intra-well clustering, otherwise "
                        "cluster-level inference is required). Only INDEPENDENT_SINGLE_CELL_OR_LIMITING_DILUTION_UNIT with "
                        "independent_biological_units_n >= max_binomial_denominator_n carries "
                        "EXACT_INDEPENDENT_BINOMIAL_BONFERRONI_DEFF_EQ_1_UNIT_MATCHED. "