Download scripts/reproduce.py from PureOne/controlled-spectral-reconstruction: direct link, hf CLI and curl.
- Browser
- Download file 4.48 kB
-
https://huggingface.co/datasets/PureOne/controlled-spectral-reconstruction/resolve/main/scripts/reproduce.py
- Command line
-
hf download hf://datasets/PureOne/controlled-spectral-reconstruction/scripts/reproduce.py
-
curl -L -o reproduce.py https://huggingface.co/datasets/PureOne/controlled-spectral-reconstruction/resolve/main/scripts/reproduce.py
4.48 kB
| """Reproduce supplied checks in a temporary copy, preserving release files.""" | |
| from __future__ import annotations | |
| import argparse | |
| import json | |
| from pathlib import Path | |
| import platform | |
| import shutil | |
| import subprocess | |
| import sys | |
| import tempfile | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def main(argv=None) -> int: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--exact-only", action="store_true", help="Skip the 126 FEM checks; the 10 Decimal examples still run.") | |
| parser.add_argument("--output", type=Path, help="Optional JSON run report; no output file is written by default.") | |
| args = parser.parse_args(argv) | |
| report = {"status": "PASS", "mode": "without_fem" if args.exact_only else "full", | |
| "python": platform.python_version(), "platform": platform.system(), "suites": []} | |
| with tempfile.TemporaryDirectory(prefix="spectral_reproduction_") as tmp: | |
| work = Path(tmp) / "research" | |
| shutil.copytree(ROOT / "research", work) | |
| commands = [[sys.executable, "-I", str(work / "query_minimax_verify.py")], | |
| [sys.executable, "-I", str(work / "validation_v2/noisy_counterexamples.py")], | |
| [sys.executable, "-I", str(work / "validation_v2/constructive_verification.py")]] | |
| if args.exact_only: | |
| commands[-1].append("--skip-fem") | |
| for command in commands: | |
| print("Running " + Path(command[2]).name + "...", flush=True) | |
| process = subprocess.run(command, cwd=work, text=True, encoding="utf-8", capture_output=True) | |
| if process.returncode: | |
| print(process.stdout) | |
| print(process.stderr) | |
| print("FAIL: verification suite returned a nonzero exit status.") | |
| return 1 | |
| query = json.loads((work / "query_minimax_verification.json").read_text(encoding="utf-8")) | |
| noise = json.loads((work / "validation_v2/noisy_counterexamples_results.json").read_text(encoding="utf-8")) | |
| constructive = json.loads((work / "validation_v2/constructive_verification_results.json").read_text(encoding="utf-8")) | |
| originals = ROOT / "research" | |
| checks = [ | |
| query == json.loads((originals / "query_minimax_verification.json").read_text(encoding="utf-8")), | |
| noise == json.loads((originals / "validation_v2/noisy_counterexamples_results.json").read_text(encoding="utf-8")), | |
| query["exact_rational_checks"] == 10622, | |
| query["high_precision_infinite_mass_checks"] == 10, | |
| noise["status"] == "PASS" and noise["assertions_total"] == 592, | |
| constructive["status"] == "PASS" and constructive["exact_assertions"] == 891, | |
| constructive["numerical_assertions"] == (0 if args.exact_only else 126), | |
| ] | |
| baseline = json.loads((originals / "validation_v2/constructive_verification_results.json").read_text(encoding="utf-8")) | |
| for key in ("seed", "graphs", "critical_coupling", "flux_convention", "hessian_formula", "inverse_metric_algorithm"): | |
| checks.append(constructive[key] == baseline[key]) | |
| baseline_categories = baseline["assertions_by_category"] | |
| if args.exact_only: | |
| baseline_categories = {k: v for k, v in baseline_categories.items() if not k.startswith("fem_")} | |
| checks.append(constructive["assertions_by_category"] == baseline_categories) | |
| if not all(checks): | |
| print("FAIL: reproduced counts or exact records differ from the supplied release.") | |
| return 1 | |
| report["suites"] = [ | |
| {"suite": "query_minimax", "exact": 10622, "numerical": 10}, | |
| {"suite": "constructive", "exact": 891, "numerical": 0 if args.exact_only else 126}, | |
| {"suite": "noisy_counterexamples", "exact": 592, "numerical": 0}, | |
| ] | |
| report["exact_checks"] = 12105 | |
| report["numerical_checks"] = 10 if args.exact_only else 136 | |
| report["worst_fem_relative_error"] = max((row["relative_error"] for row in constructive["finite_element_normalization"]), default=None) | |
| report["limits"] = "Finite exact and floating-point checks; no formal proof or novelty certification." | |
| if args.output: | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| args.output.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8") | |
| print(json.dumps(report, indent=2)) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |