Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/construct-ae-p58-happy-ending-l3-s0/environment/Dockerfile +7 -0
- tasks/construct-ae-p58-happy-ending-l3-s0/environment/instance.json +1 -0
- tasks/construct-ae-p58-happy-ending-l3-s0/solution/solve.sh +5 -0
- tasks/construct-ae-p58-happy-ending-l3-s0/tests/check.py +69 -0
- tasks/construct-ae-p58-happy-ending-l3-s0/tests/instance.json +1 -0
- tasks/construct-ae-p58-happy-ending-l3-s0/tests/run.py +127 -0
- tasks/construct-ae-p58-happy-ending-l3-s0/tests/test.sh +9 -0
- tasks/construct-mc-bibd-l3-s2/environment/Dockerfile +7 -0
- tasks/construct-mc-bibd-l3-s2/environment/instance.json +1 -0
- tasks/construct-mc-bibd-l3-s2/solution/solve.sh +5 -0
- tasks/construct-mc-bibd-l3-s2/tests/check.py +25 -0
- tasks/construct-mc-bibd-l3-s2/tests/instance.json +1 -0
- tasks/construct-mc-bibd-l3-s2/tests/run.py +127 -0
- tasks/construct-mc-bibd-l3-s2/tests/test.sh +9 -0
- tasks/construct-mc-golomb-l1-s2/environment/Dockerfile +7 -0
- tasks/construct-mc-golomb-l1-s2/environment/instance.json +1 -0
- tasks/construct-mc-golomb-l1-s2/solution/solve.sh +5 -0
- tasks/construct-mc-golomb-l1-s2/tests/check.py +27 -0
- tasks/construct-mc-golomb-l1-s2/tests/instance.json +1 -0
- tasks/construct-mc-golomb-l1-s2/tests/run.py +127 -0
- tasks/construct-mc-golomb-l1-s2/tests/test.sh +9 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/environment/Dockerfile +7 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/environment/instance.json +1 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/solution/solve.sh +5 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/tests/check.py +11 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/tests/instance.json +1 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/tests/run.py +127 -0
- tasks/construct-mc-graph-k-coloring-l3-s6/tests/test.sh +9 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/environment/Dockerfile +7 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/environment/instance.json +1 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/solution/solve.sh +5 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/tests/check.py +20 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/tests/instance.json +1 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/tests/run.py +127 -0
- tasks/construct-mc-low-autocorrelation-l5-s2/tests/test.sh +9 -0
- tasks/construct-mc-number-partitioning-l2-s2/environment/Dockerfile +7 -0
- tasks/construct-mc-number-partitioning-l2-s2/environment/instance.json +1 -0
- tasks/construct-mc-number-partitioning-l2-s2/solution/solve.sh +5 -0
- tasks/construct-mc-number-partitioning-l2-s2/tests/check.py +14 -0
- tasks/construct-mc-number-partitioning-l2-s2/tests/instance.json +1 -0
- tasks/construct-mc-number-partitioning-l2-s2/tests/run.py +127 -0
- tasks/construct-mc-number-partitioning-l2-s2/tests/test.sh +9 -0
- tasks/construct-mc-number-partitioning-l2-s5/environment/Dockerfile +7 -0
- tasks/construct-mc-number-partitioning-l2-s5/environment/instance.json +1 -0
- tasks/construct-mc-number-partitioning-l2-s5/solution/solve.sh +5 -0
- tasks/construct-mc-number-partitioning-l2-s5/tests/check.py +14 -0
- tasks/construct-mc-number-partitioning-l2-s5/tests/instance.json +1 -0
- tasks/construct-mc-number-partitioning-l2-s5/tests/run.py +127 -0
- tasks/construct-mc-number-partitioning-l2-s5/tests/test.sh +9 -0
- tasks/construct-mc-number-partitioning-l6-s3/environment/Dockerfile +7 -0
tasks/construct-ae-p58-happy-ending-l3-s0/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-ae-p58-happy-ending-l3-s0/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 32, "k": 7, "max_abs": 1000000000000000000, "family": "ae_p58_happy_ending", "subset": "construct"}
|
tasks/construct-ae-p58-happy-ending-l3-s0/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"points": [[0, 0], [846000, -846000000], [846001, -845999998], [846002, -845999990], [846003, -845999954], [846004, -845999762], [1692000, -3384000000], [1692001, -3383999990], [1692002, -3383999988], [1692003, -3383999924], [1692004, -3383999922], [1692005, -3383999914], [1692006, -3383999250], [1692007, -3383999248], [1692008, -3383999240], [1692009, -3383999204], [2538000, -7614000000], [2538001, -7613999944], [2538002, -7613999934], [2538003, -7613999932], [2538004, -7613999250], [2538005, -7613999240], [2538006, -7613999238], [2538007, -7613999174], [2538008, -7613999172], [2538009, -7613999164], [3384000, -13536000000], [3384001, -13535999638], [3384002, -13535999582], [3384003, -13535999572], [3384004, -13535999570], [4230000, -21150000000]]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p58-happy-ending-l3-s0/tests/check.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Erdos-Szekeres happy ending (AlphaEvolve problem 58): n = 2^(k-2) integer points in general position with no
|
| 2 |
+
k points in convex position. Exact integer orientation tests; the largest convex-position subset is computed by
|
| 3 |
+
the O(n^4) bottom-vertex / angular-order dynamic programme.
|
| 4 |
+
|
| 5 |
+
Upstream bug: the notebook's verifier uses float orientations with a 1e-9 threshold (and numba fastmath); its
|
| 6 |
+
33- and 65-point sets (claimed to have "0 convex k-gons") contain a convex 7-gon / 8-gon under exact arithmetic."""
|
| 7 |
+
import functools
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
from run import Invalid, int_list
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def orient_table(p):
|
| 15 |
+
n = len(p)
|
| 16 |
+
o = np.zeros((n, n, n), dtype=np.int8)
|
| 17 |
+
for i in range(n):
|
| 18 |
+
xi, yi = p[i]
|
| 19 |
+
for j in range(i + 1, n):
|
| 20 |
+
dx, dy = p[j][0] - xi, p[j][1] - yi
|
| 21 |
+
for k in range(j + 1, n):
|
| 22 |
+
c = dx * (p[k][1] - yi) - dy * (p[k][0] - xi)
|
| 23 |
+
if c == 0:
|
| 24 |
+
raise Invalid(f"points {p[i]}, {p[j]}, {p[k]} are collinear")
|
| 25 |
+
s = 1 if c > 0 else -1
|
| 26 |
+
o[i, j, k] = o[j, k, i] = o[k, i, j] = s
|
| 27 |
+
o[i, k, j] = o[k, j, i] = o[j, i, k] = -s
|
| 28 |
+
return o
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def max_convex(p, o):
|
| 32 |
+
n = len(p)
|
| 33 |
+
best = min(n, 3)
|
| 34 |
+
order = sorted(range(n), key=lambda i: (p[i][1], p[i][0]))
|
| 35 |
+
for bi, b in enumerate(order):
|
| 36 |
+
rest = order[bi + 1:]
|
| 37 |
+
m = len(rest)
|
| 38 |
+
if m < 2:
|
| 39 |
+
continue
|
| 40 |
+
rest = sorted(rest, key=functools.cmp_to_key(lambda u, v: -int(o[b, u, v])))
|
| 41 |
+
r = np.array(rest)
|
| 42 |
+
chain = np.zeros((m, m), dtype=np.int32) # chain[i, j]: longest convex chain b .. r_i -> r_j
|
| 43 |
+
for j in range(1, m):
|
| 44 |
+
for i in range(j):
|
| 45 |
+
v = 3
|
| 46 |
+
if i > 0:
|
| 47 |
+
ok = (chain[:i, i] > 0) & (o[r[:i], r[i], r[j]] > 0)
|
| 48 |
+
if ok.any():
|
| 49 |
+
v = max(v, int(chain[:i, i][ok].max()) + 1)
|
| 50 |
+
chain[i, j] = v
|
| 51 |
+
close = o[r[:j], r[j], b] > 0
|
| 52 |
+
if close.any():
|
| 53 |
+
best = max(best, int(chain[:j, j][close].max()))
|
| 54 |
+
return best
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def check(inst, ans):
|
| 58 |
+
n, k, lim = inst["n"], inst["k"], inst["max_abs"]
|
| 59 |
+
pts = ans.get("points")
|
| 60 |
+
if not isinstance(pts, list) or len(pts) != n:
|
| 61 |
+
raise Invalid(f"points must be a list of {n} [x, y] pairs")
|
| 62 |
+
p = [tuple(int_list(q, 2, -lim, lim, "point")) for q in pts]
|
| 63 |
+
if len(set(p)) != n:
|
| 64 |
+
raise Invalid("points must be distinct")
|
| 65 |
+
o = orient_table(p)
|
| 66 |
+
mc = max_convex(p, o)
|
| 67 |
+
if mc >= k:
|
| 68 |
+
raise Invalid(f"the set contains {mc} points in convex position (>= {k})")
|
| 69 |
+
return None, {"max_convex_subset": mc}
|
tasks/construct-ae-p58-happy-ending-l3-s0/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 32, "k": 7, "max_abs": 1000000000000000000, "family": "ae_p58_happy_ending", "subset": "construct"}
|
tasks/construct-ae-p58-happy-ending-l3-s0/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-ae-p58-happy-ending-l3-s0/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-bibd-l3-s2/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-mc-bibd-l3-s2/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"v": 15, "k": 3, "lambda": 1, "b": 35, "family": "mc_bibd", "subset": "construct"}
|
tasks/construct-mc-bibd-l3-s2/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"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], [9, 10, 13], [10, 11, 14], [0, 11, 12], [1, 12, 13], [2, 13, 14], [0, 3, 14], [0, 2, 8], [1, 3, 9], [2, 4, 10], [3, 5, 11], [4, 6, 12], [5, 7, 13], [6, 8, 14], [0, 7, 9], [1, 8, 10], [2, 9, 11], [3, 10, 12], [4, 11, 13], [5, 12, 14], [0, 6, 13], [1, 7, 14], [0, 5, 10], [1, 6, 11], [2, 7, 12], [3, 8, 13], [4, 9, 14]]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-bibd-l3-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-l3-s2/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"v": 15, "k": 3, "lambda": 1, "b": 35, "family": "mc_bibd", "subset": "construct"}
|
tasks/construct-mc-bibd-l3-s2/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-mc-bibd-l3-s2/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-golomb-l1-s2/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-mc-golomb-l1-s2/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 7, "max_length": 25, "fixed": [["marks", 1, 2]], "family": "mc_golomb", "subset": "construct"}
|
tasks/construct-mc-golomb-l1-s2/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"marks": [0, 2, 6, 9, 14, 24, 25]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-golomb-l1-s2/tests/check.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision
|
| 2 |
+
problem with the target length stated). Accepts any valid ruler.
|
| 3 |
+
Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation
|
| 4 |
+
model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..)
|
| 5 |
+
was accepted. Here the length bound is part of the instance and enforced."""
|
| 6 |
+
import itertools
|
| 7 |
+
|
| 8 |
+
from run import Invalid, int_list
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def check(inst, ans):
|
| 12 |
+
n, L = inst["n"], inst["max_length"]
|
| 13 |
+
a = int_list(ans.get("marks"), n, 0, L, "marks")
|
| 14 |
+
if a[0] != 0:
|
| 15 |
+
raise Invalid("first mark must be 0")
|
| 16 |
+
if any(a[i] >= a[i + 1] for i in range(n - 1)):
|
| 17 |
+
raise Invalid("marks must be strictly increasing")
|
| 18 |
+
for name, i, v in inst.get("fixed", []):
|
| 19 |
+
if a[i] != v:
|
| 20 |
+
raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
|
| 21 |
+
seen = set()
|
| 22 |
+
for i, j in itertools.combinations(range(n), 2):
|
| 23 |
+
d = a[j] - a[i]
|
| 24 |
+
if d in seen:
|
| 25 |
+
raise Invalid(f"difference {d} occurs twice")
|
| 26 |
+
seen.add(d)
|
| 27 |
+
return None, {"length": a[-1]}
|
tasks/construct-mc-golomb-l1-s2/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 7, "max_length": 25, "fixed": [["marks", 1, 2]], "family": "mc_golomb", "subset": "construct"}
|
tasks/construct-mc-golomb-l1-s2/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-mc-golomb-l1-s2/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-graph-k-coloring-l3-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
|
tasks/construct-mc-graph-k-coloring-l3-s6/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 51, "k": 4, "edges": [[0, 1], [0, 2], [0, 7], [0, 10], [0, 21], [0, 23], [0, 27], [0, 38], [0, 43], [0, 44], [1, 2], [1, 7], [1, 11], [1, 13], [1, 14], [1, 18], [1, 21], [1, 22], [1, 23], [1, 32], [1, 36], [2, 14], [2, 21], [2, 30], [3, 8], [3, 12], [3, 15], [3, 19], [3, 22], [3, 23], [3, 27], [3, 28], [3, 30], [3, 31], [3, 33], [3, 35], [3, 45], [3, 48], [4, 20], [4, 25], [4, 26], [4, 43], [5, 9], [5, 15], [5, 16], [5, 28], [5, 34], [5, 35], [5, 49], [6, 8], [6, 9], [6, 33], [6, 42], [6, 44], [6, 47], [7, 13], [7, 32], [7, 35], [7, 36], [7, 47], [8, 12], [8, 15], [8, 18], [8, 20], [8, 23], [8, 31], [8, 37], [8, 38], [9, 10], [9, 19], [9, 26], [9, 31], [9, 37], [9, 40], [10, 16], [10, 24], [10, 25], [10, 33], [11, 14], [11, 32], [11, 33], [11, 34], [11, 35], [11, 43], [12, 38], [12, 48], [13, 20], [14, 15], [14, 17], [14, 20], [14, 31], [14, 39], [14, 41], [15, 16], [15, 19], [15, 27], [16, 19], [16, 43], [16, 44], [17, 22], [17, 28], [17, 44], [18, 31], [18, 40], [18, 45], [18, 46], [19, 20], [19, 23], [19, 25], [19, 35], [19, 37], [19, 38], [19, 47], [20, 24], [20, 31], [20, 33], [21, 31], [21, 33], [21, 45], [21, 50], [22, 23], [22, 41], [23, 26], [23, 30], [23, 34], [23, 37], [23, 48], [24, 27], [24, 29], [24, 39], [24, 41], [24, 43], [24, 44], [24, 47], [25, 50], [26, 34], [26, 35], [26, 36], [26, 47], [26, 49], [26, 50], [27, 32], [27, 38], [27, 40], [27, 43], [27, 44], [27, 48], [27, 50], [28, 33], [28, 41], [28, 47], [29, 31], [29, 39], [29, 47], [30, 31], [30, 48], [31, 32], [32, 34], [32, 44], [32, 47], [33, 34], [33, 39], [35, 47], [36, 41], [36, 43], [37, 38], [37, 43], [37, 49], [38, 47], [39, 42], [39, 46], [40, 43], [40, 44], [41, 46], [41, 48], [41, 49], [42, 43], [42, 47], [43, 47], [44, 49], [44, 50], [45, 48], [45, 50], [46, 47], [47, 48]], "family": "mc_graph_k_coloring", "subset": "construct"}
|
tasks/construct-mc-graph-k-coloring-l3-s6/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, 2, 0, 0, 0, 0, 3, 3, 1, 3, 3, 2, 0, 0, 1, 2, 2, 0, 3, 1, 3, 3, 2, 0, 1, 3, 2, 3, 3, 1, 2, 0, 2, 1, 1, 0, 0, 1, 1, 3, 1, 3, 1, 1, 1, 3, 2, 3, 2, 0]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-graph-k-coloring-l3-s6/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-l3-s6/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 51, "k": 4, "edges": [[0, 1], [0, 2], [0, 7], [0, 10], [0, 21], [0, 23], [0, 27], [0, 38], [0, 43], [0, 44], [1, 2], [1, 7], [1, 11], [1, 13], [1, 14], [1, 18], [1, 21], [1, 22], [1, 23], [1, 32], [1, 36], [2, 14], [2, 21], [2, 30], [3, 8], [3, 12], [3, 15], [3, 19], [3, 22], [3, 23], [3, 27], [3, 28], [3, 30], [3, 31], [3, 33], [3, 35], [3, 45], [3, 48], [4, 20], [4, 25], [4, 26], [4, 43], [5, 9], [5, 15], [5, 16], [5, 28], [5, 34], [5, 35], [5, 49], [6, 8], [6, 9], [6, 33], [6, 42], [6, 44], [6, 47], [7, 13], [7, 32], [7, 35], [7, 36], [7, 47], [8, 12], [8, 15], [8, 18], [8, 20], [8, 23], [8, 31], [8, 37], [8, 38], [9, 10], [9, 19], [9, 26], [9, 31], [9, 37], [9, 40], [10, 16], [10, 24], [10, 25], [10, 33], [11, 14], [11, 32], [11, 33], [11, 34], [11, 35], [11, 43], [12, 38], [12, 48], [13, 20], [14, 15], [14, 17], [14, 20], [14, 31], [14, 39], [14, 41], [15, 16], [15, 19], [15, 27], [16, 19], [16, 43], [16, 44], [17, 22], [17, 28], [17, 44], [18, 31], [18, 40], [18, 45], [18, 46], [19, 20], [19, 23], [19, 25], [19, 35], [19, 37], [19, 38], [19, 47], [20, 24], [20, 31], [20, 33], [21, 31], [21, 33], [21, 45], [21, 50], [22, 23], [22, 41], [23, 26], [23, 30], [23, 34], [23, 37], [23, 48], [24, 27], [24, 29], [24, 39], [24, 41], [24, 43], [24, 44], [24, 47], [25, 50], [26, 34], [26, 35], [26, 36], [26, 47], [26, 49], [26, 50], [27, 32], [27, 38], [27, 40], [27, 43], [27, 44], [27, 48], [27, 50], [28, 33], [28, 41], [28, 47], [29, 31], [29, 39], [29, 47], [30, 31], [30, 48], [31, 32], [32, 34], [32, 44], [32, 47], [33, 34], [33, 39], [35, 47], [36, 41], [36, 43], [37, 38], [37, 43], [37, 49], [38, 47], [39, 42], [39, 46], [40, 43], [40, 44], [41, 46], [41, 48], [41, 49], [42, 43], [42, 47], [43, 47], [44, 49], [44, 50], [45, 48], [45, 50], [46, 47], [47, 48]], "family": "mc_graph_k_coloring", "subset": "construct"}
|
tasks/construct-mc-graph-k-coloring-l3-s6/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-l3-s6/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-low-autocorrelation-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-low-autocorrelation-l5-s2/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 40, "bound": 108, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"}
|
tasks/construct-mc-low-autocorrelation-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 |
+
{"seq": [1, 1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-low-autocorrelation-l5-s2/tests/check.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound
|
| 2 |
+
(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic."""
|
| 3 |
+
from run import Invalid, int_list
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def check(inst, ans):
|
| 7 |
+
n, bound = inst["n"], inst["bound"]
|
| 8 |
+
s = int_list(ans.get("seq"), n, -1, 1, "seq")
|
| 9 |
+
if any(v == 0 for v in s):
|
| 10 |
+
raise Invalid("entries must be -1 or +1")
|
| 11 |
+
c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)]
|
| 12 |
+
e = sum(v * v for v in c)
|
| 13 |
+
# fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream)
|
| 14 |
+
seqs = {"seq": s, "c": c}
|
| 15 |
+
for name, i, v in inst.get("fixed", []):
|
| 16 |
+
if seqs[name][i] != v:
|
| 17 |
+
raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
|
| 18 |
+
if e > bound:
|
| 19 |
+
raise Invalid(f"energy {e} exceeds the bound {bound}")
|
| 20 |
+
return None, {"energy": e}
|
tasks/construct-mc-low-autocorrelation-l5-s2/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 40, "bound": 108, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"}
|
tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-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-number-partitioning-l2-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-number-partitioning-l2-s2/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 15, "k": 3, "family": "mc_number_partitioning", "subset": "construct"}
|
tasks/construct-mc-number-partitioning-l2-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 |
+
{"x": [0, 2, 1, 1, 0, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-number-partitioning-l2-s2/tests/check.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0)."""
|
| 2 |
+
from run import Invalid, int_list
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def check(inst, ans):
|
| 6 |
+
n, k = inst["n"], inst["k"]
|
| 7 |
+
x = int_list(ans.get("x"), n, 0, k - 1, "x")
|
| 8 |
+
target = n * (n + 1) // 2 // k
|
| 9 |
+
sums = [0] * k
|
| 10 |
+
for i, s in enumerate(x):
|
| 11 |
+
sums[s] += i + 1
|
| 12 |
+
if any(t != target for t in sums):
|
| 13 |
+
raise Invalid(f"subset sums {sums} are not all {target}")
|
| 14 |
+
return None, {}
|
tasks/construct-mc-number-partitioning-l2-s2/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 15, "k": 3, "family": "mc_number_partitioning", "subset": "construct"}
|
tasks/construct-mc-number-partitioning-l2-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-number-partitioning-l2-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-number-partitioning-l2-s5/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-mc-number-partitioning-l2-s5/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 15, "k": 5, "family": "mc_number_partitioning", "subset": "construct"}
|
tasks/construct-mc-number-partitioning-l2-s5/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"x": [0, 2, 4, 1, 3, 1, 3, 0, 2, 4, 4, 3, 2, 1, 0]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-number-partitioning-l2-s5/tests/check.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0)."""
|
| 2 |
+
from run import Invalid, int_list
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def check(inst, ans):
|
| 6 |
+
n, k = inst["n"], inst["k"]
|
| 7 |
+
x = int_list(ans.get("x"), n, 0, k - 1, "x")
|
| 8 |
+
target = n * (n + 1) // 2 // k
|
| 9 |
+
sums = [0] * k
|
| 10 |
+
for i, s in enumerate(x):
|
| 11 |
+
sums[s] += i + 1
|
| 12 |
+
if any(t != target for t in sums):
|
| 13 |
+
raise Invalid(f"subset sums {sums} are not all {target}")
|
| 14 |
+
return None, {}
|
tasks/construct-mc-number-partitioning-l2-s5/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 15, "k": 5, "family": "mc_number_partitioning", "subset": "construct"}
|
tasks/construct-mc-number-partitioning-l2-s5/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-mc-number-partitioning-l2-s5/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-number-partitioning-l6-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
|