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/common.py +85 -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/cpu_queue.py +167 -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/fetch_remote.py +73 -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/readiness.py +52 -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/common.py
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Paths and immutable receipts for the x1 completion evaluation (CPU only)."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import hashlib
|
| 5 |
+
import json
|
| 6 |
+
import os
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from datetime import datetime, timezone
|
| 9 |
+
|
| 10 |
+
ROOT = Path(__file__).resolve().parent
|
| 11 |
+
S = ROOT.parents[2]
|
| 12 |
+
F = S.parent / "paired_finetune_intradataset_20260927"
|
| 13 |
+
ARMS = ("lora", "scsemi", "pairedcal", "raw", "refcal")
|
| 14 |
+
COHORTS = ("imperial_eskd", "giroux2022", "ji2025_chili", "immicro", "ye2026_sepsis")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def now() -> str:
|
| 18 |
+
return datetime.now(timezone.utc).isoformat()
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def read(path: Path) -> dict:
|
| 22 |
+
return json.loads(path.read_text())
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def sha(path: Path) -> str:
|
| 26 |
+
with path.open("rb") as stream:
|
| 27 |
+
return hashlib.file_digest(stream, "sha256").hexdigest()
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def atomic(path: Path, data: dict) -> None:
|
| 31 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 32 |
+
temp = path.with_suffix(path.suffix + f".tmp-{os.getpid()}")
|
| 33 |
+
temp.write_text(json.dumps(data, indent=2, allow_nan=False) + "\n")
|
| 34 |
+
temp.replace(path)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def bind(path: Path) -> dict:
|
| 38 |
+
return {"path": str(path), "sha256": sha(path), "bytes": path.stat().st_size}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def verify_receipt(path: Path) -> dict:
|
| 42 |
+
rec = read(path)
|
| 43 |
+
if rec.get("state") != "completed":
|
| 44 |
+
raise ValueError(f"Incomplete receipt: {path}")
|
| 45 |
+
for entry in rec["outputs"]:
|
| 46 |
+
source = Path(entry["path"])
|
| 47 |
+
if not source.is_file() or source.stat().st_size != entry["bytes"] or sha(source) != entry["sha256"]:
|
| 48 |
+
raise ValueError(f"Changed receipt output: {source}")
|
| 49 |
+
return rec
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def supports() -> list[Path]:
|
| 53 |
+
return [p for c in COHORTS for p in sorted((S / "protocol/splits" / c).rglob("support.json"))]
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def relative(support: Path) -> Path:
|
| 57 |
+
return support.parent.relative_to(S / "protocol/splits")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def generated(rel: Path, arm: str) -> Path:
|
| 61 |
+
return S / "generated" / (Path("global") / rel.parts[0] if arm in ("raw", "refcal") else rel) / f"{arm}.npz"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def candidates(rel: Path) -> list[Path]:
|
| 65 |
+
cohort, _, unit = rel.parts[:3]
|
| 66 |
+
result = [S / "scores" / rel / "score"]
|
| 67 |
+
if cohort == "giroux2022":
|
| 68 |
+
result.append(S / "recoveries/giroux_width_comparison_20261015" / unit / "score")
|
| 69 |
+
if cohort in ("imperial_eskd", "ji2025_chili"):
|
| 70 |
+
result.append(S / "recoveries/disease_width_comparison_20261015" / cohort / unit / "score")
|
| 71 |
+
if cohort == "immicro":
|
| 72 |
+
result.append(S / "recoveries/all_width_results_20261015" / rel / "score")
|
| 73 |
+
return result
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def output_record(base: Path, receipt: Path, state: str) -> dict:
|
| 77 |
+
cohort = read(base / "score/summary.json")["dataset"]
|
| 78 |
+
return {"state": state, "score_summary": str(base / "score/summary.json"),
|
| 79 |
+
"extras_manifest": str(base / "extras" / cohort / "strict/manifest.json"),
|
| 80 |
+
"contrast_manifest": str(base / "contrast" / cohort / "strict/manifest.json"),
|
| 81 |
+
"statistics_status": str(base / "statistics/status.json"),
|
| 82 |
+
"bootstrap_csv": str(base / "statistics/donor_bootstrap_2000.csv"),
|
| 83 |
+
"donor_deg_summary": str(base / "statistics/donor_deg/donor_deg_summary.csv"),
|
| 84 |
+
"individual_bootstrap_csv": str(base / "statistics/individual_donor_bootstrap_2000.csv"),
|
| 85 |
+
"receipt": str(receipt)}
|
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/cpu_queue.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Independent, bounded CPU queue; all available x1 LoRA results before comparator arms."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import argparse
|
| 5 |
+
import fcntl
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
import sys
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
from common import ARMS, ROOT, S, atomic, bind, candidates, generated, now, output_record, read, relative, supports, verify_receipt
|
| 11 |
+
from readiness import generation_readiness
|
| 12 |
+
|
| 13 |
+
sys.path.insert(0, str(S / "tools"))
|
| 14 |
+
from runtime import Runtime
|
| 15 |
+
|
| 16 |
+
PYTHON = "/home/sj_server_1/miniforge3/envs/cxg_corpus/bin/python"
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def inspect_unit(support: Path, arms: list[str]) -> dict:
|
| 20 |
+
rel = relative(support)
|
| 21 |
+
name = "-".join(rel.parts)
|
| 22 |
+
sup = read(support)
|
| 23 |
+
result = {"unit": name, "cohort": sup["cohort"], "relative": str(rel), "support_sha256": sup["sha256"],
|
| 24 |
+
"n_pairs": sup["n_pairs"], "support_path": str(support), "arms": {},
|
| 25 |
+
"scsemi_available": generation_readiness(S, rel, "scsemi", ROOT / "remote_operation_receipts")["ready"]}
|
| 26 |
+
canonical = S / "receipts" / f"{name}-score.json"
|
| 27 |
+
if canonical.exists() and read(canonical).get("state") == "completed":
|
| 28 |
+
adoption = ROOT / "adopted" / f"{name}.json"
|
| 29 |
+
if not adoption.exists():
|
| 30 |
+
verify_receipt(canonical)
|
| 31 |
+
base = S / "scores" / rel
|
| 32 |
+
if read(base / "scoring_support.json")["support_sha256"] != sup["sha256"]:
|
| 33 |
+
raise ValueError("Canonical full score support mismatch")
|
| 34 |
+
tracked = sorted(p for p in base.rglob("*") if p.is_file() and p.suffix in (".json", ".csv", ".parquet")
|
| 35 |
+
and "_fetch_tmp" not in p.parts)
|
| 36 |
+
atomic(adoption, {"state": "completed", "at": now(), "kind": "canonical_full_adoption",
|
| 37 |
+
"canonical_receipt": bind(canonical), "support_sha256": sup["sha256"],
|
| 38 |
+
"outputs": [bind(p) for p in tracked]})
|
| 39 |
+
summary = read(S / "scores" / rel / "score/summary.json")
|
| 40 |
+
result["scsemi_available"] = "scsemi" in summary["arms"]
|
| 41 |
+
for arm in arms:
|
| 42 |
+
if arm in summary["arms"]:
|
| 43 |
+
result["arms"][arm] = output_record(S / "scores" / rel, adoption, "canonical_full_reused")
|
| 44 |
+
for arm in arms:
|
| 45 |
+
if arm in result["arms"]:
|
| 46 |
+
continue
|
| 47 |
+
base = ROOT / "units" / rel / arm
|
| 48 |
+
receipt = base / "FULL_RECEIPT.json"
|
| 49 |
+
if receipt.exists():
|
| 50 |
+
result["arms"][arm] = output_record(base, receipt, "full_completed")
|
| 51 |
+
elif (base / "receipts/score.json").exists():
|
| 52 |
+
result["arms"][arm] = output_record(base, base / "receipts/score.json", "core_only")
|
| 53 |
+
else:
|
| 54 |
+
ready = generation_readiness(S, rel, arm, ROOT / "remote_operation_receipts")
|
| 55 |
+
if not ready["ready"]:
|
| 56 |
+
result["arms"][arm] = ready
|
| 57 |
+
continue
|
| 58 |
+
cache = next((p for p in candidates(rel) if (p / "summary.json").exists()
|
| 59 |
+
and arm in read(p / "summary.json").get("arms", [])), None)
|
| 60 |
+
result["arms"][arm] = {"state": "pending", "core_cache_candidate": str(cache) if cache else None,
|
| 61 |
+
"generation_readiness": ready}
|
| 62 |
+
return result
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def snapshot(arms: list[str], phase: str = "ready", active: dict | None = None) -> dict:
|
| 66 |
+
units = [inspect_unit(p, arms) for p in supports()]
|
| 67 |
+
full = {"full_completed", "canonical_full_reused"}
|
| 68 |
+
out = {"schema": "pbisc.x1.priority-evaluation.v1", "phase": phase, "at": now(), "active": active,
|
| 69 |
+
"units": units, "n_units": len(units), "x1_full_units": sum(u["arms"]["lora"]["state"] in full for u in units),
|
| 70 |
+
"all_selected_arms_completed": all(a["state"] in full for u in units for a in u["arms"].values()),
|
| 71 |
+
"gpu_operations": 0, "missing_scsemi": [u["unit"] for u in units if not u["scsemi_available"]]}
|
| 72 |
+
out["workers"] = {p.stem: read(p) for p in sorted(ROOT.glob("WORKER_*.json"))}
|
| 73 |
+
atomic(ROOT / "STATUS.json", out)
|
| 74 |
+
return out
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def main() -> None:
|
| 78 |
+
parser = argparse.ArgumentParser()
|
| 79 |
+
parser.add_argument("--run", action="store_true")
|
| 80 |
+
parser.add_argument("--once", action="store_true")
|
| 81 |
+
parser.add_argument("--arms", default=",".join(ARMS))
|
| 82 |
+
parser.add_argument("--prepare-caches", action="store_true", help="Validate and expose all saved cores before expensive missing metrics")
|
| 83 |
+
parser.add_argument("--worker-index", type=int, default=0)
|
| 84 |
+
parser.add_argument("--workers", type=int, default=1)
|
| 85 |
+
parser.add_argument("--memory-gib", type=int, default=28, help="Hard memory cap for one full evaluation, no automatic resize")
|
| 86 |
+
args = parser.parse_args()
|
| 87 |
+
arms = args.arms.split(",")
|
| 88 |
+
if len(set(arms)) != len(arms) or "lora" not in arms or not set(arms) <= set(ARMS):
|
| 89 |
+
raise ValueError("Unique known arms including lora required")
|
| 90 |
+
if args.workers not in (1, 2) or not 0 <= args.worker_index < args.workers:
|
| 91 |
+
raise ValueError("One or two disjoint CPU workers supported")
|
| 92 |
+
if not 8 <= args.memory_gib <= 28:
|
| 93 |
+
raise ValueError("Full evaluation memory cap must be 8..28 GiB")
|
| 94 |
+
arms = ["lora"] + [x for x in arms if x != "lora"]
|
| 95 |
+
config = ROOT / "WORKER_CONFIG.json"
|
| 96 |
+
if config.exists() and read(config)["workers"] != args.workers:
|
| 97 |
+
raise ValueError("Worker partition changed; preserve and explicitly reconcile before launching")
|
| 98 |
+
atomic(config, {"workers": args.workers, "ownership": "stable supports() index modulo workers", "arms": arms})
|
| 99 |
+
lock = (ROOT / f".queue-worker{args.worker_index}.lock").open("a")
|
| 100 |
+
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
| 101 |
+
worker_status = ROOT / f"WORKER_{args.worker_index}.json"
|
| 102 |
+
def mark(phase: str, active: dict | None = None) -> None:
|
| 103 |
+
atomic(worker_status, {"phase": phase, "active": active, "at": now(), "pid": __import__("os").getpid(),
|
| 104 |
+
"worker_index": args.worker_index, "workers": args.workers, "memory_gib": args.memory_gib})
|
| 105 |
+
def owned(units: list[dict]) -> list[dict]:
|
| 106 |
+
return [u for i, u in enumerate(units) if i % args.workers == args.worker_index]
|
| 107 |
+
mark("ready")
|
| 108 |
+
state = snapshot(arms)
|
| 109 |
+
if not args.run:
|
| 110 |
+
print({k: state[k] for k in ("phase", "n_units", "x1_full_units", "missing_scsemi")})
|
| 111 |
+
return
|
| 112 |
+
runtime = Runtime(ROOT)
|
| 113 |
+
if args.prepare_caches:
|
| 114 |
+
for unit in owned(state["units"]):
|
| 115 |
+
for arm in arms:
|
| 116 |
+
info = unit["arms"][arm]
|
| 117 |
+
if info["state"] != "pending" or not info.get("core_cache_candidate"):
|
| 118 |
+
continue
|
| 119 |
+
support = Path(unit["support_path"])
|
| 120 |
+
rel = relative(support)
|
| 121 |
+
mark("adopting_core", {"unit": unit["unit"], "arm": arm})
|
| 122 |
+
snapshot(arms, "adopting_core", {"unit": unit["unit"], "arm": arm})
|
| 123 |
+
runtime.execute("adopt-" + unit["unit"] + "-" + arm,
|
| 124 |
+
[PYTHON, "-u", str(ROOT / "evaluate_arm.py"), "--support", str(support), "--arm", arm, "--adopt-only"],
|
| 125 |
+
resource="cpu", memory_gib=4, threads=2,
|
| 126 |
+
inputs=[support, ROOT / "evaluate_arm.py", ROOT / "common.py", generated(rel, arm).with_suffix(".log")],
|
| 127 |
+
# The core-readiness process may have completed this same core meanwhile.
|
| 128 |
+
# Its authoritative receipt is verified inside evaluate_arm's per-arm lock.
|
| 129 |
+
outputs=[])
|
| 130 |
+
state = snapshot(arms)
|
| 131 |
+
while True:
|
| 132 |
+
active_arms = arms if state["x1_full_units"] == state["n_units"] else ["lora"]
|
| 133 |
+
jobs = [(u, arm) for arm in active_arms for u in owned(state["units"])
|
| 134 |
+
if u["arms"][arm]["state"] in ("pending", "core_only")]
|
| 135 |
+
if jobs:
|
| 136 |
+
unit, arm = jobs[0]
|
| 137 |
+
support = Path(unit["support_path"])
|
| 138 |
+
rel = relative(support)
|
| 139 |
+
active = {"unit": unit["unit"], "arm": arm}
|
| 140 |
+
mark("running", active)
|
| 141 |
+
snapshot(arms, "running", active)
|
| 142 |
+
command = [PYTHON, "-u", str(ROOT / "evaluate_arm.py"), "--support", str(support), "--arm", arm, "--threads", "2"]
|
| 143 |
+
runtime.execute("full-" + unit["unit"] + "-" + arm, command, resource="cpu", memory_gib=args.memory_gib, threads=2,
|
| 144 |
+
inputs=[support, ROOT / "evaluate_arm.py", ROOT / "common.py", generated(rel, arm).with_suffix(".log")],
|
| 145 |
+
outputs=[ROOT / "units" / rel / arm / "FULL_RECEIPT.json"], wait_seconds=7 * 86400)
|
| 146 |
+
state = snapshot(arms)
|
| 147 |
+
continue
|
| 148 |
+
if state["x1_full_units"] == state["n_units"]:
|
| 149 |
+
mark("assigned_ready_arms_completed")
|
| 150 |
+
snapshot(arms, "x1_complete_with_explicit_comparator_gaps" if not state["all_selected_arms_completed"] else "completed")
|
| 151 |
+
return
|
| 152 |
+
if args.once:
|
| 153 |
+
mark("ready_outputs_done_waiting_generation")
|
| 154 |
+
snapshot(arms, "ready_outputs_done_waiting_generation")
|
| 155 |
+
return
|
| 156 |
+
mark("waiting_generation_or_other_worker")
|
| 157 |
+
state = snapshot(arms, "waiting_generation_or_other_worker")
|
| 158 |
+
time.sleep(60)
|
| 159 |
+
state = snapshot(arms)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
if __name__ == "__main__":
|
| 163 |
+
try:
|
| 164 |
+
main()
|
| 165 |
+
except BaseException as error:
|
| 166 |
+
atomic(ROOT / "ERROR.json", {"state": "stopped_needs_inspection", "at": now(), "error": str(error)})
|
| 167 |
+
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/fetch_remote.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Fetch only completed generation payloads and metadata, never scSemi model/work trees."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import argparse
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
import shlex
|
| 6 |
+
import subprocess
|
| 7 |
+
import sys
|
| 8 |
+
from common import ROOT, S, atomic, bind, now, read, sha
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def requested_paths() -> list[str]:
|
| 12 |
+
paths = []
|
| 13 |
+
for cohort, draws in (("giroux2022", range(5)), ("ji2025_chili", range(2))):
|
| 14 |
+
for draw in draws:
|
| 15 |
+
rel = Path(cohort) / "disease" / f"draw{draw}"
|
| 16 |
+
for arm in ("pairedcal", "scsemi"):
|
| 17 |
+
for suffix in (".npz", ".log", ".validation.json") if arm == "scsemi" else (".npz", ".log"):
|
| 18 |
+
paths.append(str(Path("generated") / rel / f"{arm}{suffix}"))
|
| 19 |
+
paths.append(str(Path("scsemi") / rel / "inputs/inputs_manifest.json"))
|
| 20 |
+
for name in ("CONDITIONS.json", "test_raw.npz", "test_cal.npz"):
|
| 21 |
+
paths.append(str(Path("data") / rel / name))
|
| 22 |
+
return paths
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def main() -> None:
|
| 26 |
+
parser = argparse.ArgumentParser()
|
| 27 |
+
parser.add_argument("--execute", action="store_true")
|
| 28 |
+
args = parser.parse_args()
|
| 29 |
+
script = """import pathlib,json,hashlib,sys
|
| 30 |
+
root=pathlib.Path(sys.argv[1]); result=[]
|
| 31 |
+
for name in json.loads(sys.argv[2]):
|
| 32 |
+
p=root/name
|
| 33 |
+
if p.is_file():
|
| 34 |
+
with p.open('rb') as f: digest=hashlib.file_digest(f,'sha256').hexdigest()
|
| 35 |
+
result.append({'relative':name,'bytes':p.stat().st_size,'sha256':digest})
|
| 36 |
+
print(json.dumps(result))
|
| 37 |
+
"""
|
| 38 |
+
command = ["python3", "-c", script, str(S), __import__("json").dumps(requested_paths())]
|
| 39 |
+
result = subprocess.run(["ssh", "-o", "BatchMode=yes", "spark-0110", shlex.join(command)], capture_output=True, text=True, check=True)
|
| 40 |
+
files = __import__("json").loads(result.stdout)
|
| 41 |
+
manifest = {"state": "planned", "at": now(), "host": "server_2", "files": files,
|
| 42 |
+
"missing_remote": sorted(set(requested_paths()) - {x["relative"] for x in files}),
|
| 43 |
+
"scope": "completed NPZ/log/export validation/condition metadata only; no model or training directories"}
|
| 44 |
+
atomic(ROOT / "REMOTE_FETCH_PLAN.json", manifest)
|
| 45 |
+
if not args.execute:
|
| 46 |
+
print("Planned", len(files), "files; missing", manifest["missing_remote"])
|
| 47 |
+
return
|
| 48 |
+
verified = []
|
| 49 |
+
for entry in files:
|
| 50 |
+
target = S / entry["relative"]
|
| 51 |
+
if target.exists():
|
| 52 |
+
if target.stat().st_size != entry["bytes"] or sha(target) != entry["sha256"]:
|
| 53 |
+
raise ValueError(f"Existing file differs; preserve and inspect: {target}")
|
| 54 |
+
disposition = "existing_identical_preserved"
|
| 55 |
+
else:
|
| 56 |
+
target.parent.mkdir(parents=True, exist_ok=True)
|
| 57 |
+
temporary = target.with_name(target.name + ".x1-fetch-partial")
|
| 58 |
+
if temporary.exists():
|
| 59 |
+
raise ValueError(f"Partial transfer needs inspection: {temporary}")
|
| 60 |
+
subprocess.run(["rsync", "-a", "--protect-args", "spark-0110:" + str(target), str(temporary)], check=True)
|
| 61 |
+
if temporary.stat().st_size != entry["bytes"] or sha(temporary) != entry["sha256"]:
|
| 62 |
+
raise ValueError(f"Transfer mismatch: {temporary}")
|
| 63 |
+
if target.exists():
|
| 64 |
+
raise ValueError(f"Concurrent writer produced target: {target}")
|
| 65 |
+
temporary.rename(target)
|
| 66 |
+
disposition = "copied_missing_only"
|
| 67 |
+
verified.append({**bind(target), "disposition": disposition})
|
| 68 |
+
atomic(ROOT / "REMOTE_FETCH_VERIFIED.json", {"state": "completed", "at": now(), "source": bind(ROOT / "REMOTE_FETCH_PLAN.json"),
|
| 69 |
+
"outputs": verified, "no_training_or_inference": True})
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
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/readiness.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Discovery-only generation completion gate; file presence never means completion."""
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
import hashlib
|
| 4 |
+
import json
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def generation_readiness(plan: Path, rel: Path, arm: str, receipt_store: Path | None = None) -> dict:
|
| 9 |
+
cohort = rel.parts[0]
|
| 10 |
+
tag = f"global-{cohort}-{arm}" if arm in ("raw", "refcal") else "-".join(rel.parts) + "-" + ("scexport" if arm == "scsemi" else arm)
|
| 11 |
+
canonical = plan / "receipts" / f"{tag}.json"
|
| 12 |
+
receipt = canonical if canonical.exists() else (receipt_store / canonical.name if receipt_store else canonical)
|
| 13 |
+
def waiting(reason: str, state: str = "waiting_generation") -> dict:
|
| 14 |
+
return {"ready": False, "state": state, "reason": reason, "operation_receipt": str(receipt)}
|
| 15 |
+
if not receipt.is_file():
|
| 16 |
+
return waiting("Completed generation operation receipt not available")
|
| 17 |
+
try:
|
| 18 |
+
operation = json.loads(receipt.read_text())
|
| 19 |
+
except (ValueError, OSError):
|
| 20 |
+
return waiting("Generation operation receipt is not readable JSON")
|
| 21 |
+
if operation.get("state") != "completed":
|
| 22 |
+
return waiting("Generation operation state=" + str(operation.get("state")),
|
| 23 |
+
"generation_failed_needs_inspection" if operation.get("state") == "failed" else "waiting_generation")
|
| 24 |
+
folder = plan / "generated" / (Path("global") / cohort if arm in ("raw", "refcal") else rel)
|
| 25 |
+
npz, log = folder / f"{arm}.npz", folder / f"{arm}.log"
|
| 26 |
+
bindings = {entry.get("path"): entry for entry in operation.get("outputs", [])}
|
| 27 |
+
for file in (npz, log):
|
| 28 |
+
record = bindings.get(str(file))
|
| 29 |
+
if not record or not file.is_file() or file.stat().st_size <= 0 or file.stat().st_size != record.get("bytes"):
|
| 30 |
+
return waiting("Completed operation output is absent, empty, or not size-bound: " + file.name)
|
| 31 |
+
try:
|
| 32 |
+
log_bytes = log.read_bytes()
|
| 33 |
+
sampler = json.loads(log_bytes)
|
| 34 |
+
except (ValueError, OSError):
|
| 35 |
+
return waiting("Sampler receipt still empty, incomplete, or unreadable")
|
| 36 |
+
if not isinstance(sampler, dict):
|
| 37 |
+
return waiting("Sampler receipt must be a JSON object")
|
| 38 |
+
if hashlib.sha256(log_bytes).hexdigest() != bindings[str(log)].get("sha256"):
|
| 39 |
+
return waiting("Sampler receipt does not match completed operation hash", "generation_failed_needs_inspection")
|
| 40 |
+
if sampler.get("output") != str(npz) or sampler.get("output_sha256") != bindings[str(npz)].get("sha256"):
|
| 41 |
+
return waiting("Sampler receipt does not bind the completed generated output", "generation_failed_needs_inspection")
|
| 42 |
+
if arm == "scsemi":
|
| 43 |
+
validation = npz.with_suffix(".validation.json")
|
| 44 |
+
try:
|
| 45 |
+
proof = json.loads(validation.read_text())
|
| 46 |
+
except (ValueError, OSError):
|
| 47 |
+
return waiting("scSemi export validation pending")
|
| 48 |
+
if proof.get("passed") is not True or proof.get("npz_sha256") != sampler["output_sha256"]:
|
| 49 |
+
return waiting("scSemi export validation mismatch", "generation_failed_needs_inspection")
|
| 50 |
+
return {"ready": True, "state": "generation_completed", "operation_receipt": str(receipt),
|
| 51 |
+
"sampler_receipt": str(log), "npz_sha256": sampler["output_sha256"],
|
| 52 |
+
"note": "Full NPZ/support/checkpoint validation remains mandatory in evaluate_arm before scoring"}
|