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…
# control & recovery counts (stressed-arm recovery calibrants, Day-28
# uninfected negative controls, and Day-28 recovery calibrants)!
# ------------------------------------------------------------------
# 63. R17-B1 (a): Positive control with EVERY component's sampling-unit basis reconciled
# (both multi-well 209/209 bank fixture AND single-cell unit-matched bank fixture) -> PASS,
# exact_directional_confidence_certified=True, all_sampling_units_reconciled=True!
p_r17_mw = build_passing_reference_payload(openislet_root=resolved_root)
r_r17_mw = evaluate_wholegraft_gate0v_and_stress_ap1903(p_r17_mw, openislet_root=resolved_root)
sb_r17_mw = r_r17_mw["sampling_unit_basis"]
all_inf_arms_cal_rec = all(
r_r17_mw["stress_ap1903_regimes"][reg]["lineages"][lin].get("spike_calibrant_sampling_units_reconciled") is True
for reg in INFECTED_AP1903_REGIMES
for lin in GRAFT_LINEAGES
)
all_d28_ctrl_and_cal_rec = all(
(
r_r17_mw["pathogen_results"][p]["lineage_results"][lin].get("uninfected_ctrl_sampling_unit_reconciled") is True
and r_r17_mw["pathogen_results"][p]["lineage_results"][lin].get("spike_calibrant_sampling_units_reconciled") is True
)
for p in GATE0V_PATHOGENS
for lin in GRAFT_LINEAGES
)
p_r17_sc = build_passing_reference_payload(
independent_sampling_unit_class="INDEPENDENT_SINGLE_CELL_OR_LIMITING_DILUTION_UNIT",
independent_biological_units_n=5_200_000,
openislet_root=resolved_root,
)
r_r17_sc = evaluate_wholegraft_gate0v_and_stress_ap1903(p_r17_sc, openislet_root=resolved_root)
ok_r17_a = bool(
r_r17_mw["verdict"] == "PASS_WHOLEGRAFT_BANK_QUALIFICATION"
and r_r17_mw["exact_directional_confidence_certified"] is True
and sb_r17_mw["all_sampling_units_reconciled"] is True
and sb_r17_mw["estimand_partitions_checked"] == 209
and sb_r17_mw["estimand_partitions_reconciled"] == 209
and all_inf_arms_cal_rec
and all_d28_ctrl_and_cal_rec
and r_r17_sc["verdict"] == "PASS_WHOLEGRAFT_BANK_QUALIFICATION"
and r_r17_sc["exact_directional_confidence_certified"] is True
and r_r17_sc["sampling_unit_basis"]["all_sampling_units_reconciled"] is True
)
cases.append({
"case": "r17_b1_a_positive_control_all_calibrants_and_neg_ctrl_reconciled_passes",
"expected_verdict": "PASS_WHOLEGRAFT_BANK_QUALIFICATION",
"actual_verdict": r_r17_mw["verdict"],
"expected_token": None,
"checked_partitions": sb_r17_mw["estimand_partitions_checked"],
"reconciled_partitions": sb_r17_mw["estimand_partitions_reconciled"],
"hard_stops": [],
"holds": [],
"passed": ok_r17_a,
})
# 64. R17-B1 (b): Missing or mismatched stressed-arm recovery calibrant sampling-unit reconciliation
# (`spike_calibrant` or `fragile_infected_spike_calibrant`) -> HOLD, certified=False, reconciled=False!
p_r17_b_h = copy.deepcopy(p_r17_mw)
p_r17_b_h["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"].pop("spike_calibrant", None)
r_r17_b_h = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_b_h), openislet_root=resolved_root)
p_r17_b_f = copy.deepcopy(p_r17_mw)
p_r17_b_f["gate0v_kill_stress_ap1903"]["active_or_persistent_hcmv_infection"]["pericyte"]["per_unit_counts"].pop("fragile_infected_spike_calibrant", None)
r_r17_b_f = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_b_f), openislet_root=resolved_root)
p_r17_b_mm = copy.deepcopy(p_r17_mw)
p_r17_b_mm["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"]["spike_calibrant"][0]["k"] -= 1
r_r17_b_mm = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_b_mm), openislet_root=resolved_root)
ok_r17_b = all(
(
r_x["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_x["exact_directional_confidence_certified"] is False
and r_x["release_authorizing"] is False
and r_x["clustering_design_effect_deff"] is None
and r_x["sampling_unit_basis"]["all_sampling_units_reconciled"] is False
and r_x["sampling_unit_basis"]["estimand_partitions_reconciled"] == 208
and r_x["sampling_unit_basis"]["estimand_partitions_checked"] == 209
and "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS" in r_x["holds"]
)
for r_x in (r_r17_b_h, r_r17_b_f, r_r17_b_mm)
)
cases.append({
"case": "r17_b1_b_missing_or_mismatched_stressed_recovery_calibrant_partition_holds",
"expected_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
"actual_verdict": r_r17_b_h["verdict"],
"expected_token": "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS",
"hard_stops": [],
"holds": r_r17_b_h["holds"][:3],
"passed": ok_r17_b,
})
# 65. R17-B1 (c): Missing or mismatched Day-28 negative-control sampling-unit reconciliation
# (multi-well missing/mismatch AND single-cell `independent_biological_units_n < uninfected_ctrl_scored_n`)
# -> HOLD, exact_directional_confidence_certified=False, all_sampling_units_reconciled=False!
p_r17_c_miss = copy.deepcopy(p_r17_mw)
p_r17_c_miss["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"].pop("uninfected_ctrl_per_unit_counts", None)
r_r17_c_miss = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_c_miss), openislet_root=resolved_root)
p_r17_c_mm = copy.deepcopy(p_r17_mw)
p_r17_c_mm["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"]["uninfected_ctrl_fp_k"] = 20
# Deliberately do NOT reconcile uninfected_ctrl_per_unit_counts -> aggregate-vs-unit mismatch!
r_r17_c_mm = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_c_mm), openislet_root=resolved_root)
p_r17_c_sc = copy.deepcopy(p_r17_sc)
p_r17_c_sc["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"]["uninfected_ctrl_scored_n"] = 5_300_000
r_r17_c_sc = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_c_sc), openislet_root=resolved_root)
ok_r17_c = bool(
all(
(
r_x["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_x["exact_directional_confidence_certified"] is False
and r_x["release_authorizing"] is False
and r_x["clustering_design_effect_deff"] is None
and r_x["sampling_unit_basis"]["all_sampling_units_reconciled"] is False
and "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS" in r_x["holds"]
)
for r_x in (r_r17_c_miss, r_r17_c_mm, r_r17_c_sc)
)
and r_r17_c_miss["sampling_unit_basis"]["estimand_partitions_reconciled"] == 208
and r_r17_c_mm["sampling_unit_basis"]["estimand_partitions_reconciled"] == 208
)
cases.append({
"case": "r17_b1_c_missing_or_mismatched_day28_neg_ctrl_sampling_unit_basis_holds",
"expected_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
"actual_verdict": r_r17_c_miss["verdict"],
"expected_token": "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS",
"hard_stops": [],
"holds": r_r17_c_miss["holds"][:3],
"passed": ok_r17_c,
})
# 66. R17-B1 (d): Missing or mismatched Day-28 recovery calibrant sampling-unit reconciliation
# (`spike_calibrant_per_unit_counts`, `fragile_infected_spike_per_unit_counts`, or unit-ID mismatch)
# -> HOLD, exact_directional_confidence_certified=False, all_sampling_units_reconciled=False!
p_r17_d_h = copy.deepcopy(p_r17_mw)
p_r17_d_h["gate0v_b_infectious_challenge"]["pathogens"]["cvb4_e2"]["day28_persistence_by_lineage"]["beta"].pop("spike_calibrant_per_unit_counts", None)
r_r17_d_h = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_d_h), openislet_root=resolved_root)
p_r17_d_f = copy.deepcopy(p_r17_mw)
p_r17_d_f["gate0v_b_infectious_challenge"]["pathogens"]["hcmv"]["day28_persistence_by_lineage"]["plvap_iec"].pop("fragile_infected_spike_per_unit_counts", None)
r_r17_d_f = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_d_f), openislet_root=resolved_root)
p_r17_d_uid = copy.deepcopy(p_r17_mw)
for _idx_u, _row_u in enumerate(
p_r17_d_uid["gate0v_b_infectious_challenge"]["pathogens"]["cvb4_e2"]["day28_persistence_by_lineage"]["beta"]["spike_calibrant_per_unit_counts"]
):
_row_u["unit_id"] = f"UNLINKED-CAL-UNIT-{_idx_u + 1:02d}"
r_r17_d_uid = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_d_uid), openislet_root=resolved_root)
ok_r17_d = bool(
all(
(
r_x["verdict"] == "HOLD_INCOMPLETE_OR_UNDERPOWERED"
and r_x["exact_directional_confidence_certified"] is False
and r_x["release_authorizing"] is False
and r_x["clustering_design_effect_deff"] is None
and r_x["sampling_unit_basis"]["all_sampling_units_reconciled"] is False
and r_x["sampling_unit_basis"]["estimand_partitions_reconciled"] == 208
and r_x["sampling_unit_basis"]["estimand_partitions_checked"] == 209
)
for r_x in (r_r17_d_h, r_r17_d_f, r_r17_d_uid)
)
and "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS" in r_r17_d_h["holds"]
and "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS" in r_r17_d_f["holds"]
and "HOLD_SAMPLING_UNIT_SUBSET_OR_ID_CONTRADICTION" in r_r17_d_uid["holds"]
)
cases.append({
"case": "r17_b1_d_missing_or_mismatched_day28_recovery_calibrant_partition_holds",
"expected_verdict": "HOLD_INCOMPLETE_OR_UNDERPOWERED",
"actual_verdict": r_r17_d_h["verdict"],
"expected_token": "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS",
"hard_stops": [],
"holds": r_r17_d_h["holds"][:3],
"passed": ok_r17_d,
})
# 67. R17-B1 (e): Biological FAIL_HARD_STOP co-occurring with missing stressed/Day-28 recovery
# calibrant AND negative-control reconciliation MUST preserve FAIL_HARD_STOP precedence while
# setting exact_directional_confidence_certified=False and all_sampling_units_reconciled=False!
def _strip_all_three_cal_and_ctrl(pl_obj: Dict[str, Any]) -> None:
pl_obj["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["per_unit_counts"].pop("spike_calibrant", None)
pl_obj["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"].pop("uninfected_ctrl_per_unit_counts", None)
pl_obj["gate0v_b_infectious_challenge"]["pathogens"]["hcmv"]["day28_persistence_by_lineage"]["plvap_iec"].pop("fragile_infected_spike_per_unit_counts", None)
p_r17_e_vp = copy.deepcopy(p_r17_mw)
_strip_all_three_cal_and_ctrl(p_r17_e_vp)
p_r17_e_vp["gate0v_kill_stress_ap1903"]["active_or_persistent_cvb4_infection"]["beta"]["post_ap1903_viable_viral_pos_k"] = 1
r_r17_e_vp = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_e_vp), openislet_root=resolved_root)
p_r17_e_d28 = copy.deepcopy(p_r17_mw)
_strip_all_three_cal_and_ctrl(p_r17_e_d28)
p_r17_e_d28["gate0v_b_infectious_challenge"]["pathogens"]["cvb3"]["day28_persistence_by_lineage"]["alpha"]["stage2_confirmed_infectious_k"] = 1
r_r17_e_d28 = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_e_d28), openislet_root=resolved_root)
p_r17_e_cx = copy.deepcopy(p_r17_mw)
_strip_all_three_cal_and_ctrl(p_r17_e_cx)
p_r17_e_cx["cxadr_ko_present"] = True
r_r17_e_cx = evaluate_wholegraft_gate0v_and_stress_ap1903(_seal(p_r17_e_cx), openislet_root=resolved_root)
ok_r17_e = all(
(
r_x["verdict"] == "FAIL_HARD_STOP"
and r_x["exact_directional_confidence_certified"] is False
and r_x["release_authorizing"] is False
and r_x["sampling_unit_basis"]["all_sampling_units_reconciled"] is False
and "HOLD_SAMPLING_UNIT_PARTITION_MISMATCH_OR_INSUFFICIENT_UNITS" in r_x["holds"]
and len(r_x["hard_stops"]) >= 1
)
for r_x in (r_r17_e_vp, r_r17_e_d28, r_r17_e_cx)
)
cases.append({
"case": "r17_b1_e_biological_hard_stop_preserved_when_calibrant_and_neg_ctrl_reconciliation_missing",
"expected_verdict": "FAIL_HARD_STOP",
"actual_verdict": r_r17_e_vp["verdict"],
"expected_token": "POST_AP1903_VIABLE_VIRAL_SURVIVOR",
"hard_stops": r_r17_e_vp["hard_stops"][:3],
"holds": r_r17_e_vp["holds"][:3],
"passed": ok_r17_e,
})
passed_n = sum(1 for c in cases if c["passed"])
return {
"total_cases": len(cases),
"passed_cases": passed_n,
"all_passed": passed_n == len(cases),
"cases": cases,
}
def _normalize_receipt_for_portable_check(receipt_doc: Dict[str, Any]) -> Dict[str, Any]:
"""
B8 Portable `--check` Projection:
Strips volatile runtime metadata (`python_version`) and normalizes ONLY the known
public-bundle vs full-repo redaction metadata (`bundle_mode`, `protected_manifest_source`,
`facts_source`, and the two publisher-redacted study digests `17375075.json`/`39571901.json`
ONLY AFTER verifying `matches is True` against the exact mode-specific pin!).
ALL scientific outputs, ALL 20 `matches` flags, ALL 18 shared file hashes, ALL Playbook §4.1.20
hashes, `post_render_bytes`, Decimal bounds, adversarial tests, and 3D FVM unrounded floats
MUST match 100% identically!
"""
proj = copy.deepcopy(receipt_doc)
proj.pop("python_version", None)
part_c = proj.get("part_c_protected_invariance_and_ceg_delta_diff")
if isinstance(part_c, dict):
part_c.pop("bundle_mode", None)
part_c.pop("protected_manifest_source", None)
r4 = part_c.get("r4_playbook_sec4120_dec114_and_renderer_compatibility")
if isinstance(r4, dict):
rd_rep = r4.get("render_documentation_protocol_doc_replay")
if isinstance(rd_rep, dict):
rd_rep.pop("facts_source", None)