#!/usr/bin/env python3 """Run a list of (k, eps, d) configurations at high precision, append to JSON. Usage: sweep.py OUTJSON "50:1/25:19,21,23" "46:25/861:17,19,21" ... """ from __future__ import annotations import json import os import sys import time from fractions import Fraction as Fr HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) from run_hp import run # noqa: E402 def main(): out = sys.argv[1] specs = sys.argv[2:] prec = int(os.environ.get("SAH_PREC", "512")) block = int(os.environ.get("SAH_BLOCK", "128")) results = [] if os.path.exists(out): results = json.load(open(out)) for spec in specs: k, eps, ds = spec.split(":") for d in [int(x) for x in ds.split(",")]: if any(r.get("d") == d and r.get("k") == int(k) and r.get("eps") == eps and "M" in r for r in results): continue try: r = run(int(k), Fr(eps), d, block=block, prec=prec, verbose=False) results.append(r) except Exception as ex: results.append({"k": int(k), "eps": eps, "d": d, "error": str(ex)}) with open(out, "w") as f: json.dump(results, f, indent=2) print("done", out, flush=True) if __name__ == "__main__": main()