OpenIslet

scripts/evaluate_gate0v_composite_release.py

IIP-0043 / DEC-122 (CAND-034 / EXP-031) Executable Dual-Evaluator Composite Release Wrapper

script Release v0.8.0 gen-eb955f8266035aba 357 KB · 28 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/evaluate_gate0v_composite_release.py · SHA-256: 2be0252340222fe4…

        f_r16_st0_r1.write_text(json.dumps(ocr_r16_st0_r1, sort_keys=True), encoding="utf-8")
        f_r16_ks0_r2 = Path(td) / "r16_b1_ocr_ks0_r2.json"
        f_r16_ks0_r2.write_text(json.dumps(ocr_r16_ks0_r2, sort_keys=True), encoding="utf-8")
        f_r16_det0_r2 = Path(td) / "r16_b1_ocr_det0_r2.json"
        f_r16_det0_r2.write_text(json.dumps(ocr_r16_det0_r2, sort_keys=True), encoding="utf-8")

        r_85_st0_r2, rc_85_st0_r2 = evaluate_composite_lot_file(
            clin_r2_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=trusted_store,
            openislet_root=openislet_root,
            nw08_ocr_json_path=f_r16_st0_r2,
        )
        r_85_st0_r1, rc_85_st0_r1 = evaluate_composite_lot_file(
            clin_r1_390_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=trusted_store,
            openislet_root=openislet_root,
            nw08_ocr_json_path=f_r16_st0_r1,
        )
        r_85_ks0_r2, rc_85_ks0_r2 = evaluate_composite_lot_file(
            clin_r2_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=trusted_store,
            openislet_root=openislet_root,
            nw08_ocr_json_path=f_r16_ks0_r2,
        )
        r_85_ks0_api = evaluate_composite_clinical_release(
            clin_r2_bundle,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=trusted_store,
            openislet_root=openislet_root,
            nw08_ocr_record=ocr_r16_ks0_r2,
        )
        r_85_det0_r2, rc_85_det0_r2 = evaluate_composite_lot_file(
            clin_r2_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=trusted_store,
            openislet_root=openislet_root,
            nw08_ocr_json_path=f_r16_det0_r2,
        )

        # Independent biological FAIL_HARD_STOP (adverse supplemental HCMV reactivation) + zero-SE
        # STUDENT_T_ESTIMATED_SE OCR MUST still exit 3 (`FAIL_HARD_STOP_COMPOSITE_RELEASE`) while
        # preserving OCR HOLD diagnostics (`HOLD_NW08_INFERENTIAL_MODEL_REQUIRES_POSITIVE_SE`)!
        g0v_clin_bio_fail = copy.deepcopy(g0v_clin)
        g0v_clin_bio_fail["gate0v_b_infectious_challenge"]["pathogens"]["hcmv"] = {
            "day28_latent_and_defective_genome_arm": {"reactivation_7d_outgrowth_pfu_ml": "2.5"}
        }
        g0v_clin_bio_fail["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_clin_bio_fail)
        clin_bio_fail_bundle = _make_composite_bundle(
            clin_lot_id,
            mcb_id,
            pv_lead,
            leg_clin,
            g0v_clin_bio_fail,
            nw08_route_id="R2_DZ40",
            nw08_measurement_evidence_sha256=clin_ev_sha,
            nw08_measurement_not_before_utc="2026-11-28T00:00:00Z",
        )
        clin_bio_fail_f = Path(td) / "r16_b1_clin_bio_fail_r2.json"
        clin_bio_fail_f.write_text(json.dumps(clin_bio_fail_bundle, sort_keys=True), encoding="utf-8")
        ocr_r16_bio_fail_st0 = v38.build_bound_nw08_ocr_record(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            route_id="R2_DZ40",
            lot_payload_sha256=clin_bio_fail_bundle["payload_sha256"],
            measured_ocr=1.097,
            uncertainty_se=0.0,
            ocr_uncertainty_model="STUDENT_T_ESTIMATED_SE",
            ocr_replicates_n=6,
            measurement_record_id="OCR-R16-B1-BIOFAIL-ST0",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        f_r16_bio_fail_st0 = Path(td) / "r16_b1_ocr_bio_fail_st0.json"
        f_r16_bio_fail_st0.write_text(json.dumps(ocr_r16_bio_fail_st0, sort_keys=True), encoding="utf-8")
        r_85_bio_hs, rc_85_bio_hs = evaluate_composite_lot_file(
            clin_bio_fail_f,
            legacy_evaluator=leg_fn,
            gate0v_evaluator=g0v_fn,
            trusted_qualification_store=trusted_store,
            openislet_root=openislet_root,
            nw08_ocr_json_path=f_r16_bio_fail_st0,
        )

        tok_pos_se = "HOLD_NW08_INFERENTIAL_MODEL_REQUIRES_POSITIVE_SE"
        ok_85 = bool(
            rc_85_st0_r2 == 2
            and r_85_st0_r2["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_85_st0_r2["release_authorizing"] is False
            and tok_pos_se in r_85_st0_r2["holds"]
            and (r_85_st0_r2.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
            and rc_85_st0_r1 == 2
            and r_85_st0_r1["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_85_st0_r1["release_authorizing"] is False
            and tok_pos_se in r_85_st0_r1["holds"]
            and (r_85_st0_r1.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
            and rc_85_ks0_r2 == 2
            and r_85_ks0_r2["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_85_ks0_r2["release_authorizing"] is False
            and tok_pos_se in r_85_ks0_r2["holds"]
            and (r_85_ks0_r2.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
            and r_85_ks0_api["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_85_ks0_api["release_authorizing"] is False
            and tok_pos_se in r_85_ks0_api["holds"]
            and (r_85_ks0_api.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
            and rc_85_det0_r2 == 0
            and r_85_det0_r2["composite_verdict"] == "PASS_COMPOSITE_CLINICAL_RELEASE"
            and r_85_det0_r2["release_authorizing"] is True
            and (r_85_det0_r2.get("nw08_measured_ocr_dispatch_result") or {}).get("ocr_uncertainty_model")
            == "ZERO_UNCERTAINTY_DETERMINISTIC_POINT"
            and rc_85_bio_hs == 3
            and r_85_bio_hs["composite_verdict"] == "FAIL_HARD_STOP_COMPOSITE_RELEASE"
            and r_85_bio_hs["release_authorizing"] is False
            and tok_pos_se in r_85_bio_hs["holds"]
            and (r_85_bio_hs.get("nw08_measured_ocr_dispatch_result") or {}).get("solver_executed") is False
            and rc_83_t6 == 3
            and r_83_t6["composite_verdict"] == "FAIL_HARD_STOP_COMPOSITE_RELEASE"
        )
        cases.append({
            "case": "r16_b1_coupled_zero_se_inferential_models_held_exit_2_det_pass_pos_se_fail_bio_hard_stop_exit_3",
            "expected_verdict": "HOLD_2_DET_PASS_0_BIO_FAIL_3",
            "actual_verdict": (
                f"{r_85_st0_r2['composite_verdict']}_{rc_85_st0_r2}__"
                f"{r_85_ks0_r2['composite_verdict']}_{rc_85_ks0_r2}__"
                f"{r_85_det0_r2['composite_verdict']}_{rc_85_det0_r2}__"
                f"{r_85_bio_hs['composite_verdict']}_{rc_85_bio_hs}"
            ),
            "operational_tier": r_85_st0_r2["operational_tier"],
            "legacy_passed": (r_85_st0_r2.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_85_st0_r2.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_85_st0_r2.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (r_85_st0_r2.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (r_85_st0_r2.get("gate0v_result_summary") or {}).get("verdict"),
            "expected_token": tok_pos_se,
            "exit_code": rc_85_st0_r2 if ok_85 else -1,
            "hard_stops": r_85_bio_hs["hard_stops"][:2],
            "holds": r_85_st0_r2["holds"][:3],
            "passed": ok_85,
        })

        # ------------------------------------------------------------------
        # Round-17 Closure Regressions (R17-B1, R17-B2, R17-M1)
        # ------------------------------------------------------------------
        # 86. R17-B1 (a)-(e): Composite offline acceptance suite for mandatory sampling-unit
        #     reconciliation of ALL release-critical recovery calibrants and Day-28 negative controls!
        def _eval_r17_bank_variant(tag: str, mutator: Callable[[Dict[str, Any]], None]) -> Tuple[Dict[str, Any], int]:
            g0v_mut = copy.deepcopy(g0v_bank)
            mutator(g0v_mut)
            g0v_mut["payload_sha256"] = v38.compute_canonical_lot_sha256(g0v_mut)
            b_mut = _make_composite_bundle(bank_lot_id, mcb_id, pv_lead, leg_bank, g0v_mut)
            fp_mut = Path(td) / f"r17_b1_bank_{tag}.json"
            fp_mut.write_text(json.dumps(b_mut, sort_keys=True), encoding="utf-8")
            return evaluate_composite_lot_file(
                fp_mut,
                legacy_evaluator=leg_fn,
                gate0v_evaluator=g0v_fn,
                openislet_root=openislet_root,
            )

        r_86_a, rc_86_a = _eval_r17_bank_variant("pos_ctrl", lambda _p: None)
        r_86_b, rc_86_b = _eval_r17_bank_variant(
            "miss_stress_cal",
            lambda p: p["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"].pop("spike_calibrant", None),
        )
        r_86_c, rc_86_c = _eval_r17_bank_variant(
            "miss_d28_neg_ctrl",
            lambda p: p["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"].pop("uninfected_ctrl_per_unit_counts", None),
        )
        r_86_d, rc_86_d = _eval_r17_bank_variant(
            "miss_d28_cal",
            lambda p: p["gate0v_b_infectious_challenge"]["pathogens"]["hcmv"]["day28_persistence_by_lineage"]["plvap_iec"].pop("fragile_infected_spike_per_unit_counts", None),
        )

        def _mut_86_e(p: Dict[str, Any]) -> None:
            p["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"].pop("spike_calibrant", None)
            p["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"].pop("uninfected_ctrl_per_unit_counts", None)
            p["gate0v_b_infectious_challenge"]["pathogens"]["hcmv"]["day28_persistence_by_lineage"]["plvap_iec"].pop("fragile_infected_spike_per_unit_counts", None)
            p["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["post_ap1903_viable_viral_pos_k"] = 1

        r_86_e, rc_86_e = _eval_r17_bank_variant("bio_hard_stop_with_missing_cal", _mut_86_e)

        g0v_86_a = r_86_a.get("gate0v_result_summary") or {}
        sb_86_a = g0v_86_a.get("sampling_unit_basis") or {}
        tok_part_mm = "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS"
        ok_86 = bool(
            rc_86_a == 0
            and r_86_a["composite_verdict"] == "PASS_COMPOSITE_BANK_QUALIFICATION"
            and g0v_86_a.get("exact_directional_confidence_certified") is True
            and sb_86_a.get("all_sampling_units_reconciled") is True
            and sb_86_a.get("estimand_partitions_checked") == 209
            and sb_86_a.get("estimand_partitions_reconciled") == 209
            and all(
                (
                    rc_x == 2
                    and r_x["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
                    and r_x["release_authorizing"] is False
                    and tok_part_mm in r_x["holds"]
                    and (r_x.get("gate0v_result_summary") or {}).get("exact_directional_confidence_certified") is False
                    and ((r_x.get("gate0v_result_summary") or {}).get("sampling_unit_basis") or {}).get("all_sampling_units_reconciled") is False
                    and ((r_x.get("gate0v_result_summary") or {}).get("sampling_unit_basis") or {}).get("estimand_partitions_reconciled") == 208
                )
                for r_x, rc_x in ((r_86_b, rc_86_b), (r_86_c, rc_86_c), (r_86_d, rc_86_d))
            )
            and rc_86_e == 3
            and r_86_e["composite_verdict"] == "FAIL_HARD_STOP_COMPOSITE_RELEASE"
            and r_86_e["release_authorizing"] is False
            and (r_86_e.get("gate0v_result_summary") or {}).get("exact_directional_confidence_certified") is False
            and ((r_86_e.get("gate0v_result_summary") or {}).get("sampling_unit_basis") or {}).get("all_sampling_units_reconciled") is False
            and len(r_86_e["hard_stops"]) >= 1
        )
        cases.append({
            "case": "r17_b1_composite_sampling_unit_reconciliation_calibrants_and_neg_ctrl_a_through_e",
            "expected_verdict": "PASS_0_HOLDS_2_HARD_STOP_3",
            "actual_verdict": (
                f"{r_86_a['composite_verdict']}_{rc_86_a}__"
                f"{r_86_b['composite_verdict']}_{rc_86_b}__"
                f"{r_86_c['composite_verdict']}_{rc_86_c}__"
                f"{r_86_d['composite_verdict']}_{rc_86_d}__"
                f"{r_86_e['composite_verdict']}_{rc_86_e}"
            ),
            "operational_tier": r_86_a["operational_tier"],
            "legacy_passed": (r_86_a.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_86_a.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_86_a.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": g0v_86_a.get("gate0v_evaluator_passed"),
            "gate0v_verdict": g0v_86_a.get("verdict"),
            "checked_partitions": sb_86_a.get("estimand_partitions_checked"),
            "reconciled_partitions": sb_86_a.get("estimand_partitions_reconciled"),
            "expected_token": tok_part_mm,
            "exit_code": 0 if ok_86 else -1,
            "hard_stops": r_86_e["hard_stops"][:2],
            "holds": r_86_b["holds"][:3],
            "passed": ok_86,
        })

        # 87. R17-B2 + R17-M1: Coupled clinical release with Sol's exact sub-ULP positive-SE OCR
        #     record (`R2_DZ40, OCR=1.097, SE=1e-20, STUDENT_T_ESTIMATED_SE, n=6`) and KNOWN_SIGMA_NORMAL
        #     verifies strictly upward native solver scaling (`mult_f64 > 1.0`, `eff_ocr >= ocr_u95_dec`),
        #     rejects old under-covering `z=1.6448536269514722` (HOLD exit 2), AND confirms direct
        #     `dispatch_and_solve_nw08_measured_ocr` emits `qualification_scope` & `physical_qualification_complete=False`!
        from decimal import Decimal as _Decimal
        from fractions import Fraction as _Fraction