#!/usr/bin/env python3 # -*- coding: utf-8 -*- """window.py — job #2743: this run's own measurement of a state, independent of the producer. For a residue tuple at level n it reports, from scratch (cover90.coverage, the instrument gated 7/7 against the route's own published geometry in #1356): * the least number of holes over ALL windows of the fixed target length R on [0, X), and where that window starts — the same objective the producer optimises, measured over a range that contains the producer's own buffer (R + 200 offsets) as a strict subset; * the exact hole offsets inside that best window (the closure input); * the state's longest covered run on [0, L) — the object the route actually cares about, which the fixed-window objective only proxies. Deterministic: no seeds, no time boxes, byte-stable under SAH_DETERMINISTIC=1. stdout is the artifact; nothing is written anywhere else. """ import argparse import hashlib import json import os import sys import time sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "work2731")) import cover90 as C # noqa: E402 (pinned instrument of this run, reused, not copied) from cover90 import stamp # noqa: E402 def main(): ap = argparse.ArgumentParser() ap.add_argument("--residues", required=True) ap.add_argument("--level", type=int, required=True) ap.add_argument("--R", type=int, required=True) ap.add_argument("--X", type=int, default=20000) ap.add_argument("--L", type=int, default=2000000, help="range for the longest-run scan") ap.add_argument("--out", required=True) a = ap.parse_args() if a.level < len(C.PRIMES): C.set_level(a.level) d = json.load(open(a.residues, encoding="utf-8")) res = (d.get("best_residues") or d.get("residues")) if isinstance(d, dict) else d src = d.get("source") if isinstance(d, dict) else a.residues if len(res) != a.level: raise SystemExit("residue count %d != level %d" % (len(res), a.level)) t0 = time.time() holes, start = C.evaluate(res, a.X, a.R) cnt = C.coverage(res, a.X) win_holes = [int(i) for i in (__import__("numpy").flatnonzero(cnt[start:start + a.R]) + start)] run, run_start = C.best_run(res, a.L) out = { "tool": "window/1", "at": stamp(), "source": src, "level": a.level, "R": a.R, "X": a.X, "L": a.L, "residues_sha256_16": hashlib.sha256(json.dumps(res).encode()).hexdigest()[:16], "window_holes": int(holes), "window_start": int(start), "window_hole_list": win_holes, "producer_buffer_covered": int(holes) == 0, "longest_run": int(run), "longest_run_start": int(run_start), "seconds": round(time.time() - t0, 2), } json.dump(out, open(a.out, "w", encoding="utf-8"), indent=1) print(json.dumps({k: out[k] for k in ("level", "R", "window_holes", "window_start", "longest_run", "longest_run_start")}, indent=1)) return 0 if __name__ == "__main__": sys.exit(main())