"""Primary machine verifier for the Claim 2 resolution evidence.""" from __future__ import annotations import json import sys from pathlib import Path MAX_FINAL_ERROR = 5e-4 MAX_REDUCTION_RATIO = 0.12 MAX_SLOPE = -1.25 MAX_REFERENCE_DISAGREEMENT = 5e-6 MAX_CONSTANT_RESIDUAL = 2e-11 def verify_payload(payload: dict) -> dict: failures: list[str] = [] checked = 0 for case in payload["cases"]: if case["reference"]["max_constant_residual"] > MAX_CONSTANT_RESIDUAL: failures.append( f"{case['density']}/{case['discretization']}/{case['kernel']}: reference constant residual" ) if case["max_probe_constant_residual"] > MAX_CONSTANT_RESIDUAL: failures.append( f"{case['density']}/{case['discretization']}/{case['kernel']}: probe constant residual" ) for record in case["signals"]: checked += 1 label = ( f"{case['density']}/{case['discretization']}/" f"{case['kernel']}/{record['signal']}" ) if record["reference_stability"] > MAX_REFERENCE_DISAGREEMENT: failures.append(label + ": unstable reference") if record["signal"] == "constant": if record["final_error"] > MAX_CONSTANT_RESIDUAL: failures.append(label + ": does not preserve constants") continue if record["final_error"] > MAX_FINAL_ERROR: failures.append(label + ": final uniform error too large") if record["reduction_ratio"] > MAX_REDUCTION_RATIO: failures.append(label + ": insufficient error reduction") if record["loglog_slope"] > MAX_SLOPE: failures.append(label + ": convergence slope too shallow") return { "verifier": "primary", "checked_signal_cases": checked, "thresholds": { "max_final_error": MAX_FINAL_ERROR, "max_reduction_ratio": MAX_REDUCTION_RATIO, "max_loglog_slope": MAX_SLOPE, "max_reference_disagreement": MAX_REFERENCE_DISAGREEMENT, "max_constant_residual": MAX_CONSTANT_RESIDUAL, }, "pass": not failures, "failures": failures, } def main() -> int: if len(sys.argv) != 3: raise SystemExit("usage: verify_resolution.py INPUT_JSON OUTPUT_JSON") payload = json.loads(Path(sys.argv[1]).read_text(encoding="utf-8")) result = verify_payload(payload) Path(sys.argv[2]).write_text( json.dumps(result, indent=2) + "\n", encoding="utf-8" ) print("PRIMARY_VERIFIER=" + json.dumps(result, sort_keys=True)) return 0 if result["pass"] else 1 if __name__ == "__main__": raise SystemExit(main())