Repository navigation
Expand file tree
/
Copy pathbenchmark_runtime.py
More file actions
81 lines (59 loc) · 1.97 KB
/
Copy pathbenchmark_runtime.py
File metadata and controls
81 lines (59 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"""Runtime benchmark for example experiment packs."""
from __future__ import annotations
import json
from pathlib import Path
import subprocess
import sys
ROOT = Path(__file__).resolve().parent
EXAMPLES_DIR = ROOT / "examples"
CASES = [
{
"name": "smoke-keep-revert",
"baseline_below": 1.0,
"expected_final": 1.0,
"proposals": ["proposals/bad_patch.py", "proposals/fix_patch.py"],
},
]
def run_python(script: Path, *args: str) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[sys.executable, str(script), *args],
cwd=str(script.parent),
capture_output=True,
text=True,
check=True,
)
def run_measure(exp_dir: Path) -> dict:
proc = run_python(exp_dir / "measure.py")
return json.loads(proc.stdout.strip())
def main() -> int:
passed = 0
failures = []
for case in CASES:
exp_dir = EXAMPLES_DIR / case["name"]
run_python(exp_dir / "reset.py")
baseline = run_measure(exp_dir)
if float(baseline["score"]) >= case["baseline_below"]:
failures.append(f"{case['name']}: baseline too high ({baseline['score']})")
continue
proposal_args: list[str] = []
for proposal in case["proposals"]:
proposal_args.extend(["--proposal", str(exp_dir / proposal)])
run_python(exp_dir / "loop.py", *proposal_args)
final = run_measure(exp_dir)
if float(final["score"]) != case["expected_final"]:
failures.append(
f"{case['name']}: final score {final['score']} != {case['expected_final']}"
)
continue
passed += 1
total = len(CASES)
score = passed / total if total else 0.0
print(f"SCORE {score:.4f} ({passed}/{total})")
if failures:
for failure in failures:
print(f"FAIL {failure}")
return 1
print("PASS benchmark_runtime")
return 0
if __name__ == "__main__":
raise SystemExit(main())