"""Recompute the finite comparisons for the standalone pentagon manuscript.""" import argparse import json from concurrent.futures import ThreadPoolExecutor from hashlib import sha256 import os from pathlib import Path import subprocess import sys from time import monotonic ROOT = Path(__file__).resolve().parent CHECKS = ROOT / "checks" NONCONVEX = [ ("nonconvex/check_three_circles.py",), ("nonconvex/independent_three_circle.py",), ] CONVEX = [ ("convex/verify_maxtri_case_b.py",), ("convex/verify_twoear_cover.py", "u_half"), ("convex/verify_twoear_cover.py", "alpha_quarter"), ("convex/certify_local_radius.py",), ("convex/check_flux.py",), ("convex/verify_metric_cover.py", "u_three_quarters"), ("convex/verify_metric_cover.py", "a_seven_sixteenths"), ("convex/verify_harmonic_bridge.py",), ("convex/compare_annulus.py",), ] def check_files(): manifest = json.loads((CHECKS / "SHA256SUMS.json").read_text(encoding="utf-8")) for name, digest in manifest.items(): if sha256((CHECKS / name).read_bytes()).hexdigest() != digest: raise RuntimeError(f"Checksum mismatch in {name}") def run(command, log_dir): script = CHECKS / command[0] key = "_".join((script.stem, *[arg.lstrip("-") for arg in command[1:]])) env = dict(os.environ, PYTHONUTF8="1", OPENBLAS_NUM_THREADS="1") log = log_dir / (key + ".log") start = monotonic() with log.open("w", encoding="utf-8") as stream: subprocess.run([sys.executable, "-B", str(script), *command[1:]], cwd=script.parent, stdout=stream, stderr=subprocess.STDOUT, env=env, check=True) print(f"PASS {' '.join(command)} ({monotonic() - start:.1f} s)", flush=True) def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--quick", action="store_true", help="Only the two standard-library nonconvex checks.") parser.add_argument("--jobs", type=int, default=3, help="Maximum concurrent checkers; use 1 to conserve memory.") parser.add_argument("--logs", type=Path, default=ROOT / "replay-logs", help="Directory for the individual checkers' output.") args = parser.parse_args() if not __debug__ or os.environ.get("PYTHONOPTIMIZE"): parser.error("Python assertions must be enabled.") if args.jobs < 1: parser.error("--jobs must be positive.") check_files() commands = NONCONVEX if args.quick else NONCONVEX + CONVEX args.logs.mkdir(parents=True, exist_ok=True) total = monotonic() with ThreadPoolExecutor(max_workers=args.jobs) as pool: list(pool.map(lambda command: run(command, args.logs), commands)) print(f"PASS all {len(commands)} selected checks ({monotonic() - total:.1f} s)") if __name__ == "__main__": main()