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-p32-spherical-design-l3-s0/environment/Dockerfile +7 -0
- tasks/construct-ae-p32-spherical-design-l3-s0/environment/instance.json +1 -0
- tasks/construct-ae-p32-spherical-design-l3-s0/solution/solve.sh +5 -0
- tasks/construct-ae-p32-spherical-design-l3-s0/tests/check.py +53 -0
- tasks/construct-ae-p32-spherical-design-l3-s0/tests/instance.json +1 -0
- tasks/construct-ae-p32-spherical-design-l3-s0/tests/run.py +127 -0
- tasks/construct-ae-p32-spherical-design-l3-s0/tests/test.sh +9 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/environment/Dockerfile +7 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/environment/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/solution/solve.sh +5 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/tests/check.py +12 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/tests/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/tests/run.py +127 -0
- tasks/construct-ae-p38-factorial-factors-l4-s7/tests/test.sh +9 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/environment/Dockerfile +7 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/environment/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/solution/solve.sh +5 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/tests/check.py +12 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/tests/instance.json +1 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/tests/run.py +127 -0
- tasks/construct-ae-p38-factorial-factors-l4-s9/tests/test.sh +9 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/Dockerfile +7 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/solution/solve.sh +5 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/check.py +38 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/run.py +127 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/test.sh +9 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/Dockerfile +7 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/solution/solve.sh +5 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/check.py +38 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/instance.json +1 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/run.py +127 -0
- tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/test.sh +9 -0
- tasks/construct-mc-all-interval-l4-s0/environment/Dockerfile +7 -0
- tasks/construct-mc-all-interval-l4-s0/environment/instance.json +1 -0
- tasks/construct-mc-all-interval-l4-s0/solution/solve.sh +5 -0
- tasks/construct-mc-all-interval-l4-s0/tests/check.py +17 -0
- tasks/construct-mc-all-interval-l4-s0/tests/instance.json +1 -0
- tasks/construct-mc-all-interval-l4-s0/tests/run.py +127 -0
- tasks/construct-mc-all-interval-l4-s0/tests/test.sh +9 -0
- tasks/construct-mc-all-interval-l4-s7/environment/Dockerfile +7 -0
- tasks/construct-mc-all-interval-l4-s7/environment/instance.json +1 -0
- tasks/construct-mc-all-interval-l4-s7/solution/solve.sh +5 -0
- tasks/construct-mc-all-interval-l4-s7/tests/check.py +17 -0
- tasks/construct-mc-all-interval-l4-s7/tests/instance.json +1 -0
- tasks/construct-mc-all-interval-l4-s7/tests/run.py +127 -0
- tasks/construct-mc-all-interval-l4-s7/tests/test.sh +9 -0
- tasks/construct-mc-costas-array-l2-s1/environment/Dockerfile +7 -0
tasks/construct-ae-p32-spherical-design-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-p32-spherical-design-l3-s0/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"t": 11, "N": 74, "family": "ae_p32_spherical_designs", "subset": "construct"}
|
tasks/construct-ae-p32-spherical-design-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.012181667145405233, 0.04406897535978663, 0.9989542193695851], [-0.34509997965572176, 0.1288545422759548, 0.9296787138449899], [0.23747361043298654, 0.3418894723530763, 0.9092402724484091], [-0.32378205632304635, -0.3291285139317033, 0.8870397969202556], [-0.10993350849569812, 0.5729830527072197, 0.812160726100531], [0.2744579502057163, -0.22493372978572318, 0.9349212003016938], [-0.6534839630036191, -0.07190886886669999, 0.7535169703964181], [0.25299574593404456, 0.6967407302922258, 0.6712268672298005], [-0.010398400762923468, -0.5027450682876482, 0.8643721823231134], [-0.4618410803115458, 0.4708548451282171, 0.7516638419905183], [0.627438824897458, -0.14847517075208097, 0.7643792544813325], [-0.5453160870286349, -0.5500712840928189, 0.6324965989191212], [0.048969718331694057, 0.9175723189756453, 0.3945415138311445], [0.4892159559041672, -0.5425159389853568, 0.6828939920921904], [-0.81392520194265, 0.18872951249061465, 0.5494605870830696], [0.5823595847147662, 0.22298324806204858, 0.7817517413952744], [-0.2050507825973778, -0.8030358265572386, 0.5595423467636168], [-0.31107530920789656, 0.8231570019133022, 0.4750207387076015], [0.8703740102023202, -0.28071432210609365, 0.40453498208294386], [-0.8176271032254404, -0.36824248281426336, 0.4425871596894356], [0.5145074079265113, 0.77988736882637, 0.35645170659406883], [0.19142328938975714, -0.7762697279296711, 0.600635025434914], [-0.7120409190324745, 0.5539218124477209, 0.4314723111834884], [0.9064725278017296, 0.06584189535584978, 0.4170999893990552], [-0.4737634222761198, -0.8343827984733857, 0.2816976487742496], [0.04603618708121533, 0.9986352864976358, 0.02466240135932157], [0.6852908054148145, -0.6348149093921444, 0.3569125142487421], [-0.9651405292573391, -0.0641545378637349, 0.2537478158651896], [0.6805111710486733, 0.49353469627313834, 0.5415976824660019], [0.014831151279722055, -0.9798774134655895, 0.19904846528346834], [-0.5022309830571787, 0.8491282151422244, 0.1635399459055802], [0.9857407500185974, -0.15933937822729607, -0.054093773199063264], [-0.7747182430523816, -0.6221106842542281, 0.11309261876253046], [0.4313629926999053, 0.9020540701662835, -0.014980755168657862], [0.38887800023493346, -0.8959131674601799, 0.21474053484320701], [-0.9014574832720917, 0.4193034025659316, 0.10751308036410531], [0.9106067863732784, 0.36380787047524216, 0.1960589553965844], [-0.27026489973758855, -0.9598619148107799, -0.0749799204161639], [-0.2796605209160264, 0.9463119158020885, -0.1621226420089359], [0.8637706418386029, -0.5030461013203664, -0.029067133400249072], [-0.929857029507562, -0.3504861834172364, -0.11191666501907623], [0.7631659919727551, 0.6458413806344182, -0.021600457320835178], [0.17712686726384438, -0.9571695622060861, -0.2290251123337919], [-0.7247383217031171, 0.6757579734218067, -0.13455677765093038], [0.9739180659158915, 0.14509853607838757, -0.1744420124584615], [-0.5942315932267775, -0.7725023885682474, -0.22389478168889565], [0.053793278821594605, 0.8924222614337699, -0.4479830247353778], [0.5963328565480022, -0.7949538264718048, -0.11151474332632134], [-0.9904348678868937, 0.09540543335148603, -0.09968237437424204], [0.7785214004564788, 0.5067954501668749, -0.37021993560779204], [-0.12745344083785073, -0.8688231852495284, -0.47843692707759927], [-0.45966953338825445, 0.7548880882687413, -0.4678118150117518], [0.8119439845237596, -0.20453903959281072, -0.5467273061391131], [-0.8163819613066496, -0.35179411235057867, -0.4579971569437702], [0.414034606264739, 0.8123220472529616, -0.41074108190192016], [0.39225879479859094, -0.7719354429052335, -0.5002486480639982], [-0.8144247845090498, 0.3995170409556142, -0.4208306124362365], [0.7919945789998984, 0.16503183652265635, -0.5878002039543139], [-0.519980948113389, -0.6441432781884862, -0.5609806153190068], [-0.10341519007317898, 0.685333778051037, -0.7208487435824663], [0.7316541544540598, -0.5052409069568021, -0.45761755233773854], [-0.8564091296158046, 0.04024373247575535, -0.5147269613174734], [0.48015191704276494, 0.5478567190479273, -0.6850599623056352], [-0.08319102926775795, -0.6454567001345148, -0.7592528570251376], [-0.5168863414134482, 0.4594617754350795, -0.7223042205153344], [0.45375396544341395, -0.22108855803657526, -0.86326542172711], [-0.49732200103061647, -0.32236373779958016, -0.8054517042273777], [0.14473782202670907, 0.4553146812108867, -0.8784870539449021], [0.32158098913622624, -0.5287876581868304, -0.7854739206208277], [-0.5679332181119199, 0.032811953562417055, -0.8224203520514654], [0.47326046614950557, 0.15280889139839626, -0.8675678497325415], [-0.11488178427308975, -0.3004992992274901, -0.946838078451653], [-0.24057036662670686, 0.24509927744022886, -0.9391763641081315], [0.06146349535335018, -0.000945371150052198, -0.9981088843469621]]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p32-spherical-design-l3-s0/tests/check.py
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Spherical t-design with N points on S^2 (numerical, tolerance 1e-10 on every harmonic average).
|
| 2 |
+
|
| 3 |
+
Upstream (AlphaEvolve `spherical_t_designs.ipynb`) scored sum_k dim_k/C_k(1) * sum_{i,j} C_k(<x_i,x_j>), whose
|
| 4 |
+
pair sums cancel to ~1e-10 in float64 and can even go negative; its printed acceptance test
|
| 5 |
+
`calculate_design_score(...) < 1e-8` compares the NEGATED error and is therefore always true (bug). Here we
|
| 6 |
+
evaluate the point averages of an orthonormal real spherical-harmonic basis directly (no cancellation).
|
| 7 |
+
"""
|
| 8 |
+
import numpy as np
|
| 9 |
+
|
| 10 |
+
from run import Invalid, float_matrix
|
| 11 |
+
|
| 12 |
+
TOL = 1e-10
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def harmonics(X, t):
|
| 16 |
+
"""Rows: real spherical harmonics Y_lm (1 <= l <= t) normalised so that their mean square on S^2 is 1."""
|
| 17 |
+
ct = np.clip(X[:, 2], -1.0, 1.0)
|
| 18 |
+
st = np.sqrt(np.maximum(0.0, 1.0 - ct * ct))
|
| 19 |
+
ph = np.arctan2(X[:, 1], X[:, 0])
|
| 20 |
+
P = {(0, 0): np.ones_like(ct)}
|
| 21 |
+
for m in range(1, t + 1):
|
| 22 |
+
P[(m, m)] = (np.sqrt(3.0) if m == 1 else np.sqrt((2 * m + 1) / (2 * m))) * st * P[(m - 1, m - 1)]
|
| 23 |
+
for m in range(0, t):
|
| 24 |
+
P[(m + 1, m)] = np.sqrt(2 * m + 3) * ct * P[(m, m)]
|
| 25 |
+
for m in range(0, t + 1):
|
| 26 |
+
for l in range(m + 2, t + 1):
|
| 27 |
+
a = np.sqrt((4 * l * l - 1) / (l * l - m * m))
|
| 28 |
+
b = np.sqrt(((l - 1) ** 2 - m * m) / (4 * (l - 1) ** 2 - 1))
|
| 29 |
+
P[(l, m)] = a * (ct * P[(l - 1, m)] - b * P[(l - 2, m)])
|
| 30 |
+
rows = []
|
| 31 |
+
for l in range(1, t + 1):
|
| 32 |
+
rows.append(P[(l, 0)])
|
| 33 |
+
for m in range(1, l + 1):
|
| 34 |
+
rows.append(P[(l, m)] * np.cos(m * ph))
|
| 35 |
+
rows.append(P[(l, m)] * np.sin(m * ph))
|
| 36 |
+
return np.array(rows)
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def check(inst, ans):
|
| 40 |
+
t, n = inst["t"], inst["N"]
|
| 41 |
+
X = np.array(float_matrix(ans.get("points"), n, 3, "points"))
|
| 42 |
+
nr = np.linalg.norm(X, axis=1)
|
| 43 |
+
if nr.min() < 0.5 or nr.max() > 2.0:
|
| 44 |
+
raise Invalid("points must be (approximately) unit vectors")
|
| 45 |
+
X = X / nr[:, None]
|
| 46 |
+
G = X @ X.T
|
| 47 |
+
np.fill_diagonal(G, -1.0)
|
| 48 |
+
if G.max() > 1.0 - 1e-8:
|
| 49 |
+
raise Invalid("two points coincide (or nearly: distance < 1.4e-4)")
|
| 50 |
+
dev = np.abs(harmonics(X, t).mean(axis=1)).max()
|
| 51 |
+
if not dev <= TOL:
|
| 52 |
+
raise Invalid(f"not a {t}-design: some harmonic of degree <= {t} has point average {dev:.3e} > {TOL}")
|
| 53 |
+
return None, {"max_harmonic_average": float(dev)}
|
tasks/construct-ae-p32-spherical-design-l3-s0/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"t": 11, "N": 74, "family": "ae_p32_spherical_designs", "subset": "construct"}
|
tasks/construct-ae-p32-spherical-design-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-p32-spherical-design-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-ae-p38-factorial-factors-l4-s7/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-ae-p38-factorial-factors-l4-s7/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 1031, "t": 322, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-l4-s7/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"factors": [2254, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 322, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 323, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 324, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 325, 326, 326, 326, 326, 326, 326, 327, 327, 327, 327, 327, 327, 327, 327, 327, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 328, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 329, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 330, 331, 331, 331, 332, 332, 332, 332, 332, 332, 332, 332, 332, 332, 332, 332, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 333, 334, 334, 334, 334, 334, 334, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 335, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 336, 337, 337, 337, 338, 338, 338, 338, 338, 338, 338, 338, 338, 338, 339, 339, 339, 339, 339, 339, 339, 339, 339, 340, 340, 340, 340, 340, 340, 340, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 341, 343, 343, 343, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 344, 346, 346, 346, 346, 346, 347, 347, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 348, 349, 349, 352, 352, 353, 353, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 354, 355, 355, 355, 355, 355, 355, 355, 355, 355, 355, 355, 355, 355, 355, 356, 356, 356, 356, 356, 356, 356, 356, 356, 356, 356, 358, 358, 358, 358, 358, 359, 359, 362, 362, 362, 362, 362, 363, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 367, 367, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 373, 373, 379, 379, 381, 381, 381, 381, 381, 381, 381, 381, 382, 382, 382, 382, 382, 383, 383, 386, 386, 386, 386, 386, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 389, 389, 393, 393, 393, 393, 393, 393, 393, 394, 394, 394, 394, 394, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 397, 397, 398, 398, 398, 398, 398, 401, 401, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 409, 409, 411, 411, 411, 411, 411, 411, 411, 412, 412, 412, 412, 412, 412, 412, 412, 412, 412, 417, 417, 417, 417, 417, 417, 417, 419, 419, 421, 421, 422, 422, 422, 422, 428, 428, 428, 428, 428, 428, 428, 428, 428, 431, 431, 433, 433, 439, 439, 443, 443, 446, 446, 446, 446, 447, 447, 447, 447, 447, 447, 449, 449, 453, 453, 453, 453, 453, 453, 454, 454, 454, 454, 457, 457, 458, 458, 458, 458, 461, 461, 463, 463, 466, 466, 466, 466, 467, 467, 471, 471, 471, 471, 471, 471, 478, 478, 478, 478, 479, 479, 482, 482, 482, 482, 487, 487, 491, 491, 499, 499, 502, 502, 502, 502, 503, 503, 509, 509, 514, 514, 514, 514, 521, 523, 526, 526, 526, 538, 538, 538, 541, 542, 542, 542, 547, 554, 554, 554, 557, 562, 562, 562, 563, 566, 566, 566, 569, 571, 577, 586, 586, 586, 587, 593, 599, 601, 607, 613, 614, 614, 614, 617, 619, 622, 622, 622, 626, 626, 626, 631, 634, 634, 634, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p38-factorial-factors-l4-s7/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-l4-s7/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 1031, "t": 322, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-l4-s7/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-ae-p38-factorial-factors-l4-s7/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-ae-p38-factorial-factors-l4-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-p38-factorial-factors-l4-s9/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 1164, "t": 365, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-l4-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 |
+
{"factors": [365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 365, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 366, 367, 367, 367, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 368, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 369, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 370, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 371, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 372, 373, 373, 373, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 374, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 375, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 376, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 377, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 378, 379, 379, 379, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 380, 381, 381, 381, 381, 381, 381, 381, 381, 381, 382, 382, 382, 382, 382, 382, 383, 383, 383, 384, 384, 384, 384, 384, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 385, 386, 386, 386, 386, 386, 386, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 387, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 388, 389, 389, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 390, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 392, 393, 393, 393, 393, 393, 393, 393, 393, 394, 394, 394, 394, 394, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 395, 397, 397, 398, 398, 398, 398, 398, 400, 400, 400, 400, 400, 400, 400, 401, 401, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 402, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 404, 405, 405, 405, 407, 409, 409, 411, 411, 411, 411, 411, 411, 411, 411, 412, 412, 412, 412, 412, 412, 412, 412, 412, 412, 412, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 413, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 415, 416, 416, 416, 416, 416, 416, 416, 417, 417, 417, 417, 417, 417, 417, 417, 419, 419, 421, 421, 422, 422, 422, 422, 422, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 426, 428, 428, 428, 428, 428, 428, 428, 428, 428, 428, 431, 431, 433, 433, 436, 436, 436, 436, 436, 436, 436, 436, 436, 436, 439, 439, 443, 443, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 445, 446, 446, 446, 446, 446, 447, 447, 447, 447, 447, 447, 447, 449, 449, 452, 452, 452, 452, 452, 452, 452, 452, 452, 452, 453, 453, 453, 453, 453, 453, 453, 454, 454, 454, 454, 454, 457, 457, 458, 458, 458, 458, 458, 461, 461, 463, 463, 466, 466, 466, 466, 467, 467, 471, 471, 471, 471, 471, 471, 471, 478, 478, 478, 478, 479, 479, 482, 482, 482, 482, 487, 487, 489, 489, 489, 489, 489, 489, 489, 491, 491, 499, 499, 501, 501, 501, 501, 501, 501, 502, 502, 502, 502, 503, 503, 509, 509, 514, 514, 514, 514, 519, 519, 519, 519, 519, 519, 521, 521, 523, 523, 526, 526, 526, 526, 537, 537, 537, 537, 537, 537, 538, 538, 538, 538, 541, 541, 542, 542, 542, 542, 543, 543, 543, 543, 543, 543, 547, 547, 554, 554, 554, 554, 557, 557, 562, 562, 562, 562, 563, 563, 566, 566, 566, 566, 569, 569, 571, 571, 577, 577, 586, 586, 586, 587, 593, 599, 601, 607, 613, 614, 614, 614, 617, 619, 622, 622, 622, 626, 626, 626, 631, 634, 634, 634, 641, 643, 647, 653, 659, 661, 662, 662, 662, 673, 674, 674, 674, 677, 683, 691, 694, 694, 694, 698, 698, 698, 701, 706, 706, 706, 709, 718, 718, 718, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p38-factorial-factors-l4-s9/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-l4-s9/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 1164, "t": 365, "family": "ae_p38_factorial_factors", "subset": "construct"}
|
tasks/construct-ae-p38-factorial-factors-l4-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-p38-factorial-factors-l4-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-l4-s2/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 3700, "t": 148, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l4-s2/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"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]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/check.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A
|
| 2 |
+
(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for
|
| 3 |
+
"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1."""
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from run import Invalid, int_list
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _primes(n):
|
| 10 |
+
s = np.ones(n + 1, dtype=bool)
|
| 11 |
+
s[:2] = False
|
| 12 |
+
for i in range(2, int(n ** .5) + 1):
|
| 13 |
+
if s[i]:
|
| 14 |
+
s[i * i::i] = False
|
| 15 |
+
return np.nonzero(s)[0]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def check(inst, ans):
|
| 19 |
+
n, t = inst["N"], inst["t"]
|
| 20 |
+
a = ans.get("A")
|
| 21 |
+
if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20):
|
| 22 |
+
raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers")
|
| 23 |
+
int_list(a, None, 1, n, "A")
|
| 24 |
+
if len(set(a)) != len(a):
|
| 25 |
+
raise Invalid("A must consist of distinct integers")
|
| 26 |
+
x = np.array(sorted(a), dtype=np.int64)
|
| 27 |
+
iu, ju = np.triu_indices(len(x))
|
| 28 |
+
va, vb = x[iu], x[ju]
|
| 29 |
+
left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet
|
| 30 |
+
for p in _primes(int((n * n + 1) ** .5) + 1):
|
| 31 |
+
q = int(p) * int(p)
|
| 32 |
+
idx = np.nonzero(left)[0]
|
| 33 |
+
hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0
|
| 34 |
+
left[idx[hit]] = False
|
| 35 |
+
if not left.any():
|
| 36 |
+
return None, {"size": len(a)}
|
| 37 |
+
k = int(np.nonzero(left)[0][0])
|
| 38 |
+
raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree")
|
tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 3700, "t": 148, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 1796, "t": 72, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l4-s5/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"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]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-ae-p52-erdos-squarefree-l4-s5/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-l4-s5/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"N": 1796, "t": 72, "family": "ae_p52_erdos_squarefree", "subset": "construct"}
|
tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-all-interval-l4-s0/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-mc-all-interval-l4-s0/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 16, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l4-s0/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"x": [0, 15, 1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-all-interval-l4-s0/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-l4-s0/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 16, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l4-s0/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-mc-all-interval-l4-s0/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-all-interval-l4-s7/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|
tasks/construct-mc-all-interval-l4-s7/environment/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 30, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l4-s7/solution/solve.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
# oracle: a known valid construction (planted witness or published solution)
|
| 3 |
+
cat > /workdir/answer.json <<'RLMATH_EOF'
|
| 4 |
+
{"x": [0, 29, 1, 28, 2, 27, 3, 26, 4, 25, 5, 24, 6, 23, 7, 22, 8, 21, 9, 20, 10, 19, 11, 18, 12, 17, 13, 16, 14, 15]}
|
| 5 |
+
RLMATH_EOF
|
tasks/construct-mc-all-interval-l4-s7/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-l4-s7/tests/instance.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"n": 30, "fixed": [], "family": "mc_all_interval", "subset": "construct"}
|
tasks/construct-mc-all-interval-l4-s7/tests/run.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py.
|
| 2 |
+
|
| 3 |
+
Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only.
|
| 4 |
+
|
| 5 |
+
python3 /tests/run.py /tests/instance.json /workdir/answer.json
|
| 6 |
+
|
| 7 |
+
Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists.
|
| 8 |
+
|
| 9 |
+
check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer.
|
| 10 |
+
construct : value is ignored; a returned check means the witness is valid -> reward 1.0
|
| 11 |
+
optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where
|
| 12 |
+
progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize)
|
| 13 |
+
clip((baseline - s) / (baseline - best_known), 0, 1) (minimize)
|
| 14 |
+
inst must carry "direction", "baseline", "best_known".
|
| 15 |
+
"""
|
| 16 |
+
import json
|
| 17 |
+
import math
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
VALID_FLOOR = 0.1
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
class Invalid(Exception):
|
| 25 |
+
pass
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# ------------------------------------------------------------ input helpers
|
| 29 |
+
|
| 30 |
+
def int_list(v, n=None, lo=None, hi=None, name="list"):
|
| 31 |
+
if not isinstance(v, list):
|
| 32 |
+
raise Invalid(f"{name} must be a list")
|
| 33 |
+
if n is not None and len(v) != n:
|
| 34 |
+
raise Invalid(f"{name} must have length {n}, got {len(v)}")
|
| 35 |
+
for x in v:
|
| 36 |
+
if isinstance(x, bool) or not isinstance(x, int):
|
| 37 |
+
raise Invalid(f"{name} must contain integers only")
|
| 38 |
+
if (lo is not None and x < lo) or (hi is not None and x > hi):
|
| 39 |
+
raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]")
|
| 40 |
+
return v
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def as_int(x, name="value", lo=None, hi=None):
|
| 44 |
+
return int_list([x], 1, lo, hi, name)[0]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def num(x, name="value"):
|
| 48 |
+
if isinstance(x, bool) or not isinstance(x, (int, float)):
|
| 49 |
+
raise Invalid(f"{name} must be a number")
|
| 50 |
+
if not math.isfinite(x):
|
| 51 |
+
raise Invalid(f"{name} is not finite")
|
| 52 |
+
return float(x)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def float_matrix(v, rows=None, cols=None, name="matrix"):
|
| 56 |
+
if not isinstance(v, list) or (rows is not None and len(v) != rows):
|
| 57 |
+
raise Invalid(f"{name} must be a list of {rows} rows")
|
| 58 |
+
out = []
|
| 59 |
+
for r in v:
|
| 60 |
+
if not isinstance(r, list) or (cols is not None and len(r) != cols):
|
| 61 |
+
raise Invalid(f"each row of {name} must have {cols} numbers")
|
| 62 |
+
out.append([num(x, name) for x in r])
|
| 63 |
+
return out
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def float_list(v, n=None, name="list"):
|
| 67 |
+
if not isinstance(v, list) or (n is not None and len(v) != n):
|
| 68 |
+
raise Invalid(f"{name} must be a list of length {n}")
|
| 69 |
+
return [num(x, name) for x in v]
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
# ------------------------------------------------------------------ reward
|
| 73 |
+
|
| 74 |
+
def optimize_reward(inst, s):
|
| 75 |
+
b, best = inst["baseline"], inst["best_known"]
|
| 76 |
+
if inst.get("progress_scale") == "log":
|
| 77 |
+
# for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0);
|
| 78 |
+
# progress is measured in log10(value + floor)
|
| 79 |
+
f = inst.get("log_floor", 1e-3)
|
| 80 |
+
b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s))
|
| 81 |
+
if inst["direction"] == "maximize":
|
| 82 |
+
p = (s - b) / (best - b)
|
| 83 |
+
else:
|
| 84 |
+
p = (b - s) / (b - best)
|
| 85 |
+
return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p))
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def grade(inst, ans, check):
|
| 89 |
+
try:
|
| 90 |
+
if not isinstance(ans, dict):
|
| 91 |
+
raise Invalid("answer must be a JSON object")
|
| 92 |
+
value, extra = check(inst, ans)
|
| 93 |
+
if inst.get("subset") == "optimize":
|
| 94 |
+
s = float(value)
|
| 95 |
+
if not math.isfinite(s):
|
| 96 |
+
raise Invalid("non-finite score")
|
| 97 |
+
return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})}
|
| 98 |
+
return 1.0, {"valid": True, **(extra or {})}
|
| 99 |
+
except Invalid as e:
|
| 100 |
+
return 0.0, {"valid": False, "error": str(e)}
|
| 101 |
+
except Exception as e: # any malformed answer
|
| 102 |
+
return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"}
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def main():
|
| 106 |
+
here = os.path.dirname(os.path.abspath(__file__))
|
| 107 |
+
sys.path.insert(0, here)
|
| 108 |
+
# import ourselves as `run` so check.py's `from run import Invalid` is the same class
|
| 109 |
+
import run as R # noqa: E402
|
| 110 |
+
import check as family # noqa: E402
|
| 111 |
+
|
| 112 |
+
inst = json.load(open(sys.argv[1]))
|
| 113 |
+
try:
|
| 114 |
+
ans = json.load(open(sys.argv[2]))
|
| 115 |
+
except Exception as e:
|
| 116 |
+
reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"}
|
| 117 |
+
else:
|
| 118 |
+
reward, det = R.grade(inst, ans, family.check)
|
| 119 |
+
det["reward"] = reward
|
| 120 |
+
if os.path.isdir("/logs/verifier"):
|
| 121 |
+
with open("/logs/verifier/details.json", "w") as f:
|
| 122 |
+
json.dump(det, f)
|
| 123 |
+
print(reward)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
if __name__ == "__main__":
|
| 127 |
+
main()
|
tasks/construct-mc-all-interval-l4-s7/tests/test.sh
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
mkdir -p /logs/verifier
|
| 3 |
+
if [ ! -s /workdir/answer.json ]; then
|
| 4 |
+
echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json
|
| 5 |
+
echo 0 > /logs/verifier/reward.txt
|
| 6 |
+
exit 0
|
| 7 |
+
fi
|
| 8 |
+
timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \
|
| 9 |
+
> /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt
|
tasks/construct-mc-costas-array-l2-s1/environment/Dockerfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11.16-slim
|
| 2 |
+
RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \
|
| 3 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 4 |
+
RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \
|
| 5 |
+
python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755
|
| 6 |
+
WORKDIR /workdir
|
| 7 |
+
COPY instance.json /workdir/instance.json
|