amphora commited on
Commit
8711a86
·
verified ·
1 Parent(s): a696fcd

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. tasks/construct-ae-p52-erdos-squarefree-l3-s2/environment/Dockerfile +7 -0
  2. tasks/construct-ae-p52-erdos-squarefree-l3-s2/environment/instance.json +1 -0
  3. tasks/construct-ae-p52-erdos-squarefree-l3-s2/solution/solve.sh +5 -0
  4. tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/check.py +38 -0
  5. tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/instance.json +1 -0
  6. tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/run.py +127 -0
  7. tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/test.sh +9 -0
  8. tasks/construct-ae-p54-touching-cylinders-l2-s0/environment/Dockerfile +7 -0
  9. tasks/construct-ae-p54-touching-cylinders-l2-s0/environment/instance.json +1 -0
  10. tasks/construct-ae-p54-touching-cylinders-l2-s0/solution/solve.sh +5 -0
  11. tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/check.py +62 -0
  12. tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/instance.json +1 -0
  13. tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/run.py +127 -0
  14. tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/test.sh +9 -0
  15. tasks/construct-ae-p58-happy-ending-l4-s0/environment/Dockerfile +7 -0
  16. tasks/construct-ae-p58-happy-ending-l4-s0/environment/instance.json +1 -0
  17. tasks/construct-ae-p58-happy-ending-l4-s0/solution/solve.sh +5 -0
  18. tasks/construct-ae-p58-happy-ending-l4-s0/tests/check.py +69 -0
  19. tasks/construct-ae-p58-happy-ending-l4-s0/tests/instance.json +1 -0
  20. tasks/construct-ae-p58-happy-ending-l4-s0/tests/run.py +127 -0
  21. tasks/construct-ae-p58-happy-ending-l4-s0/tests/test.sh +9 -0
  22. tasks/construct-mc-bibd-l4-s2/environment/Dockerfile +7 -0
  23. tasks/construct-mc-bibd-l4-s2/environment/instance.json +1 -0
  24. tasks/construct-mc-bibd-l4-s2/solution/solve.sh +5 -0
  25. tasks/construct-mc-bibd-l4-s2/tests/check.py +25 -0
  26. tasks/construct-mc-bibd-l4-s2/tests/instance.json +1 -0
  27. tasks/construct-mc-bibd-l4-s2/tests/run.py +127 -0
  28. tasks/construct-mc-bibd-l4-s2/tests/test.sh +9 -0
  29. tasks/construct-mc-bibd-l4-s5/environment/Dockerfile +7 -0
  30. tasks/construct-mc-bibd-l4-s5/environment/instance.json +1 -0
  31. tasks/construct-mc-bibd-l4-s5/solution/solve.sh +5 -0
  32. tasks/construct-mc-bibd-l4-s5/tests/check.py +25 -0
  33. tasks/construct-mc-bibd-l4-s5/tests/instance.json +1 -0
  34. tasks/construct-mc-bibd-l4-s5/tests/run.py +127 -0
  35. tasks/construct-mc-bibd-l4-s5/tests/test.sh +9 -0
  36. tasks/construct-mc-debruijn-l4-s2/environment/Dockerfile +7 -0
  37. tasks/construct-mc-debruijn-l4-s2/environment/instance.json +1 -0
  38. tasks/construct-mc-debruijn-l4-s2/solution/solve.sh +5 -0
  39. tasks/construct-mc-debruijn-l4-s2/tests/check.py +15 -0
  40. tasks/construct-mc-debruijn-l4-s2/tests/instance.json +1 -0
  41. tasks/construct-mc-debruijn-l4-s2/tests/run.py +127 -0
  42. tasks/construct-mc-debruijn-l4-s2/tests/test.sh +9 -0
  43. tasks/construct-mc-golomb-l6-s2/environment/Dockerfile +7 -0
  44. tasks/construct-mc-golomb-l6-s2/environment/instance.json +1 -0
  45. tasks/construct-mc-golomb-l6-s2/solution/solve.sh +5 -0
  46. tasks/construct-mc-golomb-l6-s2/tests/check.py +27 -0
  47. tasks/construct-mc-golomb-l6-s2/tests/instance.json +1 -0
  48. tasks/construct-mc-golomb-l6-s2/tests/run.py +127 -0
  49. tasks/construct-mc-golomb-l6-s2/tests/test.sh +9 -0
  50. tasks/construct-mc-graph-k-coloring-l4-s1/environment/Dockerfile +7 -0
tasks/construct-ae-p52-erdos-squarefree-l3-s2/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p52-erdos-squarefree-l3-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 1344, "t": 54, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s2/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332]}
5
+ RLMATH_EOF
tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/check.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A
2
+ (a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for
3
+ "never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1."""
4
+ import numpy as np
5
+
6
+ from run import Invalid, int_list
7
+
8
+
9
+ def _primes(n):
10
+ s = np.ones(n + 1, dtype=bool)
11
+ s[:2] = False
12
+ for i in range(2, int(n ** .5) + 1):
13
+ if s[i]:
14
+ s[i * i::i] = False
15
+ return np.nonzero(s)[0]
16
+
17
+
18
+ def check(inst, ans):
19
+ n, t = inst["N"], inst["t"]
20
+ a = ans.get("A")
21
+ if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20):
22
+ raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers")
23
+ int_list(a, None, 1, n, "A")
24
+ if len(set(a)) != len(a):
25
+ raise Invalid("A must consist of distinct integers")
26
+ x = np.array(sorted(a), dtype=np.int64)
27
+ iu, ju = np.triu_indices(len(x))
28
+ va, vb = x[iu], x[ju]
29
+ left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet
30
+ for p in _primes(int((n * n + 1) ** .5) + 1):
31
+ q = int(p) * int(p)
32
+ idx = np.nonzero(left)[0]
33
+ hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0
34
+ left[idx[hit]] = False
35
+ if not left.any():
36
+ return None, {"size": len(a)}
37
+ k = int(np.nonzero(left)[0][0])
38
+ raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree")
tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 1344, "t": 54, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p52-erdos-squarefree-l3-s2/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p54-touching-cylinders-l2-s0/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p54-touching-cylinders-l2-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 9, "unit_radius": false, "tol": 1e-09, "r_min": 0.1, "r_max": 10.0, "family": "ae_p54_touching_cylinders", "subset": "construct"}
tasks/construct-ae-p54-touching-cylinders-l2-s0/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"cylinders": [[0.19857821545445875, -0.23831984674253506, -0.24522717314179707, 0.6511120386651232, -0.2084217497676763, 0.7298037320602897, 0.1525803323841557], [-0.045817225700147575, -0.6222633532305163, -0.4434641824479314, 0.19047945804717148, -0.5789996892270514, 0.7927653725643129, 0.10952216244488278], [0.04511053991130861, 0.002258745581368144, 0.1327198625952239, 0.3150895961875385, 0.9410429983263167, -0.12311223202992576, 0.28130367386886235], [-0.04184799590104818, -0.4929695222129185, -0.21439853571132267, -0.9509235907009279, 0.18770702863812652, -0.2459886095905652, 0.1298601091306748], [-0.35528274690077316, -0.028970026215526707, 0.008740679923735735, -0.01079665387167614, 0.40786673831291614, 0.9129776317321024, 0.10519100783876235], [-0.4619833104980376, -0.8801089686879998, -0.5580356575434811, 0.6029986301609905, -0.6282442325369595, 0.4916318096991041, 0.32241514004377336], [-0.9849026328771985, 0.8655202022895421, -0.2956387569232707, 0.5457084539243082, 0.3629981695308365, -0.7552712176647558, 0.982076826179542], [0.2034187738303467, -0.5901674339738545, 0.7902692635587766, 0.5837162724755628, -0.57134244456614, -0.5769255795026095, 0.38776071759683944], [1.0601921587661116, -0.13292772033315334, -0.9322465519973098, -0.3970124429449542, -0.8566866695601167, -0.329346429075639, 0.9346691702719084]]}
5
+ RLMATH_EOF
tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/check.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Pairwise touching infinite cylinders (AlphaEvolve problem 54).
2
+
3
+ Each cylinder: a point on its axis, an axis direction and a radius. Two cylinders touch (externally) when the
4
+ distance between their axes equals r_i + r_j. Checked in floating point with an absolute tolerance
5
+ (inst["tol"]); contact points (midpoints of closest approach) must lie in [-100, 100]^3 as upstream, which rules
6
+ out near-parallel pairs "touching at infinity"."""
7
+ import itertools
8
+ import math
9
+
10
+ from run import Invalid, float_matrix
11
+
12
+
13
+ def _sub(a, b):
14
+ return [a[0] - b[0], a[1] - b[1], a[2] - b[2]]
15
+
16
+
17
+ def _dot(a, b):
18
+ return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]
19
+
20
+
21
+ def _cross(a, b):
22
+ return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]]
23
+
24
+
25
+ def check(inst, ans):
26
+ n, unit, tol = inst["n"], inst["unit_radius"], inst["tol"]
27
+ rows = float_matrix(ans.get("cylinders"), n, 6 if unit else 7, "cylinders")
28
+ cyl = []
29
+ for r in rows:
30
+ p, v = r[:3], r[3:6]
31
+ nv = math.sqrt(_dot(v, v))
32
+ if nv < 1e-9:
33
+ raise Invalid("zero axis direction")
34
+ v = [c / nv for c in v]
35
+ rad = 1.0 if unit else r[6]
36
+ if not unit and not (inst["r_min"] <= rad <= inst["r_max"]):
37
+ raise Invalid(f"radius {rad} outside [{inst['r_min']}, {inst['r_max']}]")
38
+ if max(abs(c) for c in p) > 1000:
39
+ raise Invalid("axis point too far from the origin")
40
+ cyl.append((p, v, rad))
41
+ worst = 0.0
42
+ for (p1, v1, r1), (p2, v2, r2) in itertools.combinations(cyl, 2):
43
+ w = _sub(p2, p1)
44
+ c = _cross(v1, v2)
45
+ nc = math.sqrt(_dot(c, c))
46
+ if nc < 1e-9:
47
+ d = math.sqrt(_dot(_cross(w, v1), _cross(w, v1)))
48
+ mid = [(p1[i] + p2[i]) / 2 for i in range(3)]
49
+ else:
50
+ d = abs(_dot(w, c)) / nc
51
+ b = _dot(v1, v2)
52
+ den = 1 - b * b
53
+ t1 = (_dot(w, v1) - b * _dot(w, v2)) / den
54
+ t2 = (b * _dot(w, v1) - _dot(w, v2)) / den
55
+ mid = [(p1[i] + t1 * v1[i] + p2[i] + t2 * v2[i]) / 2 for i in range(3)]
56
+ if max(abs(m) for m in mid) > 100:
57
+ raise Invalid("a contact point lies outside [-100, 100]^3")
58
+ err = abs(d - (r1 + r2))
59
+ worst = max(worst, err)
60
+ if err > tol:
61
+ raise Invalid(f"axis distance {d:.12g} differs from r_i + r_j = {r1 + r2:.12g} by {err:.3g} > {tol}")
62
+ return None, {"max_error": worst}
tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 9, "unit_radius": false, "tol": 1e-09, "r_min": 0.1, "r_max": 10.0, "family": "ae_p54_touching_cylinders", "subset": "construct"}
tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p54-touching-cylinders-l2-s0/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-ae-p58-happy-ending-l4-s0/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-ae-p58-happy-ending-l4-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 64, "k": 8, "max_abs": 1000000000000000000, "family": "ae_p58_happy_ending", "subset": "construct"}
tasks/construct-ae-p58-happy-ending-l4-s0/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"points": [[0, 0], [15448000, -15448000000], [15448001, -15447999998], [15448002, -15447999990], [15448003, -15447999954], [15448004, -15447999762], [15448005, -15447998562], [30896000, -61792000000], [30896001, -61791999990], [30896002, -61791999988], [30896003, -61791999924], [30896004, -61791999922], [30896005, -61791999914], [30896006, -61791999250], [30896007, -61791999248], [30896008, -61791999240], [30896009, -61791999204], [30896010, -61791989110], [30896011, -61791989108], [30896012, -61791989100], [30896013, -61791989064], [30896014, -61791988872], [46344000, -139032000000], [46344001, -139031999944], [46344002, -139031999934], [46344003, -139031999932], [46344004, -139031999250], [46344005, -139031999240], [46344006, -139031999238], [46344007, -139031999174], [46344008, -139031999172], [46344009, -139031999164], [46344010, -139031985368], [46344011, -139031985358], [46344012, -139031985356], [46344013, -139031985292], [46344014, -139031985290], [46344015, -139031985282], [46344016, -139031984618], [46344017, -139031984616], [46344018, -139031984608], [46344019, -139031984572], [61792000, -247168000000], [61792001, -247167999638], [61792002, -247167999582], [61792003, -247167999572], [61792004, -247167999570], [61792005, -247167988778], [61792006, -247167988722], [61792007, -247167988712], [61792008, -247167988710], [61792009, -247167988028], [61792010, -247167988018], [61792011, -247167988016], [61792012, -247167987952], [61792013, -247167987950], [61792014, -247167987942], [77240000, -386200000000], [77240001, -386199997328], [77240002, -386199996966], [77240003, -386199996910], [77240004, -386199996900], [77240005, -386199996898], [92688000, -556128000000]]}
5
+ RLMATH_EOF
tasks/construct-ae-p58-happy-ending-l4-s0/tests/check.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Erdos-Szekeres happy ending (AlphaEvolve problem 58): n = 2^(k-2) integer points in general position with no
2
+ k points in convex position. Exact integer orientation tests; the largest convex-position subset is computed by
3
+ the O(n^4) bottom-vertex / angular-order dynamic programme.
4
+
5
+ Upstream bug: the notebook's verifier uses float orientations with a 1e-9 threshold (and numba fastmath); its
6
+ 33- and 65-point sets (claimed to have "0 convex k-gons") contain a convex 7-gon / 8-gon under exact arithmetic."""
7
+ import functools
8
+
9
+ import numpy as np
10
+
11
+ from run import Invalid, int_list
12
+
13
+
14
+ def orient_table(p):
15
+ n = len(p)
16
+ o = np.zeros((n, n, n), dtype=np.int8)
17
+ for i in range(n):
18
+ xi, yi = p[i]
19
+ for j in range(i + 1, n):
20
+ dx, dy = p[j][0] - xi, p[j][1] - yi
21
+ for k in range(j + 1, n):
22
+ c = dx * (p[k][1] - yi) - dy * (p[k][0] - xi)
23
+ if c == 0:
24
+ raise Invalid(f"points {p[i]}, {p[j]}, {p[k]} are collinear")
25
+ s = 1 if c > 0 else -1
26
+ o[i, j, k] = o[j, k, i] = o[k, i, j] = s
27
+ o[i, k, j] = o[k, j, i] = o[j, i, k] = -s
28
+ return o
29
+
30
+
31
+ def max_convex(p, o):
32
+ n = len(p)
33
+ best = min(n, 3)
34
+ order = sorted(range(n), key=lambda i: (p[i][1], p[i][0]))
35
+ for bi, b in enumerate(order):
36
+ rest = order[bi + 1:]
37
+ m = len(rest)
38
+ if m < 2:
39
+ continue
40
+ rest = sorted(rest, key=functools.cmp_to_key(lambda u, v: -int(o[b, u, v])))
41
+ r = np.array(rest)
42
+ chain = np.zeros((m, m), dtype=np.int32) # chain[i, j]: longest convex chain b .. r_i -> r_j
43
+ for j in range(1, m):
44
+ for i in range(j):
45
+ v = 3
46
+ if i > 0:
47
+ ok = (chain[:i, i] > 0) & (o[r[:i], r[i], r[j]] > 0)
48
+ if ok.any():
49
+ v = max(v, int(chain[:i, i][ok].max()) + 1)
50
+ chain[i, j] = v
51
+ close = o[r[:j], r[j], b] > 0
52
+ if close.any():
53
+ best = max(best, int(chain[:j, j][close].max()))
54
+ return best
55
+
56
+
57
+ def check(inst, ans):
58
+ n, k, lim = inst["n"], inst["k"], inst["max_abs"]
59
+ pts = ans.get("points")
60
+ if not isinstance(pts, list) or len(pts) != n:
61
+ raise Invalid(f"points must be a list of {n} [x, y] pairs")
62
+ p = [tuple(int_list(q, 2, -lim, lim, "point")) for q in pts]
63
+ if len(set(p)) != n:
64
+ raise Invalid("points must be distinct")
65
+ o = orient_table(p)
66
+ mc = max_convex(p, o)
67
+ if mc >= k:
68
+ raise Invalid(f"the set contains {mc} points in convex position (>= {k})")
69
+ return None, {"max_convex_subset": mc}
tasks/construct-ae-p58-happy-ending-l4-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 64, "k": 8, "max_abs": 1000000000000000000, "family": "ae_p58_happy_ending", "subset": "construct"}
tasks/construct-ae-p58-happy-ending-l4-s0/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-ae-p58-happy-ending-l4-s0/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-bibd-l4-s2/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-mc-bibd-l4-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 16, "k": 4, "lambda": 3, "b": 60, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l4-s2/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"blocks": [[0, 1, 2, 7], [3, 5, 9, 14], [2, 8, 10, 11], [2, 5, 7, 14], [3, 5, 11, 13], [1, 2, 4, 9], [4, 7, 8, 12], [0, 2, 13, 15], [1, 6, 8, 9], [0, 8, 9, 11], [1, 5, 8, 11], [4, 10, 12, 14], [3, 7, 8, 12], [2, 5, 9, 12], [0, 4, 5, 14], [5, 6, 7, 8], [3, 4, 5, 13], [1, 7, 12, 14], [1, 4, 7, 11], [3, 12, 13, 15], [2, 4, 9, 13], [6, 8, 12, 13], [1, 2, 5, 12], [0, 4, 8, 15], [3, 6, 9, 12], [0, 5, 10, 12], [0, 3, 9, 10], [0, 2, 3, 7], [0, 4, 7, 13], [0, 1, 12, 13], [4, 9, 12, 15], [11, 12, 14, 15], [7, 9, 11, 13], [4, 6, 11, 15], [4, 5, 6, 10], [0, 8, 9, 14], [8, 10, 13, 14], [3, 7, 10, 11], [1, 6, 10, 13], [0, 10, 11, 12], [1, 5, 8, 15], [7, 9, 10, 15], [1, 3, 4, 11], [5, 9, 11, 13], [0, 1, 3, 6], [3, 4, 8, 14], [0, 5, 6, 15], [1, 13, 14, 15], [1, 9, 10, 14], [6, 7, 13, 14], [2, 4, 6, 10], [1, 3, 10, 15], [6, 7, 9, 15], [2, 3, 8, 15], [2, 8, 10, 13], [2, 11, 14, 15], [0, 6, 11, 14], [2, 3, 6, 14], [5, 7, 10, 15], [2, 6, 11, 12]]}
5
+ RLMATH_EOF
tasks/construct-mc-bibd-l4-s2/tests/check.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0).
2
+ Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly
3
+ lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream
4
+ (its 0/1 incidence-matrix model does not forbid equal columns)."""
5
+ import itertools
6
+
7
+ from run import Invalid, int_list
8
+
9
+
10
+ def check(inst, ans):
11
+ v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"]
12
+ blocks = ans.get("blocks")
13
+ if not isinstance(blocks, list) or len(blocks) != b:
14
+ raise Invalid(f"blocks must be a list of exactly {b} blocks")
15
+ pair = {}
16
+ for B in blocks:
17
+ B = int_list(B, k, 0, v - 1, "block")
18
+ if len(set(B)) != k:
19
+ raise Invalid("a block contains a repeated point")
20
+ for p in itertools.combinations(sorted(B), 2):
21
+ pair[p] = pair.get(p, 0) + 1
22
+ for p in itertools.combinations(range(v), 2):
23
+ if pair.get(p, 0) != lam:
24
+ raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}")
25
+ return None, {}
tasks/construct-mc-bibd-l4-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 16, "k": 4, "lambda": 3, "b": 60, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l4-s2/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-mc-bibd-l4-s2/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-bibd-l4-s5/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-mc-bibd-l4-s5/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 19, "k": 9, "lambda": 4, "b": 19, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l4-s5/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"blocks": [[1, 4, 5, 6, 7, 9, 11, 16, 17], [2, 5, 6, 7, 8, 10, 12, 17, 18], [0, 3, 6, 7, 8, 9, 11, 13, 18], [0, 1, 4, 7, 8, 9, 10, 12, 14], [1, 2, 5, 8, 9, 10, 11, 13, 15], [2, 3, 6, 9, 10, 11, 12, 14, 16], [3, 4, 7, 10, 11, 12, 13, 15, 17], [4, 5, 8, 11, 12, 13, 14, 16, 18], [0, 5, 6, 9, 12, 13, 14, 15, 17], [1, 6, 7, 10, 13, 14, 15, 16, 18], [0, 2, 7, 8, 11, 14, 15, 16, 17], [1, 3, 8, 9, 12, 15, 16, 17, 18], [0, 2, 4, 9, 10, 13, 16, 17, 18], [0, 1, 3, 5, 10, 11, 14, 17, 18], [0, 1, 2, 4, 6, 11, 12, 15, 18], [0, 1, 2, 3, 5, 7, 12, 13, 16], [1, 2, 3, 4, 6, 8, 13, 14, 17], [2, 3, 4, 5, 7, 9, 14, 15, 18], [0, 3, 4, 5, 6, 8, 10, 15, 16]]}
5
+ RLMATH_EOF
tasks/construct-mc-bibd-l4-s5/tests/check.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0).
2
+ Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly
3
+ lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream
4
+ (its 0/1 incidence-matrix model does not forbid equal columns)."""
5
+ import itertools
6
+
7
+ from run import Invalid, int_list
8
+
9
+
10
+ def check(inst, ans):
11
+ v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"]
12
+ blocks = ans.get("blocks")
13
+ if not isinstance(blocks, list) or len(blocks) != b:
14
+ raise Invalid(f"blocks must be a list of exactly {b} blocks")
15
+ pair = {}
16
+ for B in blocks:
17
+ B = int_list(B, k, 0, v - 1, "block")
18
+ if len(set(B)) != k:
19
+ raise Invalid("a block contains a repeated point")
20
+ for p in itertools.combinations(sorted(B), 2):
21
+ pair[p] = pair.get(p, 0) + 1
22
+ for p in itertools.combinations(range(v), 2):
23
+ if pair.get(p, 0) != lam:
24
+ raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}")
25
+ return None, {}
tasks/construct-mc-bibd-l4-s5/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 19, "k": 9, "lambda": 4, "b": 19, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l4-s5/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-mc-bibd-l4-s5/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-debruijn-l4-s2/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-mc-debruijn-l4-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"b": 4, "n": 4, "family": "mc_debruijn", "subset": "construct"}
tasks/construct-mc-debruijn-l4-s2/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"seq": [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 2, 1, 0, 0, 2, 2, 0, 0, 2, 3, 0, 0, 3, 1, 0, 0, 3, 2, 0, 0, 3, 3, 0, 1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 1, 1, 0, 1, 1, 2, 0, 1, 1, 3, 0, 1, 2, 1, 0, 1, 2, 2, 0, 1, 2, 3, 0, 1, 3, 1, 0, 1, 3, 2, 0, 1, 3, 3, 0, 2, 0, 2, 0, 3, 0, 2, 1, 1, 0, 2, 1, 2, 0, 2, 1, 3, 0, 2, 2, 1, 0, 2, 2, 2, 0, 2, 2, 3, 0, 2, 3, 1, 0, 2, 3, 2, 0, 2, 3, 3, 0, 3, 0, 3, 1, 1, 0, 3, 1, 2, 0, 3, 1, 3, 0, 3, 2, 1, 0, 3, 2, 2, 0, 3, 2, 3, 0, 3, 3, 1, 0, 3, 3, 2, 0, 3, 3, 3, 1, 1, 1, 1, 2, 1, 1, 1, 3, 1, 1, 2, 2, 1, 1, 2, 3, 1, 1, 3, 2, 1, 1, 3, 3, 1, 2, 1, 2, 1, 3, 1, 2, 2, 2, 1, 2, 2, 3, 1, 2, 3, 2, 1, 2, 3, 3, 1, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 3, 2, 1, 3, 3, 3, 2, 2, 2, 2, 3, 2, 2, 3, 3, 2, 3, 2, 3, 3, 3, 3]}
5
+ RLMATH_EOF
tasks/construct-mc-debruijn-l4-s2/tests/check.py ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence."""
2
+ from run import Invalid, int_list
3
+
4
+
5
+ def check(inst, ans):
6
+ b, n = inst["b"], inst["n"]
7
+ m = b ** n
8
+ x = int_list(ans.get("seq"), m, 0, b - 1, "seq")
9
+ seen = set()
10
+ for i in range(m):
11
+ w = tuple(x[(i + k) % m] for k in range(n))
12
+ if w in seen:
13
+ raise Invalid(f"window {w} occurs twice")
14
+ seen.add(w)
15
+ return None, {}
tasks/construct-mc-debruijn-l4-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"b": 4, "n": 4, "family": "mc_debruijn", "subset": "construct"}
tasks/construct-mc-debruijn-l4-s2/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-mc-debruijn-l4-s2/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-golomb-l6-s2/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json
tasks/construct-mc-golomb-l6-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 18, "max_length": 216, "fixed": [], "family": "mc_golomb", "subset": "construct"}
tasks/construct-mc-golomb-l6-s2/solution/solve.sh ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # oracle: a known valid construction (planted witness or published solution)
3
+ cat > /workdir/answer.json <<'RLMATH_EOF'
4
+ {"marks": [0, 2, 10, 22, 53, 56, 82, 83, 89, 98, 130, 148, 153, 167, 188, 192, 205, 216]}
5
+ RLMATH_EOF
tasks/construct-mc-golomb-l6-s2/tests/check.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision
2
+ problem with the target length stated). Accepts any valid ruler.
3
+ Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation
4
+ model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..)
5
+ was accepted. Here the length bound is part of the instance and enforced."""
6
+ import itertools
7
+
8
+ from run import Invalid, int_list
9
+
10
+
11
+ def check(inst, ans):
12
+ n, L = inst["n"], inst["max_length"]
13
+ a = int_list(ans.get("marks"), n, 0, L, "marks")
14
+ if a[0] != 0:
15
+ raise Invalid("first mark must be 0")
16
+ if any(a[i] >= a[i + 1] for i in range(n - 1)):
17
+ raise Invalid("marks must be strictly increasing")
18
+ for name, i, v in inst.get("fixed", []):
19
+ if a[i] != v:
20
+ raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
21
+ seen = set()
22
+ for i, j in itertools.combinations(range(n), 2):
23
+ d = a[j] - a[i]
24
+ if d in seen:
25
+ raise Invalid(f"difference {d} occurs twice")
26
+ seen.add(d)
27
+ return None, {"length": a[-1]}
tasks/construct-mc-golomb-l6-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 18, "max_length": 216, "fixed": [], "family": "mc_golomb", "subset": "construct"}
tasks/construct-mc-golomb-l6-s2/tests/run.py ADDED
@@ -0,0 +1,127 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
2
+
3
+ Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
4
+
5
+ python3 /tests/run.py /tests/instance.json /workdir/answer.json
6
+
7
+ Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
8
+
9
+ check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
10
+ construct : value is ignored; a returned check means the witness is valid -> reward 1.0
11
+ optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
12
+ progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
13
+ clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
14
+ inst must carry "direction", "baseline", "best_known".
15
+ """
16
+ import json
17
+ import math
18
+ import os
19
+ import sys
20
+
21
+ VALID_FLOOR = 0.1
22
+
23
+
24
+ class Invalid(Exception):
25
+ pass
26
+
27
+
28
+ # ------------------------------------------------------------ input helpers
29
+
30
+ def int_list(v, n=None, lo=None, hi=None, name="list"):
31
+ if not isinstance(v, list):
32
+ raise Invalid(f"{name} must be a list")
33
+ if n is not None and len(v) != n:
34
+ raise Invalid(f"{name} must have length {n}, got {len(v)}")
35
+ for x in v:
36
+ if isinstance(x, bool) or not isinstance(x, int):
37
+ raise Invalid(f"{name} must contain integers only")
38
+ if (lo is not None and x < lo) or (hi is not None and x > hi):
39
+ raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
40
+ return v
41
+
42
+
43
+ def as_int(x, name="value", lo=None, hi=None):
44
+ return int_list([x], 1, lo, hi, name)[0]
45
+
46
+
47
+ def num(x, name="value"):
48
+ if isinstance(x, bool) or not isinstance(x, (int, float)):
49
+ raise Invalid(f"{name} must be a number")
50
+ if not math.isfinite(x):
51
+ raise Invalid(f"{name} is not finite")
52
+ return float(x)
53
+
54
+
55
+ def float_matrix(v, rows=None, cols=None, name="matrix"):
56
+ if not isinstance(v, list) or (rows is not None and len(v) != rows):
57
+ raise Invalid(f"{name} must be a list of {rows} rows")
58
+ out = []
59
+ for r in v:
60
+ if not isinstance(r, list) or (cols is not None and len(r) != cols):
61
+ raise Invalid(f"each row of {name} must have {cols} numbers")
62
+ out.append([num(x, name) for x in r])
63
+ return out
64
+
65
+
66
+ def float_list(v, n=None, name="list"):
67
+ if not isinstance(v, list) or (n is not None and len(v) != n):
68
+ raise Invalid(f"{name} must be a list of length {n}")
69
+ return [num(x, name) for x in v]
70
+
71
+
72
+ # ------------------------------------------------------------------ reward
73
+
74
+ def optimize_reward(inst, s):
75
+ b, best = inst["baseline"], inst["best_known"]
76
+ if inst.get("progress_scale") == "log":
77
+ # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
78
+ # progress is measured in log10(value + floor)
79
+ f = inst.get("log_floor", 1e-3)
80
+ b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
81
+ if inst["direction"] == "maximize":
82
+ p = (s - b) / (best - b)
83
+ else:
84
+ p = (b - s) / (b - best)
85
+ return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
86
+
87
+
88
+ def grade(inst, ans, check):
89
+ try:
90
+ if not isinstance(ans, dict):
91
+ raise Invalid("answer must be a JSON object")
92
+ value, extra = check(inst, ans)
93
+ if inst.get("subset") == "optimize":
94
+ s = float(value)
95
+ if not math.isfinite(s):
96
+ raise Invalid("non-finite score")
97
+ return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
98
+ return 1.0, {"valid": True, **(extra or {})}
99
+ except Invalid as e:
100
+ return 0.0, {"valid": False, "error": str(e)}
101
+ except Exception as e: # any malformed answer
102
+ return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
103
+
104
+
105
+ def main():
106
+ here = os.path.dirname(os.path.abspath(__file__))
107
+ sys.path.insert(0, here)
108
+ # import ourselves as `run` so check.py's `from run import Invalid` is the same class
109
+ import run as R # noqa: E402
110
+ import check as family # noqa: E402
111
+
112
+ inst = json.load(open(sys.argv[1]))
113
+ try:
114
+ ans = json.load(open(sys.argv[2]))
115
+ except Exception as e:
116
+ reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
117
+ else:
118
+ reward, det = R.grade(inst, ans, family.check)
119
+ det["reward"] = reward
120
+ if os.path.isdir("/logs/verifier"):
121
+ with open("/logs/verifier/details.json", "w") as f:
122
+ json.dump(det, f)
123
+ print(reward)
124
+
125
+
126
+ if __name__ == "__main__":
127
+ main()
tasks/construct-mc-golomb-l6-s2/tests/test.sh ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ mkdir -p /logs/verifier
3
+ if [ ! -s /workdir/answer.json ]; then
4
+ echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
5
+ echo 0 > /logs/verifier/reward.txt
6
+ exit 0
7
+ fi
8
+ timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
9
+ > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
tasks/construct-mc-graph-k-coloring-l4-s1/environment/Dockerfile ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ FROM python:3.11.16-slim
2
+ RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
3
+ && rm -rf /var/lib/apt/lists/*
4
+ RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
5
+ python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
6
+ WORKDIR /workdir
7
+ COPY instance.json /workdir/instance.json