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…
# forced always_solve_3d=True exactly!
d_r08_ov5_def = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40",
10.0,
0.0,
openislet_root=openislet_root,
baseline_vasc_ocr_mult=5.0,
)
d_r08_ov5_forced = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40",
10.0,
0.0,
openislet_root=openislet_root,
baseline_vasc_ocr_mult=5.0,
always_solve_3d=True,
)
ok_13 = bool(
d_r08_ov5_def["solver_executed"] is True
and d_r08_ov5_def["trigger_dispatched"] is True
and d_r08_ov5_def["baseline_ocr_override_applied"] is True
and d_r08_ov5_def["adjudicated_verdict"] == "FAIL"
and d_r08_ov5_forced["adjudicated_verdict"] == "FAIL"
and d_r08_ov5_def["passes_15mmhg_floor_unrounded"] is False
and d_r08_ov5_def["face_min_mmhg_unrounded"] < 15.0
and abs(d_r08_ov5_def["face_min_mmhg_unrounded"] - d_r08_ov5_forced["face_min_mmhg_unrounded"]) < 1e-12
)
tests.append({
"test": "r08_b2_r2_dz40_default_pbed40_base5p0_meas10p0_fails_in_default_and_forced",
"baseline_min_face_unrounded_mmhg": d_r08_ov5_def["baseline_min_face_unrounded_mmhg"],
"default_face_min_unrounded_mmhg": d_r08_ov5_def["face_min_mmhg_unrounded"],
"forced_face_min_unrounded_mmhg": d_r08_ov5_forced["face_min_mmhg_unrounded"],
"default_verdict": d_r08_ov5_def["adjudicated_verdict"],
"forced_verdict": d_r08_ov5_forced["adjudicated_verdict"],
"solver_executed": d_r08_ov5_def["solver_executed"],
"passed": ok_13,
})
# 14. R08-B2 (c): Canonical zero-increase monotone fast-path (ocr_u95 <= baseline on >=15.0
# native baseline, zero overrides) agrees 100% with forced 3D solve (PASS >= 15.0 mmHg)!
d_r08_mono_def = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40",
1.097,
0.0,
openislet_root=openislet_root,
)
d_r08_mono_forced = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40",
1.097,
0.0,
openislet_root=openislet_root,
always_solve_3d=True,
)
ok_14 = bool(
d_r08_mono_def["within_provably_monotone_no_increase_domain"] is True
and d_r08_mono_def["solver_executed"] is False
and d_r08_mono_def["adjudicated_verdict"] == "PASS"
and d_r08_mono_forced["adjudicated_verdict"] == "PASS"
and d_r08_mono_forced["face_min_mmhg_unrounded"] >= 15.0
)
tests.append({
"test": "r08_b2_canonical_zero_increase_monotone_fast_path_agrees_with_forced_3d",
"within_provably_monotone_no_increase_domain": d_r08_mono_def["within_provably_monotone_no_increase_domain"],
"default_verdict": d_r08_mono_def["adjudicated_verdict"],
"forced_verdict": d_r08_mono_forced["adjudicated_verdict"],
"forced_face_min_unrounded_mmhg": d_r08_mono_forced["face_min_mmhg_unrounded"],
"passed": ok_14,
})
# 15. R09-B3 (a): Exact canonical dispatch (ZERO 1e-12 deadband) — 1-ULP p_bed_mmhg overrides
# below and above 40.0 mmHg MUST set p_bed_override_applied=True and execute native 3D FVM!
pbed_1ulp_lo = math.nextafter(40.0, 0.0)
pbed_1ulp_hi = math.nextafter(40.0, math.inf)
d_r09_pb_lo = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", 1.0, 0.0, openislet_root=openislet_root, p_bed_mmhg=pbed_1ulp_lo
)
d_r09_pb_lo_frc = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", 1.0, 0.0, openislet_root=openislet_root, p_bed_mmhg=pbed_1ulp_lo, always_solve_3d=True
)
d_r09_pb_hi = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", 1.0, 0.0, openislet_root=openislet_root, p_bed_mmhg=pbed_1ulp_hi
)
ok_15 = bool(
d_r09_pb_lo["p_bed_override_applied"] is True
and d_r09_pb_lo["any_parameter_override_applied"] is True
and d_r09_pb_lo["within_provably_monotone_no_increase_domain"] is False
and d_r09_pb_lo["solver_executed"] is True
and d_r09_pb_lo["effective_p_bed_mmhg"] == pbed_1ulp_lo
and d_r09_pb_lo["solver_p_bed_mmhg_verified"] == pbed_1ulp_lo
and d_r09_pb_lo["face_min_mmhg_unrounded"] is not None
and d_r09_pb_lo["face_min_mmhg_unrounded"] == d_r09_pb_lo_frc["face_min_mmhg_unrounded"]
and d_r09_pb_hi["p_bed_override_applied"] is True
and d_r09_pb_hi["any_parameter_override_applied"] is True
and d_r09_pb_hi["solver_executed"] is True
and d_r09_pb_hi["effective_p_bed_mmhg"] == pbed_1ulp_hi
and d_r09_pb_hi["solver_p_bed_mmhg_verified"] == pbed_1ulp_hi
and d_r09_pb_hi["face_min_mmhg_unrounded"] is not None
)
tests.append({
"test": "r09_b3_r2_dz40_one_ulp_pbed_below_and_above_40mmhg_executes_native_3d_fvm",
"pbed_1ulp_below_40": pbed_1ulp_lo,
"pbed_1ulp_above_40": pbed_1ulp_hi,
"below_solver_executed": d_r09_pb_lo["solver_executed"],
"above_solver_executed": d_r09_pb_hi["solver_executed"],
"below_face_min_unrounded_mmhg": d_r09_pb_lo["face_min_mmhg_unrounded"],
"above_face_min_unrounded_mmhg": d_r09_pb_hi["face_min_mmhg_unrounded"],
"passed": ok_15,
})
# 16. R09-B3 (b): Exact canonical dispatch (ZERO 1e-12 deadband) — 1-ULP baseline_vasc_ocr_mult
# overrides above and below 1.097 MUST set baseline_ocr_override_applied=True and execute 3D FVM!
base_1ulp_hi = math.nextafter(1.097, math.inf)
base_1ulp_lo = math.nextafter(1.097, 0.0)
d_r09_b_hi = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", 1.0, 0.0, openislet_root=openislet_root, baseline_vasc_ocr_mult=base_1ulp_hi
)
d_r09_b_lo = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", 1.0, 0.0, openislet_root=openislet_root, baseline_vasc_ocr_mult=base_1ulp_lo
)
ok_16 = bool(
d_r09_b_hi["baseline_ocr_override_applied"] is True
and d_r09_b_hi["any_parameter_override_applied"] is True
and d_r09_b_hi["within_provably_monotone_no_increase_domain"] is False
and d_r09_b_hi["solver_executed"] is True
and d_r09_b_hi["face_min_mmhg_unrounded"] is not None
and d_r09_b_lo["baseline_ocr_override_applied"] is True
and d_r09_b_lo["any_parameter_override_applied"] is True
and d_r09_b_lo["within_provably_monotone_no_increase_domain"] is False
and d_r09_b_lo["solver_executed"] is True
and d_r09_b_lo["face_min_mmhg_unrounded"] is not None
)
tests.append({
"test": "r09_b3_r2_dz40_one_ulp_baseline_vasc_ocr_above_and_below_1p097_executes_native_3d_fvm",
"baseline_1ulp_above_1p097": base_1ulp_hi,
"baseline_1ulp_below_1p097": base_1ulp_lo,
"above_solver_executed": d_r09_b_hi["solver_executed"],
"below_solver_executed": d_r09_b_lo["solver_executed"],
"above_face_min_unrounded_mmhg": d_r09_b_hi["face_min_mmhg_unrounded"],
"below_face_min_unrounded_mmhg": d_r09_b_lo["face_min_mmhg_unrounded"],
"passed": ok_16,
})
# 17. R09-B3 (c): 1-ULP positive measured_ocr AND sub-ULP positive uncertainty_se at canonical
# baseline MUST both exit monotone fast-path and execute native 3D FVM!
meas_1ulp_hi = math.nextafter(1.097, math.inf)
d_r09_m_hi = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", meas_1ulp_hi, 0.0, openislet_root=openislet_root
)
d_r09_se_tiny = dispatch_and_solve_nw08_measured_ocr(
"R2_DZ40", 1.097, 1e-20, openislet_root=openislet_root, **_known_sig
)
ok_17 = bool(
d_r09_m_hi["within_provably_monotone_no_increase_domain"] is False
and d_r09_m_hi["solver_executed"] is True
and d_r09_m_hi["face_min_mmhg_unrounded"] is not None
and d_r09_se_tiny["within_provably_monotone_no_increase_domain"] is False
and d_r09_se_tiny["solver_executed"] is True
and d_r09_se_tiny["face_min_mmhg_unrounded"] is not None
)
tests.append({
"test": "r09_b3_r2_dz40_one_ulp_and_sub_ulp_positive_measured_ocr_executes_native_3d_fvm",
"meas_1ulp_solver_executed": d_r09_m_hi["solver_executed"],
"sub_ulp_se_solver_executed": d_r09_se_tiny["solver_executed"],
"meas_1ulp_face_min_unrounded_mmhg": d_r09_m_hi["face_min_mmhg_unrounded"],
"passed": ok_17,
})
# 18. R09-M1 + R09-B1 + R14-B1: Explicit operator file/CLI entry point `evaluate_nw08_measured_ocr_file`
# handles PASS (exit 0), mesh-converged FAIL (exit 3), mesh-straddling HOLD (exit 2),
# duplicate-key JSON (exit 2), and NaN JSON (exit 2)!
with tempfile.TemporaryDirectory() as td_ocr:
td_op = Path(td_ocr)
f_pass = td_op / "nw08_pass.json"
f_pass.write_text('{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0.0}', encoding="utf-8")
f_fail = td_op / "nw08_fail.json"
f_fail.write_text(
'{"route_id": "R2_DZ40", "measured_ocr": 10.0, "uncertainty_se": 0.0, '
'"baseline_vasc_ocr_mult": 5.0}',
encoding="utf-8",
)
f_straddle = td_op / "nw08_straddle.json"
f_straddle.write_text(
'{"route_id": "R2_DZ40", "measured_ocr": 2.099752752324571, "uncertainty_se": 0.0, '
'"baseline_vasc_ocr_mult": 2.0, "p_bed_mmhg": 32.0}',
encoding="utf-8",
)
f_dup = td_op / "nw08_dup.json"
f_dup.write_text(
'{"route_id": "R1_350_stress", "route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0.0}',
encoding="utf-8",
)
f_nan = td_op / "nw08_nan.json"
f_nan.write_text('{"route_id": "R2_DZ40", "measured_ocr": NaN, "uncertainty_se": 0.0}', encoding="utf-8")
res_p, rc_p = evaluate_nw08_measured_ocr_file(f_pass, openislet_root=openislet_root)
res_f, rc_f = evaluate_nw08_measured_ocr_file(f_fail, openislet_root=openislet_root)
res_st, rc_st = evaluate_nw08_measured_ocr_file(f_straddle, openislet_root=openislet_root)
res_d, rc_d = evaluate_nw08_measured_ocr_file(f_dup, openislet_root=openislet_root)
res_n, rc_n = evaluate_nw08_measured_ocr_file(f_nan, openislet_root=openislet_root)
ok_18 = bool(
rc_p == 0
and res_p.get("adjudicated_verdict") == "PASS"
and rc_f == 3
and res_f.get("adjudicated_verdict") == "FAIL"
and res_f.get("solver_executed") is True
and rc_st == 2
and res_st.get("adjudicated_verdict") == "HOLD"
and "HOLD_NW08_MESH_CONVERGENCE_STRADDLES_15MMHG_FLOOR" in (res_st.get("holds") or [])
and rc_d == 2
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:DUPLICATE_JSON_KEY" in (res_d.get("holds") or [])
and rc_n == 2
and "HOLD_NW08_AMBIGUOUS_OR_NONCANONICAL_OCR_JSON:NON_STANDARD_JSON_CONSTANT" in (res_n.get("holds") or [])
)
tests.append({
"test": "r09_m1_b1_operator_nw08_ocr_file_entrypoint_pass_fail_and_strict_json_holds",
"pass_rc": rc_p,
"fail_rc": rc_f,
"straddle_hold_rc": rc_st,
"dup_key_rc": rc_d,
"nan_rc": rc_n,
"passed": ok_18,
})
# 19. R10-B2: Out-of-float64-range integers (10**400), overflowing float (1e500), sum overflow (1e308+1e308),
# and unhashable list route_id fail closed cleanly (structured HOLD exit 2 on file entry point; ValueError on API)!
with tempfile.TemporaryDirectory() as td_r10_ocr:
td_r10_o = Path(td_r10_ocr)
bad_ocr_files = (
("meas_1e400", f'{{"route_id": "R2_DZ40", "measured_ocr": {10**400}, "uncertainty_se": 0}}'),
("se_1e400", f'{{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": {10**400}}}'),
("pbed_1e400", f'{{"route_id": "R2_DZ40", "measured_ocr": 1.097, "uncertainty_se": 0, "p_bed_mmhg": {10**400}}}'),
("meas_1e500", '{"route_id": "R2_DZ40", "measured_ocr": 1e500, "uncertainty_se": 0}'),
("sum_overflow", '{"route_id": "R2_DZ40", "measured_ocr": 1e308, "uncertainty_se": 1e308}'),
("list_route", '{"route_id": ["R2_DZ40"], "measured_ocr": 1.097, "uncertainty_se": 0}'),
)
r10_f_ok = True
for b_tag, b_raw in bad_ocr_files:
bf = td_r10_o / f"bad_{b_tag}.json"
bf.write_text(b_raw, encoding="utf-8")
bres, brc = evaluate_nw08_measured_ocr_file(bf, openislet_root=openislet_root)
if not (brc == 2 and bres.get("adjudicated_verdict") == "HOLD" and bres.get("solver_executed") is False):
r10_f_ok = False
r10_api_ok = True
for bad_call in (
lambda: dispatch_and_solve_nw08_measured_ocr("R2_DZ40", 10 ** 400, 0.0, openislet_root=openislet_root),
lambda: dispatch_and_solve_nw08_measured_ocr("R2_DZ40", 1.097, 10 ** 400, openislet_root=openislet_root),
lambda: dispatch_and_solve_nw08_measured_ocr("R2_DZ40", 1.097, 0.0, p_bed_mmhg=10 ** 400, openislet_root=openislet_root),
lambda: dispatch_and_solve_nw08_measured_ocr("R2_DZ40", 1e308, 1e308, openislet_root=openislet_root),
lambda: dispatch_and_solve_nw08_measured_ocr(["R2_DZ40"], 1.097, 0.0, openislet_root=openislet_root), # type: ignore[arg-type]
):
raised_ve = False
try: