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-p38-factorial-factors-l1-s2/environment/Dockerfile +7 -0
- tasks/construct-ae-p38-factorial-factors-l1-s2/environment/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l1-s2/solution/solve.sh +5 -0
- tasks/construct-ae-p38-factorial-factors-l1-s2/tests/check.py +12 -0
- tasks/construct-ae-p38-factorial-factors-l1-s2/tests/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l1-s2/tests/run.py +127 -0
- tasks/construct-ae-p38-factorial-factors-l1-s2/tests/test.sh +9 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/environment/Dockerfile +7 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/environment/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/solution/solve.sh +5 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/tests/check.py +12 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/tests/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/tests/run.py +127 -0
- tasks/construct-ae-p38-factorial-factors-l1-s5/tests/test.sh +9 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/environment/Dockerfile +7 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/environment/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/solution/solve.sh +5 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/check.py +38 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/run.py +127 -0
- tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/test.sh +9 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/Dockerfile +7 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/solution/solve.sh +5 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/check.py +38 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/run.py +127 -0
- tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/test.sh +9 -0
- tasks/construct-mc-all-interval-l5-s3/environment/Dockerfile +7 -0
- tasks/construct-mc-all-interval-l5-s3/environment/instance.json +1 -0
- tasks/construct-mc-all-interval-l5-s3/solution/solve.sh +5 -0
- tasks/construct-mc-all-interval-l5-s3/tests/check.py +17 -0
- tasks/construct-mc-all-interval-l5-s3/tests/instance.json +1 -0
- tasks/construct-mc-all-interval-l5-s3/tests/run.py +127 -0
- tasks/construct-mc-all-interval-l5-s3/tests/test.sh +9 -0
- tasks/construct-mc-all-interval-l5-s4/environment/Dockerfile +7 -0
- tasks/construct-mc-all-interval-l5-s4/environment/instance.json +1 -0
- tasks/construct-mc-all-interval-l5-s4/solution/solve.sh +5 -0
- tasks/construct-mc-all-interval-l5-s4/tests/check.py +17 -0
- tasks/construct-mc-all-interval-l5-s4/tests/instance.json +1 -0
- tasks/construct-mc-all-interval-l5-s4/tests/run.py +127 -0
- tasks/construct-mc-all-interval-l5-s4/tests/test.sh +9 -0
- tasks/construct-mc-bibd-l2-s0/environment/Dockerfile +7 -0
- tasks/construct-mc-bibd-l2-s0/environment/instance.json +1 -0
- tasks/construct-mc-bibd-l2-s0/solution/solve.sh +5 -0
- tasks/construct-mc-bibd-l2-s0/tests/check.py +25 -0
- tasks/construct-mc-bibd-l2-s0/tests/instance.json +1 -0
- tasks/construct-mc-bibd-l2-s0/tests/run.py +127 -0
- tasks/construct-mc-bibd-l2-s0/tests/test.sh +9 -0
- tasks/construct-mc-bibd-l6-s1/environment/Dockerfile +7 -0
tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s2/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 44, "t": 12, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-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 |
+
{"factors": [96, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 17, 17, 19, 19, 22, 22, 22, 22, 23, 29, 31, 37, 41, 43]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p38-factorial-factors-l1-s2/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-l1-s2/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 44, "t": 12, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-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-ae-p38-factorial-factors-l1-s5/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 52, "t": 15, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-l1-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 |
+
{"factors": [45, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 18, 19, 19, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 26, 26, 26, 26, 29, 31, 37, 41, 43, 47]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p38-factorial-factors-l1-s5/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-l1-s5/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 52, "t": 15, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-l1-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-ae-p38-factorial-factors-l1-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-ae-p52-erdos-squarefree-l1-s9/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-ae-p52-erdos-squarefree-l1-s9/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 55, "t": 2, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l1-s9/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"A": [7, 32]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p52-erdos-squarefree-l1-s9/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-l1-s9/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 55, "t": 2, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 8984, "t": 360, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l5-s1/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332, 1357, 1382, 1407, 1432, 1457, 1482, 1507, 1532, 1557, 1582, 1607, 1632, 1657, 1682, 1707, 1732, 1757, 1782, 1807, 1832, 1857, 1882, 1907, 1932, 1957, 1982, 2007, 2032, 2057, 2082, 2107, 2132, 2157, 2182, 2207, 2232, 2257, 2282, 2307, 2332, 2357, 2382, 2407, 2432, 2457, 2482, 2507, 2532, 2557, 2582, 2607, 2632, 2657, 2682, 2707, 2732, 2757, 2782, 2807, 2832, 2857, 2882, 2907, 2932, 2957, 2982, 3007, 3032, 3057, 3082, 3107, 3132, 3157, 3182, 3207, 3232, 3257, 3282, 3307, 3332, 3357, 3382, 3407, 3432, 3457, 3482, 3507, 3532, 3557, 3582, 3607, 3632, 3657, 3682, 3707, 3732, 3757, 3782, 3807, 3832, 3857, 3882, 3907, 3932, 3957, 3982, 4007, 4032, 4057, 4082, 4107, 4132, 4157, 4182, 4207, 4232, 4257, 4282, 4307, 4332, 4357, 4382, 4407, 4432, 4457, 4482, 4507, 4532, 4557, 4582, 4607, 4632, 4657, 4682, 4707, 4732, 4757, 4782, 4807, 4832, 4857, 4882, 4907, 4932, 4957, 4982, 5007, 5032, 5057, 5082, 5107, 5132, 5157, 5182, 5207, 5232, 5257, 5282, 5307, 5332, 5357, 5382, 5407, 5432, 5457, 5482, 5507, 5532, 5557, 5582, 5607, 5632, 5657, 5682, 5707, 5732, 5757, 5782, 5807, 5832, 5857, 5882, 5907, 5932, 5957, 5982, 6007, 6032, 6057, 6082, 6107, 6132, 6157, 6182, 6207, 6232, 6257, 6282, 6307, 6332, 6357, 6382, 6407, 6432, 6457, 6482, 6507, 6532, 6557, 6582, 6607, 6632, 6657, 6682, 6707, 6732, 6757, 6782, 6807, 6832, 6857, 6882, 6907, 6932, 6957, 6982, 7007, 7032, 7057, 7082, 7107, 7132, 7157, 7182, 7207, 7232, 7257, 7282, 7307, 7332, 7357, 7382, 7407, 7432, 7457, 7482, 7507, 7532, 7557, 7582, 7607, 7632, 7657, 7682, 7707, 7732, 7757, 7782, 7807, 7832, 7857, 7882, 7907, 7932, 7957, 7982, 8007, 8032, 8057, 8082, 8107, 8132, 8157, 8182, 8207, 8232, 8257, 8282, 8307, 8332, 8357, 8382, 8407, 8432, 8457, 8482, 8507, 8532, 8557, 8582, 8607, 8632, 8657, 8682, 8707, 8732, 8757, 8782, 8807, 8832, 8857, 8882, 8907, 8932, 8957, 8982]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p52-erdos-squarefree-l5-s1/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-l5-s1/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 8984, "t": 360, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-all-interval-l5-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-all-interval-l5-s3/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 52, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l5-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, 51, 1, 50, 2, 49, 3, 48, 4, 47, 5, 46, 6, 45, 7, 44, 8, 43, 9, 42, 10, 41, 11, 40, 12, 39, 13, 38, 14, 37, 15, 36, 16, 35, 17, 34, 18, 33, 19, 32, 20, 31, 21, 30, 22, 29, 23, 28, 24, 27, 25, 26]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-all-interval-l5-s3/tests/check.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series."""
|
| 2 |
+
from run import Invalid, int_list
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def check(inst, ans):
|
| 6 |
+
n = inst["n"]
|
| 7 |
+
x = int_list(ans.get("x"), n, 0, n - 1, "x")
|
| 8 |
+
if sorted(x) != list(range(n)):
|
| 9 |
+
raise Invalid("x is not a permutation of 0..n-1")
|
| 10 |
+
d = [abs(x[i + 1] - x[i]) for i in range(n - 1)]
|
| 11 |
+
if sorted(d) != list(range(1, n)):
|
| 12 |
+
raise Invalid("consecutive differences are not a permutation of 1..n-1")
|
| 13 |
+
seqs = {"x": x, "d": d}
|
| 14 |
+
for name, i, v in inst.get("fixed", []):
|
| 15 |
+
if seqs[name][i] != v:
|
| 16 |
+
raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
|
| 17 |
+
return None, {}
|
tasks/construct-mc-all-interval-l5-s3/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 52, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l5-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-all-interval-l5-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-all-interval-l5-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-all-interval-l5-s4/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 56, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l5-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, 55, 1, 54, 2, 53, 3, 52, 4, 51, 5, 50, 6, 49, 7, 48, 8, 47, 9, 46, 10, 45, 11, 44, 12, 43, 13, 42, 14, 41, 15, 40, 16, 39, 17, 38, 18, 37, 19, 36, 20, 35, 21, 34, 22, 33, 23, 32, 24, 31, 25, 30, 26, 29, 27, 28]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-all-interval-l5-s4/tests/check.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series."""
|
| 2 |
+
from run import Invalid, int_list
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def check(inst, ans):
|
| 6 |
+
n = inst["n"]
|
| 7 |
+
x = int_list(ans.get("x"), n, 0, n - 1, "x")
|
| 8 |
+
if sorted(x) != list(range(n)):
|
| 9 |
+
raise Invalid("x is not a permutation of 0..n-1")
|
| 10 |
+
d = [abs(x[i + 1] - x[i]) for i in range(n - 1)]
|
| 11 |
+
if sorted(d) != list(range(1, n)):
|
| 12 |
+
raise Invalid("consecutive differences are not a permutation of 1..n-1")
|
| 13 |
+
seqs = {"x": x, "d": d}
|
| 14 |
+
for name, i, v in inst.get("fixed", []):
|
| 15 |
+
if seqs[name][i] != v:
|
| 16 |
+
raise Invalid(f"fixed value {name}[{i}] = {v} not respected")
|
| 17 |
+
return None, {}
|
tasks/construct-mc-all-interval-l5-s4/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 56, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l5-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-all-interval-l5-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-bibd-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-bibd-l2-s0/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"v": 11, "k": 5, "lambda": 2, "b": 11, "family": "mc_bibd", "subset": "construct"}
|
tasks/construct-mc-bibd-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 |
+
{"blocks": [[1, 3, 4, 5, 9], [2, 4, 5, 6, 10], [0, 3, 5, 6, 7], [1, 4, 6, 7, 8], [2, 5, 7, 8, 9], [3, 6, 8, 9, 10], [0, 4, 7, 9, 10], [0, 1, 5, 8, 10], [0, 1, 2, 6, 9], [1, 2, 3, 7, 10], [0, 2, 3, 4, 8]]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-bibd-l2-s0/tests/check.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0).
|
| 2 |
+
Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly
|
| 3 |
+
lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream
|
| 4 |
+
(its 0/1 incidence-matrix model does not forbid equal columns)."""
|
| 5 |
+
import itertools
|
| 6 |
+
|
| 7 |
+
from run import Invalid, int_list
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def check(inst, ans):
|
| 11 |
+
v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"]
|
| 12 |
+
blocks = ans.get("blocks")
|
| 13 |
+
if not isinstance(blocks, list) or len(blocks) != b:
|
| 14 |
+
raise Invalid(f"blocks must be a list of exactly {b} blocks")
|
| 15 |
+
pair = {}
|
| 16 |
+
for B in blocks:
|
| 17 |
+
B = int_list(B, k, 0, v - 1, "block")
|
| 18 |
+
if len(set(B)) != k:
|
| 19 |
+
raise Invalid("a block contains a repeated point")
|
| 20 |
+
for p in itertools.combinations(sorted(B), 2):
|
| 21 |
+
pair[p] = pair.get(p, 0) + 1
|
| 22 |
+
for p in itertools.combinations(range(v), 2):
|
| 23 |
+
if pair.get(p, 0) != lam:
|
| 24 |
+
raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}")
|
| 25 |
+
return None, {}
|
tasks/construct-mc-bibd-l2-s0/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"v": 11, "k": 5, "lambda": 2, "b": 11, "family": "mc_bibd", "subset": "construct"}
|
tasks/construct-mc-bibd-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-bibd-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-bibd-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
|