#!/usr/bin/env python3 # -*- coding: utf-8 -*- """calib-ladder.py — the route's own pre-registered requirement: measure the instrument's strength against the PUBLISHED ladder before reading anything at a level whose value is not published (see the route text: "the instrument's strength is MEASURED against the published ladder before any new level is read, so a negative has a scale attached"). This runs the SAME maximiser, unchanged, at levels 13, 16, 19, 22 — where A144311 is published and exact — with an equal, small time budget per level, and reports recovery = best run found / published value. If recovery is high at the calibrated levels, the instrument is sound and its result at n = 25 has a scale; if recovery is already low, the instrument is the explanation and no conclusion about n = 25 follows. """ import argparse import json import time import numpy as np import cover90 as C import cover90max as M PUBLISHED = {13: 545, 16: 869, 19: 1283, 22: 1709} def main(): ap = argparse.ArgumentParser() ap.add_argument("--X", type=int, default=40000) ap.add_argument("--seconds", type=float, default=60) ap.add_argument("--seed", type=int, default=5) ap.add_argument("--out", required=True) ap.add_argument("--log") a = ap.parse_args() fh = open(a.log, "w", encoding="utf-8") if a.log else None def log(rec): if fh: fh.write(json.dumps(rec) + "\n"); fh.flush() rows = [] for level in sorted(PUBLISHED): n = C.set_level(level) assert n == level and len(C.PRIMES) == level, (n, len(C.PRIMES), level) t0 = time.time() start = [int(np.random.default_rng(level).integers(0, p)) for p in C.PRIMES] res, best, bstart, traj, it, kicks, restarts = M.run(a.X, a.seconds, a.seed + level, start, log) cnt = C.coverage(res, a.X) r2, s2 = M.score(cnt, a.X) rows.append({"level": n, "level_requested": level, "primes": len(C.PRIMES), "published": PUBLISHED[level], "best_run": r2, "best_run_start": s2, "recovery_pct": round(100.0 * r2 / PUBLISHED[level], 2), "iterations": it, "restarts": restarts, "seconds": round(time.time() - t0, 1), "residues": res}) print(json.dumps({"level": n, "published": PUBLISHED[level], "best": r2, "recovery_pct": rows[-1]["recovery_pct"]})) out = {"tool": "calib-ladder/1", "at": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), "X": a.X, "seconds_per_level": a.seconds, "rows": rows} json.dump(out, open(a.out, "w", encoding="utf-8"), indent=1) if fh: fh.close() return 0 if __name__ == "__main__": import sys sys.exit(main())