amphora commited on
Commit
552d4df
·
verified ·
1 Parent(s): 821fbb4

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-p38-factorial-factors-l3-s3/environment/Dockerfile +7 -0
  2. tasks/construct-ae-p38-factorial-factors-l3-s3/environment/instance.json +1 -0
  3. tasks/construct-ae-p38-factorial-factors-l3-s3/solution/solve.sh +5 -0
  4. tasks/construct-ae-p38-factorial-factors-l3-s3/tests/check.py +12 -0
  5. tasks/construct-ae-p38-factorial-factors-l3-s3/tests/instance.json +1 -0
  6. tasks/construct-ae-p38-factorial-factors-l3-s3/tests/run.py +127 -0
  7. tasks/construct-ae-p38-factorial-factors-l3-s3/tests/test.sh +9 -0
  8. tasks/construct-ae-p38-factorial-factors-l3-s4/environment/Dockerfile +7 -0
  9. tasks/construct-ae-p38-factorial-factors-l3-s4/environment/instance.json +1 -0
  10. tasks/construct-ae-p38-factorial-factors-l3-s4/solution/solve.sh +5 -0
  11. tasks/construct-ae-p38-factorial-factors-l3-s4/tests/check.py +12 -0
  12. tasks/construct-ae-p38-factorial-factors-l3-s4/tests/instance.json +1 -0
  13. tasks/construct-ae-p38-factorial-factors-l3-s4/tests/run.py +127 -0
  14. tasks/construct-ae-p38-factorial-factors-l3-s4/tests/test.sh +9 -0
  15. tasks/construct-ae-p52-erdos-squarefree-l3-s8/environment/Dockerfile +7 -0
  16. tasks/construct-ae-p52-erdos-squarefree-l3-s8/environment/instance.json +1 -0
  17. tasks/construct-ae-p52-erdos-squarefree-l3-s8/solution/solve.sh +5 -0
  18. tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/check.py +38 -0
  19. tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/instance.json +1 -0
  20. tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/run.py +127 -0
  21. tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/test.sh +9 -0
  22. tasks/construct-mc-bibd-l4-s1/environment/Dockerfile +7 -0
  23. tasks/construct-mc-bibd-l4-s1/environment/instance.json +1 -0
  24. tasks/construct-mc-bibd-l4-s1/solution/solve.sh +5 -0
  25. tasks/construct-mc-bibd-l4-s1/tests/check.py +25 -0
  26. tasks/construct-mc-bibd-l4-s1/tests/instance.json +1 -0
  27. tasks/construct-mc-bibd-l4-s1/tests/run.py +127 -0
  28. tasks/construct-mc-bibd-l4-s1/tests/test.sh +9 -0
  29. tasks/construct-mc-costas-array-l1-s3/environment/Dockerfile +7 -0
  30. tasks/construct-mc-costas-array-l1-s3/environment/instance.json +1 -0
  31. tasks/construct-mc-costas-array-l1-s3/solution/solve.sh +5 -0
  32. tasks/construct-mc-costas-array-l1-s3/tests/check.py +22 -0
  33. tasks/construct-mc-costas-array-l1-s3/tests/instance.json +1 -0
  34. tasks/construct-mc-costas-array-l1-s3/tests/run.py +127 -0
  35. tasks/construct-mc-costas-array-l1-s3/tests/test.sh +9 -0
  36. tasks/construct-mc-costas-array-l1-s4/environment/Dockerfile +7 -0
  37. tasks/construct-mc-costas-array-l1-s4/environment/instance.json +1 -0
  38. tasks/construct-mc-costas-array-l1-s4/solution/solve.sh +5 -0
  39. tasks/construct-mc-costas-array-l1-s4/tests/check.py +22 -0
  40. tasks/construct-mc-costas-array-l1-s4/tests/instance.json +1 -0
  41. tasks/construct-mc-costas-array-l1-s4/tests/run.py +127 -0
  42. tasks/construct-mc-costas-array-l1-s4/tests/test.sh +9 -0
  43. tasks/construct-mc-golomb-l2-s0/environment/Dockerfile +7 -0
  44. tasks/construct-mc-golomb-l2-s0/environment/instance.json +1 -0
  45. tasks/construct-mc-golomb-l2-s0/solution/solve.sh +5 -0
  46. tasks/construct-mc-golomb-l2-s0/tests/check.py +27 -0
  47. tasks/construct-mc-golomb-l2-s0/tests/instance.json +1 -0
  48. tasks/construct-mc-golomb-l2-s0/tests/run.py +127 -0
  49. tasks/construct-mc-golomb-l2-s0/tests/test.sh +9 -0
  50. tasks/construct-mc-golomb-l6-s1/environment/Dockerfile +7 -0
tasks/construct-ae-p38-factorial-factors-l3-s3/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-p38-factorial-factors-l3-s3/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 275, "t": 83, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s3/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
+ {"factors": [83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 97, 97, 101, 101, 103, 103, 104, 104, 104, 104, 104, 104, 104, 106, 106, 106, 106, 106, 107, 107, 109, 109, 111, 111, 111, 111, 111, 111, 111, 113, 113, 118, 118, 118, 118, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 127, 127, 128, 128, 131, 131, 134, 134, 134, 134, 137, 137, 139, 142, 142, 142, 146, 146, 146, 149, 151, 157, 158, 158, 158, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271]}
5
+ RLMATH_EOF
tasks/construct-ae-p38-factorial-factors-l3-s3/tests/check.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check."""
2
+ import math
3
+
4
+ from run import Invalid, int_list
5
+
6
+
7
+ def check(inst, ans):
8
+ n, t = inst["N"], inst["t"]
9
+ f = int_list(ans.get("factors"), n, t, None, "factors")
10
+ if math.prod(f) != math.factorial(n):
11
+ raise Invalid(f"the product of the factors is not {n}!")
12
+ return None, {"min_factor": min(f)}
tasks/construct-ae-p38-factorial-factors-l3-s3/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 275, "t": 83, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s3/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-p38-factorial-factors-l3-s3/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-p38-factorial-factors-l3-s4/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-p38-factorial-factors-l3-s4/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 284, "t": 85, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s4/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
+ {"factors": [85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 101, 101, 102, 102, 102, 102, 102, 103, 103, 106, 106, 106, 106, 106, 107, 107, 109, 109, 111, 111, 111, 111, 111, 111, 111, 113, 113, 118, 118, 118, 118, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 126, 127, 127, 128, 131, 131, 134, 134, 134, 134, 137, 137, 139, 139, 142, 142, 142, 142, 146, 146, 146, 149, 151, 157, 158, 158, 158, 163, 166, 166, 166, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283]}
5
+ RLMATH_EOF
tasks/construct-ae-p38-factorial-factors-l3-s4/tests/check.py ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check."""
2
+ import math
3
+
4
+ from run import Invalid, int_list
5
+
6
+
7
+ def check(inst, ans):
8
+ n, t = inst["N"], inst["t"]
9
+ f = int_list(ans.get("factors"), n, t, None, "factors")
10
+ if math.prod(f) != math.factorial(n):
11
+ raise Invalid(f"the product of the factors is not {n}!")
12
+ return None, {"min_factor": min(f)}
tasks/construct-ae-p38-factorial-factors-l3-s4/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 284, "t": 85, "family": "ae_p38_factorial_factors", "subset": "construct"}
tasks/construct-ae-p38-factorial-factors-l3-s4/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-p38-factorial-factors-l3-s4/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-p52-erdos-squarefree-l3-s8/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-s8/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 1067, "t": 43, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s8/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]}
5
+ RLMATH_EOF
tasks/construct-ae-p52-erdos-squarefree-l3-s8/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-s8/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"N": 1067, "t": 43, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
tasks/construct-ae-p52-erdos-squarefree-l3-s8/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-s8/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-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-l4-s1/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 13, "k": 3, "lambda": 2, "b": 52, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l4-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": [[2, 5, 7], [5, 10, 11], [0, 11, 12], [0, 10, 12], [0, 1, 5], [0, 3, 10], [0, 5, 11], [0, 3, 9], [0, 1, 2], [5, 10, 12], [1, 7, 12], [1, 5, 9], [5, 8, 9], [1, 7, 11], [1, 9, 11], [1, 3, 12], [2, 9, 11], [2, 5, 12], [7, 9, 10], [2, 6, 7], [3, 7, 11], [3, 7, 9], [0, 2, 6], [1, 3, 6], [3, 6, 12], [2, 3, 10], [2, 3, 8], [2, 11, 12], [8, 10, 11], [1, 2, 8], [3, 8, 11], [4, 8, 12], [0, 8, 9], [0, 4, 7], [3, 4, 5], [3, 4, 5], [1, 4, 10], [4, 9, 12], [2, 4, 10], [1, 4, 8], [4, 6, 11], [2, 4, 9], [0, 4, 7], [4, 6, 11], [5, 6, 7], [5, 6, 8], [6, 9, 10], [1, 6, 10], [7, 8, 12], [7, 8, 10], [0, 6, 8], [6, 9, 12]]}
5
+ RLMATH_EOF
tasks/construct-mc-bibd-l4-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-l4-s1/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"v": 13, "k": 3, "lambda": 2, "b": 52, "family": "mc_bibd", "subset": "construct"}
tasks/construct-mc-bibd-l4-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-l4-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-costas-array-l1-s3/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-costas-array-l1-s3/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 5, "fixed": [], "family": "mc_costas_array", "subset": "construct"}
tasks/construct-mc-costas-array-l1-s3/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
+ {"x": [0, 2, 3, 1, 4]}
5
+ RLMATH_EOF
tasks/construct-mc-costas-array-l1-s3/tests/check.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array.
2
+ Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment)."""
3
+ import itertools
4
+
5
+ from run import Invalid, int_list
6
+
7
+
8
+ def check(inst, ans):
9
+ n = inst["n"]
10
+ x = int_list(ans.get("x"), n, 0, n - 1, "x")
11
+ if sorted(x) != list(range(n)):
12
+ raise Invalid("x is not a permutation of 0..n-1")
13
+ for name, i, v in inst.get("fixed", []):
14
+ if x[i] != v:
15
+ raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
16
+ vecs = set()
17
+ for i, j in itertools.combinations(range(n), 2):
18
+ d = (j - i, x[j] - x[i])
19
+ if d in vecs:
20
+ raise Invalid(f"repeated displacement vector {d}")
21
+ vecs.add(d)
22
+ return None, {}
tasks/construct-mc-costas-array-l1-s3/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 5, "fixed": [], "family": "mc_costas_array", "subset": "construct"}
tasks/construct-mc-costas-array-l1-s3/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-costas-array-l1-s3/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-costas-array-l1-s4/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-costas-array-l1-s4/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 7, "fixed": [["x", 1, 1]], "family": "mc_costas_array", "subset": "construct"}
tasks/construct-mc-costas-array-l1-s4/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
+ {"x": [0, 1, 6, 4, 3, 5, 2]}
5
+ RLMATH_EOF
tasks/construct-mc-costas-array-l1-s4/tests/check.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array.
2
+ Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment)."""
3
+ import itertools
4
+
5
+ from run import Invalid, int_list
6
+
7
+
8
+ def check(inst, ans):
9
+ n = inst["n"]
10
+ x = int_list(ans.get("x"), n, 0, n - 1, "x")
11
+ if sorted(x) != list(range(n)):
12
+ raise Invalid("x is not a permutation of 0..n-1")
13
+ for name, i, v in inst.get("fixed", []):
14
+ if x[i] != v:
15
+ raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
16
+ vecs = set()
17
+ for i, j in itertools.combinations(range(n), 2):
18
+ d = (j - i, x[j] - x[i])
19
+ if d in vecs:
20
+ raise Invalid(f"repeated displacement vector {d}")
21
+ vecs.add(d)
22
+ return None, {}
tasks/construct-mc-costas-array-l1-s4/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 7, "fixed": [["x", 1, 1]], "family": "mc_costas_array", "subset": "construct"}
tasks/construct-mc-costas-array-l1-s4/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-costas-array-l1-s4/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-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-mc-golomb-l2-s0/environment/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 9, "max_length": 44, "fixed": [], "family": "mc_golomb", "subset": "construct"}
tasks/construct-mc-golomb-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
+ {"marks": [0, 1, 5, 12, 25, 27, 35, 41, 44]}
5
+ RLMATH_EOF
tasks/construct-mc-golomb-l2-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-l2-s0/tests/instance.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"n": 9, "max_length": 44, "fixed": [], "family": "mc_golomb", "subset": "construct"}
tasks/construct-mc-golomb-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-mc-golomb-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-mc-golomb-l6-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