{"unit_id": f"W{i+1}", "k": base_k + (1 if i < rem_k else 0), "n": base_n + (1 if i < rem_n else 0)} for i in range(n_units) ] def _mk_r8_gate0v( prod: str, bank: str, lot: str, route: str, mat_ev: Mapping[str, Any], ts: str = "2026-10-12T09:30:00Z", *, candidate_gene: Optional[str] = None, comparator_nt_lot_id: Optional[str] = None, coating_identity: Optional[Mapping[str, str]] = None, prereq_receipts: Optional[Mapping[str, str]] = None, treated_72h_n: int = 120000, veh_72h_k: int = 180, veh_72h_n: int = 200, direct_inf_veh_k: int = 120, spike_k: int = 36, spike_n: int = 36, tier_override: Optional[str] = None, transient_engagement: Optional[Mapping[str, Any]] = None, ) -> dict[str, Any]: p_t24 = _mk_r8_unit_part(0, 6000) p_v24 = _mk_r8_unit_part(180, 200) p_t72 = _mk_r8_unit_part(0, treated_72h_n) p_v72 = _mk_r8_unit_part(veh_72h_k, veh_72h_n) p_dinf = _mk_r8_unit_part(direct_inf_veh_k, veh_72h_n) p_vir = _mk_r8_unit_part(0, treated_72h_n) p_sp = _mk_r8_unit_part(spike_k, spike_n) rmap: dict[str, dict[str, dict[str, Any]]] = {} for rname in sorted(REQUIRED_5_REGIMES): lmap: dict[str, dict[str, Any]] = {} for lname in sorted(REQUIRED_5_LINEAGES): cell: dict[str, Any] = { "treated_24h_survivors_k": 0, "treated_24h_input_n": 6000, "veh_24h_alive_k": 180, "veh_24h_input_n": 200, "treated_72h_survivors_k": 0, "treated_72h_input_n": treated_72h_n, "veh_72h_alive_k": veh_72h_k, "veh_72h_input_n": veh_72h_n, "per_unit_counts_treated_24h": [dict(u) for u in p_t24], "per_unit_counts_veh_24h": [dict(u) for u in p_v24], "per_unit_counts_treated_72h": [dict(u) for u in p_t72], "per_unit_counts_veh_72h": [dict(u) for u in p_v72], } if rname in VIRAL_REGIMES: cell.update({ "aliquot_linkage_mode": "SAME_72H_ALIQUOT", "aliquot_linkage_id": f"ALQ-{lot}-{rname[:4]}-{lname[:4]}", "pre_ap1903_lineage_input_cells_n": treated_72h_n, "post_ap1903_viable_survivors_total_n": 0, "post_ap1903_viable_viral_pos_k": 0, "caspase9_3_fold_over_veh": 8.2, "infected_cell_escape_mode": "DIRECT_INFECTED_VEHICLE_DENOMINATOR", "pretreat_infected_veh_survivor_k": direct_inf_veh_k, "spike_healthy_recovered_k": spike_k, "spike_healthy_input_n": spike_n, "spike_fragile_recovered_k": spike_k, "spike_fragile_input_n": spike_n, "per_unit_counts_direct_infected_veh_72h": [dict(u) for u in p_dinf], "per_unit_counts_viral_pos_72h": [dict(u) for u in p_vir], "per_unit_counts_spike_healthy": [dict(u) for u in p_sp], "per_unit_counts_spike_fragile": [dict(u) for u in p_sp], }) lmap[lname] = cell rmap[rname] = lmap default_tier = "PASS_WHOLEGRAFT_AUTOLOGOUS_PROCESS_QUAL" if prod == "ISLET1_DESIGN_D1B_LEAN_K2" else "PASS_WHOLEGRAFT_BANK_QUALIFICATION" body: dict[str, Any] = { "stage": "GATE-0V-KILL", "verdict": "PASS", "product_id": prod, "bank_id": bank, "lot_id": lot, "route_id": route, "evidence_scope": "exact_product", "recorded_at_utc": ts, "parent_receipt_sha256": mat_ev["receipt_sha256"], "canonical_gate0v_producer_sha256": "4" * 64, "canonical_gate0v_tier": tier_override or default_tier, "independent_sampling_unit_class": "RECONCILED_MULTI_WELL_CELL_ASSAY_WITH_UNIT_PARTITION", "independent_biological_units_n": 6, "clustering_design_effect_deff": 1, "exposed_product_tested": True, "regime_by_lineage_raw_counts": rmap, } if candidate_gene is not None: body["candidate_gene"] = candidate_gene if comparator_nt_lot_id is not None: body["comparator_nt_lot_id"] = comparator_nt_lot_id if coating_identity is not None: body.update(coating_identity) if prereq_receipts is not None: body["prerequisite_receipt_sha256s"] = dict(prereq_receipts) if transient_engagement is not None: body["transient_target_engagement_record"] = dict(transient_engagement) body["specimen_id"] = transient_engagement["specimen_id"] _t_es = parse_utc_iso_ts(transient_engagement["assay_window_start_utc"]) _t_ee = parse_utc_iso_ts(transient_engagement["assay_window_end_utc"]) _t_st_sw = (_t_es + timedelta(minutes=30)) if _t_es else None _t_en_sw = (_t_ee - timedelta(minutes=15)) if _t_ee else None body["assay_started_at_utc"] = _t_st_sw.strftime("%Y-%m-%dT%H:%M:%SZ") if _t_st_sw else transient_engagement["assay_window_start_utc"] body["assay_completed_at_utc"] = _t_en_sw.strftime("%Y-%m-%dT%H:%M:%SZ") if _t_en_sw else transient_engagement["assay_window_end_utc"] if _t_st_sw is not None: body["assay_24h_collection_utc"] = (_t_st_sw + timedelta(hours=24)).strftime("%Y-%m-%dT%H:%M:%SZ") body["assay_72h_collection_utc"] = (_t_st_sw + timedelta(hours=72)).strftime("%Y-%m-%dT%H:%M:%SZ") return _sign_receipt(body) def _mk_r8_gate31( prod: str, bank: str, lot: str, mat_ev: Optional[Mapping[str, Any]] = None, *, coating_stab: Optional[bool] = True, ts: str = "2026-10-12T09:45:00Z", ) -> dict[str, Any]: pblks = [ {"block_id": f"G31-B{i+1}", "open_sink_t_half_h": oh, "limited_exchange_t_half_h": lh} for i, (lh, oh) in enumerate([(54.0, 44.5), (55.2, 45.8), (56.0, 46.4), (56.5, 47.0), (57.1, 47.4), (57.2, 47.9)]) ] diffs = [b["open_sink_t_half_h"] - 0.50 * b["limited_exchange_t_half_h"] for b in pblks] l95_c = paired_t_summary(diffs)[3] os_vals = [b["open_sink_t_half_h"] for b in pblks] os_b = sample_t_one_sided_bounds(os_vals, alpha=0.025) body: dict[str, Any] = { "stage": "GATE-31", "verdict": "PASS", "product_id": prod, "bank_id": bank, "lot_id": lot, "route_id": "R1", "evidence_scope": "exact_product", "recorded_at_utc": ts, "canonical_gate31_producer_sha256": "5" * 64, "bead_psd_lot_id": lot, "barrier_film_lot_id": lot, "kinetics_336h_lot_id": lot, "open_sink_lot_id": lot, "reconciled_slab_geometry_mode": "EXPANDED_390UM_2X125UM_BANDS", "kinetics_assay_regime": "PAIRED_LIMITED_EXCHANGE_AND_OPEN_SINK", "bead_d99_u95_um": 46.0, "bead_d50_um": 32.0, "crystal_d99_um": 12.0, "barrier_geometry_mode": "PLANAR_CO_CAST_LAMINA_FACE_HYDROGEL_FILM", "barrier_thickness_l95_um": 22.0, "catalase_uniprot_id": "P04040", "conserved_cao2_loading_mg": 791.5, "cumulative_sub15_mmhg_duration_h": 1.8, "hard_hypoxia_floor_min_po2_mmhg": 13.6, "whole_device_washout_dec134": { "time_min_series": [0.0, 1.8, 3.4, 5.8, 9.0, 15.0, 20.0], "remaining_peak_pct_series": [100.0, 70.0, 50.0, 24.0, 10.0, 4.5, 2.5], "raw_trace_sha256": sha256_bytes(canonical_json_bytes({"time_min": [0.0, 1.8, 3.4, 5.8, 9.0, 15.0, 20.0], "remaining_peak_pct": [100.0, 70.0, 50.0, 24.0, 10.0, 4.5, 2.5]})), "trace_span_min": 20.0, "tail_remaining_pct": 2.5, "mass_recovery_pct": 98.5, "t50_min": 3.4, "mean_transit_min": 4.53, "t90_min": 9.0, }, "vascular_midpoint_horizon_h": 60.0, "halflife_l95_h": 52.08, "halflife_u95_h": 59.92, "kinetic_law_code": 0, "hour0_24_o2_ratio_l95": 0.85, "hour0_72_o2_cum_frac_l95": 0.30, "h2o2_z70_u95_uM": 1.4, "obs_h2o2_measurement_site": "BARRIER_TISSUE_INTERFACE_Z_70P0_UM", "obs_h2o2_z_um": 70.0, "day7_catalase_retention_l95_pct": 82.0, "day14_catalase_retained_l95_iu": 80000.0, "pre_cure_catalase_load_iu_333cm2": 148000.0, "gate31c_paired_blocks": pblks, "gate31c_open_minus_half_limited_l95_h": round(l95_c, 8), "gate31c_open_sink_halflife_l95_h": round(os_b[1], 4), "gate31c_open_sink_halflife_u95_h": round(os_b[2], 4), "gate31c_open_sink_h2o2_u95_uM": 1.6, "obs_open_sink_h2o2_measurement_site": "BARRIER_TISSUE_INTERFACE_Z_70P0_UM", "obs_open_sink_h2o2_z_um": 70.0, } if mat_ev is not None: body["parent_receipt_sha256"] = mat_ev["receipt_sha256"] if coating_stab is not None: body["coating_stability_verified"] = coating_stab if coating_stab is True: body["coating_stability_evidence"] = { "day14_barrier_thickness_retention_pct": 98.5, "day14_catalase_retention_ratio_vs_uncoated": 0.98, "o2_permeability_ratio_vs_uncoated": 0.99, "coating_delamination_events": 0, } return _sign_receipt(body) def _mk_r8_hour0(prod: str, lineages: FrozenSet[str] = REQUIRED_HOUR0_LINEAGES_FULL) -> dict[str, dict[str, Any]]: sp = CANONICAL_WAVE6_PRODUCTS[prod] out: dict[str, dict[str, Any]] = {} for lin in sorted(lineages): row: dict[str, Any] = { "hlae_molecules_per_cell": 22000.0 if sp["hla_e_engineered"] else "N/A_CONSTRUCT_LACKS_HLAE_MODULE", "cd47_median_molecules_per_cell": 240000.0 if sp["cd47_engineered"] else "N/A_CONSTRUCT_LACKS_CD47_MODULE", "cd47_p10_molecules_per_cell": 195000.0 if sp["cd47_engineered"] else "N/A_CONSTRUCT_LACKS_CD47_MODULE", } if sp["autologous_self_hla"]: row["autologous_hla_abc_preservation_pct"] = 94.0 out[lin] = row return out def _mk_r8_shields(prod: str, val: float = 92.5) -> dict[str, float]: return {c: val for c in sorted(SHIELD_COMPONENTS_BY_PRODUCT[prod])} def _mk_r8_pfd_trace(horizon_h: float = 840.0) -> tuple[list[float], list[float]]: # Unified mass balance on initial_pirfenidone_loading_mg = 18.75 mg: # 24h = 1.80 mg (9.6% burst <= 15%), 336h = 13.50 mg (72.0% usable <= 85%), # 840h = 17.60 mg (t50 crosses 8.80 mg inside [216h, 264h] = [9.0d, 11.0d], linear t50 = 9.75 d), # supremum burst Cmax <= 0.08 ug/mL (< 0.20), max 24-h rate <= 1.80 mg/d! if horizon_h <= 336.0: times = [0.0, 1.0, 3.0, 6.0, 12.0, 24.0, 48.0, 72.0, 120.0, 168.0, 216.0, 264.0, 336.0] cum = [0.0, 0.20, 0.45, 0.75, 1.20, 1.80, 3.00, 4.10, 5.70, 7.10, 8.30, 10.10, 13.50] else: times = [0.0, 1.0, 3.0, 6.0, 12.0, 24.0, 48.0, 72.0, 120.0, 168.0, 216.0, 264.0, 336.0, 432.0, 528.0, 672.0, 840.0] cum = [0.0, 0.20, 0.45, 0.75, 1.20, 1.80, 3.00, 4.10, 5.70, 7.10, 8.30, 10.10, 13.50, 15.20, 16.30, 17.20, 17.60] return times, cum def _mk_r8_a4b_prereg_and_cohorts( prod: str, bank: str, lot: str, route: str, a4a_ev: Mapping[str, Any], coat: Mapping[str, str], *, start_dt_str: str = "2026-12-20T08:00:00Z", prereg_ts: str = "2026-12-18T08:00:00Z", mode: str = "TERMINAL_HISTOLOGY", ) -> tuple[dict[str, Any], dict[str, Any]]: st = parse_utc_iso_ts(start_dt_str) early_recs: list[dict[str, Any]] = [] d28_recs: list[dict[str, Any]] = [] roster: dict[str, str] = {} early_assigned: list[str] = [] d28_assigned: list[str] = [] for i in range(8): imp_ts = (st + timedelta(hours=i)).strftime("%Y-%m-%dT%H:%M:%SZ") ep = (st + timedelta(hours=48 + i)).strftime("%Y-%m-%dT%H:%M:%SZ") dp = (st + timedelta(days=28, hours=i)).strftime("%Y-%m-%dT%H:%M:%SZ") ec_id = f"L-COAT-{i+1:02d}" if mode == "VALIDATED_NONTERMINAL_LONGITUDINAL_IMAGING" else f"E-COAT-{i+1:02d}" ev_id = f"L-VEH-{i+1:02d}" if mode == "VALIDATED_NONTERMINAL_LONGITUDINAL_IMAGING" else f"E-VEH-{i+1:02d}" dc_id = ec_id if mode == "VALIDATED_NONTERMINAL_LONGITUDINAL_IMAGING" else f"D28-COAT-{i+1:02d}" dv_id = ev_id if mode == "VALIDATED_NONTERMINAL_LONGITUDINAL_IMAGING" else f"D28-VEH-{i+1:02d}" roster[ec_id] = "COATED"; roster[ev_id] = "BLANK_VEHICLE" roster[dc_id] = "COATED"; roster[dv_id] = "BLANK_VEHICLE" early_assigned.extend([ec_id, ev_id]) d28_assigned.extend([dc_id, dv_id]) early_recs.append({"animal_id": ec_id, "arm": "COATED", "implanted_at_utc": imp_ts, "assessed_at_utc": ep, "raw_lectin_perfusion_signal": round(104.0 + 1.0 * (i - 3.5), 3), "adverse_event_code": "NONE"}) early_recs.append({"animal_id": ev_id, "arm": "BLANK_VEHICLE", "implanted_at_utc": imp_ts, "assessed_at_utc": ep, "raw_lectin_perfusion_signal": round(100.0 + 0.9 * (i - 3.5), 3), "adverse_event_code": "NONE"}) d28_recs.append({"animal_id": dc_id, "arm": "COATED", "implanted_at_utc": imp_ts, "assessed_at_utc": dp, "pericapsular_collagen_thickness_um": round(58.0 + 1.5 * (i - 3.5), 3), "raw_lectin_vessel_density": round(106.0 + 1.0 * (i - 3.5), 3), "adverse_event_code": "NONE"}) d28_recs.append({"animal_id": dv_id, "arm": "BLANK_VEHICLE", "implanted_at_utc": imp_ts, "assessed_at_utc": dp, "pericapsular_collagen_thickness_um": round(100.0 + 1.8 * (i - 3.5), 3), "raw_lectin_vessel_density": round(100.0 + 0.9 * (i - 3.5), 3), "adverse_event_code": "NONE"}) prereg = _sign_receipt({ "stage": "A-4b-PREREGISTRATION", "verdict": "PASS", "product_id": prod, "bank_id": bank, "lot_id": lot, "route_id": route, "evidence_scope": "exact_product", "recorded_at_utc": prereg_ts, "parent_receipt_sha256": a4a_ev["receipt_sha256"], **coat, "early_assay_mode": mode, "primary_collagen_endpoint": "PERICAPSULAR_COLLAGEN_THICKNESS_UM", "randomized_animal_roster": roster, "early_cohort_assigned_ids": early_assigned, "day28_cohort_assigned_ids": d28_assigned, "max_attrition_rate_pct": 15.0, "max_arm_attrition_diff_pp": 10.0, "exclusion_timing_cutoff_rule": "LOCKED_BEFORE_HISTOLOGY_UNBLINDING", "missing_data_sensitivity_rule": "WORST_CASE_TIPPING_POINT_BOUND", "perfusion_normalization_scale": "VEHICLE_CONTROL_MEAN_PCT", "tipping_point_collagen_bounds_um": [20.0, 1500.0], "tipping_point_perfusion_bounds_pct": [0.0, 200.0], }) unblind_ts = (st + timedelta(days=30)).strftime("%Y-%m-%dT%H:%M:%SZ") cohorts = { "histology_unblinding_utc": unblind_ts, "early_assay_mode": mode, "early_cohort_enrolled_coated_n": 8, "early_cohort_enrolled_vehicle_n": 8, "early_cohort_exclusions": [], "early_cohort_records": early_recs, "day28_cohort_enrolled_coated_n": 8, "day28_cohort_enrolled_vehicle_n": 8, "day28_cohort_exclusions": [], "day28_cohort_records": d28_recs, } return prereg, cohorts def _mk_r8_a4b_cohorts(start_dt_str: str = "2026-12-20T08:00:00Z") -> dict[str, Any]: st = parse_utc_iso_ts(start_dt_str) early_recs: list[dict[str, Any]] = [] d28_recs: list[dict[str, Any]] = [] for i in range(8): imp_ts = (st + timedelta(hours=i)).strftime("%Y-%m-%dT%H:%M:%SZ")