#!/usr/bin/env python3 """timing-probe.py -- price the pre-registered T37 experiment and measure the parallel split. Two questions the return must answer with numbers rather than with a plan: (1) what does the script the pre-registration says to reuse UNCHANGED actually cost, and how does that cost scale with D -- so the T37 estimate is anchored on THIS machine, on the same basis as the route's recorded T31 wall clock (94-166 s), instead of on another run; (2) what does the split across cores actually buy -- the pre-registration assumes a near-linear 8-core split of the 1.7 CPU-h, so the speedup is measured here on a fixed workload. Cost basis: every number is WALL clock on this machine, including each script's own reported wall_s, so the two instruments are compared on one basis and the sibling-load inflation (six sessions share this box) is disclosed rather than hidden. Run detached (nohup) and read the log; prints a JSON summary to stdout and to work/timing-probe.json. """ import json import os import subprocess import sys import time W = os.path.dirname(os.path.abspath(__file__)) RUN = os.path.dirname(W) PY = sys.executable PRE = os.path.join(RUN, "sources", "return-1296", "job1930-k2.py") MINE = os.path.join(W, "k2fold.py") FOLDS = ["23", "29", "31", "37"] D = {13: 1485, 17: 22275, 19: 378675, 23: 7952175, 29: 214708725, 31: 6226553025, 37: 6226553025 * 35} def run(args, tag, parse_json=False, outfile=None): t0 = time.perf_counter() p = subprocess.run(args, cwd=RUN, capture_output=True, text=True) wall = time.perf_counter() - t0 inner, workers, wsum = None, None, None j = None if parse_json: for line in reversed((p.stdout or "").splitlines()): # the predecessor prints its JSON line = line.strip() if line.startswith("{"): try: j = json.loads(line) except Exception: j = None if j is not None: break if j is None and outfile and os.path.exists(outfile): # k2fold writes its JSON to a file try: j = json.load(open(outfile, encoding="utf-8")) except Exception: j = None if j: inner = j.get("wall_s") workers = j.get("workers") if isinstance(j.get("worker_wall_s"), list): wsum = round(sum(j["worker_wall_s"]), 2) print("--- %-34s exit=%d wall=%8.2f s inner_wall_s=%s workers=%s sum_worker_wall=%s" % (tag, p.returncode, wall, inner, workers, wsum), flush=True) if p.returncode != 0: print((p.stderr or "")[-600:], flush=True) return {"tag": tag, "exit": p.returncode, "wall_s": round(wall, 2), "inner_wall_s": inner, "workers": workers, "sum_worker_wall_s": wsum} def main(): out = {"folds": FOLDS, "note": "all costs are WALL seconds on this machine", "runs": []} # (1) the predecessor, unchanged, on the two cheapest tiles we can afford here out["runs"].append(run([PY, PRE, "tile", "23"] + FOLDS, "job1930-k2 tile T23", True)) out["runs"].append(run([PY, PRE, "tile", "29"] + FOLDS, "job1930-k2 tile T29", True)) # (2) the split on a FIXED workload: T23, 1 worker vs 8 workers (k2fold writes its JSON to a file) for w in (1, 8): of = os.path.join(W, "probe-t23-%d.json" % w) out["runs"].append(run([PY, MINE, "tile", "23", str(w), of], "k2fold tile T23 workers=%d" % w, True, outfile=of)) p23 = out["runs"][0] p29 = out["runs"][1] per_D = {x: p["inner_wall_s"] / D[int(p["tag"].split()[-1][1:])] for x, p in ((23, p23), (29, p29))} use = max(per_D.values()) # the conservative anchor mine23 = [r for r in out["runs"] if "k2fold" in r["tag"]] m1 = next(r for r in mine23 if r["workers"] == 1) m8 = next(r for r in mine23 if r["workers"] == 8) out["model"] = { "wall_s_per_D_T23": per_D[23], "wall_s_per_D_T29": per_D[29], "wall_s_per_D_used": use, "predicted_hours_reusing_job1930_k2": {x: round(use * D[x] / 3600.0, 2) for x in (29, 31, 37)}, "route_recorded_T31_wall_s": [94, 166], "parallel_speedup_8_over_1_T23": round(m1["wall_s"] / m8["wall_s"], 2), "core_seconds_of_my_T23_spectrum": m8["sum_worker_wall_s"], "predicted_hours_my_instrument_T37": round( (m8["sum_worker_wall_s"] or 0) * (D[37] / D[23]) / 3600.0, 1), } print(json.dumps(out["model"], indent=1), flush=True) with open(os.path.join(W, "timing-probe.json"), "w", encoding="utf-8") as f: json.dump(out, f, indent=1) print("PROBE DONE", flush=True) if __name__ == "__main__": main()