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…

            route_id="R2_DZ40",
            lot_payload_sha256=clin_r2_bundle["payload_sha256"],
            measured_ocr=2.099752752324571,
            uncertainty_se=0.0,
            baseline_vasc_ocr_mult=2.0,
            p_bed_mmhg=32.0,
            measurement_record_id="OCR-R14-B1-R2-REV",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        f_r14_r1_rev = Path(td) / "r14_b1_ocr_r1_rev.json"
        f_r14_r1_rev.write_text(json.dumps(ocr_r14_r1_rev, sort_keys=True), encoding="utf-8")
        f_r14_r2_rev = Path(td) / "r14_b1_ocr_r2_rev.json"
        f_r14_r2_rev.write_text(json.dumps(ocr_r14_r2_rev, sort_keys=True), encoding="utf-8")
        r_82_r1, rc_82_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_r14_r1_rev,
        )
        r_82_r2, rc_82_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_r14_r2_rev,
        )
        ok_82 = bool(
            rc_82_r1 == 2
            and r_82_r1["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_82_r1["release_authorizing"] is False
            and "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR" in r_82_r1["holds"]
            and (r_82_r1.get("nw08_measured_ocr_dispatch_result") or {}).get("adjudicated_verdict") == "HOLD"
            and rc_82_r2 == 2
            and r_82_r2["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_82_r2["release_authorizing"] is False
            and "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR" in r_82_r2["holds"]
            and (r_82_r2.get("nw08_measured_ocr_dispatch_result") or {}).get("adjudicated_verdict") == "HOLD"
        )
        cases.append({
            "case": "r14_b1_coupled_mesh_reversals_r1_390_and_r2_dz40_route_to_hold_exit_2",
            "expected_verdict": "HOLD_COMPOSITE_RELEASE",
            "actual_verdict": r_82_r1["composite_verdict"],
            "operational_tier": r_82_r1["operational_tier"],
            "legacy_passed": (r_82_r1.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_82_r1.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_82_r1.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (r_82_r1.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (r_82_r1.get("gate0v_result_summary") or {}).get("verdict"),
            "expected_token": "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR",
            "exit_code": rc_82_r1 if ok_82 else -1,
            "hard_stops": r_82_r1["hard_stops"][:2],
            "holds": r_82_r1["holds"][:3],
            "passed": ok_82,
        })

        # 83. R14-B2: Coupled OCR record with bare positive SE (no model/df) -> HOLD exit 2;
        #     same OCR=1.25, SE=0.06 with small-sample STUDENT_T_ESTIMATED_SE (n=6, df=5) -> FAIL exit 3!
        ocr_r14_bare_se = v38.build_bound_nw08_ocr_record(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            route_id="R1_390_stress",
            lot_payload_sha256=clin_r1_390_bundle["payload_sha256"],
            measured_ocr=1.25,
            uncertainty_se=0.06,
            measurement_record_id="OCR-R14-B2-BARE-SE",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        ocr_r14_t6 = v38.build_bound_nw08_ocr_record(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            route_id="R1_390_stress",
            lot_payload_sha256=clin_r1_390_bundle["payload_sha256"],
            measured_ocr=1.25,
            uncertainty_se=0.06,
            ocr_uncertainty_model="STUDENT_T_ESTIMATED_SE",
            ocr_replicates_n=6,
            measurement_record_id="OCR-R14-B2-STUDENT-T6",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        f_r14_bare = Path(td) / "r14_b2_bare_se.json"
        f_r14_bare.write_text(json.dumps(ocr_r14_bare_se, sort_keys=True), encoding="utf-8")
        f_r14_t6 = Path(td) / "r14_b2_student_t6.json"
        f_r14_t6.write_text(json.dumps(ocr_r14_t6, sort_keys=True), encoding="utf-8")
        r_83_bare, rc_83_bare = 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_r14_bare,
        )
        r_83_t6, rc_83_t6 = 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_r14_t6,
        )
        ok_83 = bool(
            rc_83_bare == 2
            and r_83_bare["composite_verdict"] == "HOLD_COMPOSITE_RELEASE"
            and r_83_bare["release_authorizing"] is False
            and "HOLD_NW08_OCR_MISSING_UNCERTAINTY_MODEL_OR_DF" in r_83_bare["holds"]
            and (r_83_bare.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"
            and r_83_t6["release_authorizing"] is False
            and "FAIL_HARD_STOP_NW08_3D_FVM_BELOW_15MMHG_FLOOR" in r_83_t6["hard_stops"]
            and (r_83_t6.get("nw08_measured_ocr_dispatch_result") or {}).get("ocr_degrees_of_freedom") == 5
        )
        cases.append({
            "case": "r14_b2_coupled_bare_se_held_exit_2_and_student_t_n6_flips_to_fail_exit_3",
            "expected_verdict": "HOLD_2_FAIL_3",
            "actual_verdict": f"{r_83_bare['composite_verdict']}_{rc_83_bare}__{r_83_t6['composite_verdict']}_{rc_83_t6}",
            "operational_tier": r_83_t6["operational_tier"],
            "legacy_passed": (r_83_t6.get("legacy_result_summary") or {}).get("legacy_evaluator_passed"),
            "legacy_tier": (r_83_t6.get("legacy_result_summary") or {}).get("lot_release_readiness_tier"),
            "legacy_resolved_pvid": (r_83_t6.get("legacy_result_summary") or {}).get("resolved_product_variant_id"),
            "gate0v_passed": (r_83_t6.get("gate0v_result_summary") or {}).get("gate0v_evaluator_passed"),
            "gate0v_verdict": (r_83_t6.get("gate0v_result_summary") or {}).get("verdict"),
            "expected_token": "HOLD_NW08_OCR_MISSING_UNCERTAINTY_MODEL_OR_DF",
            "exit_code": 0 if ok_83 else -1,
            "hard_stops": r_83_t6["hard_stops"][:2],
            "holds": r_83_bare["holds"][:3],
            "passed": ok_83,
        })

        # 84. R14-B3: Concurrent direct `verify_iip0043` and wrapper `_get_v38_module()` share the
        #     canonical process-wide lock and produce identical serial/concurrent 3D FVM minima!
        from concurrent.futures import ThreadPoolExecutor as _TPE
        import threading as _thr

        direct_copy = _load_module("iip0043_r14_b3_direct_copy_self_test", _resolve_gate0v_verifier_path())
        shared_lock_ok = bool(direct_copy._FVM_SOLVER_LOCK is v38._FVM_SOLVER_LOCK)
        ser_35 = direct_copy.dispatch_and_solve_nw08_measured_ocr("R3P_35", 1.3164, 0.0, openislet_root=openislet_root, p_bed_mmhg=35.0)
        ser_30 = v38.dispatch_and_solve_nw08_measured_ocr("R3P_30", 1.3164, 0.0, openislet_root=openislet_root, p_bed_mmhg=30.0)
        conc_match = True
        for _att in range(3):
            b_sync = _thr.Barrier(2)

            def _run_c(m_obj, rt, pb):
                b_sync.wait(timeout=10)
                rr = m_obj.dispatch_and_solve_nw08_measured_ocr(rt, 1.3164, 0.0, openislet_root=openislet_root, p_bed_mmhg=pb)
                return (rr["face_min_mmhg_unrounded"], rr["adjudicated_verdict"])

            with _TPE(max_workers=2) as tp:
                f1 = tp.submit(_run_c, direct_copy, "R3P_35", 35.0)
                f2 = tp.submit(_run_c, v38, "R3P_30", 30.0)
                p1, p2 = f1.result(), f2.result()
            if p1 != (ser_35["face_min_mmhg_unrounded"], ser_35["adjudicated_verdict"]) or p2 != (
                ser_30["face_min_mmhg_unrounded"],
                ser_30["adjudicated_verdict"],
            ):
                conc_match = False
        ok_84 = bool(shared_lock_ok and conc_match)
        cases.append({
            "case": "r14_b3_concurrent_direct_and_wrapper_shared_lock_identical_serial_concurrent_results",
            "expected_verdict": "SHARED_LOCK_AND_EXACT_CONCURRENT_PARITY",
            "actual_verdict": "SHARED_LOCK_AND_EXACT_CONCURRENT_PARITY" if ok_84 else "CONCURRENT_MISMATCH",
            "operational_tier": "CROSS_INTERFACE_CONCURRENCY",
            "legacy_passed": True,
            "legacy_tier": LEGACY_PASS_TIER,
            "legacy_resolved_pvid": pv_lead,
            "gate0v_passed": True,
            "gate0v_verdict": "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE",
            "expected_token": None,
            "exit_code": 0 if ok_84 else -1,
            "hard_stops": [],
            "holds": [],
            "passed": ok_84,
        })

        # ------------------------------------------------------------------
        # Round-16 Closure Regression (R16-B1 Coupled Zero-SE Inferential Models)
        # ------------------------------------------------------------------
        # 85. R16-B1: Coupled composite release (`--nw08-ocr-json` AND Python API `nw08_ocr_record=`)
        #     rejects `uncertainty_se == 0` under BOTH `STUDENT_T_ESTIMATED_SE` and `KNOWN_SIGMA_NORMAL`
        #     BEFORE solving (`HOLD_COMPOSITE_RELEASE`, exit 2, `HOLD_NW08_INFERENTIAL_MODEL_REQUIRES_POSITIVE_SE`,
        #     `solver_executed = False`, `release_authorizing = False`), retains explicit
        #     `ZERO_UNCERTAINTY_DETERMINISTIC_POINT` PASS (exit 0), preserves positive-SE Student-t
        #     FAIL (`R1_390_stress, OCR=1.25, SE=0.06, n=6` -> exit 3), AND preserves independent
        #     biological `FAIL_HARD_STOP` precedence (`exit 3` over zero-SE OCR `HOLD` while recording
        #     `HOLD_NW08_INFERENTIAL_MODEL_REQUIRES_POSITIVE_SE` and `solver_executed = False`)!
        ocr_r16_st0_r2 = 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_r2_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-ST0-R2",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        ocr_r16_st0_r1 = v38.build_bound_nw08_ocr_record(
            lot_id=clin_lot_id,
            mcb_id=mcb_id,
            product_variant_id=pv_lead,
            route_id="R1_390_stress",
            lot_payload_sha256=clin_r1_390_bundle["payload_sha256"],
            measured_ocr=1.25,
            uncertainty_se=0.0,
            ocr_uncertainty_model="STUDENT_T_ESTIMATED_SE",
            ocr_replicates_n=6,
            measurement_record_id="OCR-R16-B1-ST0-R1",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        ocr_r16_ks0_r2 = 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_r2_bundle["payload_sha256"],
            measured_ocr=1.097,
            uncertainty_se=0.0,
            ocr_uncertainty_model="KNOWN_SIGMA_NORMAL",
            ocr_uncertainty_provenance="calibrated_respirometer_known_sigma_cert_v1",
            measurement_record_id="OCR-R16-B1-KS0-R2",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        ocr_r16_det0_r2 = 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_r2_bundle["payload_sha256"],
            measured_ocr=1.097,
            uncertainty_se=0.0,
            ocr_uncertainty_model="ZERO_UNCERTAINTY_DETERMINISTIC_POINT",
            measurement_record_id="OCR-R16-B1-DET0-R2",
            measurement_evidence_sha256=clin_ev_sha,
            measurement_timestamp_utc="2026-11-29T01:00:00Z",
        )
        f_r16_st0_r2 = Path(td) / "r16_b1_ocr_st0_r2.json"
        f_r16_st0_r2.write_text(json.dumps(ocr_r16_st0_r2, sort_keys=True), encoding="utf-8")
        f_r16_st0_r1 = Path(td) / "r16_b1_ocr_st0_r1.json"