amphora commited on
Commit
2b2efc5
·
verified ·
1 Parent(s): 0e5db60

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-mc-bibd-l2-s1/environment/Dockerfile +7 -0
  2. tasks/construct-mc-bibd-l2-s1/environment/instance.json +1 -0
  3. tasks/construct-mc-bibd-l2-s1/solution/solve.sh +5 -0
  4. tasks/construct-mc-bibd-l2-s1/tests/check.py +25 -0
  5. tasks/construct-mc-bibd-l2-s1/tests/instance.json +1 -0
  6. tasks/construct-mc-bibd-l2-s1/tests/run.py +127 -0
  7. tasks/construct-mc-bibd-l2-s1/tests/test.sh +9 -0
  8. tasks/construct-mc-bibd-l5-s2/environment/Dockerfile +7 -0
  9. tasks/construct-mc-bibd-l5-s2/environment/instance.json +1 -0
  10. tasks/construct-mc-bibd-l5-s2/solution/solve.sh +5 -0
  11. tasks/construct-mc-bibd-l5-s2/tests/check.py +25 -0
  12. tasks/construct-mc-bibd-l5-s2/tests/instance.json +1 -0
  13. tasks/construct-mc-bibd-l5-s2/tests/run.py +127 -0
  14. tasks/construct-mc-bibd-l5-s2/tests/test.sh +9 -0
  15. tasks/construct-mc-golomb-l4-s0/environment/Dockerfile +7 -0
  16. tasks/construct-mc-golomb-l4-s0/environment/instance.json +1 -0
  17. tasks/construct-mc-golomb-l4-s0/solution/solve.sh +5 -0
  18. tasks/construct-mc-golomb-l4-s0/tests/check.py +27 -0
  19. tasks/construct-mc-golomb-l4-s0/tests/instance.json +1 -0
  20. tasks/construct-mc-golomb-l4-s0/tests/run.py +127 -0
  21. tasks/construct-mc-golomb-l4-s0/tests/test.sh +9 -0
  22. tasks/construct-mc-graph-k-coloring-l1-s0/environment/Dockerfile +7 -0
  23. tasks/construct-mc-graph-k-coloring-l1-s0/environment/instance.json +1 -0
  24. tasks/construct-mc-graph-k-coloring-l1-s0/solution/solve.sh +5 -0
  25. tasks/construct-mc-graph-k-coloring-l1-s0/tests/check.py +11 -0
  26. tasks/construct-mc-graph-k-coloring-l1-s0/tests/instance.json +1 -0
  27. tasks/construct-mc-graph-k-coloring-l1-s0/tests/run.py +127 -0
  28. tasks/construct-mc-graph-k-coloring-l1-s0/tests/test.sh +9 -0
  29. tasks/construct-mc-graph-k-coloring-l1-s7/environment/Dockerfile +7 -0
  30. tasks/construct-mc-graph-k-coloring-l1-s7/environment/instance.json +1 -0
  31. tasks/construct-mc-graph-k-coloring-l1-s7/solution/solve.sh +5 -0
  32. tasks/construct-mc-graph-k-coloring-l1-s7/tests/check.py +11 -0
  33. tasks/construct-mc-graph-k-coloring-l1-s7/tests/instance.json +1 -0
  34. tasks/construct-mc-graph-k-coloring-l1-s7/tests/run.py +127 -0
  35. tasks/construct-mc-graph-k-coloring-l1-s7/tests/test.sh +9 -0
  36. tasks/construct-mc-graph-k-coloring-l1-s9/environment/Dockerfile +7 -0
  37. tasks/construct-mc-graph-k-coloring-l1-s9/environment/instance.json +1 -0
  38. tasks/construct-mc-graph-k-coloring-l1-s9/solution/solve.sh +5 -0
  39. tasks/construct-mc-graph-k-coloring-l1-s9/tests/check.py +11 -0
  40. tasks/construct-mc-graph-k-coloring-l1-s9/tests/instance.json +1 -0
  41. tasks/construct-mc-graph-k-coloring-l1-s9/tests/run.py +127 -0
  42. tasks/construct-mc-graph-k-coloring-l1-s9/tests/test.sh +9 -0
  43. tasks/construct-mc-graph-k-coloring-l5-s1/environment/Dockerfile +7 -0
  44. tasks/construct-mc-graph-k-coloring-l5-s1/environment/instance.json +1 -0
  45. tasks/construct-mc-graph-k-coloring-l5-s1/solution/solve.sh +5 -0
  46. tasks/construct-mc-graph-k-coloring-l5-s1/tests/check.py +11 -0
  47. tasks/construct-mc-graph-k-coloring-l5-s1/tests/instance.json +1 -0
  48. tasks/construct-mc-graph-k-coloring-l5-s1/tests/run.py +127 -0
  49. tasks/construct-mc-graph-k-coloring-l5-s1/tests/test.sh +9 -0
  50. tasks/construct-mc-graph-k-coloring-l5-s6/environment/Dockerfile +7 -0
tasks/construct-mc-bibd-l2-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
tasks/construct-mc-bibd-l2-s1/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 13, "k": 3, "lambda": 1, "b": 26, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l2-s1/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, 4], [1, 2, 5], [2, 3, 6], [3, 4, 7], [4, 5, 8], [5, 6, 9], [6, 7, 10], [7, 8, 11], [8, 9, 12], [0, 9, 10], [1, 10, 11], [2, 11, 12], [0, 3, 12], [0, 2, 7], [1, 3, 8], [2, 4, 9], [3, 5, 10], [4, 6, 11], [5, 7, 12], [0, 6, 8], [1, 7, 9], [2, 8, 10], [3, 9, 11], [4, 10, 12], [0, 5, 11], [1, 6, 12]]}
5
+ RLMATH_EOF
tasks/construct-mc-bibd-l2-s1/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-l2-s1/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 13, "k": 3, "lambda": 1, "b": 26, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l2-s1/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-l2-s1/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-l5-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-l5-s2/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 13, "k": 3, "lambda": 4, "b": 104, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l5-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": [[3, 4, 12], [3, 11, 12], [4, 6, 12], [4, 11, 12], [3, 4, 7], [4, 6, 11], [4, 7, 11], [4, 7, 12], [4, 6, 11], [4, 9, 10], [4, 9, 10], [4, 9, 10], [4, 9, 10], [1, 4, 8], [1, 4, 8], [1, 4, 5], [1, 4, 5], [4, 5, 8], [0, 3, 4], [3, 4, 8], [0, 3, 7], [3, 7, 12], [2, 5, 7], [0, 3, 11], [1, 3, 11], [1, 5, 6], [1, 6, 7], [1, 6, 7], [5, 6, 12], [1, 3, 10], [5, 7, 12], [1, 6, 7], [5, 7, 10], [7, 10, 11], [5, 7, 10], [7, 10, 11], [1, 7, 9], [7, 9, 12], [1, 3, 10], [1, 11, 12], [7, 9, 11], [1, 2, 12], [0, 7, 9], [4, 6, 7], [0, 7, 8], [0, 2, 7], [2, 7, 8], [2, 7, 8], [0, 6, 12], [3, 7, 8], [0, 6, 10], [6, 10, 11], [0, 3, 10], [0, 1, 12], [1, 10, 12], [6, 10, 11], [0, 1, 11], [0, 9, 12], [0, 1, 9], [0, 5, 12], [0, 1, 9], [2, 9, 11], [1, 2, 9], [1, 2, 10], [1, 8, 11], [1, 2, 8], [1, 3, 5], [2, 10, 12], [0, 5, 6], [6, 9, 12], [6, 8, 9], [0, 2, 4], [0, 8, 11], [0, 6, 8], [6, 8, 10], [3, 11, 12], [0, 8, 10], [0, 5, 11], [0, 5, 10], [3, 5, 9], [5, 6, 9], [3, 5, 9], [8, 10, 12], [8, 9, 12], [6, 8, 9], [5, 8, 12], [3, 5, 9], [2, 10, 12], [5, 8, 11], [2, 3, 6], [3, 8, 10], [5, 8, 11], [2, 3, 6], [2, 8, 12], [3, 8, 9], [2, 9, 11], [2, 9, 11], [0, 2, 4], [2, 3, 6], [2, 3, 6], [0, 2, 4], [2, 5, 11], [2, 4, 5], [2, 5, 10]]}
5
+ RLMATH_EOF
tasks/construct-mc-bibd-l5-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-l5-s2/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 13, "k": 3, "lambda": 4, "b": 104, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l5-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-l5-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-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-mc-golomb-l4-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 13, "max_length": 106, "fixed": [], "family": "mc_golomb", "subset": "construct"}
tasks/construct-mc-golomb-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
+ {"marks": [0, 2, 5, 25, 37, 43, 59, 70, 85, 89, 98, 99, 106]}
5
+ RLMATH_EOF
tasks/construct-mc-golomb-l4-s0/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-l4-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 13, "max_length": 106, "fixed": [], "family": "mc_golomb", "subset": "construct"}
tasks/construct-mc-golomb-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-mc-golomb-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-graph-k-coloring-l1-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-mc-graph-k-coloring-l1-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 20, "k": 3, "edges": [[0, 2], [0, 8], [0, 12], [0, 13], [0, 16], [0, 17], [1, 11], [2, 4], [2, 13], [3, 5], [3, 9], [3, 15], [3, 16], [4, 13], [4, 16], [4, 17], [5, 14], [5, 15], [7, 16], [9, 14], [9, 19], [10, 13], [10, 17], [11, 16], [13, 17], [13, 19], [14, 18], [14, 19], [15, 17], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l1-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
+ {"coloring": [1, 0, 0, 1, 1, 0, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 0, 0, 0, 0]}
5
+ RLMATH_EOF
tasks/construct-mc-graph-k-coloring-l1-s0/tests/check.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring."""
2
+ from run import Invalid, int_list
3
+
4
+
5
+ def check(inst, ans):
6
+ n, k = inst["n"], inst["k"]
7
+ c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring")
8
+ for u, v in inst["edges"]:
9
+ if c[u] == c[v]:
10
+ raise Invalid(f"edge ({u},{v}) is monochromatic")
11
+ return None, {}
tasks/construct-mc-graph-k-coloring-l1-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 20, "k": 3, "edges": [[0, 2], [0, 8], [0, 12], [0, 13], [0, 16], [0, 17], [1, 11], [2, 4], [2, 13], [3, 5], [3, 9], [3, 15], [3, 16], [4, 13], [4, 16], [4, 17], [5, 14], [5, 15], [7, 16], [9, 14], [9, 19], [10, 13], [10, 17], [11, 16], [13, 17], [13, 19], [14, 18], [14, 19], [15, 17], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l1-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-mc-graph-k-coloring-l1-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-graph-k-coloring-l1-s7/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-graph-k-coloring-l1-s7/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 20, "k": 3, "edges": [[0, 5], [0, 12], [0, 14], [0, 15], [1, 5], [1, 7], [1, 14], [1, 16], [1, 17], [1, 19], [2, 10], [2, 18], [3, 8], [3, 13], [4, 16], [6, 11], [6, 17], [7, 11], [7, 18], [9, 11], [9, 19], [11, 13], [11, 14], [11, 17], [11, 19], [12, 13], [12, 16], [13, 15], [14, 15], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l1-s7/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
+ {"coloring": [1, 2, 0, 0, 2, 0, 1, 0, 1, 1, 1, 2, 2, 1, 0, 2, 1, 0, 2, 0]}
5
+ RLMATH_EOF
tasks/construct-mc-graph-k-coloring-l1-s7/tests/check.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring."""
2
+ from run import Invalid, int_list
3
+
4
+
5
+ def check(inst, ans):
6
+ n, k = inst["n"], inst["k"]
7
+ c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring")
8
+ for u, v in inst["edges"]:
9
+ if c[u] == c[v]:
10
+ raise Invalid(f"edge ({u},{v}) is monochromatic")
11
+ return None, {}
tasks/construct-mc-graph-k-coloring-l1-s7/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 20, "k": 3, "edges": [[0, 5], [0, 12], [0, 14], [0, 15], [1, 5], [1, 7], [1, 14], [1, 16], [1, 17], [1, 19], [2, 10], [2, 18], [3, 8], [3, 13], [4, 16], [6, 11], [6, 17], [7, 11], [7, 18], [9, 11], [9, 19], [11, 13], [11, 14], [11, 17], [11, 19], [12, 13], [12, 16], [13, 15], [14, 15], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l1-s7/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-graph-k-coloring-l1-s7/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-l1-s9/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-graph-k-coloring-l1-s9/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 20, "k": 3, "edges": [[1, 7], [1, 8], [2, 5], [2, 7], [2, 8], [3, 6], [3, 15], [3, 16], [4, 5], [4, 7], [4, 11], [5, 7], [6, 9], [6, 14], [6, 19], [7, 9], [7, 10], [9, 11], [10, 14], [11, 15], [12, 14], [12, 15], [13, 14], [13, 17], [13, 18], [15, 17], [15, 18], [16, 18], [16, 19], [17, 19]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l1-s9/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
+ {"coloring": [0, 1, 1, 0, 1, 0, 1, 2, 2, 0, 1, 2, 2, 1, 0, 1, 2, 2, 0, 0]}
5
+ RLMATH_EOF
tasks/construct-mc-graph-k-coloring-l1-s9/tests/check.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring."""
2
+ from run import Invalid, int_list
3
+
4
+
5
+ def check(inst, ans):
6
+ n, k = inst["n"], inst["k"]
7
+ c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring")
8
+ for u, v in inst["edges"]:
9
+ if c[u] == c[v]:
10
+ raise Invalid(f"edge ({u},{v}) is monochromatic")
11
+ return None, {}
tasks/construct-mc-graph-k-coloring-l1-s9/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 20, "k": 3, "edges": [[1, 7], [1, 8], [2, 5], [2, 7], [2, 8], [3, 6], [3, 15], [3, 16], [4, 5], [4, 7], [4, 11], [5, 7], [6, 9], [6, 14], [6, 19], [7, 9], [7, 10], [9, 11], [10, 14], [11, 15], [12, 14], [12, 15], [13, 14], [13, 17], [13, 18], [15, 17], [15, 18], [16, 18], [16, 19], [17, 19]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l1-s9/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-graph-k-coloring-l1-s9/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-l5-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
tasks/construct-mc-graph-k-coloring-l5-s1/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 100, "k": 4, "edges": [[0, 1], [0, 10], [0, 17], [0, 23], [0, 44], [0, 48], [0, 51], [0, 68], [0, 85], [1, 17], [1, 37], [1, 80], [1, 83], [1, 92], [2, 7], [2, 10], [2, 13], [2, 63], [2, 64], [2, 92], [3, 25], [3, 27], [3, 42], [3, 53], [3, 92], [3, 94], [4, 8], [4, 19], [4, 25], [4, 26], [4, 48], [4, 54], [4, 63], [4, 73], [4, 74], [4, 77], [4, 94], [5, 6], [5, 9], [5, 43], [5, 44], [5, 77], [5, 85], [6, 23], [6, 28], [6, 30], [6, 40], [6, 42], [6, 47], [6, 54], [6, 64], [6, 69], [6, 81], [6, 82], [6, 93], [7, 24], [7, 25], [7, 48], [7, 49], [7, 83], [7, 99], [8, 19], [8, 60], [8, 61], [8, 73], [8, 89], [8, 94], [9, 36], [9, 43], [9, 73], [9, 74], [9, 81], [9, 82], [10, 17], [10, 30], [10, 60], [10, 63], [10, 70], [10, 76], [11, 54], [11, 56], [11, 73], [11, 92], [11, 93], [12, 26], [12, 31], [12, 43], [12, 57], [12, 60], [12, 64], [12, 68], [12, 73], [12, 78], [12, 88], [13, 16], [13, 23], [13, 47], [13, 51], [13, 58], [13, 65], [13, 76], [13, 83], [13, 93], [13, 99], [14, 32], [14, 34], [14, 42], [14, 56], [14, 84], [14, 95], [15, 43], [15, 59], [15, 66], [16, 22], [16, 49], [16, 55], [16, 84], [16, 87], [16, 89], [16, 93], [16, 97], [17, 40], [17, 41], [17, 45], [17, 49], [17, 73], [17, 90], [18, 30], [18, 32], [18, 67], [18, 70], [18, 76], [18, 94], [20, 21], [20, 22], [20, 33], [20, 35], [20, 81], [20, 93], [20, 98], [21, 52], [21, 54], [21, 59], [21, 66], [21, 77], [21, 82], [22, 61], [22, 65], [22, 80], [22, 82], [23, 27], [23, 40], [23, 53], [23, 84], [23, 93], [24, 36], [24, 59], [24, 70], [24, 97], [25, 32], [25, 41], [25, 52], [25, 79], [25, 94], [26, 52], [26, 67], [26, 80], [26, 85], [27, 32], [27, 66], [28, 29], [28, 52], [28, 57], [28, 97], [28, 99], [29, 38], [29, 74], [29, 77], [29, 87], [29, 90], [30, 36], [30, 37], [30, 43], [30, 44], [30, 57], [30, 62], [30, 77], [30, 85], [31, 32], [31, 44], [31, 58], [31, 64], [31, 81], [31, 84], [31, 94], [32, 46], [32, 51], [32, 62], [32, 63], [33, 55], [33, 61], [33, 65], [33, 81], [33, 86], [34, 49], [34, 55], [34, 61], [34, 68], [34, 73], [34, 87], [34, 91], [34, 92], [35, 52], [35, 62], [35, 92], [35, 97], [36, 52], [36, 55], [36, 62], [36, 66], [36, 87], [36, 94], [36, 96], [36, 97], [37, 38], [37, 42], [37, 52], [37, 58], [37, 64], [37, 73], [37, 74], [37, 77], [37, 84], [37, 85], [38, 39], [38, 54], [38, 83], [38, 86], [38, 89], [38, 98], [39, 60], [39, 67], [39, 85], [40, 42], [40, 56], [40, 70], [40, 82], [40, 83], [40, 95], [41, 45], [41, 53], [41, 63], [41, 74], [41, 77], [41, 92], [42, 59], [42, 66], [42, 72], [42, 74], [42, 81], [42, 89], [42, 96], [42, 98], [43, 46], [43, 47], [43, 50], [43, 61], [43, 66], [43, 67], [43, 82], [43, 84], [44, 59], [44, 90], [44, 91], [45, 71], [45, 86], [46, 56], [47, 53], [47, 55], [47, 91], [47, 92], [48, 62], [48, 80], [48, 85], [48, 87], [49, 69], [49, 71], [49, 81], [49, 83], [49, 93], [49, 95], [50, 60], [50, 63], [50, 88], [51, 53], [51, 56], [51, 66], [51, 82], [51, 85], [51, 88], [52, 71], [53, 60], [53, 71], [53, 81], [53, 87], [53, 99], [54, 64], [54, 70], [54, 71], [54, 73], [54, 83], [54, 89], [54, 90], [54, 95], [54, 96], [55, 59], [55, 66], [55, 71], [55, 76], [55, 81], [55, 90], [55, 93], [56, 68], [56, 85], [56, 91], [57, 61], [57, 94], [58, 68], [58, 74], [58, 75], [58, 76], [58, 77], [59, 60], [60, 66], [60, 84], [60, 85], [60, 98], [61, 64], [61, 74], [62, 64], [62, 68], [62, 71], [62, 73], [62, 80], [62, 84], [62, 97], [63, 69], [63, 77], [63, 83], [63, 97], [64, 92], [64, 97], [66, 73], [66, 77], [67, 70], [67, 90], [68, 70], [68, 77], [68, 86], [68, 99], [69, 97], [70, 85], [71, 86], [71, 97], [71, 98], [72, 74], [73, 87], [73, 89], [73, 92], [73, 93], [73, 94], [74, 83], [74, 92], [75, 84], [75, 88], [75, 90], [75, 91], [75, 96], [76, 86], [76, 87], [76, 92], [76, 97], [77, 98], [78, 82], [78, 84], [79, 86], [79, 88], [80, 97], [81, 98], [82, 88], [83, 96], [84, 96], [85, 90], [86, 92], [87, 95], [89, 94], [92, 93], [93, 95], [93, 97], [95, 99]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l5-s1/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
+ {"coloring": [0, 2, 0, 2, 0, 2, 3, 2, 3, 1, 1, 3, 0, 3, 2, 1, 2, 3, 3, 2, 1, 2, 3, 1, 1, 3, 2, 3, 2, 3, 0, 3, 0, 3, 3, 2, 2, 3, 2, 0, 2, 0, 1, 3, 1, 1, 1, 0, 3, 1, 1, 2, 0, 3, 1, 1, 0, 3, 0, 3, 2, 1, 1, 2, 2, 1, 0, 1, 2, 0, 0, 2, 3, 2, 2, 1, 2, 1, 1, 1, 0, 2, 0, 0, 0, 1, 0, 0, 3, 0, 0, 2, 1, 0, 1, 3, 3, 3, 3, 0]}
5
+ RLMATH_EOF
tasks/construct-mc-graph-k-coloring-l5-s1/tests/check.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring."""
2
+ from run import Invalid, int_list
3
+
4
+
5
+ def check(inst, ans):
6
+ n, k = inst["n"], inst["k"]
7
+ c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring")
8
+ for u, v in inst["edges"]:
9
+ if c[u] == c[v]:
10
+ raise Invalid(f"edge ({u},{v}) is monochromatic")
11
+ return None, {}
tasks/construct-mc-graph-k-coloring-l5-s1/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 100, "k": 4, "edges": [[0, 1], [0, 10], [0, 17], [0, 23], [0, 44], [0, 48], [0, 51], [0, 68], [0, 85], [1, 17], [1, 37], [1, 80], [1, 83], [1, 92], [2, 7], [2, 10], [2, 13], [2, 63], [2, 64], [2, 92], [3, 25], [3, 27], [3, 42], [3, 53], [3, 92], [3, 94], [4, 8], [4, 19], [4, 25], [4, 26], [4, 48], [4, 54], [4, 63], [4, 73], [4, 74], [4, 77], [4, 94], [5, 6], [5, 9], [5, 43], [5, 44], [5, 77], [5, 85], [6, 23], [6, 28], [6, 30], [6, 40], [6, 42], [6, 47], [6, 54], [6, 64], [6, 69], [6, 81], [6, 82], [6, 93], [7, 24], [7, 25], [7, 48], [7, 49], [7, 83], [7, 99], [8, 19], [8, 60], [8, 61], [8, 73], [8, 89], [8, 94], [9, 36], [9, 43], [9, 73], [9, 74], [9, 81], [9, 82], [10, 17], [10, 30], [10, 60], [10, 63], [10, 70], [10, 76], [11, 54], [11, 56], [11, 73], [11, 92], [11, 93], [12, 26], [12, 31], [12, 43], [12, 57], [12, 60], [12, 64], [12, 68], [12, 73], [12, 78], [12, 88], [13, 16], [13, 23], [13, 47], [13, 51], [13, 58], [13, 65], [13, 76], [13, 83], [13, 93], [13, 99], [14, 32], [14, 34], [14, 42], [14, 56], [14, 84], [14, 95], [15, 43], [15, 59], [15, 66], [16, 22], [16, 49], [16, 55], [16, 84], [16, 87], [16, 89], [16, 93], [16, 97], [17, 40], [17, 41], [17, 45], [17, 49], [17, 73], [17, 90], [18, 30], [18, 32], [18, 67], [18, 70], [18, 76], [18, 94], [20, 21], [20, 22], [20, 33], [20, 35], [20, 81], [20, 93], [20, 98], [21, 52], [21, 54], [21, 59], [21, 66], [21, 77], [21, 82], [22, 61], [22, 65], [22, 80], [22, 82], [23, 27], [23, 40], [23, 53], [23, 84], [23, 93], [24, 36], [24, 59], [24, 70], [24, 97], [25, 32], [25, 41], [25, 52], [25, 79], [25, 94], [26, 52], [26, 67], [26, 80], [26, 85], [27, 32], [27, 66], [28, 29], [28, 52], [28, 57], [28, 97], [28, 99], [29, 38], [29, 74], [29, 77], [29, 87], [29, 90], [30, 36], [30, 37], [30, 43], [30, 44], [30, 57], [30, 62], [30, 77], [30, 85], [31, 32], [31, 44], [31, 58], [31, 64], [31, 81], [31, 84], [31, 94], [32, 46], [32, 51], [32, 62], [32, 63], [33, 55], [33, 61], [33, 65], [33, 81], [33, 86], [34, 49], [34, 55], [34, 61], [34, 68], [34, 73], [34, 87], [34, 91], [34, 92], [35, 52], [35, 62], [35, 92], [35, 97], [36, 52], [36, 55], [36, 62], [36, 66], [36, 87], [36, 94], [36, 96], [36, 97], [37, 38], [37, 42], [37, 52], [37, 58], [37, 64], [37, 73], [37, 74], [37, 77], [37, 84], [37, 85], [38, 39], [38, 54], [38, 83], [38, 86], [38, 89], [38, 98], [39, 60], [39, 67], [39, 85], [40, 42], [40, 56], [40, 70], [40, 82], [40, 83], [40, 95], [41, 45], [41, 53], [41, 63], [41, 74], [41, 77], [41, 92], [42, 59], [42, 66], [42, 72], [42, 74], [42, 81], [42, 89], [42, 96], [42, 98], [43, 46], [43, 47], [43, 50], [43, 61], [43, 66], [43, 67], [43, 82], [43, 84], [44, 59], [44, 90], [44, 91], [45, 71], [45, 86], [46, 56], [47, 53], [47, 55], [47, 91], [47, 92], [48, 62], [48, 80], [48, 85], [48, 87], [49, 69], [49, 71], [49, 81], [49, 83], [49, 93], [49, 95], [50, 60], [50, 63], [50, 88], [51, 53], [51, 56], [51, 66], [51, 82], [51, 85], [51, 88], [52, 71], [53, 60], [53, 71], [53, 81], [53, 87], [53, 99], [54, 64], [54, 70], [54, 71], [54, 73], [54, 83], [54, 89], [54, 90], [54, 95], [54, 96], [55, 59], [55, 66], [55, 71], [55, 76], [55, 81], [55, 90], [55, 93], [56, 68], [56, 85], [56, 91], [57, 61], [57, 94], [58, 68], [58, 74], [58, 75], [58, 76], [58, 77], [59, 60], [60, 66], [60, 84], [60, 85], [60, 98], [61, 64], [61, 74], [62, 64], [62, 68], [62, 71], [62, 73], [62, 80], [62, 84], [62, 97], [63, 69], [63, 77], [63, 83], [63, 97], [64, 92], [64, 97], [66, 73], [66, 77], [67, 70], [67, 90], [68, 70], [68, 77], [68, 86], [68, 99], [69, 97], [70, 85], [71, 86], [71, 97], [71, 98], [72, 74], [73, 87], [73, 89], [73, 92], [73, 93], [73, 94], [74, 83], [74, 92], [75, 84], [75, 88], [75, 90], [75, 91], [75, 96], [76, 86], [76, 87], [76, 92], [76, 97], [77, 98], [78, 82], [78, 84], [79, 86], [79, 88], [80, 97], [81, 98], [82, 88], [83, 96], [84, 96], [85, 90], [86, 92], [87, 95], [89, 94], [92, 93], [93, 95], [93, 97], [95, 99]], "family": "mc_graph_k_coloring", "subset": "construct"}
tasks/construct-mc-graph-k-coloring-l5-s1/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-graph-k-coloring-l5-s1/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-l5-s6/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