Archive 4 checkpoints (1-4)
Browse files- paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/core_readiness.py +72 -0
- paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/evaluate_arm.py +219 -0
- paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/finish_chili1_export.py +22 -0
- paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/test_evaluation.py +84 -0
paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/core_readiness.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Expose new x1 LoRA core results immediately while independent full metrics proceed."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import fcntl
|
| 4 |
+
import subprocess
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import sys
|
| 7 |
+
import time
|
| 8 |
+
from common import ROOT, S, atomic, generated, now, read, relative, supports, verify_receipt
|
| 9 |
+
from cpu_queue import PYTHON, snapshot
|
| 10 |
+
from readiness import generation_readiness
|
| 11 |
+
sys.path.insert(0, str(S / "tools"))
|
| 12 |
+
from runtime import Runtime
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def main() -> None:
|
| 16 |
+
lock = (ROOT / ".core-readiness.lock").open("a")
|
| 17 |
+
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
| 18 |
+
runtime = Runtime(ROOT)
|
| 19 |
+
arms = read(ROOT / "WORKER_CONFIG.json")["arms"]
|
| 20 |
+
while True:
|
| 21 |
+
done = 0
|
| 22 |
+
waiting = []
|
| 23 |
+
for support in supports():
|
| 24 |
+
rel = relative(support)
|
| 25 |
+
unit = "-".join(rel.parts)
|
| 26 |
+
canonical = S / "receipts" / f"{unit}-score.json"
|
| 27 |
+
core = ROOT / "units" / rel / "lora/receipts/score.json"
|
| 28 |
+
if canonical.exists() and read(canonical).get("state") == "completed":
|
| 29 |
+
done += 1
|
| 30 |
+
continue
|
| 31 |
+
if core.exists():
|
| 32 |
+
verify_receipt(core)
|
| 33 |
+
done += 1
|
| 34 |
+
continue
|
| 35 |
+
ready = generation_readiness(S, rel, "lora", ROOT / "remote_operation_receipts")
|
| 36 |
+
if not ready["ready"]:
|
| 37 |
+
waiting.append({"unit": unit, **ready})
|
| 38 |
+
continue
|
| 39 |
+
try:
|
| 40 |
+
runtime.preflight("cpu", 16)
|
| 41 |
+
except BlockingIOError as error:
|
| 42 |
+
waiting.append({"unit": unit, "state": "waiting_memory", "reason": str(error)})
|
| 43 |
+
continue
|
| 44 |
+
atomic(ROOT / "CORE_STATUS.json", {"phase": "running", "at": now(), "active": unit, "done": done})
|
| 45 |
+
command = [PYTHON, "-u", str(ROOT / "evaluate_arm.py"), "--support", str(support), "--arm", "lora",
|
| 46 |
+
"--core-only", "--try-lock", "--threads", "2"]
|
| 47 |
+
wrapped = runtime.wrapped_command("core-" + unit, command, "cpu", 16, 2)
|
| 48 |
+
log = ROOT / "logs" / f"core-{unit}.log"
|
| 49 |
+
with log.open("a") as stream:
|
| 50 |
+
result = subprocess.run(wrapped, stdout=stream, stderr=subprocess.STDOUT)
|
| 51 |
+
if result.returncode == 75:
|
| 52 |
+
waiting.append({"unit": unit, "state": "owned_by_full_worker"})
|
| 53 |
+
continue
|
| 54 |
+
if result.returncode:
|
| 55 |
+
raise RuntimeError(f"Core evaluation failed for {unit}: exit {result.returncode}; inspect {log}")
|
| 56 |
+
verify_receipt(core)
|
| 57 |
+
done += 1
|
| 58 |
+
snapshot(arms, "core_results_updated")
|
| 59 |
+
atomic(ROOT / "CORE_STATUS.json", {"phase": "complete" if done == len(supports()) else "waiting",
|
| 60 |
+
"at": now(), "done": done, "total": len(supports()), "waiting": waiting})
|
| 61 |
+
snapshot(arms, "core_complete" if done == len(supports()) else "waiting_core_results")
|
| 62 |
+
if done == len(supports()):
|
| 63 |
+
return
|
| 64 |
+
time.sleep(30)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
if __name__ == "__main__":
|
| 68 |
+
try:
|
| 69 |
+
main()
|
| 70 |
+
except BaseException as error:
|
| 71 |
+
atomic(ROOT / "CORE_ERROR.json", {"state": "stopped_needs_inspection", "at": now(), "error": str(error)})
|
| 72 |
+
raise
|
paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/evaluate_arm.py
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Complete missing CPU metrics for one arm; reuse validated core/annotation artifacts."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import copy
|
| 6 |
+
import fcntl
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
import shutil
|
| 11 |
+
import sys
|
| 12 |
+
|
| 13 |
+
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
| 14 |
+
for key in ("OMP_NUM_THREADS", "OPENBLAS_NUM_THREADS", "MKL_NUM_THREADS", "NUMBA_NUM_THREADS"):
|
| 15 |
+
os.environ.setdefault(key, "2")
|
| 16 |
+
from common import ROOT, S, F, atomic, bind, candidates, generated, now, read, relative, sha, verify_receipt
|
| 17 |
+
|
| 18 |
+
sys.path[:0] = [str(S / "tools"), str(S / "recoveries/giroux_width_comparison_20261015")]
|
| 19 |
+
import score_strict as ST
|
| 20 |
+
from validator_fix import install
|
| 21 |
+
import numpy as np
|
| 22 |
+
import pandas as pd
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def validate_core(source: Path, arm: str, support: dict, binding: dict) -> dict:
|
| 26 |
+
"""A saved score is reusable only for the identical source and evaluator contract."""
|
| 27 |
+
summary = read(source / "summary.json")
|
| 28 |
+
if summary["dataset"] != support["cohort"] or set(summary["donors"]) != set(support["test_sample_ids"]):
|
| 29 |
+
raise ValueError("Core score support mismatch")
|
| 30 |
+
record = summary.get("per_arm", {}).get(arm)
|
| 31 |
+
if not record or record["npz_sha256"] != binding["npz_sha256"] or Path(record["npz"]).resolve() != Path(binding["npz"]).resolve():
|
| 32 |
+
raise ValueError("Core score generated source mismatch")
|
| 33 |
+
reference_manifest = read(Path(summary["reference"]["cache"]) / "reference_manifest.json")
|
| 34 |
+
if reference_manifest["reference_sha256"] != summary["reference"]["reference_sha256"]:
|
| 35 |
+
raise ValueError("Core reference cache mismatch")
|
| 36 |
+
groups = {"giroux2022": (["severe"], ["mild"]),
|
| 37 |
+
"imperial_eskd": (["covid_positive"], ["covid_negative"]),
|
| 38 |
+
"ji2025_chili": (["TOL", "FU1"], ["BC", "AC"]),
|
| 39 |
+
"ye2026_sepsis": (["adult_sepsis", "ped_sepsis"], ["adult_HC", "adult_ICU_ctrl", "ped_HC", "ped_ICU_ctrl"])}
|
| 40 |
+
contrast = summary["contrast_definition"]
|
| 41 |
+
if support["cohort"] in groups:
|
| 42 |
+
case, control = groups[support["cohort"]]
|
| 43 |
+
if contrast.get("case_groups") != case or contrast.get("control_groups") != control:
|
| 44 |
+
raise ValueError("Core contrast definition mismatch")
|
| 45 |
+
condition = record.get("condition_for_broadcast") or {}
|
| 46 |
+
if condition.get("sha256") != binding.get("condition_sha256"):
|
| 47 |
+
raise ValueError("Core broadcast condition differs from strict generation")
|
| 48 |
+
elif support["cohort"] == "immicro" and contrast.get("enabled"):
|
| 49 |
+
raise ValueError("Healthy core unexpectedly has disease contrast")
|
| 50 |
+
for raw, expected in summary["code_sha256"].items():
|
| 51 |
+
if sha(Path(raw)) != expected:
|
| 52 |
+
raise ValueError(f"Core evaluator source changed: {raw}")
|
| 53 |
+
if support["cohort"] == "giroux2022":
|
| 54 |
+
exclusion = summary.get("gene_exclusion", {})
|
| 55 |
+
if not exclusion or sha(Path(exclusion["file"])) != exclusion["sha256"]:
|
| 56 |
+
raise ValueError("Giroux sex-gene exclusion missing or changed")
|
| 57 |
+
if not summary["contrast_definition"].get("enabled") and support["cohort"] != "immicro":
|
| 58 |
+
raise ValueError("Disease core lacks its contrast")
|
| 59 |
+
model_sha = ST._legacy_module("ft_common").ANNOT_MODEL_SHA
|
| 60 |
+
if record["annotation"]["model_pt_sha256"] != model_sha:
|
| 61 |
+
raise ValueError("Core annotator mismatch")
|
| 62 |
+
label_manifest = read(source / "arms" / arm / "labels/labels.manifest.json")
|
| 63 |
+
if label_manifest["model"]["model_pt_sha256"] != model_sha:
|
| 64 |
+
raise ValueError("Core label annotator mismatch")
|
| 65 |
+
# Row-alignment and gene-source binding are checked without reannotating cells.
|
| 66 |
+
cells = pd.read_parquet(source / "arms" / arm / "generated_cells.parquet", columns=["npz_row", "donor", "label"])
|
| 67 |
+
labels = pd.read_parquet(source / "arms" / arm / "labels/labels.parquet")
|
| 68 |
+
if not np.array_equal(labels.cell_index, np.arange(len(cells))) or not np.array_equal(labels.celltype_l1_pred.astype(str), cells.label.astype(str)):
|
| 69 |
+
raise ValueError("Core cell-label rows differ")
|
| 70 |
+
with np.load(binding["npz"], allow_pickle=False) as z:
|
| 71 |
+
sample_ids = z["sample_ids"].astype(str)
|
| 72 |
+
bulk_index = z["bulk_index"]
|
| 73 |
+
positions = {sample: i for i, sample in enumerate(sample_ids)}
|
| 74 |
+
selections = [np.flatnonzero(bulk_index == positions[x]) for x in summary["donors"]]
|
| 75 |
+
expected_rows = np.concatenate(selections)
|
| 76 |
+
expected_donors = np.repeat(summary["donors"], [len(x) for x in selections])
|
| 77 |
+
if not np.array_equal(cells.npz_row, expected_rows) or not np.array_equal(cells.donor.astype(str), expected_donors):
|
| 78 |
+
raise ValueError("Core rows do not match generated source")
|
| 79 |
+
return summary
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def adopt_core(source: Path, dest: Path, arm: str, support: dict, binding: dict) -> dict:
|
| 83 |
+
summary = validate_core(source, arm, support, binding)
|
| 84 |
+
if dest.exists():
|
| 85 |
+
raise ValueError(f"Unreceipted core destination exists: {dest}")
|
| 86 |
+
dest.mkdir(parents=True)
|
| 87 |
+
result = copy.deepcopy(summary)
|
| 88 |
+
result["arms"] = [arm]
|
| 89 |
+
result["per_arm"] = {arm: summary["per_arm"][arm]}
|
| 90 |
+
result["headline"] = {arm: summary["headline"][arm]}
|
| 91 |
+
result["core_reused_from"] = str(source)
|
| 92 |
+
atomic(dest / "summary.json", result)
|
| 93 |
+
for name in ("per_donor.csv", "contrast.csv"):
|
| 94 |
+
if (source / name).exists():
|
| 95 |
+
table = pd.read_csv(source / name)
|
| 96 |
+
table[table.arm == arm].to_csv(dest / name, index=False)
|
| 97 |
+
shutil.copytree(source / "arms" / arm, dest / "arms" / arm)
|
| 98 |
+
return {"source_summary": bind(source / "summary.json"), "source_arm": arm,
|
| 99 |
+
"validated_support_sha256": support["sha256"], "annotation_reexecuted": False}
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def scientific_files(folder: Path) -> list[Path]:
|
| 103 |
+
return sorted(p for p in folder.rglob("*") if p.is_file() and p.suffix in (".json", ".csv", ".parquet", ".txt")
|
| 104 |
+
and not any(x in p.parts for x in ("_fetch_tmp", "receipts")))
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def complete_stage(folder: Path, name: str, files: list[Path], **extra: object) -> None:
|
| 108 |
+
atomic(folder / "receipts" / f"{name}.json", {"state": "completed", "stage": name, "at": now(),
|
| 109 |
+
"outputs": [bind(x) for x in files], **extra})
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def stage_done(folder: Path, name: str) -> bool:
|
| 113 |
+
receipt = folder / "receipts" / f"{name}.json"
|
| 114 |
+
if not receipt.exists():
|
| 115 |
+
if (folder / "receipts" / f"{name}.running.json").exists():
|
| 116 |
+
raise ValueError(f"Previous {name} did not complete; inspect before restart")
|
| 117 |
+
return False
|
| 118 |
+
verify_receipt(receipt)
|
| 119 |
+
return True
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def individual_bootstrap(folder: Path, arm: str) -> None:
|
| 123 |
+
long = pd.read_csv(folder / "statistics/per_donor_long.csv")
|
| 124 |
+
results = []
|
| 125 |
+
for metric, rows in long.groupby("metric", sort=True):
|
| 126 |
+
donor_values = rows.groupby("donor_id").value.mean().dropna().sort_index().to_numpy()
|
| 127 |
+
donor_values = donor_values[np.isfinite(donor_values)]
|
| 128 |
+
if len(donor_values) < 2:
|
| 129 |
+
results.append({"arm": arm, "metric": metric, "status": "not_estimable", "n_donors": len(donor_values)})
|
| 130 |
+
continue
|
| 131 |
+
rng = np.random.default_rng(20261012)
|
| 132 |
+
draws = donor_values[rng.integers(len(donor_values), size=(2000, len(donor_values)))].mean(1)
|
| 133 |
+
lo, hi = np.quantile(draws, [.025, .975])
|
| 134 |
+
results.append({"arm": arm, "metric": metric, "status": "ok", "estimate": float(donor_values.mean()),
|
| 135 |
+
"ci_low": float(lo), "ci_high": float(hi), "n_donors": len(donor_values), "n_boot": 2000,
|
| 136 |
+
"bootstrap_unit": "unique_donor_all_visits"})
|
| 137 |
+
pd.DataFrame(results).to_csv(folder / "statistics/individual_donor_bootstrap_2000.csv", index=False)
|
| 138 |
+
# One arm cannot define an inter-method difference. Keep a parseable empty
|
| 139 |
+
# table and explicit status, separately from the valid individual-arm CIs.
|
| 140 |
+
paired = folder / "statistics/donor_bootstrap_2000.csv"
|
| 141 |
+
if paired.read_text().strip() == "":
|
| 142 |
+
pd.DataFrame(columns=["metric", "arm", "baseline", "status", "reason", "estimate", "ci_low", "ci_high",
|
| 143 |
+
"n_donors", "n_paired_samples", "n_excluded_nonfinite_pairs", "n_boot", "seed",
|
| 144 |
+
"bootstrap_unit"]).to_csv(paired, index=False)
|
| 145 |
+
status_path = folder / "statistics/status.json"
|
| 146 |
+
status = read(status_path)
|
| 147 |
+
status["inter_method_bootstrap"] = {"status": "not_applicable", "reason": "Only one arm in this isolated evaluation",
|
| 148 |
+
"combined_comparisons": str(ROOT / "AGGREGATES.json")}
|
| 149 |
+
atomic(status_path, status)
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
def main() -> None:
|
| 153 |
+
parser = argparse.ArgumentParser()
|
| 154 |
+
parser.add_argument("--support", type=Path, required=True)
|
| 155 |
+
parser.add_argument("--arm", choices=("lora", "scsemi", "pairedcal", "raw", "refcal"), required=True)
|
| 156 |
+
parser.add_argument("--threads", type=int, default=2)
|
| 157 |
+
parser.add_argument("--adopt-only", action="store_true", help="Validate and adopt an existing core, without any new metrics")
|
| 158 |
+
parser.add_argument("--core-only", action="store_true", help="Compute or adopt core; leave extras and statistics to full queue")
|
| 159 |
+
parser.add_argument("--try-lock", action="store_true", help="Exit 75 when this arm is owned by another evaluation")
|
| 160 |
+
args = parser.parse_args()
|
| 161 |
+
if args.threads not in range(1, 5):
|
| 162 |
+
raise ValueError("threads must be 1..4")
|
| 163 |
+
install(ST)
|
| 164 |
+
support = ST.read_support(args.support)
|
| 165 |
+
rel = relative(args.support)
|
| 166 |
+
folder = ROOT / "units" / rel / args.arm
|
| 167 |
+
folder.mkdir(parents=True, exist_ok=True)
|
| 168 |
+
lock = (folder / ".arm.lock").open("a")
|
| 169 |
+
try:
|
| 170 |
+
fcntl.flock(lock, fcntl.LOCK_EX | (fcntl.LOCK_NB if args.try_lock else 0))
|
| 171 |
+
except BlockingIOError:
|
| 172 |
+
raise SystemExit(75)
|
| 173 |
+
final = folder / "FULL_RECEIPT.json"
|
| 174 |
+
if final.exists():
|
| 175 |
+
verify_receipt(final)
|
| 176 |
+
return
|
| 177 |
+
binding = ST.validate_generation_arm(args.arm, generated(rel, args.arm), support)
|
| 178 |
+
arms = [f"{args.arm}={generated(rel, args.arm)}"]
|
| 179 |
+
if not stage_done(folder, "score"):
|
| 180 |
+
atomic(folder / "receipts/score.running.json", {"at": now(), "support_sha256": support["sha256"]})
|
| 181 |
+
source = next((p for p in candidates(rel) if (p / "summary.json").exists() and args.arm in read(p / "summary.json").get("arms", [])), None)
|
| 182 |
+
provenance = {}
|
| 183 |
+
if args.adopt_only and source is None:
|
| 184 |
+
raise ValueError("No reusable core for --adopt-only")
|
| 185 |
+
if source:
|
| 186 |
+
provenance = adopt_core(source, folder / "score", args.arm, support, binding)
|
| 187 |
+
atomic(folder / "scoring_support.json", {"schema": "pbisc.paper.strict-score-binding.v1",
|
| 188 |
+
"support_sha256": support["sha256"], "cohort": support["cohort"], "unit": support["unit"],
|
| 189 |
+
"test_sample_ids": support["test_sample_ids"], "test_donor_ids": support["test_donor_ids"],
|
| 190 |
+
"arm_bindings": {args.arm: binding}})
|
| 191 |
+
ST._existing_score(folder / "score", support, [args.arm])
|
| 192 |
+
else:
|
| 193 |
+
ST.main(["--support-manifest", str(args.support), "--out", str(folder), "--action", "score",
|
| 194 |
+
"--arm", arms[0], "--threads", str(args.threads)])
|
| 195 |
+
complete_stage(folder, "score", scientific_files(folder / "score") + [folder / "scoring_support.json"],
|
| 196 |
+
support_sha256=support["sha256"], binding=binding, reuse=provenance)
|
| 197 |
+
if args.adopt_only or args.core_only:
|
| 198 |
+
return
|
| 199 |
+
for action in ("extras", "contrast", "stats"):
|
| 200 |
+
if stage_done(folder, action):
|
| 201 |
+
continue
|
| 202 |
+
atomic(folder / "receipts" / f"{action}.running.json", {"at": now(), "support_sha256": support["sha256"]})
|
| 203 |
+
ST.main(["--support-manifest", str(args.support), "--out", str(folder), "--action", action,
|
| 204 |
+
"--arm", arms[0], "--threads", str(args.threads)])
|
| 205 |
+
if action == "stats":
|
| 206 |
+
individual_bootstrap(folder, args.arm)
|
| 207 |
+
complete_stage(folder, action, scientific_files(folder / ("statistics" if action == "stats" else action)))
|
| 208 |
+
atomic(final, {"schema": "pbisc.x1.full-evaluation.v1", "state": "completed", "at": now(),
|
| 209 |
+
"support_sha256": support["sha256"], "arm": args.arm, "generation_binding": binding,
|
| 210 |
+
"source_files": [bind(p) for p in [Path(__file__), ROOT / "common.py", S / "tools/score_strict.py",
|
| 211 |
+
S / "tools/donor_statistics.py", S / "tools/donor_limma.R",
|
| 212 |
+
F / "tools/score_ft.py", F / "tools/extra_metrics.py", F / "tools/contrast_extra.py"]],
|
| 213 |
+
"outputs": [bind(p) for p in scientific_files(folder)],
|
| 214 |
+
"note": "Per-arm complete metrics; paired inter-method bootstrap is in aggregate output, when both arms are ready.",
|
| 215 |
+
"gpu_operations": 0})
|
| 216 |
+
|
| 217 |
+
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
+
main()
|
paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/finish_chili1_export.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Remote CPU-only export of already completed CHILI draw1 scSemi inference."""
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
import json
|
| 4 |
+
import sys
|
| 5 |
+
S = Path(__file__).resolve().parents[3]
|
| 6 |
+
sys.path.insert(0, str(S / "tools"))
|
| 7 |
+
import campaign
|
| 8 |
+
from runtime import Runtime
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class CpuOnly(Runtime):
|
| 12 |
+
def execute(self, *args, **kwargs):
|
| 13 |
+
if kwargs.get("resource", "cpu") != "cpu":
|
| 14 |
+
raise RuntimeError("No new GPU operation is authorized for this export")
|
| 15 |
+
return super().execute(*args, **kwargs)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
if __name__ == "__main__":
|
| 19 |
+
support = S / "protocol/splits/ji2025_chili/disease/draw1/support.json"
|
| 20 |
+
status = json.loads((S / "scsemi/ji2025_chili/disease/draw1/status.json").read_text())
|
| 21 |
+
assert status["pretrain_complete"] and status["infer_complete"], "Inference is not complete; no GPU fallback"
|
| 22 |
+
campaign.run_scsemi(CpuOnly(S), support)
|
paper-releases/pbisc-diffusion/updates/20261015T121654Z-x1-nine-core40-deck/diffusion/dataset/server_1/model8/plans/paper_figures_strictpairs_20261012/recoveries/x1_priority_completion_20261015/evaluation/test_evaluation.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Metadata and reuse regression checks: no GPU, new scoring, or generated expression reads."""
|
| 2 |
+
import copy
|
| 3 |
+
import tempfile
|
| 4 |
+
import unittest
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from common import ROOT, S, atomic, bind, read, relative, supports, verify_receipt
|
| 7 |
+
from evaluate_arm import validate_core, individual_bootstrap
|
| 8 |
+
import importlib.util
|
| 9 |
+
_spec = importlib.util.spec_from_file_location("priority_evaluation_aggregate", ROOT / "aggregate.py")
|
| 10 |
+
_aggregate = importlib.util.module_from_spec(_spec)
|
| 11 |
+
_spec.loader.exec_module(_aggregate)
|
| 12 |
+
matched_draw_metadata = _aggregate.matched_draw_metadata
|
| 13 |
+
import pandas as pd
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class ReuseTests(unittest.TestCase):
|
| 17 |
+
def test_single_arm_bootstrap_parseable_and_not_applicable(self):
|
| 18 |
+
with tempfile.TemporaryDirectory() as directory:
|
| 19 |
+
folder = Path(directory)
|
| 20 |
+
stats = folder / "statistics"
|
| 21 |
+
stats.mkdir()
|
| 22 |
+
pd.DataFrame({"donor_id": ["a", "b"], "metric": ["error", "error"], "value": [0.1, 0.2]}).to_csv(stats / "per_donor_long.csv", index=False)
|
| 23 |
+
(stats / "donor_bootstrap_2000.csv").write_text("\n")
|
| 24 |
+
atomic(stats / "status.json", {"disease_deg": {"status": "not_applicable"}})
|
| 25 |
+
individual_bootstrap(folder, "lora")
|
| 26 |
+
paired = pd.read_csv(stats / "donor_bootstrap_2000.csv")
|
| 27 |
+
self.assertTrue(paired.empty)
|
| 28 |
+
self.assertIn("ci_low", paired.columns)
|
| 29 |
+
self.assertEqual(read(stats / "status.json")["inter_method_bootstrap"]["status"], "not_applicable")
|
| 30 |
+
self.assertEqual(len(pd.read_csv(stats / "individual_donor_bootstrap_2000.csv")), 1)
|
| 31 |
+
|
| 32 |
+
def test_matched_draws_exclude_unmatched_and_nonfinite(self):
|
| 33 |
+
rows = pd.DataFrame([
|
| 34 |
+
{"draw": draw, "donor_id": "d", "sample_id": "s", "arm": arm, "metric": "m", "value": value}
|
| 35 |
+
for draw, arm, value in [("draw0", "lora", 0.1), ("draw0", "scsemi", 0.2),
|
| 36 |
+
("draw1", "lora", 0.3), ("draw2", "scsemi", 0.4),
|
| 37 |
+
("draw3", "lora", float("nan")), ("draw3", "scsemi", 0.5)]])
|
| 38 |
+
result = matched_draw_metadata(rows, "scsemi", "m")
|
| 39 |
+
self.assertEqual(result["n_draws_matched"], 1)
|
| 40 |
+
self.assertEqual(result["matched_draw_ids"], '["draw0"]')
|
| 41 |
+
self.assertEqual(result["n_draws_union_available"], 4)
|
| 42 |
+
|
| 43 |
+
def test_exact_requested_supports(self):
|
| 44 |
+
paths = supports()
|
| 45 |
+
self.assertEqual(len(paths), 40)
|
| 46 |
+
self.assertEqual(len({str(relative(p)) for p in paths}), 40)
|
| 47 |
+
first, second = paths[0::2], paths[1::2]
|
| 48 |
+
self.assertEqual(len(first), 20)
|
| 49 |
+
self.assertEqual(len(second), 20)
|
| 50 |
+
self.assertFalse(set(first) & set(second))
|
| 51 |
+
self.assertEqual(set(first) | set(second), set(paths))
|
| 52 |
+
|
| 53 |
+
def test_receipt_changes_rejected(self):
|
| 54 |
+
with tempfile.TemporaryDirectory() as directory:
|
| 55 |
+
root = Path(directory)
|
| 56 |
+
file = root / "table.csv"
|
| 57 |
+
file.write_text("a,b\n1,2\n")
|
| 58 |
+
rec = root / "receipt.json"
|
| 59 |
+
atomic(rec, {"state": "completed", "outputs": [bind(file)]})
|
| 60 |
+
verify_receipt(rec)
|
| 61 |
+
file.write_text("a,b\n2,2\n")
|
| 62 |
+
with self.assertRaises(ValueError):
|
| 63 |
+
verify_receipt(rec)
|
| 64 |
+
|
| 65 |
+
def test_real_core_contract_and_negatives(self):
|
| 66 |
+
source = S / "recoveries/giroux_width_comparison_20261015/draw0/score"
|
| 67 |
+
summary = read(source / "summary.json")
|
| 68 |
+
support = read(S / "protocol/splits/giroux2022/disease/draw0/support.json")
|
| 69 |
+
record = summary["per_arm"]["lora"]
|
| 70 |
+
binding = {"npz": record["npz"], "npz_sha256": record["npz_sha256"],
|
| 71 |
+
"condition_sha256": record["condition_for_broadcast"]["sha256"]}
|
| 72 |
+
self.assertEqual(validate_core(source, "lora", support, binding)["dataset"], "giroux2022")
|
| 73 |
+
bad = copy.deepcopy(support)
|
| 74 |
+
bad["test_sample_ids"] = bad["test_sample_ids"][:-1]
|
| 75 |
+
with self.assertRaises(ValueError):
|
| 76 |
+
validate_core(source, "lora", bad, binding)
|
| 77 |
+
with self.assertRaises(ValueError):
|
| 78 |
+
validate_core(source, "lora", support, {**binding, "npz_sha256": "0" * 64})
|
| 79 |
+
with self.assertRaises(ValueError):
|
| 80 |
+
validate_core(source, "lora", support, {**binding, "condition_sha256": "0" * 64})
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
unittest.main()
|