Download tools/docker_check.py from RenaissanceLabsEU/math: direct link, hf CLI and curl.
- Browser
- Download file 3.02 kB
-
https://huggingface.co/datasets/RenaissanceLabsEU/math/resolve/main/tools/docker_check.py
- Command line
-
hf download hf://datasets/RenaissanceLabsEU/math/tools/docker_check.py
-
curl -L -o docker_check.py https://huggingface.co/datasets/RenaissanceLabsEU/math/resolve/main/tools/docker_check.py
3.02 kB
| #!/usr/bin/env python3 | |
| """Run exported tasks through real containers, the way a Harbor-style runner would. | |
| python3 tools/docker_check.py [per_env=2] [--env name] | |
| For each sampled task: start `lean-arena` with no network, mount the task's workdir at /app, solution at | |
| /solution and tests at /tests, then | |
| (a) run solution/solve.sh and tests/test.sh: the reward must be 1, | |
| (b) run tests/test.sh on the untouched start file: the reward must be 0. | |
| Prints one line per task and a summary. Needs `docker build -t lean-arena -f docker/Dockerfile .` first. | |
| """ | |
| import json, os, shutil, subprocess, sys, tempfile, time | |
| ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| def run_task(td, mode): | |
| work = tempfile.mkdtemp(prefix="arena-run-") | |
| app = os.path.join(work, "app"); logs = os.path.join(work, "logs") | |
| shutil.copytree(os.path.join(td, "environment", "workdir"), app); os.makedirs(logs) | |
| for d in (app, logs): os.chmod(d, 0o777) | |
| script = ("bash /solution/solve.sh && " if mode == "solution" else "") + "bash /tests/test.sh; cat /logs/verifier/reward.txt" | |
| cmd = ["docker", "run", "--rm", "--network", "none", "--memory", "5g", "--cpus", "4", | |
| "-v", app + ":/app", "-v", logs + ":/logs", | |
| "-v", os.path.join(td, "solution") + ":/solution:ro", "-v", os.path.join(td, "tests") + ":/tests:ro", | |
| "lean-arena", "bash", "-c", script] | |
| t0 = time.time() | |
| r = subprocess.run(cmd, capture_output=True, text=True, timeout=1500) | |
| out = (r.stdout or "").strip().splitlines() | |
| reward = None | |
| try: reward = float(out[-1]) | |
| except (ValueError, IndexError): pass | |
| result = None | |
| rp = os.path.join(logs, "verifier", "result.json") | |
| if os.path.exists(rp): result = json.load(open(rp)) | |
| shutil.rmtree(work, ignore_errors=True) | |
| return reward, time.time() - t0, (r.stderr or "")[-300:], result | |
| def main(): | |
| args = [a for a in sys.argv[1:] if not a.startswith("--")] | |
| per = int(args[0]) if args else 2 | |
| only = sys.argv[sys.argv.index("--env") + 1] if "--env" in sys.argv else None | |
| tasks = [json.loads(l) for l in open(os.path.join(ROOT, "tasks.jsonl"))] | |
| envs = sorted({t["env"] for t in tasks}); bad = 0; n = 0 | |
| for env in envs: | |
| if only and env != only: continue | |
| pool = [t for t in tasks if t["env"] == env and t["split"] == "eval"] | |
| pick = [pool[i * len(pool) // per] for i in range(per)] | |
| for t in pick: | |
| td = os.path.join(ROOT, t["path"]) | |
| r1, s1, e1, _ = run_task(td, "solution"); r0, s0, e0, res0 = run_task(td, "start") | |
| ok = (r1 == 1.0 and r0 == 0.0); n += 1; bad += (not ok) | |
| print("%s %-44s reference %s (%.0fs) start file %s (%.0fs)" % ("ok " if ok else "FAIL", t["id"], r1, s1, r0, s0), flush=True) | |
| if not ok: print(" ", e1[-200:].replace("\n", " "), "|", e0[-200:].replace("\n", " ")) | |
| print("DOCKER CHECK: %d tasks, %d failures" % (n, bad)); sys.exit(1 if bad else 0) | |
| if __name__ == "__main__": | |
| main() | |