scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py
Use this file in any AI chat (paste-only or attachment-capable):
Pinned raw file: https://openislet.org/files/gen-eb955f8266035aba/scripts/verify_iip0043_wholegraft_gate0v_and_calibration.py · SHA-256: 20706180ed1ed6a2…
f_sz_str = td_12b2 / "signed_zero_str.json"
f_sz_str.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": "-0.0"}', encoding="utf-8")
r_uf_se, rc_uf_se = evaluate_nw08_measured_ocr_file(f_uf_se, openislet_root=openislet_root)
r_uf_pos, rc_uf_pos = evaluate_nw08_measured_ocr_file(f_uf_pos, openislet_root=openislet_root)
r_sz_num, rc_sz_num = evaluate_nw08_measured_ocr_file(f_sz_num, openislet_root=openislet_root)
r_sz_str, rc_sz_str = evaluate_nw08_measured_ocr_file(f_sz_str, openislet_root=openislet_root)
api_neg_zero_rejected = False
try:
dispatch_and_solve_nw08_measured_ocr("R2_DZ40", 1.097, -0.0, openislet_root=openislet_root)
except ValueError:
api_neg_zero_rejected = True
api_dec_underflow_rejected = False
try:
dispatch_and_solve_nw08_measured_ocr("R2_DZ40", 1.097, Decimal("-1e-400"), openislet_root=openislet_root)
except ValueError:
api_dec_underflow_rejected = True
ok_23 = bool(
rc_uf_se == 2
and r_uf_se.get("adjudicated_verdict") == "HOLD"
and r_uf_se.get("release_authorizing") is False
and r_uf_se.get("solver_executed") is False
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:NONZERO_FLOAT_UNDERFLOW_REJECTED" in (r_uf_se.get("holds") or [])
and rc_uf_pos == 2
and r_uf_pos.get("adjudicated_verdict") == "HOLD"
and r_uf_pos.get("release_authorizing") is False
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:NONZERO_FLOAT_UNDERFLOW_REJECTED" in (r_uf_pos.get("holds") or [])
and rc_sz_num == 2
and r_sz_num.get("adjudicated_verdict") == "HOLD"
and r_sz_num.get("release_authorizing") is False
and r_sz_num.get("solver_executed") is False
and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_sz_num.get("holds") or [])
and rc_sz_str == 2
and r_sz_str.get("adjudicated_verdict") == "HOLD"
and r_sz_str.get("release_authorizing") is False
and r_sz_str.get("solver_executed") is False
and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_sz_str.get("holds") or [])
and api_neg_zero_rejected
and api_dec_underflow_rejected
)
tests.append({
"test": "r12_b2_nw08_ocr_underflow_and_signed_zero_rejected_fail_closed",
"underflow_neg_se_rc": rc_uf_se,
"underflow_pos_ocr_rc": rc_uf_pos,
"signed_zero_num_rc": rc_sz_num,
"signed_zero_str_rc": rc_sz_str,
"api_neg_zero_rejected": api_neg_zero_rejected,
"api_dec_underflow_rejected": api_dec_underflow_rejected,
"passed": ok_23,
})
# 24. R13-M1 + R13-B4: JSON integer spelling `-0` AND quoted string `"-0"` for non-negative
# NW-08 boundary keys (`uncertainty_se`) MUST fail closed (exit 2 HOLD,
# `INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE`, `solver_executed=False`), AND live
# standalone PASS responses carry explicit `qualification_scope` & `physical_qualification_complete=False`!
with tempfile.TemporaryDirectory() as td_r13_m1:
td_13m1 = Path(td_r13_m1)
f_neg_int_0 = td_13m1 / "neg_zero_int.json"
f_neg_int_0.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": -0}', encoding="utf-8")
f_neg_str_0 = td_13m1 / "neg_zero_int_str.json"
f_neg_str_0.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": "-0"}', encoding="utf-8")
f_clean_ocr = td_13m1 / "clean_ocr.json"
f_clean_ocr.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0}', encoding="utf-8")
r_ni0, rc_ni0 = evaluate_nw08_measured_ocr_file(f_neg_int_0, openislet_root=openislet_root)
r_ns0, rc_ns0 = evaluate_nw08_measured_ocr_file(f_neg_str_0, openislet_root=openislet_root)
r_cl0, rc_cl0 = evaluate_nw08_measured_ocr_file(f_clean_ocr, openislet_root=openislet_root)
ok_24 = bool(
rc_ni0 == 2
and r_ni0.get("adjudicated_verdict") == "HOLD"
and r_ni0.get("release_authorizing") is False
and r_ni0.get("solver_executed") is False
and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_ni0.get("holds") or [])
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_ni0.get("holds") or [])
and rc_ns0 == 2
and r_ns0.get("adjudicated_verdict") == "HOLD"
and r_ns0.get("release_authorizing") is False
and r_ns0.get("solver_executed") is False
and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_ns0.get("holds") or [])
and rc_cl0 == 0
and r_cl0.get("adjudicated_verdict") == "PASS"
and r_cl0.get("release_authorizing") is False
and r_cl0.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
and r_cl0.get("physical_qualification_complete") is False
)
tests.append({
"test": "r13_m1_b4_nw08_ocr_neg_zero_integer_and_string_rejected_and_pass_scope_attached",
"neg_int_zero_rc": rc_ni0,
"neg_str_zero_rc": rc_ns0,
"clean_zero_rc": rc_cl0,
"clean_qualification_scope": r_cl0.get("qualification_scope"),
"passed": ok_24,
})
# 25. R14-B1: Both Round-13 observed mesh-resolution reversals (R1_390_stress @ 1.3164, bed=35 AND
# R2_DZ40 @ 2.099752752324571, bed=32; full 3-grid audit via force_mesh_convergence_check=True)
# plus near-floor R1_350_stress baseline (1.2067, SE=0.0) route cleanly to unresolved HOLD
# (exit 2, HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR)!
r14_r1_res, r14_r1_rc = evaluate_nw08_measured_ocr_record(
{
"route_id": "R1_390_stress",
"measured_ocr": 1.3164,
"uncertainty_se": 0.0,
"force_mesh_convergence_check": True,
},
openislet_root=openislet_root,
)
r14_r2_res, r14_r2_rc = evaluate_nw08_measured_ocr_record(
{
"route_id": "R2_DZ40",
"measured_ocr": 2.099752752324571,
"uncertainty_se": 0.0,
"baseline_vasc_ocr_mult": 2.0,
"p_bed_mmhg": 32.0,
"force_mesh_convergence_check": True,
},
openislet_root=openislet_root,
)
r14_r1_350_base_res, r14_r1_350_base_rc = evaluate_nw08_measured_ocr_record(
{"route_id": "R1_350_stress", "measured_ocr": 1.2067, "uncertainty_se": 0.0},
openislet_root=openislet_root,
)
mc_r1 = r14_r1_res.get("mesh_convergence_verification") or {}
mc_r2 = r14_r2_res.get("mesh_convergence_verification") or {}
mc_350b = r14_r1_350_base_res.get("mesh_convergence_verification") or {}
ok_25 = bool(
r14_r1_rc == 2
and r14_r1_res.get("adjudicated_verdict") == "HOLD"
and r14_r1_res.get("release_authorizing") is False
and r14_r1_res.get("passes_15mmhg_floor_unrounded") is False
and "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR" in (r14_r1_res.get("holds") or [])
and mc_r1.get("executed") is True
and mc_r1.get("straddles_canonical_15mmhg_floor") is True
and len(mc_r1.get("grid_ladder") or []) == 3
and mc_r1["grid_ladder"][0]["face_min_mmhg_unrounded"] > 15.0
and mc_r1["grid_ladder"][1]["face_min_mmhg_unrounded"] < 15.0
and mc_r1["grid_ladder"][2]["face_min_mmhg_unrounded"] > 15.0
and r14_r2_rc == 2
and r14_r2_res.get("adjudicated_verdict") == "HOLD"
and r14_r2_res.get("release_authorizing") is False
and "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR" in (r14_r2_res.get("holds") or [])
and mc_r2.get("executed") is True
and mc_r2.get("straddles_canonical_15mmhg_floor") is True
and len(mc_r2.get("grid_ladder") or []) == 3
and mc_r2["grid_ladder"][0]["face_min_mmhg_unrounded"] < 15.0
and mc_r2["grid_ladder"][1]["face_min_mmhg_unrounded"] > 15.0
and mc_r2["grid_ladder"][2]["face_min_mmhg_unrounded"] > 15.0
and r14_r1_350_base_rc == 2
and r14_r1_350_base_res.get("adjudicated_verdict") == "HOLD"
and mc_350b.get("executed") is True
and mc_350b.get("straddles_canonical_15mmhg_floor") is True
)
tests.append({
"test": "r14_b1_mesh_convergence_reversals_r1_390_r2_dz40_and_r1_350_baseline_route_to_hold",
"r1_390_grid_mins": [g["face_min_mmhg_unrounded"] for g in (mc_r1.get("grid_ladder") or [])],
"r1_390_bounds_mmhg": [mc_r1.get("conservative_po2_lower_bound_mmhg"), mc_r1.get("conservative_po2_upper_bound_mmhg")],
"r1_390_verdict": r14_r1_res.get("adjudicated_verdict"),
"r1_390_rc": r14_r1_rc,
"r2_dz40_grid_mins": [g["face_min_mmhg_unrounded"] for g in (mc_r2.get("grid_ladder") or [])],
"r2_dz40_bounds_mmhg": [mc_r2.get("conservative_po2_lower_bound_mmhg"), mc_r2.get("conservative_po2_upper_bound_mmhg")],
"r2_dz40_verdict": r14_r2_res.get("adjudicated_verdict"),
"r2_dz40_rc": r14_r2_rc,
"r1_350_baseline_verdict": r14_r1_350_base_res.get("adjudicated_verdict"),
"passed": ok_25,
})
# 26. R14-B2: Small-sample OCR inference (R1_390_stress, OCR=1.25, SE=0.06, n=6 -> df=5,
# t_{0.95, 5} = 2.0150484, u95 = 1.370903 -> native 14.98082429 < 15.0, 3-grid decisive FAIL exit 3),
# independent justified upper bound reproduces FAIL exit 3, bare undeclared SE=0.06 HOLDs exit 2,
# and declared KNOWN_SIGMA_NORMAL at 1.25 +/- 0.06 still HOLDs exit 2 under Blocker #1 mesh check!
r14_b2_bare, r14_b2_bare_rc = evaluate_nw08_measured_ocr_record(
{"route_id": "R1_390_stress", "measured_ocr": 1.25, "uncertainty_se": 0.06},
openislet_root=openislet_root,
)
r14_b2_t6, r14_b2_t6_rc = evaluate_nw08_measured_ocr_record(
{
"route_id": "R1_390_stress",
"measured_ocr": 1.25,
"uncertainty_se": 0.06,
"ocr_uncertainty_model": NW08_OCR_UNCERTAINTY_MODEL_STUDENT_T,
"ocr_replicates_n": 6,
},
openislet_root=openislet_root,
)
r14_b2_indep, r14_b2_indep_rc = evaluate_nw08_measured_ocr_record(
{
"route_id": "R1_390_stress",
"measured_ocr": 1.25,
"uncertainty_se": 0.06,
"ocr_uncertainty_model": NW08_OCR_UNCERTAINTY_MODEL_INDEPENDENT_UPPER,
"ocr_replicates_n": 6,
"measured_ocr_u95_override": 1.370903,
"ocr_uncertainty_provenance": "independent_student_t_df5_upper_95_bound_v1",
},
openislet_root=openislet_root,
)
r14_b2_norm, r14_b2_norm_rc = evaluate_nw08_measured_ocr_record(
{
"route_id": "R1_390_stress",
"measured_ocr": 1.25,
"uncertainty_se": 0.06,
"ocr_uncertainty_model": NW08_OCR_UNCERTAINTY_MODEL_KNOWN_SIGMA,
"ocr_uncertainty_provenance": "calibrated_respirometer_known_sigma_cert_v1",
},
openislet_root=openislet_root,
)
ok_26 = bool(
r14_b2_bare_rc == 2
and r14_b2_bare.get("adjudicated_verdict") == "HOLD"
and r14_b2_bare.get("solver_executed") is False
and "HOLD_NW08_OCR_MISSING_UNCERTAINTY_MODEL_OR_DF" in (r14_b2_bare.get("holds") or [])
and r14_b2_t6_rc == 3
and r14_b2_t6.get("adjudicated_verdict") == "FAIL"
and r14_b2_t6.get("ocr_degrees_of_freedom") == 5
and abs(float(r14_b2_t6.get("applied_one_sided_95_multiplier") or 0.0) - 2.0150484) < 1e-6
and abs(float(r14_b2_t6.get("face_min_mmhg_unrounded") or 0.0) - 14.98082429) < 1e-5
and (r14_b2_t6.get("mesh_convergence_verification") or {}).get("conservative_po2_upper_bound_mmhg", 99.0) < 15.0
and r14_b2_indep_rc == 3
and r14_b2_indep.get("adjudicated_verdict") == "FAIL"
and r14_b2_norm_rc == 2
and r14_b2_norm.get("adjudicated_verdict") == "HOLD"
and "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR" in (r14_b2_norm.get("holds") or [])
)
tests.append({
"test": "r14_b2_small_sample_student_t_n6_flips_1p25_se0p06_to_fail_and_rejects_bare_se",
"bare_se_rc": r14_b2_bare_rc,
"student_t_n6_rc": r14_b2_t6_rc,
"student_t_n6_multiplier": r14_b2_t6.get("applied_one_sided_95_multiplier"),
"student_t_n6_u95": r14_b2_t6.get("solved_at_vascular_ocr_u95"),
"student_t_n6_face_min_unrounded": r14_b2_t6.get("face_min_mmhg_unrounded"),
"independent_upper_rc": r14_b2_indep_rc,
"known_sigma_normal_rc": r14_b2_norm_rc,
"passed": ok_26,
})
# 27. R14-B3: Process-wide lock & callback-owner serialization across separately loaded verifier
# module instances (direct + composite-wrapper-loaded copy) running barrier-synchronized concurrent solves!
comp_script_path = openislet_root / "scripts" / "evaluate_gate0v_composite_release.py"
r14_b3_shared_lock = False
r14_b3_callbacks_restored = False
r14_b3_all_matched = False
if comp_script_path.is_file():
comp_spec = importlib.util.spec_from_file_location("iip0043_r14_b3_comp_probe", str(comp_script_path))
if comp_spec is not None and comp_spec.loader is not None:
comp_probe = importlib.util.module_from_spec(comp_spec)
comp_spec.loader.exec_module(comp_probe)
wrapped_v38 = comp_probe._get_v38_module()
# Also load a second completely distinct exec_module copy of verify_iip0043 to prove
# process-wide lock sharing holds EVEN WITHOUT sys.modules reuse!
iso_spec = importlib.util.spec_from_file_location("iip0043_r14_b3_isolated_copy", str(Path(__file__).resolve()))