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…
mcb_id="MCB-R13-001",
product_variant_id="ISLET1_A4_ARM1B",
qualification_tier="LOT_RELEASE_SURROGATE",
bridged_mcb_qualification_sha256=brec_r13["sha256"],
independent_biological_units_n=6_000_000,
independent_sampling_unit_class="INDEPENDENT_SINGLE_CELL_OR_LIMITING_DILUTION_UNIT",
openislet_root=resolved_root,
)
r_sc_clean = evaluate_wholegraft_gate0v_and_stress_ap1903(
p_sc_clin, trusted_qualification_store=st_r13, openislet_root=resolved_root
)
# Inject supplemental infected stress arm with aggregate=0 but per_unit_counts viral-pos k=1!
p_sc_adv_vp = copy.deepcopy(p_sc_clin)
sup_cvb = copy.deepcopy(b_r13["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"])
sup_cvb["beta"]["per_unit_counts"]["infected_viral_pos_72h"][0]["k"] = 1
p_sc_adv_vp["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"] = sup_cvb
r_sc_adv_vp = evaluate_wholegraft_gate0v_and_stress_ap1903(
_seal(p_sc_adv_vp), trusted_qualification_store=st_r13, openislet_root=resolved_root
)
# Inject supplemental arm with aggregate ap1903_72h=0 but per_unit_counts ap1903_72h k=1!
p_sc_adv_a72 = copy.deepcopy(p_sc_clin)
sup_er = copy.deepcopy(b_r13["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"])
sup_er["beta"]["per_unit_counts"]["ap1903_72h"][0]["k"] = 1
p_sc_adv_a72["gate0v_kill_stress_ap1903"]["er_stress_tg_or_tm"] = sup_er
r_sc_adv_a72 = evaluate_wholegraft_gate0v_and_stress_ap1903(
_seal(p_sc_adv_a72), trusted_qualification_store=st_r13, openislet_root=resolved_root
)
# Clean unexpected per_unit_counts in single-cell mode -> HOLD_UNEXPECTED_PER_UNIT_COUNTS_IN_SINGLE_CELL_MODE!
p_sc_unexp = copy.deepcopy(p_sc_clin)
p_sc_unexp["gate0v_kill_stress_ap1903"]["normoxia_baseline"]["beta"]["per_unit_counts"] = copy.deepcopy(
b_r13["gate0v_kill_stress_ap1903"]["normoxia_baseline"]["beta"]["per_unit_counts"]
)
r_sc_unexp = evaluate_wholegraft_gate0v_and_stress_ap1903(
_seal(p_sc_unexp), trusted_qualification_store=st_r13, openislet_root=resolved_root
)
# 58. R13-B1 (b): Multi-well malformed row (missing/invalid unit_id or non-dict) BEFORE an
# adverse k=1 row MUST NEVER early-return or downgrade FAIL_HARD_STOP to HOLD!
p_mw_mal_adv = copy.deepcopy(b_r13)
vp_rows = p_mw_mal_adv["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"]["infected_viral_pos_72h"]
vp_rows[0]["unit_id"] = "" # malformed row 0 BEFORE valid adverse row 1!
vp_rows[1]["k"] = 1
r_mw_mal_adv = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_mw_mal_adv), openislet_root=resolved_root)
p_mw_nondict_adv = copy.deepcopy(b_r13)
vp_rows2 = p_mw_nondict_adv["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"]["infected_viral_pos_72h"]
vp_rows2[0] = "not_a_dict_row"
vp_rows2[2] = {"k": 1, "n": 1000} # adverse row itself missing unit_id!
r_mw_nondict_adv = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_mw_nondict_adv), openislet_root=resolved_root)
# 59. R13-B2: Sol's impossible same-well subset (125 direct infected-vehicle survivors in WELL-01
# which has only 90 total veh_72h viable survivors, aggregate sums unchanged!) AND unit-ID set
# mismatch MUST fail closed with `HOLD_SAMPLING_UNIT_SUBSET_OR_ID_CONTRADICTION` (reconciled < 209)!
p_sub_125_90 = copy.deepcopy(b_r13)
div_rows = p_sub_125_90["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"]["direct_infected_veh_72h"]
div_rows[0]["k"] = 125
for _idx in range(1, len(div_rows)):
div_rows[_idx]["k"] = 0
r_sub_125_90 = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_sub_125_90), openislet_root=resolved_root)
p_uid_mm = copy.deepcopy(b_r13)
div_rows_uid = p_uid_mm["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"]["direct_infected_veh_72h"]
for _idx, _row in enumerate(div_rows_uid):
_row["unit_id"] = f"ALT-UNIT-{_idx + 1:02d}"
r_uid_mm = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_uid_mm), openislet_root=resolved_root)
# 60. R13-B3: Pure subtractive policy — `require_trusted_nw08_ocr_record=True` on `BANK_QUALIFICATION`
# rejected at direct admission (`HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION`),
# while preserving biological `FAIL_HARD_STOP` if `cxadr_ko_present=True`!
p_bank_req_ocr = copy.deepcopy(b_r13)
p_bank_req_ocr["require_trusted_nw08_ocr_record"] = True
r_bank_req_ocr = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_bank_req_ocr), openislet_root=resolved_root)
p_bank_req_ocr_fail = copy.deepcopy(p_bank_req_ocr)
p_bank_req_ocr_fail["cxadr_ko_present"] = True
r_bank_req_ocr_fail = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_bank_req_ocr_fail), openislet_root=resolved_root)
# 61. R13-B4: Live PASS responses across ALL 3 tiers (Bank, Surrogate, Autologous Process Qual)
# carry explicit machine-readable `qualification_scope` & `physical_qualification_complete=False`
# on BOTH Python API and `--evaluate-lot` file intake!
pq_r13 = build_authenticated_process_qualification_record(
product_variant_id="ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN",
process_qual_id="PQ-R13-001",
)
write_record_to_trusted_qualification_store(st_r13, pq_r13, category="process_qualifications")
p_auto_r13 = build_passing_reference_payload(
lot_id="AUTO-R13-001",
mcb_id="MCB-AUTO-R13-001",
product_variant_id="ISLET1_D1_AUTO_V2_L1A_CIITA_CD64T_IL1RN",
qualification_tier="AUTOLOGOUS_D1B_PROCESS_QUAL",
process_qualification_ref_sha256=pq_r13["sha256"],
openislet_root=resolved_root,
)
r_bank_pass_13 = evaluate_wholegraft_gate0v_and_stress_ap1903(b_r13, openislet_root=resolved_root)
r_auto_pass_13 = evaluate_wholegraft_gate0v_and_stress_ap1903(
p_auto_r13, trusted_qualification_store=st_r13, openislet_root=resolved_root
)
f_b_r13 = td_13 / "bank_pass_r13.json"
f_b_r13.write_text(json.dumps(b_r13, sort_keys=True), encoding="utf-8")
r_bank_file_13, rc_bank_file_13 = evaluate_wholegraft_gate0v_lot_file(f_b_r13, openislet_root=resolved_root)
# 62. R13-M1 & R13-M2: JSON integer `-0` rejected fail-closed at `--evaluate-lot` intake AND
# unvalidated `deff` cleared to `None` on invalid spec (`units=3, deff=2.0`) AND missing
# estimand partition (`deff=1.0`), recording raw value in `submitted_clustering_design_effect_deff_unvalidated`!
f_neg_int_lot = td_13 / "lot_neg_zero_int.json"
f_neg_int_lot.write_text('{"qualification_tier": "BANK_QUALIFICATION", "probe_int": -0}', encoding="utf-8")
r_nil, rc_nil = evaluate_wholegraft_gate0v_lot_file(f_neg_int_lot, openislet_root=resolved_root)
p_u3_d2 = copy.deepcopy(b_r13)
p_u3_d2["clustering_and_independence_spec"]["independent_biological_units_n"] = 3
p_u3_d2["clustering_and_independence_spec"]["clustering_design_effect_deff"] = "2.0"
r_u3_d2 = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_u3_d2), openislet_root=resolved_root)
p_miss_part_d1 = copy.deepcopy(b_r13)
p_miss_part_d1["gate0v_b_infectious_challenge"]["pathogens"]["cvb4_e2"]["day28_persistence_by_lineage"]["beta"].pop("per_unit_counts", None)
r_mp_d1 = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_miss_part_d1), openislet_root=resolved_root)
ok_r13_b1a = bool(
r_sc_clean["verdict"] == "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE"
and r_sc_adv_vp["verdict"] == "FAIL_HARD_STOP"
and "HARD_STOP_ADVERSE_PER_UNIT_POST_AP1903_VIRAL_ESCAPE" in r_sc_adv_vp["hard_stops"]
and "HOLD_UNEXPECTED_PER_UNIT_COUNTS_IN_SINGLE_CELL_MODE" in r_sc_adv_vp["holds"]
and r_sc_adv_vp["exact_directional_confidence_certified"] is False
and r_sc_adv_a72["verdict"] == "FAIL_HARD_STOP"
and "HARD_STOP_ADVERSE_PER_UNIT_CONTRADICTS_AGGREGATE_OR_BREACHES_KILL_FLOOR" in r_sc_adv_a72["hard_stops"]
and r_sc_unexp["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and "HOLD_UNEXPECTED_PER_UNIT_COUNTS_IN_SINGLE_CELL_MODE" in r_sc_unexp["holds"]
and r_sc_unexp["exact_directional_confidence_certified"] is False
)
cases.append({
"case": "r13_b1_single_cell_adverse_per_unit_counts_supplemental_arm_hard_stop_and_clean_hold",
"expected_verdict": "FAIL_HARD_STOP",
"actual_verdict": r_sc_adv_vp["verdict"],
"expected_token": "HARD_STOP_ADVERSE_PER_UNIT_POST_AP1903_VIRAL_ESCAPE",
"hard_stops": r_sc_adv_vp["hard_stops"][:3],
"holds": r_sc_unexp["holds"][:3],
"passed": ok_r13_b1a,
})
ok_r13_b1b = bool(
r_mw_mal_adv["verdict"] == "FAIL_HARD_STOP"
and "HARD_STOP_ADVERSE_PER_UNIT_POST_AP1903_VIRAL_ESCAPE" in r_mw_mal_adv["hard_stops"]
and r_mw_mal_adv["exact_directional_confidence_certified"] is False
and r_mw_nondict_adv["verdict"] == "FAIL_HARD_STOP"
and "HARD_STOP_ADVERSE_PER_UNIT_POST_AP1903_VIRAL_ESCAPE" in r_mw_nondict_adv["hard_stops"]
and r_mw_nondict_adv["exact_directional_confidence_certified"] is False
)
cases.append({
"case": "r13_b1_multi_well_malformed_row_before_adverse_row_preserves_hard_stop",
"expected_verdict": "FAIL_HARD_STOP",
"actual_verdict": r_mw_mal_adv["verdict"],
"expected_token": "HARD_STOP_ADVERSE_PER_UNIT_POST_AP1903_VIRAL_ESCAPE",
"hard_stops": r_mw_mal_adv["hard_stops"][:3],
"holds": r_mw_mal_adv["holds"][:3],
"passed": ok_r13_b1b,
})
sub_basis = r_sub_125_90["sampling_unit_basis"]
ok_r13_b2 = bool(
r_sub_125_90["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_sub_125_90["exact_directional_confidence_certified"] is False
and r_sub_125_90["release_authorizing"] is False
and r_sub_125_90["clustering_design_effect_deff"] is None
and "HOLD_SAMPLING_UNIT_SUBSET_OR_ID_CONTRADICTION" in r_sub_125_90["holds"]
and sub_basis["all_sampling_units_reconciled"] is False
and sub_basis["estimand_partitions_reconciled"] < sub_basis["estimand_partitions_checked"]
and r_uid_mm["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_uid_mm["exact_directional_confidence_certified"] is False
and "HOLD_SAMPLING_UNIT_SUBSET_OR_ID_CONTRADICTION" in r_uid_mm["holds"]
)
cases.append({
"case": "r13_b2_within_unit_direct_infected_veh_125_gt_90_and_unit_id_mismatch_hold",
"expected_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
"actual_verdict": r_sub_125_90["verdict"],
"expected_token": "HOLD_SAMPLING_UNIT_SUBSET_OR_ID_CONTRADICTION",
"hard_stops": r_sub_125_90["hard_stops"][:2],
"holds": r_sub_125_90["holds"][:3],
"passed": ok_r13_b2,
})
ok_r13_b3 = bool(
r_bank_req_ocr["verdict"] == "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION"
and r_bank_req_ocr["release_authorizing"] is False
and r_bank_req_ocr["gate0v_component_passed"] is False
and "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION" in r_bank_req_ocr["holds"]
and r_bank_req_ocr_fail["verdict"] == "FAIL_HARD_STOP"
and "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION" in r_bank_req_ocr_fail["holds"]
)
cases.append({
"case": "r13_b3_bank_require_trusted_nw08_ocr_rejected_at_direct_admission",
"expected_verdict": "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION",
"actual_verdict": r_bank_req_ocr["verdict"],
"expected_token": "HOLD_NW08_REQUIRED_OCR_NOT_PERMITTED_ON_BANK_QUALIFICATION",
"hard_stops": r_bank_req_ocr_fail["hard_stops"][:2],
"holds": r_bank_req_ocr["holds"][:3],
"passed": ok_r13_b3,
})
ok_r13_b4 = bool(
r_bank_pass_13["verdict"] == "PASS_WHOLEGRAFT_BANK_QUALIFICATION"
and r_bank_pass_13.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
and r_bank_pass_13.get("physical_qualification_complete") is False
and r_sc_clean["verdict"] == "PASS_WHOLEGRAFT_LOT_RELEASE_SURROGATE"
and r_sc_clean.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
and r_sc_clean.get("physical_qualification_complete") is False
and r_auto_pass_13["verdict"] == "PASS_WHOLEGRAFT_AUTOLOGOUS_PROCESS_QUAL"
and r_auto_pass_13.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
and r_auto_pass_13.get("physical_qualification_complete") is False
and rc_bank_file_13 == 0
and r_bank_file_13.get("qualification_scope") == QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL
and r_bank_file_13.get("physical_qualification_complete") is False
)
cases.append({
"case": "r13_b4_live_pass_emits_qualification_scope_and_physical_qualification_complete_false_all_tiers",
"expected_verdict": "PASS_WHOLEGRAFT_BANK_QUALIFICATION",
"actual_verdict": r_bank_pass_13["verdict"],
"expected_token": QUALIFICATION_SCOPE_MODELED_PENDING_PHYSICAL,
"hard_stops": [],
"holds": [],
"passed": ok_r13_b4,
})
ok_r13_m12 = bool(
rc_nil == 2
and r_nil["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_nil.get("holds") or [])
and "HOLD_GATE0V_AMBIGUOUS_OR_NONCANONICAL_LOT_JSON:INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE" in (r_nil.get("holds") or [])
and r_u3_d2["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_u3_d2["clustering_design_effect_deff"] is None
and r_u3_d2["submitted_clustering_design_effect_deff_unvalidated"] == "2.0"
and r_u3_d2["sampling_unit_basis"]["clustering_design_effect_deff"] is None
and r_u3_d2["sampling_unit_basis"]["submitted_clustering_design_effect_deff_unvalidated"] == "2.0"
and r_mp_d1["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_mp_d1["clustering_design_effect_deff"] is None
and r_mp_d1["submitted_clustering_design_effect_deff_unvalidated"] == "1.0"
and r_mp_d1["sampling_unit_basis"]["clustering_design_effect_deff"] is None
and r_mp_d1["sampling_unit_basis"]["submitted_clustering_design_effect_deff_unvalidated"] == "1.0"
)
cases.append({
"case": "r13_m1_m2_neg_zero_int_rejected_and_unvalidated_deff_cleared_to_none",
"expected_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
"actual_verdict": r_u3_d2["verdict"],
"expected_token": "INVALID_NEGATIVE_OR_SIGNED_ZERO_BOUNDARY_VALUE",
"hard_stops": [],
"holds": (r_nil.get("holds") or [])[:3],
"passed": ok_r13_m12,
})
# ------------------------------------------------------------------
# Round-17 Blocker #1 Paired Offline Acceptance Suite (a)-(e):
# Mandatory typed sampling-unit reconciliation for ALL release-critical