"""E2: apply the frozen failure policy's verdict to the two phase 3 phlash fits that failed on gpu502-11. The verdict (results/E2_fit_failures.json; bench_h2h.fit_retry.classify/decide on the original attempts) is 'deterministic' -> MISSING, no retry. This script lays the fits out as the policy prescribes: * the original attempt -> /attempts/attempt00_job_/ with ATTEMPT.json (read-only); * /MISSING.json via bench_h2h.fit_retry.write_missing (the fit is never scored in the primary result); * the re-run made before the classification (55051135_) -> fits/sensitivity_rerun/p3///, scored only in the labelled sensitivity line. PYTHONPATH=/tool /usr/bin/python3 -B e2_apply_missing.py """ import dataclasses, json, os from pathlib import Path from bench_h2h import fit_retry as FR PH = Path("$WORK/bench_h2h_20260915/real/e2_phlash_20261102") X = Path("$WORK/paper_exp_20261102") RERUN = {"54999600_73": "55051135_73", "54999600_97": "55051135_97"} def main(): cls = json.load(open(X / "E2/results/E2_fit_failures.json")) done = [] for c in cls["cases"]: if c["decision"] != "missing": raise SystemExit(f"{c['fit']}: decision {c['decision']}, not missing; nothing to apply") _, pop, wid = c["fit"].split("/") fit_dir = PH / "fits" / "p3" / pop / wid rerun_out = PH / "fits" / "sensitivity_rerun" / "p3" / pop / wid attempt_src = next((PH / "fits" / "attempts").glob(f"p3_{pop}_{wid}.failed-*")) if (fit_dir / "MISSING.json").exists(): done.append(c["fit"]); continue # 1. the re-run (if finished) leaves the primary fit path for the sensitivity tree if fit_dir.exists(): if not (fit_dir / "curve64.npz").exists(): raise SystemExit(f"{fit_dir} exists without a curve: the re-run has not finished") rerun_out.parent.mkdir(parents=True, exist_ok=True) os.replace(fit_dir, rerun_out) # 2. the original attempt goes into /attempts/, as fit_retry.archive_attempt lays it out v = FR.Verdict(**c["verdict"]) target = fit_dir / "attempts" / f"attempt00_job{c['original_job']}_{FR.utc_stamp()}" target.parent.mkdir(parents=True) os.replace(attempt_src, target) (target / "ATTEMPT.json").write_text(json.dumps({ "schema": FR.ATTEMPT_SCHEMA, "utc": FR.utc_stamp(), "job_id": c["original_job"], "verdict": dataclasses.asdict(v), "decision": "missing", "moved": sorted(p.name for p in target.iterdir())}, indent=1, sort_keys=True) + "\n") FR._make_read_only(target) # 3. the terminal record subs = [{"job_id": c["original_job"], "utc": None, "retry": None, "resources": {"gres": "gpu:1", "cpus": 4, "mem": "16G", "time": "02:00:00"}}] FR.write_missing(fit_dir, v, c["why"], subs) rec = json.load(open(fit_dir / "MISSING.json")) rec_note = {"rerun_for_sensitivity_only": {"job": RERUN.get(c["original_job"]), "path": str(rerun_out), "present": (rerun_out / "curve64.npz").exists()}} (fit_dir.parent / f"{wid}.MISSING_NOTE.json").write_text(json.dumps(rec_note, indent=1) + "\n") done.append(c["fit"]) print(c["fit"], "MISSING written; state", rec["state"], "| re-run kept for sensitivity:", rec_note["rerun_for_sensitivity_only"]["present"]) print("applied:", done) if __name__ == "__main__": main()