diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/environment/Dockerfile b/tasks/construct-ae-p32-spherical-design-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/environment/instance.json b/tasks/construct-ae-p32-spherical-design-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..247aa546bc3e1dad5dc06feec32540928cfdcb4f --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"t": 11, "N": 74, "family": "ae_p32_spherical_designs", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/solution/solve.sh b/tasks/construct-ae-p32-spherical-design-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a51363cc56b7f80da2ee5243829ab0eede1c05a2 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]]} +RLMATH_EOF diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/tests/check.py b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..5973c15b3df2d6228d713d9b186ced8e47dcbb48 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/check.py @@ -0,0 +1,53 @@ +"""Spherical t-design with N points on S^2 (numerical, tolerance 1e-10 on every harmonic average). + +Upstream (AlphaEvolve `spherical_t_designs.ipynb`) scored sum_k dim_k/C_k(1) * sum_{i,j} C_k(), whose +pair sums cancel to ~1e-10 in float64 and can even go negative; its printed acceptance test +`calculate_design_score(...) < 1e-8` compares the NEGATED error and is therefore always true (bug). Here we +evaluate the point averages of an orthonormal real spherical-harmonic basis directly (no cancellation). +""" +import numpy as np + +from run import Invalid, float_matrix + +TOL = 1e-10 + + +def harmonics(X, t): + """Rows: real spherical harmonics Y_lm (1 <= l <= t) normalised so that their mean square on S^2 is 1.""" + ct = np.clip(X[:, 2], -1.0, 1.0) + st = np.sqrt(np.maximum(0.0, 1.0 - ct * ct)) + ph = np.arctan2(X[:, 1], X[:, 0]) + P = {(0, 0): np.ones_like(ct)} + for m in range(1, t + 1): + P[(m, m)] = (np.sqrt(3.0) if m == 1 else np.sqrt((2 * m + 1) / (2 * m))) * st * P[(m - 1, m - 1)] + for m in range(0, t): + P[(m + 1, m)] = np.sqrt(2 * m + 3) * ct * P[(m, m)] + for m in range(0, t + 1): + for l in range(m + 2, t + 1): + a = np.sqrt((4 * l * l - 1) / (l * l - m * m)) + b = np.sqrt(((l - 1) ** 2 - m * m) / (4 * (l - 1) ** 2 - 1)) + P[(l, m)] = a * (ct * P[(l - 1, m)] - b * P[(l - 2, m)]) + rows = [] + for l in range(1, t + 1): + rows.append(P[(l, 0)]) + for m in range(1, l + 1): + rows.append(P[(l, m)] * np.cos(m * ph)) + rows.append(P[(l, m)] * np.sin(m * ph)) + return np.array(rows) + + +def check(inst, ans): + t, n = inst["t"], inst["N"] + X = np.array(float_matrix(ans.get("points"), n, 3, "points")) + nr = np.linalg.norm(X, axis=1) + if nr.min() < 0.5 or nr.max() > 2.0: + raise Invalid("points must be (approximately) unit vectors") + X = X / nr[:, None] + G = X @ X.T + np.fill_diagonal(G, -1.0) + if G.max() > 1.0 - 1e-8: + raise Invalid("two points coincide (or nearly: distance < 1.4e-4)") + dev = np.abs(harmonics(X, t).mean(axis=1)).max() + if not dev <= TOL: + raise Invalid(f"not a {t}-design: some harmonic of degree <= {t} has point average {dev:.3e} > {TOL}") + return None, {"max_harmonic_average": float(dev)} diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/tests/instance.json b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..247aa546bc3e1dad5dc06feec32540928cfdcb4f --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"t": 11, "N": 74, "family": "ae_p32_spherical_designs", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/tests/run.py b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p32-spherical-design-l3-s0/tests/test.sh b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p32-spherical-design-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9f558a96e31fea60cdbd697494a0ab090e941166 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"N": 1031, "t": 322, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56701ef93f428b9909dd4f5b654a7ae2296c7b10 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9f558a96e31fea60cdbd697494a0ab090e941166 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"N": 1031, "t": 322, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2aca60244e59dc7d92329d8220b1129053f65df1 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"N": 1164, "t": 365, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..295900c5b69ab3f95afbce8215f54a262751c6a0 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2aca60244e59dc7d92329d8220b1129053f65df1 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"N": 1164, "t": 365, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35ae1c66284a1ed20f4e1cdd26c5dbd16fa1f1ea --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"N": 3700, "t": 148, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aba4c615358126a4e58edc0dafc0921a44ba453c --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35ae1c66284a1ed20f4e1cdd26c5dbd16fa1f1ea --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"N": 3700, "t": 148, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ecc36d9224dddadbff45a6fdf9a0c4cd8e5df70 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"N": 1796, "t": 72, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6706aa516beb6e56a727ba2ac304970515de49da --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ecc36d9224dddadbff45a6fdf9a0c4cd8e5df70 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"N": 1796, "t": 72, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-all-interval-l4-s0/environment/Dockerfile b/tasks/construct-mc-all-interval-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l4-s0/environment/instance.json b/tasks/construct-mc-all-interval-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c284e9f8f3211aec581051af3ad9694d809021b2 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s0/solution/solve.sh b/tasks/construct-mc-all-interval-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c1f945b50f17b16724e12b23e20d66116e481f7a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 15, 1, 14, 2, 13, 3, 12, 4, 11, 5, 10, 6, 9, 7, 8]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l4-s0/tests/check.py b/tasks/construct-mc-all-interval-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l4-s0/tests/instance.json b/tasks/construct-mc-all-interval-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c284e9f8f3211aec581051af3ad9694d809021b2 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s0/tests/run.py b/tasks/construct-mc-all-interval-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l4-s0/tests/test.sh b/tasks/construct-mc-all-interval-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-all-interval-l4-s7/environment/Dockerfile b/tasks/construct-mc-all-interval-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l4-s7/environment/instance.json b/tasks/construct-mc-all-interval-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..234600bfd86605b63248d57cfe4f39fb63dd79e1 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s7/solution/solve.sh b/tasks/construct-mc-all-interval-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..03c089715c582cd71e0b3b4ead8fd679ea4b988f --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l4-s7/tests/check.py b/tasks/construct-mc-all-interval-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l4-s7/tests/instance.json b/tasks/construct-mc-all-interval-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..234600bfd86605b63248d57cfe4f39fb63dd79e1 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s7/tests/run.py b/tasks/construct-mc-all-interval-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l4-s7/tests/test.sh b/tasks/construct-mc-all-interval-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l2-s1/environment/Dockerfile b/tasks/construct-mc-costas-array-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l2-s1/environment/instance.json b/tasks/construct-mc-costas-array-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6638a9ab878c6fd2bcc6d41692af4a33a5aff6e9 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l2-s1/solution/solve.sh b/tasks/construct-mc-costas-array-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dd0188a39cedb732f490600210e42f09f0bff350 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [8, 5, 6, 0, 2, 1, 4, 9, 7, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l2-s1/tests/check.py b/tasks/construct-mc-costas-array-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l2-s1/tests/instance.json b/tasks/construct-mc-costas-array-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6638a9ab878c6fd2bcc6d41692af4a33a5aff6e9 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l2-s1/tests/run.py b/tasks/construct-mc-costas-array-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l2-s1/tests/test.sh b/tasks/construct-mc-costas-array-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l6-s0/environment/Dockerfile b/tasks/construct-mc-costas-array-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l6-s0/environment/instance.json b/tasks/construct-mc-costas-array-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89db9d4489a00e919ed948b243e88f951b1a5f28 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 28, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l6-s0/solution/solve.sh b/tasks/construct-mc-costas-array-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8f4f8b30f2859b17204e9ab4a7de44bd8fffcd28 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 1, 3, 7, 15, 2, 5, 11, 23, 18, 8, 17, 6, 13, 27, 26, 24, 20, 12, 25, 22, 16, 4, 9, 19, 10, 21, 14]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l6-s0/tests/check.py b/tasks/construct-mc-costas-array-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l6-s0/tests/instance.json b/tasks/construct-mc-costas-array-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89db9d4489a00e919ed948b243e88f951b1a5f28 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 28, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l6-s0/tests/run.py b/tasks/construct-mc-costas-array-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l6-s0/tests/test.sh b/tasks/construct-mc-costas-array-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-debruijn-l3-s3/environment/Dockerfile b/tasks/construct-mc-debruijn-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-debruijn-l3-s3/environment/instance.json b/tasks/construct-mc-debruijn-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d050ddd3b74f17b5aa046b3ae6e6a9fa57c4b78 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"b": 2, "n": 7, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l3-s3/solution/solve.sh b/tasks/construct-mc-debruijn-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..001bcf28896be42a8c5281904e878629b3dd75a8 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l3-s3/tests/check.py b/tasks/construct-mc-debruijn-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/tests/check.py @@ -0,0 +1,15 @@ +"""De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + b, n = inst["b"], inst["n"] + m = b ** n + x = int_list(ans.get("seq"), m, 0, b - 1, "seq") + seen = set() + for i in range(m): + w = tuple(x[(i + k) % m] for k in range(n)) + if w in seen: + raise Invalid(f"window {w} occurs twice") + seen.add(w) + return None, {} diff --git a/tasks/construct-mc-debruijn-l3-s3/tests/instance.json b/tasks/construct-mc-debruijn-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d050ddd3b74f17b5aa046b3ae6e6a9fa57c4b78 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"b": 2, "n": 7, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l3-s3/tests/run.py b/tasks/construct-mc-debruijn-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-debruijn-l3-s3/tests/test.sh b/tasks/construct-mc-debruijn-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2605d097575ca812d9fd9c813661f915fbfbd8cd --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 41, "k": 4, "edges": [[0, 3], [0, 6], [0, 7], [0, 20], [0, 21], [1, 2], [1, 15], [1, 21], [1, 25], [1, 26], [1, 32], [1, 38], [2, 3], [2, 7], [2, 13], [2, 27], [2, 28], [2, 36], [2, 40], [3, 11], [3, 17], [3, 25], [4, 5], [4, 13], [4, 23], [4, 26], [4, 29], [4, 32], [4, 38], [4, 40], [5, 6], [5, 11], [5, 15], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 24], [5, 29], [5, 30], [5, 35], [5, 36], [5, 39], [6, 8], [6, 18], [6, 27], [6, 32], [7, 12], [7, 18], [7, 19], [7, 24], [7, 25], [7, 26], [7, 31], [7, 39], [8, 22], [8, 29], [9, 11], [9, 19], [9, 23], [9, 31], [9, 32], [10, 14], [10, 22], [10, 34], [10, 35], [10, 37], [11, 13], [11, 19], [11, 21], [11, 22], [11, 23], [11, 30], [11, 36], [11, 37], [12, 14], [12, 21], [12, 27], [12, 29], [12, 34], [13, 25], [13, 26], [13, 27], [13, 29], [13, 38], [13, 39], [14, 15], [14, 30], [14, 32], [14, 33], [14, 40], [15, 19], [15, 24], [15, 30], [15, 34], [15, 38], [15, 39], [16, 18], [16, 21], [16, 24], [16, 25], [16, 29], [16, 40], [17, 35], [17, 39], [17, 40], [18, 26], [18, 30], [18, 39], [19, 22], [19, 26], [20, 36], [20, 37], [20, 39], [21, 24], [21, 25], [21, 29], [21, 32], [21, 33], [21, 37], [21, 38], [21, 39], [22, 24], [22, 35], [22, 36], [22, 40], [23, 27], [23, 34], [23, 36], [24, 25], [24, 33], [25, 26], [25, 38], [26, 29], [27, 29], [27, 34], [27, 35], [28, 30], [28, 32], [28, 36], [29, 38], [30, 36], [30, 37], [34, 35], [36, 38]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e52c33e5f0783c2a8bea274e12573847dac7b440 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 0, 1, 2, 0, 1, 2, 2, 0, 2, 1, 3, 1, 2, 0, 3, 1, 1, 3, 0, 2, 2, 2, 1, 0, 3, 1, 0, 3, 3, 2, 0, 1, 1, 2, 3, 0, 0, 1, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/tests/check.py b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2605d097575ca812d9fd9c813661f915fbfbd8cd --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 41, "k": 4, "edges": [[0, 3], [0, 6], [0, 7], [0, 20], [0, 21], [1, 2], [1, 15], [1, 21], [1, 25], [1, 26], [1, 32], [1, 38], [2, 3], [2, 7], [2, 13], [2, 27], [2, 28], [2, 36], [2, 40], [3, 11], [3, 17], [3, 25], [4, 5], [4, 13], [4, 23], [4, 26], [4, 29], [4, 32], [4, 38], [4, 40], [5, 6], [5, 11], [5, 15], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 24], [5, 29], [5, 30], [5, 35], [5, 36], [5, 39], [6, 8], [6, 18], [6, 27], [6, 32], [7, 12], [7, 18], [7, 19], [7, 24], [7, 25], [7, 26], [7, 31], [7, 39], [8, 22], [8, 29], [9, 11], [9, 19], [9, 23], [9, 31], [9, 32], [10, 14], [10, 22], [10, 34], [10, 35], [10, 37], [11, 13], [11, 19], [11, 21], [11, 22], [11, 23], [11, 30], [11, 36], [11, 37], [12, 14], [12, 21], [12, 27], [12, 29], [12, 34], [13, 25], [13, 26], [13, 27], [13, 29], [13, 38], [13, 39], [14, 15], [14, 30], [14, 32], [14, 33], [14, 40], [15, 19], [15, 24], [15, 30], [15, 34], [15, 38], [15, 39], [16, 18], [16, 21], [16, 24], [16, 25], [16, 29], [16, 40], [17, 35], [17, 39], [17, 40], [18, 26], [18, 30], [18, 39], [19, 22], [19, 26], [20, 36], [20, 37], [20, 39], [21, 24], [21, 25], [21, 29], [21, 32], [21, 33], [21, 37], [21, 38], [21, 39], [22, 24], [22, 35], [22, 36], [22, 40], [23, 27], [23, 34], [23, 36], [24, 25], [24, 33], [25, 26], [25, 38], [26, 29], [27, 29], [27, 34], [27, 35], [28, 30], [28, 32], [28, 36], [29, 38], [30, 36], [30, 37], [34, 35], [36, 38]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/tests/run.py b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l3-s1/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-langford-l3-s1/environment/Dockerfile b/tasks/construct-mc-langford-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l3-s1/environment/instance.json b/tasks/construct-mc-langford-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..747f9d960c734695516f8469ef7a5d734525dd77 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "fixed": [["seq", 3, 2], ["seq", 11, 14], ["seq", 13, 11], ["seq", 26, 14], ["seq", 27, 7], ["seq", 28, 10]], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s1/solution/solve.sh b/tasks/construct-mc-langford-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7f33e0df64e06723c221a0367ae20291b209942 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [2, 6, 3, 2, 4, 12, 3, 15, 6, 4, 13, 14, 9, 11, 1, 5, 1, 10, 12, 7, 8, 5, 9, 15, 13, 11, 14, 7, 10, 8]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l3-s1/tests/check.py b/tasks/construct-mc-langford-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l3-s1/tests/instance.json b/tasks/construct-mc-langford-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..747f9d960c734695516f8469ef7a5d734525dd77 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "fixed": [["seq", 3, 2], ["seq", 11, 14], ["seq", 13, 11], ["seq", 26, 14], ["seq", 27, 7], ["seq", 28, 10]], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s1/tests/run.py b/tasks/construct-mc-langford-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l3-s1/tests/test.sh b/tasks/construct-mc-langford-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l2-s3/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-magic-sequence-l2-s3/environment/instance.json b/tasks/construct-mc-magic-sequence-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a4b3ed26e32c2c84eef3c46b9e920dd9c537d0d1 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "fixed": [["x", 4, 0]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s3/solution/solve.sh b/tasks/construct-mc-magic-sequence-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ddb4d9051e8932e2715ae167552403c3aceac21e --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [5, 2, 1, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l2-s3/tests/check.py b/tasks/construct-mc-magic-sequence-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l2-s3/tests/instance.json b/tasks/construct-mc-magic-sequence-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a4b3ed26e32c2c84eef3c46b9e920dd9c537d0d1 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "fixed": [["x", 4, 0]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s3/tests/run.py b/tasks/construct-mc-magic-sequence-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-magic-sequence-l2-s3/tests/test.sh b/tasks/construct-mc-magic-sequence-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l1-s3/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l1-s3/environment/instance.json b/tasks/construct-mc-max-clique-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9c1f722ca825c3a5719058ba357f60c95d2cff66 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 7], [0, 11], [0, 12], [0, 13], [0, 15], [0, 16], [0, 20], [0, 22], [0, 23], [1, 6], [1, 8], [1, 12], [1, 14], [1, 15], [1, 16], [1, 19], [2, 3], [2, 10], [2, 17], [2, 20], [2, 23], [3, 4], [3, 5], [3, 7], [3, 13], [3, 22], [3, 23], [3, 24], [4, 13], [4, 23], [5, 14], [5, 17], [6, 7], [6, 8], [6, 11], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 24], [7, 8], [7, 12], [7, 13], [7, 15], [7, 17], [7, 23], [7, 24], [8, 12], [8, 13], [8, 17], [8, 18], [8, 23], [9, 14], [9, 19], [9, 20], [9, 21], [10, 13], [10, 14], [10, 15], [11, 15], [11, 19], [11, 24], [12, 13], [12, 15], [12, 16], [12, 17], [12, 20], [12, 24], [13, 15], [13, 16], [13, 17], [13, 19], [14, 17], [14, 23], [14, 24], [15, 16], [15, 17], [15, 24], [16, 19], [17, 20], [17, 24], [18, 19], [19, 20], [19, 22], [19, 24], [20, 24], [21, 22], [21, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s3/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e27301e7c045278926758b94ec9c29fdf0e47ce3 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [6, 7, 8, 13, 17]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s3/tests/check.py b/tasks/construct-mc-max-clique-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l1-s3/tests/instance.json b/tasks/construct-mc-max-clique-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9c1f722ca825c3a5719058ba357f60c95d2cff66 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 7], [0, 11], [0, 12], [0, 13], [0, 15], [0, 16], [0, 20], [0, 22], [0, 23], [1, 6], [1, 8], [1, 12], [1, 14], [1, 15], [1, 16], [1, 19], [2, 3], [2, 10], [2, 17], [2, 20], [2, 23], [3, 4], [3, 5], [3, 7], [3, 13], [3, 22], [3, 23], [3, 24], [4, 13], [4, 23], [5, 14], [5, 17], [6, 7], [6, 8], [6, 11], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 24], [7, 8], [7, 12], [7, 13], [7, 15], [7, 17], [7, 23], [7, 24], [8, 12], [8, 13], [8, 17], [8, 18], [8, 23], [9, 14], [9, 19], [9, 20], [9, 21], [10, 13], [10, 14], [10, 15], [11, 15], [11, 19], [11, 24], [12, 13], [12, 15], [12, 16], [12, 17], [12, 20], [12, 24], [13, 15], [13, 16], [13, 17], [13, 19], [14, 17], [14, 23], [14, 24], [15, 16], [15, 17], [15, 24], [16, 19], [17, 20], [17, 24], [18, 19], [19, 20], [19, 22], [19, 24], [20, 24], [21, 22], [21, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s3/tests/run.py b/tasks/construct-mc-max-clique-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l1-s3/tests/test.sh b/tasks/construct-mc-max-clique-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l1-s4/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l1-s4/environment/instance.json b/tasks/construct-mc-max-clique-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad3d6c1bd0b6f456c7e7d380b771da4aa7da90b5 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 15], [0, 20], [0, 22], [1, 3], [1, 7], [1, 9], [1, 12], [1, 15], [1, 18], [1, 20], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [2, 14], [2, 16], [3, 4], [3, 11], [3, 12], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [4, 8], [4, 12], [4, 18], [4, 20], [4, 21], [5, 8], [5, 16], [5, 19], [5, 20], [6, 7], [6, 10], [6, 11], [6, 14], [6, 16], [6, 17], [6, 18], [6, 23], [6, 24], [7, 8], [7, 9], [7, 10], [7, 13], [7, 16], [7, 19], [8, 13], [8, 15], [8, 17], [8, 22], [8, 23], [9, 11], [9, 14], [9, 17], [9, 18], [9, 22], [10, 13], [10, 14], [10, 16], [10, 22], [10, 24], [11, 13], [11, 14], [11, 15], [11, 16], [11, 20], [11, 23], [12, 19], [12, 21], [13, 14], [13, 18], [13, 23], [13, 24], [14, 19], [14, 21], [14, 23], [15, 20], [16, 17], [16, 20], [16, 22], [17, 21], [17, 24], [18, 19], [18, 20], [19, 21], [20, 21], [20, 23], [21, 24], [22, 23], [22, 24], [23, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s4/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..85fcafc42e7865aea462766c63921b5372544019 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [2, 6, 7, 10, 16]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s4/tests/check.py b/tasks/construct-mc-max-clique-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l1-s4/tests/instance.json b/tasks/construct-mc-max-clique-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad3d6c1bd0b6f456c7e7d380b771da4aa7da90b5 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 15], [0, 20], [0, 22], [1, 3], [1, 7], [1, 9], [1, 12], [1, 15], [1, 18], [1, 20], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [2, 14], [2, 16], [3, 4], [3, 11], [3, 12], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [4, 8], [4, 12], [4, 18], [4, 20], [4, 21], [5, 8], [5, 16], [5, 19], [5, 20], [6, 7], [6, 10], [6, 11], [6, 14], [6, 16], [6, 17], [6, 18], [6, 23], [6, 24], [7, 8], [7, 9], [7, 10], [7, 13], [7, 16], [7, 19], [8, 13], [8, 15], [8, 17], [8, 22], [8, 23], [9, 11], [9, 14], [9, 17], [9, 18], [9, 22], [10, 13], [10, 14], [10, 16], [10, 22], [10, 24], [11, 13], [11, 14], [11, 15], [11, 16], [11, 20], [11, 23], [12, 19], [12, 21], [13, 14], [13, 18], [13, 23], [13, 24], [14, 19], [14, 21], [14, 23], [15, 20], [16, 17], [16, 20], [16, 22], [17, 21], [17, 24], [18, 19], [18, 20], [19, 21], [20, 21], [20, 23], [21, 24], [22, 23], [22, 24], [23, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s4/tests/run.py b/tasks/construct-mc-max-clique-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l1-s4/tests/test.sh b/tasks/construct-mc-max-clique-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s2/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l5-s2/environment/instance.json b/tasks/construct-mc-max-clique-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c67de52f8e9621a0b2433421bf65c612d99c1360 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 2], [0, 3], [0, 9], [0, 10], [0, 12], [0, 13], [0, 14], [0, 15], [0, 17], [0, 20], [0, 21], [0, 22], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 31], [0, 32], [0, 33], [0, 35], [0, 37], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 47], [0, 48], [0, 51], [0, 52], [0, 53], [0, 54], [0, 55], [0, 60], [0, 62], [0, 63], [0, 65], [0, 66], [0, 67], [0, 70], [0, 72], [0, 74], [0, 75], [0, 77], [0, 82], [0, 83], [0, 84], [0, 86], [0, 87], [0, 89], [1, 3], [1, 4], [1, 6], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 19], [1, 20], [1, 22], [1, 25], [1, 27], [1, 30], [1, 33], [1, 35], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 44], [1, 46], [1, 48], [1, 50], [1, 53], [1, 57], [1, 62], [1, 64], [1, 67], [1, 68], [1, 69], [1, 70], [1, 74], [1, 76], [1, 79], [1, 81], [1, 83], [1, 86], [1, 87], [1, 88], [2, 3], [2, 4], [2, 7], [2, 9], [2, 10], [2, 15], [2, 19], [2, 20], [2, 21], [2, 22], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 31], [2, 34], [2, 40], [2, 41], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 49], [2, 50], [2, 51], [2, 53], [2, 54], [2, 57], [2, 58], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 69], [2, 71], [2, 76], [2, 80], [2, 81], [2, 82], [2, 83], [2, 85], [2, 87], [2, 89], [3, 6], [3, 9], [3, 12], [3, 15], [3, 16], [3, 17], [3, 21], [3, 27], [3, 29], [3, 32], [3, 33], [3, 36], [3, 37], [3, 41], [3, 44], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 52], [3, 53], [3, 55], [3, 56], [3, 58], [3, 59], [3, 60], [3, 61], [3, 63], [3, 65], [3, 67], [3, 69], [3, 72], [3, 75], [3, 77], [3, 79], [3, 82], [3, 84], [3, 86], [4, 5], [4, 10], [4, 11], [4, 12], [4, 14], [4, 16], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 31], [4, 32], [4, 33], [4, 36], [4, 38], [4, 40], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 50], [4, 53], [4, 55], [4, 56], [4, 57], [4, 58], [4, 62], [4, 64], [4, 65], [4, 67], [4, 68], [4, 71], [4, 72], [4, 75], [4, 76], [4, 77], [4, 80], [4, 81], [4, 82], [4, 83], [4, 85], [4, 86], [4, 88], [4, 89], [5, 6], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 16], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 34], [5, 37], [5, 38], [5, 40], [5, 47], [5, 48], [5, 49], [5, 54], [5, 55], [5, 56], [5, 59], [5, 60], [5, 61], [5, 66], [5, 69], [5, 71], [5, 73], [5, 75], [5, 78], [5, 79], [5, 80], [5, 85], [5, 88], [6, 11], [6, 12], [6, 13], [6, 17], [6, 19], [6, 21], [6, 24], [6, 25], [6, 27], [6, 28], [6, 30], [6, 31], [6, 37], [6, 39], [6, 43], [6, 46], [6, 47], [6, 51], [6, 52], [6, 56], [6, 57], [6, 59], [6, 60], [6, 62], [6, 63], [6, 65], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [6, 73], [6, 74], [6, 77], [6, 79], [6, 82], [6, 86], [6, 89], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 21], [7, 23], [7, 24], [7, 26], [7, 27], [7, 31], [7, 32], [7, 37], [7, 39], [7, 40], [7, 44], [7, 47], [7, 54], [7, 55], [7, 57], [7, 59], [7, 61], [7, 63], [7, 65], [7, 68], [7, 73], [7, 74], [7, 76], [7, 79], [7, 80], [7, 82], [7, 87], [8, 10], [8, 12], [8, 13], [8, 15], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 25], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 34], [8, 38], [8, 40], [8, 41], [8, 42], [8, 45], [8, 46], [8, 47], [8, 49], [8, 51], [8, 52], [8, 54], [8, 55], [8, 56], [8, 60], [8, 61], [8, 62], [8, 68], [8, 70], [8, 73], [8, 74], [8, 77], [8, 83], [8, 85], [8, 86], [8, 87], [9, 10], [9, 11], [9, 13], [9, 16], [9, 17], [9, 19], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [9, 29], [9, 31], [9, 34], [9, 35], [9, 36], [9, 37], [9, 42], [9, 44], [9, 46], [9, 49], [9, 51], [9, 53], [9, 54], [9, 56], [9, 58], [9, 59], [9, 60], [9, 63], [9, 64], [9, 67], [9, 68], [9, 72], [9, 73], [9, 80], [9, 82], [9, 85], [9, 87], [9, 89], [10, 11], [10, 12], [10, 13], [10, 14], [10, 18], [10, 19], [10, 20], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [10, 31], [10, 33], [10, 34], [10, 35], [10, 37], [10, 38], [10, 40], [10, 43], [10, 44], [10, 49], [10, 50], [10, 51], [10, 53], [10, 54], [10, 57], [10, 58], [10, 60], [10, 62], [10, 63], [10, 64], [10, 65], [10, 67], [10, 68], [10, 73], [10, 75], [10, 76], [10, 79], [10, 80], [10, 82], [10, 88], [11, 13], [11, 14], [11, 15], [11, 18], [11, 19], [11, 22], [11, 23], [11, 24], [11, 27], [11, 28], [11, 29], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 41], [11, 45], [11, 47], [11, 49], [11, 50], [11, 53], [11, 54], [11, 55], [11, 58], [11, 60], [11, 61], [11, 62], [11, 63], [11, 65], [11, 67], [11, 68], [11, 70], [11, 73], [11, 75], [11, 76], [11, 78], [11, 79], [11, 80], [11, 81], [11, 85], [11, 89], [12, 15], [12, 17], [12, 18], [12, 19], [12, 20], [12, 23], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 41], [12, 44], [12, 47], [12, 48], [12, 49], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 63], [12, 66], [12, 67], [12, 68], [12, 69], [12, 71], [12, 72], [12, 75], [12, 76], [12, 78], [12, 79], [12, 81], [12, 83], [12, 84], [12, 85], [12, 87], [12, 88], [13, 14], [13, 15], [13, 17], [13, 18], [13, 20], [13, 21], [13, 23], [13, 27], [13, 29], [13, 30], [13, 31], [13, 32], [13, 39], [13, 40], [13, 42], [13, 46], [13, 47], [13, 49], [13, 51], [13, 52], [13, 53], [13, 56], [13, 58], [13, 61], [13, 65], [13, 66], [13, 67], [13, 68], [13, 71], [13, 72], [13, 74], [13, 76], [13, 80], [13, 83], [13, 84], [13, 85], [13, 88], [14, 15], [14, 16], [14, 18], [14, 19], [14, 22], [14, 23], [14, 24], [14, 25], [14, 27], [14, 28], [14, 31], [14, 34], [14, 35], [14, 36], [14, 37], [14, 38], [14, 40], [14, 41], [14, 42], [14, 44], [14, 47], [14, 51], [14, 52], [14, 53], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 66], [14, 68], [14, 74], [14, 75], [14, 80], [14, 82], [14, 83], [14, 84], [14, 86], [14, 87], [15, 16], [15, 18], [15, 19], [15, 20], [15, 22], [15, 24], [15, 26], [15, 28], [15, 29], [15, 32], [15, 33], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 46], [15, 52], [15, 54], [15, 60], [15, 61], [15, 64], [15, 68], [15, 69], [15, 70], [15, 72], [15, 73], [15, 74], [15, 75], [15, 76], [15, 79], [15, 82], [15, 83], [15, 85], [15, 86], [15, 88], [16, 17], [16, 20], [16, 22], [16, 26], [16, 29], [16, 32], [16, 33], [16, 35], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 44], [16, 45], [16, 46], [16, 49], [16, 50], [16, 51], [16, 53], [16, 54], [16, 56], [16, 58], [16, 59], [16, 64], [16, 65], [16, 69], [16, 73], [16, 74], [16, 75], [16, 76], [16, 77], [16, 78], [16, 79], [16, 80], [16, 81], [16, 82], [16, 84], [16, 87], [16, 88], [16, 89], [17, 18], [17, 19], [17, 24], [17, 25], [17, 27], [17, 30], [17, 31], [17, 33], [17, 35], [17, 36], [17, 39], [17, 40], [17, 44], [17, 45], [17, 46], [17, 47], [17, 49], [17, 51], [17, 52], [17, 54], [17, 56], [17, 57], [17, 60], [17, 61], [17, 64], [17, 66], [17, 67], [17, 70], [17, 72], [17, 73], [17, 74], [17, 75], [17, 76], [17, 77], [17, 79], [17, 84], [17, 86], [18, 22], [18, 23], [18, 26], [18, 27], [18, 28], [18, 32], [18, 35], [18, 38], [18, 39], [18, 40], [18, 41], [18, 42], [18, 46], [18, 47], [18, 48], [18, 49], [18, 52], [18, 53], [18, 54], [18, 56], [18, 61], [18, 62], [18, 63], [18, 69], [18, 70], [18, 72], [18, 73], [18, 78], [18, 80], [18, 81], [18, 83], [18, 87], [18, 88], [18, 89], [19, 21], [19, 22], [19, 23], [19, 24], [19, 27], [19, 31], [19, 32], [19, 34], [19, 37], [19, 39], [19, 41], [19, 42], [19, 43], [19, 44], [19, 46], [19, 48], [19, 49], [19, 53], [19, 54], [19, 55], [19, 59], [19, 60], [19, 62], [19, 64], [19, 66], [19, 67], [19, 72], [19, 74], [19, 75], [19, 77], [19, 78], [19, 79], [19, 80], [19, 81], [19, 82], [19, 83], [19, 84], [19, 85], [19, 86], [19, 87], [20, 22], [20, 23], [20, 24], [20, 25], [20, 28], [20, 31], [20, 33], [20, 34], [20, 36], [20, 40], [20, 41], [20, 45], [20, 47], [20, 48], [20, 49], [20, 52], [20, 53], [20, 54], [20, 56], [20, 57], [20, 61], [20, 62], [20, 63], [20, 66], [20, 67], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [20, 75], [20, 76], [20, 79], [20, 80], [20, 82], [20, 83], [20, 84], [20, 85], [20, 86], [20, 87], [21, 22], [21, 23], [21, 24], [21, 26], [21, 28], [21, 33], [21, 39], [21, 41], [21, 43], [21, 44], [21, 46], [21, 47], [21, 48], [21, 49], [21, 51], [21, 53], [21, 54], [21, 57], [21, 58], [21, 61], [21, 63], [21, 66], [21, 67], [21, 68], [21, 69], [21, 72], [21, 75], [21, 77], [21, 78], [21, 79], [21, 82], [21, 83], [21, 84], [21, 87], [22, 23], [22, 24], [22, 25], [22, 27], [22, 32], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [22, 40], [22, 41], [22, 42], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 50], [22, 52], [22, 56], [22, 59], [22, 60], [22, 63], [22, 64], [22, 66], [22, 67], [22, 71], [22, 72], [22, 73], [22, 75], [22, 76], [22, 78], [22, 79], [22, 80], [22, 82], [22, 86], [22, 89], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 30], [23, 31], [23, 32], [23, 33], [23, 35], [23, 37], [23, 38], [23, 40], [23, 41], [23, 45], [23, 47], [23, 48], [23, 50], [23, 57], [23, 58], [23, 60], [23, 64], [23, 67], [23, 68], [23, 69], [23, 71], [23, 73], [23, 75], [23, 76], [23, 79], [23, 81], [23, 82], [23, 83], [23, 84], [23, 87], [24, 25], [24, 26], [24, 28], [24, 32], [24, 34], [24, 36], [24, 37], [24, 38], [24, 39], [24, 42], [24, 43], [24, 45], [24, 47], [24, 48], [24, 50], [24, 52], [24, 58], [24, 61], [24, 63], [24, 64], [24, 66], [24, 67], [24, 71], [24, 75], [24, 76], [24, 79], [24, 80], [24, 82], [24, 84], [24, 85], [24, 87], [25, 26], [25, 29], [25, 31], [25, 34], [25, 35], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 66], [25, 67], [25, 70], [25, 73], [25, 74], [25, 79], [25, 81], [25, 83], [25, 85], [25, 86], [25, 88], [26, 27], [26, 30], [26, 32], [26, 33], [26, 35], [26, 36], [26, 42], [26, 44], [26, 45], [26, 46], [26, 47], [26, 49], [26, 54], [26, 57], [26, 58], [26, 65], [26, 67], [26, 68], [26, 73], [26, 75], [26, 76], [26, 78], [26, 79], [26, 81], [26, 82], [26, 83], [26, 84], [26, 86], [26, 87], [26, 89], [27, 29], [27, 30], [27, 40], [27, 42], [27, 44], [27, 48], [27, 49], [27, 52], [27, 54], [27, 57], [27, 59], [27, 62], [27, 63], [27, 64], [27, 67], [27, 68], [27, 69], [27, 73], [27, 74], [27, 76], [27, 77], [27, 78], [27, 84], [27, 87], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 39], [28, 45], [28, 48], [28, 49], [28, 51], [28, 53], [28, 56], [28, 58], [28, 59], [28, 60], [28, 62], [28, 65], [28, 66], [28, 69], [28, 72], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 79], [28, 83], [28, 86], [28, 87], [28, 89], [29, 31], [29, 32], [29, 34], [29, 43], [29, 45], [29, 46], [29, 49], [29, 50], [29, 51], [29, 54], [29, 55], [29, 57], [29, 62], [29, 63], [29, 65], [29, 68], [29, 69], [29, 70], [29, 72], [29, 73], [29, 74], [29, 75], [29, 76], [29, 77], [29, 79], [29, 82], [29, 84], [29, 85], [29, 86], [29, 87], [30, 32], [30, 33], [30, 34], [30, 37], [30, 39], [30, 42], [30, 45], [30, 46], [30, 47], [30, 49], [30, 50], [30, 51], [30, 55], [30, 56], [30, 57], [30, 59], [30, 62], [30, 64], [30, 65], [30, 72], [30, 74], [30, 81], [30, 82], [30, 84], [30, 85], [30, 87], [30, 88], [31, 35], [31, 36], [31, 37], [31, 41], [31, 43], [31, 44], [31, 45], [31, 48], [31, 49], [31, 50], [31, 51], [31, 52], [31, 53], [31, 55], [31, 56], [31, 60], [31, 61], [31, 63], [31, 64], [31, 66], [31, 69], [31, 70], [31, 71], [31, 72], [31, 73], [31, 74], [31, 84], [31, 85], [31, 89], [32, 33], [32, 34], [32, 35], [32, 37], [32, 38], [32, 40], [32, 42], [32, 45], [32, 46], [32, 48], [32, 50], [32, 54], [32, 56], [32, 57], [32, 59], [32, 60], [32, 65], [32, 66], [32, 67], [32, 68], [32, 76], [32, 77], [32, 79], [32, 80], [32, 81], [32, 82], [32, 85], [32, 86], [32, 87], [32, 88], [32, 89], [33, 35], [33, 36], [33, 40], [33, 41], [33, 42], [33, 43], [33, 45], [33, 48], [33, 53], [33, 55], [33, 57], [33, 61], [33, 62], [33, 64], [33, 68], [33, 69], [33, 70], [33, 72], [33, 75], [33, 83], [33, 84], [33, 85], [33, 87], [33, 88], [34, 35], [34, 36], [34, 37], [34, 39], [34, 41], [34, 42], [34, 43], [34, 44], [34, 48], [34, 49], [34, 52], [34, 55], [34, 56], [34, 57], [34, 65], [34, 66], [34, 67], [34, 68], [34, 69], [34, 72], [34, 76], [34, 77], [34, 79], [34, 80], [34, 82], [34, 87], [34, 88], [34, 89], [35, 36], [35, 37], [35, 40], [35, 42], [35, 43], [35, 48], [35, 49], [35, 52], [35, 56], [35, 58], [35, 59], [35, 62], [35, 63], [35, 66], [35, 71], [35, 76], [35, 77], [35, 78], [35, 79], [35, 82], [35, 83], [35, 86], [35, 87], [35, 88], [36, 38], [36, 41], [36, 45], [36, 51], [36, 52], [36, 53], [36, 54], [36, 58], [36, 59], [36, 61], [36, 62], [36, 67], [36, 69], [36, 71], [36, 72], [36, 76], [36, 77], [36, 79], [36, 80], [36, 82], [36, 83], [36, 86], [36, 89], [37, 38], [37, 41], [37, 42], [37, 44], [37, 46], [37, 47], [37, 48], [37, 49], [37, 51], [37, 52], [37, 55], [37, 56], [37, 57], [37, 58], [37, 61], [37, 62], [37, 63], [37, 64], [37, 66], [37, 67], [37, 71], [37, 72], [37, 74], [37, 75], [37, 79], [37, 80], [37, 82], [37, 83], [37, 84], [37, 87], [37, 89], [38, 40], [38, 41], [38, 43], [38, 44], [38, 45], [38, 47], [38, 48], [38, 50], [38, 53], [38, 55], [38, 56], [38, 60], [38, 64], [38, 66], [38, 67], [38, 68], [38, 70], [38, 72], [38, 73], [38, 74], [38, 82], [38, 83], [38, 84], [38, 85], [38, 87], [38, 89], [39, 40], [39, 41], [39, 42], [39, 43], [39, 45], [39, 46], [39, 48], [39, 50], [39, 51], [39, 53], [39, 54], [39, 55], [39, 56], [39, 57], [39, 58], [39, 59], [39, 62], [39, 63], [39, 64], [39, 67], [39, 68], [39, 70], [39, 71], [39, 74], [39, 75], [39, 76], [39, 77], [39, 78], [39, 79], [39, 81], [39, 88], [40, 44], [40, 52], [40, 54], [40, 56], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 70], [40, 72], [40, 73], [40, 76], [40, 82], [40, 84], [40, 87], [40, 89], [41, 42], [41, 44], [41, 46], [41, 49], [41, 51], [41, 52], [41, 53], [41, 54], [41, 60], [41, 62], [41, 65], [41, 66], [41, 68], [41, 73], [41, 74], [41, 79], [41, 80], [41, 81], [41, 82], [41, 83], [41, 84], [41, 86], [41, 88], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 52], [42, 53], [42, 54], [42, 59], [42, 61], [42, 65], [42, 66], [42, 67], [42, 68], [42, 69], [42, 70], [42, 72], [42, 73], [42, 76], [42, 78], [42, 79], [42, 80], [42, 82], [42, 85], [42, 88], [43, 44], [43, 45], [43, 47], [43, 49], [43, 52], [43, 53], [43, 57], [43, 59], [43, 60], [43, 63], [43, 64], [43, 65], [43, 67], [43, 72], [43, 74], [43, 75], [43, 77], [43, 78], [43, 82], [43, 83], [43, 84], [43, 88], [44, 45], [44, 46], [44, 47], [44, 49], [44, 51], [44, 52], [44, 55], [44, 57], [44, 58], [44, 60], [44, 61], [44, 63], [44, 64], [44, 65], [44, 68], [44, 69], [44, 70], [44, 71], [44, 74], [44, 75], [44, 76], [44, 81], [44, 83], [44, 84], [44, 87], [44, 88], [44, 89], [45, 55], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 65], [45, 68], [45, 71], [45, 75], [45, 78], [45, 79], [45, 80], [45, 81], [45, 85], [45, 86], [45, 87], [45, 88], [45, 89], [46, 49], [46, 52], [46, 54], [46, 55], [46, 56], [46, 57], [46, 58], [46, 60], [46, 62], [46, 63], [46, 67], [46, 71], [46, 73], [46, 74], [46, 75], [46, 76], [46, 78], [46, 81], [46, 83], [46, 84], [46, 85], [46, 86], [46, 87], [46, 88], [47, 50], [47, 51], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 59], [47, 60], [47, 61], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 69], [47, 71], [47, 75], [47, 77], [47, 80], [47, 81], [47, 83], [47, 84], [47, 88], [47, 89], [48, 49], [48, 53], [48, 56], [48, 61], [48, 62], [48, 67], [48, 69], [48, 73], [48, 74], [48, 75], [48, 79], [48, 80], [48, 82], [48, 83], [48, 84], [48, 88], [48, 89], [49, 50], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 57], [49, 59], [49, 61], [49, 64], [49, 65], [49, 66], [49, 70], [49, 72], [49, 75], [49, 76], [49, 78], [49, 79], [49, 81], [49, 83], [49, 84], [49, 85], [49, 86], [49, 87], [49, 89], [50, 52], [50, 53], [50, 54], [50, 56], [50, 57], [50, 58], [50, 60], [50, 62], [50, 64], [50, 65], [50, 69], [50, 70], [50, 74], [50, 75], [50, 76], [50, 79], [50, 81], [50, 83], [50, 88], [50, 89], [51, 57], [51, 58], [51, 61], [51, 62], [51, 66], [51, 69], [51, 70], [51, 72], [51, 73], [51, 74], [51, 75], [51, 76], [51, 78], [51, 80], [51, 81], [51, 82], [51, 83], [51, 88], [52, 55], [52, 56], [52, 57], [52, 65], [52, 66], [52, 68], [52, 69], [52, 73], [52, 74], [52, 75], [52, 76], [52, 77], [52, 80], [52, 81], [52, 83], [52, 85], [53, 54], [53, 55], [53, 57], [53, 59], [53, 61], [53, 63], [53, 65], [53, 66], [53, 67], [53, 70], [53, 71], [53, 72], [53, 74], [53, 75], [53, 76], [53, 80], [53, 82], [53, 84], [53, 87], [53, 89], [54, 55], [54, 56], [54, 58], [54, 59], [54, 61], [54, 62], [54, 64], [54, 66], [54, 67], [54, 68], [54, 70], [54, 71], [54, 75], [54, 77], [54, 78], [54, 79], [54, 80], [54, 82], [54, 83], [54, 84], [54, 87], [54, 89], [55, 57], [55, 59], [55, 62], [55, 66], [55, 67], [55, 70], [55, 71], [55, 72], [55, 78], [55, 79], [55, 81], [55, 82], [55, 83], [55, 85], [55, 87], [55, 89], [56, 61], [56, 62], [56, 64], [56, 65], [56, 70], [56, 71], [56, 73], [56, 75], [56, 76], [56, 78], [56, 80], [56, 81], [56, 82], [56, 83], [56, 84], [56, 86], [56, 88], [56, 89], [57, 61], [57, 63], [57, 69], [57, 71], [57, 72], [57, 73], [57, 75], [57, 78], [57, 80], [57, 82], [57, 83], [57, 87], [57, 89], [58, 59], [58, 66], [58, 68], [58, 70], [58, 72], [58, 74], [58, 78], [58, 82], [58, 83], [58, 84], [58, 88], [58, 89], [59, 61], [59, 65], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [59, 80], [59, 81], [59, 82], [59, 83], [59, 84], [59, 85], [59, 87], [59, 88], [60, 62], [60, 64], [60, 65], [60, 67], [60, 68], [60, 76], [60, 85], [60, 87], [61, 62], [61, 63], [61, 65], [61, 67], [61, 68], [61, 70], [61, 71], [61, 73], [61, 75], [61, 78], [61, 79], [61, 80], [61, 81], [61, 84], [61, 85], [61, 86], [61, 87], [61, 88], [62, 63], [62, 64], [62, 65], [62, 67], [62, 70], [62, 71], [62, 72], [62, 73], [62, 75], [62, 76], [62, 78], [62, 81], [62, 85], [62, 86], [63, 65], [63, 67], [63, 70], [63, 72], [63, 74], [63, 75], [63, 76], [63, 77], [63, 80], [63, 81], [63, 82], [63, 83], [63, 85], [63, 86], [63, 87], [63, 88], [63, 89], [64, 65], [64, 67], [64, 68], [64, 69], [64, 73], [64, 74], [64, 76], [64, 78], [64, 80], [64, 83], [64, 84], [64, 86], [64, 87], [65, 66], [65, 68], [65, 71], [65, 73], [65, 76], [65, 77], [65, 78], [65, 80], [65, 85], [65, 86], [65, 87], [65, 88], [66, 68], [66, 72], [66, 73], [66, 74], [66, 76], [66, 77], [66, 79], [66, 85], [66, 89], [67, 69], [67, 70], [67, 71], [67, 73], [67, 74], [67, 75], [67, 79], [67, 80], [67, 81], [67, 82], [67, 85], [67, 87], [67, 89], [68, 69], [68, 72], [68, 73], [68, 75], [68, 76], [68, 77], [68, 78], [68, 79], [68, 81], [68, 82], [68, 83], [68, 85], [68, 87], [68, 89], [69, 70], [69, 71], [69, 72], [69, 77], [69, 80], [69, 87], [69, 89], [70, 71], [70, 75], [70, 77], [70, 78], [70, 79], [70, 80], [70, 81], [70, 82], [70, 84], [70, 85], [70, 88], [70, 89], [71, 72], [71, 75], [71, 77], [71, 79], [71, 81], [71, 82], [71, 87], [71, 88], [71, 89], [72, 73], [72, 79], [72, 81], [72, 83], [72, 85], [72, 86], [72, 87], [73, 76], [73, 78], [73, 79], [73, 81], [73, 83], [73, 85], [73, 87], [73, 88], [74, 75], [74, 76], [74, 78], [74, 80], [74, 81], [74, 82], [74, 86], [74, 87], [75, 77], [75, 78], [75, 79], [75, 80], [75, 83], [75, 84], [75, 86], [75, 87], [75, 88], [76, 79], [76, 80], [76, 82], [76, 83], [76, 85], [76, 86], [76, 87], [77, 79], [77, 80], [77, 82], [77, 88], [78, 79], [78, 80], [78, 81], [78, 83], [78, 84], [78, 87], [78, 88], [79, 80], [79, 82], [79, 88], [79, 89], [80, 82], [80, 84], [80, 85], [80, 89], [81, 83], [81, 84], [81, 85], [81, 86], [81, 87], [81, 89], [82, 84], [82, 88], [83, 87], [83, 88], [84, 86], [84, 87], [84, 88], [85, 88], [86, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s2/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7e5604baa57ab82940d25117f65d1357e0e415ef --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [19, 22, 24, 32, 34, 37, 42, 48, 67, 79, 80, 82]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s2/tests/check.py b/tasks/construct-mc-max-clique-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l5-s2/tests/instance.json b/tasks/construct-mc-max-clique-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c67de52f8e9621a0b2433421bf65c612d99c1360 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 2], [0, 3], [0, 9], [0, 10], [0, 12], [0, 13], [0, 14], [0, 15], [0, 17], [0, 20], [0, 21], [0, 22], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 31], [0, 32], [0, 33], [0, 35], [0, 37], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 47], [0, 48], [0, 51], [0, 52], [0, 53], [0, 54], [0, 55], [0, 60], [0, 62], [0, 63], [0, 65], [0, 66], [0, 67], [0, 70], [0, 72], [0, 74], [0, 75], [0, 77], [0, 82], [0, 83], [0, 84], [0, 86], [0, 87], [0, 89], [1, 3], [1, 4], [1, 6], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 19], [1, 20], [1, 22], [1, 25], [1, 27], [1, 30], [1, 33], [1, 35], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 44], [1, 46], [1, 48], [1, 50], [1, 53], [1, 57], [1, 62], [1, 64], [1, 67], [1, 68], [1, 69], [1, 70], [1, 74], [1, 76], [1, 79], [1, 81], [1, 83], [1, 86], [1, 87], [1, 88], [2, 3], [2, 4], [2, 7], [2, 9], [2, 10], [2, 15], [2, 19], [2, 20], [2, 21], [2, 22], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 31], [2, 34], [2, 40], [2, 41], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 49], [2, 50], [2, 51], [2, 53], [2, 54], [2, 57], [2, 58], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 69], [2, 71], [2, 76], [2, 80], [2, 81], [2, 82], [2, 83], [2, 85], [2, 87], [2, 89], [3, 6], [3, 9], [3, 12], [3, 15], [3, 16], [3, 17], [3, 21], [3, 27], [3, 29], [3, 32], [3, 33], [3, 36], [3, 37], [3, 41], [3, 44], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 52], [3, 53], [3, 55], [3, 56], [3, 58], [3, 59], [3, 60], [3, 61], [3, 63], [3, 65], [3, 67], [3, 69], [3, 72], [3, 75], [3, 77], [3, 79], [3, 82], [3, 84], [3, 86], [4, 5], [4, 10], [4, 11], [4, 12], [4, 14], [4, 16], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 31], [4, 32], [4, 33], [4, 36], [4, 38], [4, 40], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 50], [4, 53], [4, 55], [4, 56], [4, 57], [4, 58], [4, 62], [4, 64], [4, 65], [4, 67], [4, 68], [4, 71], [4, 72], [4, 75], [4, 76], [4, 77], [4, 80], [4, 81], [4, 82], [4, 83], [4, 85], [4, 86], [4, 88], [4, 89], [5, 6], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 16], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 34], [5, 37], [5, 38], [5, 40], [5, 47], [5, 48], [5, 49], [5, 54], [5, 55], [5, 56], [5, 59], [5, 60], [5, 61], [5, 66], [5, 69], [5, 71], [5, 73], [5, 75], [5, 78], [5, 79], [5, 80], [5, 85], [5, 88], [6, 11], [6, 12], [6, 13], [6, 17], [6, 19], [6, 21], [6, 24], [6, 25], [6, 27], [6, 28], [6, 30], [6, 31], [6, 37], [6, 39], [6, 43], [6, 46], [6, 47], [6, 51], [6, 52], [6, 56], [6, 57], [6, 59], [6, 60], [6, 62], [6, 63], [6, 65], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [6, 73], [6, 74], [6, 77], [6, 79], [6, 82], [6, 86], [6, 89], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 21], [7, 23], [7, 24], [7, 26], [7, 27], [7, 31], [7, 32], [7, 37], [7, 39], [7, 40], [7, 44], [7, 47], [7, 54], [7, 55], [7, 57], [7, 59], [7, 61], [7, 63], [7, 65], [7, 68], [7, 73], [7, 74], [7, 76], [7, 79], [7, 80], [7, 82], [7, 87], [8, 10], [8, 12], [8, 13], [8, 15], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 25], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 34], [8, 38], [8, 40], [8, 41], [8, 42], [8, 45], [8, 46], [8, 47], [8, 49], [8, 51], [8, 52], [8, 54], [8, 55], [8, 56], [8, 60], [8, 61], [8, 62], [8, 68], [8, 70], [8, 73], [8, 74], [8, 77], [8, 83], [8, 85], [8, 86], [8, 87], [9, 10], [9, 11], [9, 13], [9, 16], [9, 17], [9, 19], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [9, 29], [9, 31], [9, 34], [9, 35], [9, 36], [9, 37], [9, 42], [9, 44], [9, 46], [9, 49], [9, 51], [9, 53], [9, 54], [9, 56], [9, 58], [9, 59], [9, 60], [9, 63], [9, 64], [9, 67], [9, 68], [9, 72], [9, 73], [9, 80], [9, 82], [9, 85], [9, 87], [9, 89], [10, 11], [10, 12], [10, 13], [10, 14], [10, 18], [10, 19], [10, 20], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [10, 31], [10, 33], [10, 34], [10, 35], [10, 37], [10, 38], [10, 40], [10, 43], [10, 44], [10, 49], [10, 50], [10, 51], [10, 53], [10, 54], [10, 57], [10, 58], [10, 60], [10, 62], [10, 63], [10, 64], [10, 65], [10, 67], [10, 68], [10, 73], [10, 75], [10, 76], [10, 79], [10, 80], [10, 82], [10, 88], [11, 13], [11, 14], [11, 15], [11, 18], [11, 19], [11, 22], [11, 23], [11, 24], [11, 27], [11, 28], [11, 29], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 41], [11, 45], [11, 47], [11, 49], [11, 50], [11, 53], [11, 54], [11, 55], [11, 58], [11, 60], [11, 61], [11, 62], [11, 63], [11, 65], [11, 67], [11, 68], [11, 70], [11, 73], [11, 75], [11, 76], [11, 78], [11, 79], [11, 80], [11, 81], [11, 85], [11, 89], [12, 15], [12, 17], [12, 18], [12, 19], [12, 20], [12, 23], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 41], [12, 44], [12, 47], [12, 48], [12, 49], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 63], [12, 66], [12, 67], [12, 68], [12, 69], [12, 71], [12, 72], [12, 75], [12, 76], [12, 78], [12, 79], [12, 81], [12, 83], [12, 84], [12, 85], [12, 87], [12, 88], [13, 14], [13, 15], [13, 17], [13, 18], [13, 20], [13, 21], [13, 23], [13, 27], [13, 29], [13, 30], [13, 31], [13, 32], [13, 39], [13, 40], [13, 42], [13, 46], [13, 47], [13, 49], [13, 51], [13, 52], [13, 53], [13, 56], [13, 58], [13, 61], [13, 65], [13, 66], [13, 67], [13, 68], [13, 71], [13, 72], [13, 74], [13, 76], [13, 80], [13, 83], [13, 84], [13, 85], [13, 88], [14, 15], [14, 16], [14, 18], [14, 19], [14, 22], [14, 23], [14, 24], [14, 25], [14, 27], [14, 28], [14, 31], [14, 34], [14, 35], [14, 36], [14, 37], [14, 38], [14, 40], [14, 41], [14, 42], [14, 44], [14, 47], [14, 51], [14, 52], [14, 53], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 66], [14, 68], [14, 74], [14, 75], [14, 80], [14, 82], [14, 83], [14, 84], [14, 86], [14, 87], [15, 16], [15, 18], [15, 19], [15, 20], [15, 22], [15, 24], [15, 26], [15, 28], [15, 29], [15, 32], [15, 33], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 46], [15, 52], [15, 54], [15, 60], [15, 61], [15, 64], [15, 68], [15, 69], [15, 70], [15, 72], [15, 73], [15, 74], [15, 75], [15, 76], [15, 79], [15, 82], [15, 83], [15, 85], [15, 86], [15, 88], [16, 17], [16, 20], [16, 22], [16, 26], [16, 29], [16, 32], [16, 33], [16, 35], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 44], [16, 45], [16, 46], [16, 49], [16, 50], [16, 51], [16, 53], [16, 54], [16, 56], [16, 58], [16, 59], [16, 64], [16, 65], [16, 69], [16, 73], [16, 74], [16, 75], [16, 76], [16, 77], [16, 78], [16, 79], [16, 80], [16, 81], [16, 82], [16, 84], [16, 87], [16, 88], [16, 89], [17, 18], [17, 19], [17, 24], [17, 25], [17, 27], [17, 30], [17, 31], [17, 33], [17, 35], [17, 36], [17, 39], [17, 40], [17, 44], [17, 45], [17, 46], [17, 47], [17, 49], [17, 51], [17, 52], [17, 54], [17, 56], [17, 57], [17, 60], [17, 61], [17, 64], [17, 66], [17, 67], [17, 70], [17, 72], [17, 73], [17, 74], [17, 75], [17, 76], [17, 77], [17, 79], [17, 84], [17, 86], [18, 22], [18, 23], [18, 26], [18, 27], [18, 28], [18, 32], [18, 35], [18, 38], [18, 39], [18, 40], [18, 41], [18, 42], [18, 46], [18, 47], [18, 48], [18, 49], [18, 52], [18, 53], [18, 54], [18, 56], [18, 61], [18, 62], [18, 63], [18, 69], [18, 70], [18, 72], [18, 73], [18, 78], [18, 80], [18, 81], [18, 83], [18, 87], [18, 88], [18, 89], [19, 21], [19, 22], [19, 23], [19, 24], [19, 27], [19, 31], [19, 32], [19, 34], [19, 37], [19, 39], [19, 41], [19, 42], [19, 43], [19, 44], [19, 46], [19, 48], [19, 49], [19, 53], [19, 54], [19, 55], [19, 59], [19, 60], [19, 62], [19, 64], [19, 66], [19, 67], [19, 72], [19, 74], [19, 75], [19, 77], [19, 78], [19, 79], [19, 80], [19, 81], [19, 82], [19, 83], [19, 84], [19, 85], [19, 86], [19, 87], [20, 22], [20, 23], [20, 24], [20, 25], [20, 28], [20, 31], [20, 33], [20, 34], [20, 36], [20, 40], [20, 41], [20, 45], [20, 47], [20, 48], [20, 49], [20, 52], [20, 53], [20, 54], [20, 56], [20, 57], [20, 61], [20, 62], [20, 63], [20, 66], [20, 67], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [20, 75], [20, 76], [20, 79], [20, 80], [20, 82], [20, 83], [20, 84], [20, 85], [20, 86], [20, 87], [21, 22], [21, 23], [21, 24], [21, 26], [21, 28], [21, 33], [21, 39], [21, 41], [21, 43], [21, 44], [21, 46], [21, 47], [21, 48], [21, 49], [21, 51], [21, 53], [21, 54], [21, 57], [21, 58], [21, 61], [21, 63], [21, 66], [21, 67], [21, 68], [21, 69], [21, 72], [21, 75], [21, 77], [21, 78], [21, 79], [21, 82], [21, 83], [21, 84], [21, 87], [22, 23], [22, 24], [22, 25], [22, 27], [22, 32], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [22, 40], [22, 41], [22, 42], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 50], [22, 52], [22, 56], [22, 59], [22, 60], [22, 63], [22, 64], [22, 66], [22, 67], [22, 71], [22, 72], [22, 73], [22, 75], [22, 76], [22, 78], [22, 79], [22, 80], [22, 82], [22, 86], [22, 89], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 30], [23, 31], [23, 32], [23, 33], [23, 35], [23, 37], [23, 38], [23, 40], [23, 41], [23, 45], [23, 47], [23, 48], [23, 50], [23, 57], [23, 58], [23, 60], [23, 64], [23, 67], [23, 68], [23, 69], [23, 71], [23, 73], [23, 75], [23, 76], [23, 79], [23, 81], [23, 82], [23, 83], [23, 84], [23, 87], [24, 25], [24, 26], [24, 28], [24, 32], [24, 34], [24, 36], [24, 37], [24, 38], [24, 39], [24, 42], [24, 43], [24, 45], [24, 47], [24, 48], [24, 50], [24, 52], [24, 58], [24, 61], [24, 63], [24, 64], [24, 66], [24, 67], [24, 71], [24, 75], [24, 76], [24, 79], [24, 80], [24, 82], [24, 84], [24, 85], [24, 87], [25, 26], [25, 29], [25, 31], [25, 34], [25, 35], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 66], [25, 67], [25, 70], [25, 73], [25, 74], [25, 79], [25, 81], [25, 83], [25, 85], [25, 86], [25, 88], [26, 27], [26, 30], [26, 32], [26, 33], [26, 35], [26, 36], [26, 42], [26, 44], [26, 45], [26, 46], [26, 47], [26, 49], [26, 54], [26, 57], [26, 58], [26, 65], [26, 67], [26, 68], [26, 73], [26, 75], [26, 76], [26, 78], [26, 79], [26, 81], [26, 82], [26, 83], [26, 84], [26, 86], [26, 87], [26, 89], [27, 29], [27, 30], [27, 40], [27, 42], [27, 44], [27, 48], [27, 49], [27, 52], [27, 54], [27, 57], [27, 59], [27, 62], [27, 63], [27, 64], [27, 67], [27, 68], [27, 69], [27, 73], [27, 74], [27, 76], [27, 77], [27, 78], [27, 84], [27, 87], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 39], [28, 45], [28, 48], [28, 49], [28, 51], [28, 53], [28, 56], [28, 58], [28, 59], [28, 60], [28, 62], [28, 65], [28, 66], [28, 69], [28, 72], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 79], [28, 83], [28, 86], [28, 87], [28, 89], [29, 31], [29, 32], [29, 34], [29, 43], [29, 45], [29, 46], [29, 49], [29, 50], [29, 51], [29, 54], [29, 55], [29, 57], [29, 62], [29, 63], [29, 65], [29, 68], [29, 69], [29, 70], [29, 72], [29, 73], [29, 74], [29, 75], [29, 76], [29, 77], [29, 79], [29, 82], [29, 84], [29, 85], [29, 86], [29, 87], [30, 32], [30, 33], [30, 34], [30, 37], [30, 39], [30, 42], [30, 45], [30, 46], [30, 47], [30, 49], [30, 50], [30, 51], [30, 55], [30, 56], [30, 57], [30, 59], [30, 62], [30, 64], [30, 65], [30, 72], [30, 74], [30, 81], [30, 82], [30, 84], [30, 85], [30, 87], [30, 88], [31, 35], [31, 36], [31, 37], [31, 41], [31, 43], [31, 44], [31, 45], [31, 48], [31, 49], [31, 50], [31, 51], [31, 52], [31, 53], [31, 55], [31, 56], [31, 60], [31, 61], [31, 63], [31, 64], [31, 66], [31, 69], [31, 70], [31, 71], [31, 72], [31, 73], [31, 74], [31, 84], [31, 85], [31, 89], [32, 33], [32, 34], [32, 35], [32, 37], [32, 38], [32, 40], [32, 42], [32, 45], [32, 46], [32, 48], [32, 50], [32, 54], [32, 56], [32, 57], [32, 59], [32, 60], [32, 65], [32, 66], [32, 67], [32, 68], [32, 76], [32, 77], [32, 79], [32, 80], [32, 81], [32, 82], [32, 85], [32, 86], [32, 87], [32, 88], [32, 89], [33, 35], [33, 36], [33, 40], [33, 41], [33, 42], [33, 43], [33, 45], [33, 48], [33, 53], [33, 55], [33, 57], [33, 61], [33, 62], [33, 64], [33, 68], [33, 69], [33, 70], [33, 72], [33, 75], [33, 83], [33, 84], [33, 85], [33, 87], [33, 88], [34, 35], [34, 36], [34, 37], [34, 39], [34, 41], [34, 42], [34, 43], [34, 44], [34, 48], [34, 49], [34, 52], [34, 55], [34, 56], [34, 57], [34, 65], [34, 66], [34, 67], [34, 68], [34, 69], [34, 72], [34, 76], [34, 77], [34, 79], [34, 80], [34, 82], [34, 87], [34, 88], [34, 89], [35, 36], [35, 37], [35, 40], [35, 42], [35, 43], [35, 48], [35, 49], [35, 52], [35, 56], [35, 58], [35, 59], [35, 62], [35, 63], [35, 66], [35, 71], [35, 76], [35, 77], [35, 78], [35, 79], [35, 82], [35, 83], [35, 86], [35, 87], [35, 88], [36, 38], [36, 41], [36, 45], [36, 51], [36, 52], [36, 53], [36, 54], [36, 58], [36, 59], [36, 61], [36, 62], [36, 67], [36, 69], [36, 71], [36, 72], [36, 76], [36, 77], [36, 79], [36, 80], [36, 82], [36, 83], [36, 86], [36, 89], [37, 38], [37, 41], [37, 42], [37, 44], [37, 46], [37, 47], [37, 48], [37, 49], [37, 51], [37, 52], [37, 55], [37, 56], [37, 57], [37, 58], [37, 61], [37, 62], [37, 63], [37, 64], [37, 66], [37, 67], [37, 71], [37, 72], [37, 74], [37, 75], [37, 79], [37, 80], [37, 82], [37, 83], [37, 84], [37, 87], [37, 89], [38, 40], [38, 41], [38, 43], [38, 44], [38, 45], [38, 47], [38, 48], [38, 50], [38, 53], [38, 55], [38, 56], [38, 60], [38, 64], [38, 66], [38, 67], [38, 68], [38, 70], [38, 72], [38, 73], [38, 74], [38, 82], [38, 83], [38, 84], [38, 85], [38, 87], [38, 89], [39, 40], [39, 41], [39, 42], [39, 43], [39, 45], [39, 46], [39, 48], [39, 50], [39, 51], [39, 53], [39, 54], [39, 55], [39, 56], [39, 57], [39, 58], [39, 59], [39, 62], [39, 63], [39, 64], [39, 67], [39, 68], [39, 70], [39, 71], [39, 74], [39, 75], [39, 76], [39, 77], [39, 78], [39, 79], [39, 81], [39, 88], [40, 44], [40, 52], [40, 54], [40, 56], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 70], [40, 72], [40, 73], [40, 76], [40, 82], [40, 84], [40, 87], [40, 89], [41, 42], [41, 44], [41, 46], [41, 49], [41, 51], [41, 52], [41, 53], [41, 54], [41, 60], [41, 62], [41, 65], [41, 66], [41, 68], [41, 73], [41, 74], [41, 79], [41, 80], [41, 81], [41, 82], [41, 83], [41, 84], [41, 86], [41, 88], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 52], [42, 53], [42, 54], [42, 59], [42, 61], [42, 65], [42, 66], [42, 67], [42, 68], [42, 69], [42, 70], [42, 72], [42, 73], [42, 76], [42, 78], [42, 79], [42, 80], [42, 82], [42, 85], [42, 88], [43, 44], [43, 45], [43, 47], [43, 49], [43, 52], [43, 53], [43, 57], [43, 59], [43, 60], [43, 63], [43, 64], [43, 65], [43, 67], [43, 72], [43, 74], [43, 75], [43, 77], [43, 78], [43, 82], [43, 83], [43, 84], [43, 88], [44, 45], [44, 46], [44, 47], [44, 49], [44, 51], [44, 52], [44, 55], [44, 57], [44, 58], [44, 60], [44, 61], [44, 63], [44, 64], [44, 65], [44, 68], [44, 69], [44, 70], [44, 71], [44, 74], [44, 75], [44, 76], [44, 81], [44, 83], [44, 84], [44, 87], [44, 88], [44, 89], [45, 55], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 65], [45, 68], [45, 71], [45, 75], [45, 78], [45, 79], [45, 80], [45, 81], [45, 85], [45, 86], [45, 87], [45, 88], [45, 89], [46, 49], [46, 52], [46, 54], [46, 55], [46, 56], [46, 57], [46, 58], [46, 60], [46, 62], [46, 63], [46, 67], [46, 71], [46, 73], [46, 74], [46, 75], [46, 76], [46, 78], [46, 81], [46, 83], [46, 84], [46, 85], [46, 86], [46, 87], [46, 88], [47, 50], [47, 51], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 59], [47, 60], [47, 61], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 69], [47, 71], [47, 75], [47, 77], [47, 80], [47, 81], [47, 83], [47, 84], [47, 88], [47, 89], [48, 49], [48, 53], [48, 56], [48, 61], [48, 62], [48, 67], [48, 69], [48, 73], [48, 74], [48, 75], [48, 79], [48, 80], [48, 82], [48, 83], [48, 84], [48, 88], [48, 89], [49, 50], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 57], [49, 59], [49, 61], [49, 64], [49, 65], [49, 66], [49, 70], [49, 72], [49, 75], [49, 76], [49, 78], [49, 79], [49, 81], [49, 83], [49, 84], [49, 85], [49, 86], [49, 87], [49, 89], [50, 52], [50, 53], [50, 54], [50, 56], [50, 57], [50, 58], [50, 60], [50, 62], [50, 64], [50, 65], [50, 69], [50, 70], [50, 74], [50, 75], [50, 76], [50, 79], [50, 81], [50, 83], [50, 88], [50, 89], [51, 57], [51, 58], [51, 61], [51, 62], [51, 66], [51, 69], [51, 70], [51, 72], [51, 73], [51, 74], [51, 75], [51, 76], [51, 78], [51, 80], [51, 81], [51, 82], [51, 83], [51, 88], [52, 55], [52, 56], [52, 57], [52, 65], [52, 66], [52, 68], [52, 69], [52, 73], [52, 74], [52, 75], [52, 76], [52, 77], [52, 80], [52, 81], [52, 83], [52, 85], [53, 54], [53, 55], [53, 57], [53, 59], [53, 61], [53, 63], [53, 65], [53, 66], [53, 67], [53, 70], [53, 71], [53, 72], [53, 74], [53, 75], [53, 76], [53, 80], [53, 82], [53, 84], [53, 87], [53, 89], [54, 55], [54, 56], [54, 58], [54, 59], [54, 61], [54, 62], [54, 64], [54, 66], [54, 67], [54, 68], [54, 70], [54, 71], [54, 75], [54, 77], [54, 78], [54, 79], [54, 80], [54, 82], [54, 83], [54, 84], [54, 87], [54, 89], [55, 57], [55, 59], [55, 62], [55, 66], [55, 67], [55, 70], [55, 71], [55, 72], [55, 78], [55, 79], [55, 81], [55, 82], [55, 83], [55, 85], [55, 87], [55, 89], [56, 61], [56, 62], [56, 64], [56, 65], [56, 70], [56, 71], [56, 73], [56, 75], [56, 76], [56, 78], [56, 80], [56, 81], [56, 82], [56, 83], [56, 84], [56, 86], [56, 88], [56, 89], [57, 61], [57, 63], [57, 69], [57, 71], [57, 72], [57, 73], [57, 75], [57, 78], [57, 80], [57, 82], [57, 83], [57, 87], [57, 89], [58, 59], [58, 66], [58, 68], [58, 70], [58, 72], [58, 74], [58, 78], [58, 82], [58, 83], [58, 84], [58, 88], [58, 89], [59, 61], [59, 65], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [59, 80], [59, 81], [59, 82], [59, 83], [59, 84], [59, 85], [59, 87], [59, 88], [60, 62], [60, 64], [60, 65], [60, 67], [60, 68], [60, 76], [60, 85], [60, 87], [61, 62], [61, 63], [61, 65], [61, 67], [61, 68], [61, 70], [61, 71], [61, 73], [61, 75], [61, 78], [61, 79], [61, 80], [61, 81], [61, 84], [61, 85], [61, 86], [61, 87], [61, 88], [62, 63], [62, 64], [62, 65], [62, 67], [62, 70], [62, 71], [62, 72], [62, 73], [62, 75], [62, 76], [62, 78], [62, 81], [62, 85], [62, 86], [63, 65], [63, 67], [63, 70], [63, 72], [63, 74], [63, 75], [63, 76], [63, 77], [63, 80], [63, 81], [63, 82], [63, 83], [63, 85], [63, 86], [63, 87], [63, 88], [63, 89], [64, 65], [64, 67], [64, 68], [64, 69], [64, 73], [64, 74], [64, 76], [64, 78], [64, 80], [64, 83], [64, 84], [64, 86], [64, 87], [65, 66], [65, 68], [65, 71], [65, 73], [65, 76], [65, 77], [65, 78], [65, 80], [65, 85], [65, 86], [65, 87], [65, 88], [66, 68], [66, 72], [66, 73], [66, 74], [66, 76], [66, 77], [66, 79], [66, 85], [66, 89], [67, 69], [67, 70], [67, 71], [67, 73], [67, 74], [67, 75], [67, 79], [67, 80], [67, 81], [67, 82], [67, 85], [67, 87], [67, 89], [68, 69], [68, 72], [68, 73], [68, 75], [68, 76], [68, 77], [68, 78], [68, 79], [68, 81], [68, 82], [68, 83], [68, 85], [68, 87], [68, 89], [69, 70], [69, 71], [69, 72], [69, 77], [69, 80], [69, 87], [69, 89], [70, 71], [70, 75], [70, 77], [70, 78], [70, 79], [70, 80], [70, 81], [70, 82], [70, 84], [70, 85], [70, 88], [70, 89], [71, 72], [71, 75], [71, 77], [71, 79], [71, 81], [71, 82], [71, 87], [71, 88], [71, 89], [72, 73], [72, 79], [72, 81], [72, 83], [72, 85], [72, 86], [72, 87], [73, 76], [73, 78], [73, 79], [73, 81], [73, 83], [73, 85], [73, 87], [73, 88], [74, 75], [74, 76], [74, 78], [74, 80], [74, 81], [74, 82], [74, 86], [74, 87], [75, 77], [75, 78], [75, 79], [75, 80], [75, 83], [75, 84], [75, 86], [75, 87], [75, 88], [76, 79], [76, 80], [76, 82], [76, 83], [76, 85], [76, 86], [76, 87], [77, 79], [77, 80], [77, 82], [77, 88], [78, 79], [78, 80], [78, 81], [78, 83], [78, 84], [78, 87], [78, 88], [79, 80], [79, 82], [79, 88], [79, 89], [80, 82], [80, 84], [80, 85], [80, 89], [81, 83], [81, 84], [81, 85], [81, 86], [81, 87], [81, 89], [82, 84], [82, 88], [83, 87], [83, 88], [84, 86], [84, 87], [84, 88], [85, 88], [86, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s2/tests/run.py b/tasks/construct-mc-max-clique-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l5-s2/tests/test.sh b/tasks/construct-mc-max-clique-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s5/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l5-s5/environment/instance.json b/tasks/construct-mc-max-clique-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..55fab1527eae50138bdc20eec13db3695f268ca5 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 5], [0, 8], [0, 12], [0, 13], [0, 14], [0, 15], [0, 17], [0, 20], [0, 24], [0, 27], [0, 29], [0, 36], [0, 41], [0, 43], [0, 44], [0, 46], [0, 49], [0, 50], [0, 51], [0, 52], [0, 53], [0, 55], [0, 56], [0, 62], [0, 63], [0, 65], [0, 68], [0, 69], [0, 70], [0, 75], [0, 76], [0, 78], [0, 80], [0, 82], [0, 88], [1, 2], [1, 3], [1, 4], [1, 5], [1, 9], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 17], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 31], [1, 33], [1, 35], [1, 36], [1, 39], [1, 40], [1, 41], [1, 43], [1, 44], [1, 45], [1, 47], [1, 48], [1, 49], [1, 50], [1, 52], [1, 58], [1, 59], [1, 60], [1, 61], [1, 63], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 72], [1, 75], [1, 77], [1, 82], [1, 83], [1, 86], [1, 87], [1, 88], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 16], [2, 19], [2, 25], [2, 26], [2, 27], [2, 28], [2, 30], [2, 33], [2, 38], [2, 44], [2, 47], [2, 50], [2, 52], [2, 53], [2, 56], [2, 58], [2, 60], [2, 63], [2, 64], [2, 66], [2, 69], [2, 71], [2, 73], [2, 74], [2, 75], [2, 76], [2, 77], [2, 79], [2, 83], [2, 84], [2, 85], [2, 86], [2, 87], [2, 89], [3, 5], [3, 7], [3, 8], [3, 9], [3, 12], [3, 13], [3, 17], [3, 18], [3, 19], [3, 21], [3, 26], [3, 28], [3, 29], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 41], [3, 42], [3, 43], [3, 47], [3, 48], [3, 49], [3, 50], [3, 55], [3, 60], [3, 61], [3, 62], [3, 67], [3, 68], [3, 72], [3, 75], [3, 77], [3, 80], [3, 81], [3, 86], [3, 87], [3, 88], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [4, 21], [4, 24], [4, 26], [4, 27], [4, 29], [4, 33], [4, 34], [4, 36], [4, 37], [4, 41], [4, 42], [4, 43], [4, 44], [4, 48], [4, 50], [4, 51], [4, 52], [4, 53], [4, 55], [4, 57], [4, 59], [4, 61], [4, 62], [4, 65], [4, 67], [4, 68], [4, 71], [4, 72], [4, 75], [4, 79], [4, 80], [4, 82], [4, 83], [4, 86], [4, 87], [4, 88], [5, 6], [5, 8], [5, 9], [5, 11], [5, 12], [5, 14], [5, 16], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 28], [5, 29], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 39], [5, 40], [5, 42], [5, 45], [5, 46], [5, 47], [5, 48], [5, 49], [5, 50], [5, 54], [5, 56], [5, 57], [5, 58], [5, 59], [5, 61], [5, 64], [5, 65], [5, 66], [5, 68], [5, 69], [5, 72], [5, 73], [5, 76], [5, 77], [5, 78], [5, 80], [5, 85], [5, 87], [5, 88], [6, 7], [6, 8], [6, 11], [6, 13], [6, 14], [6, 16], [6, 17], [6, 20], [6, 21], [6, 22], [6, 24], [6, 27], [6, 28], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 39], [6, 40], [6, 44], [6, 45], [6, 50], [6, 53], [6, 55], [6, 56], [6, 57], [6, 62], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 72], [6, 74], [6, 79], [6, 80], [6, 83], [6, 84], [6, 86], [6, 87], [6, 88], [6, 89], [7, 12], [7, 17], [7, 18], [7, 19], [7, 21], [7, 22], [7, 25], [7, 27], [7, 31], [7, 32], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 41], [7, 44], [7, 47], [7, 49], [7, 50], [7, 55], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 64], [7, 65], [7, 68], [7, 71], [7, 72], [7, 73], [7, 74], [7, 77], [7, 78], [7, 81], [7, 82], [7, 86], [7, 87], [7, 88], [8, 9], [8, 11], [8, 12], [8, 14], [8, 16], [8, 17], [8, 18], [8, 21], [8, 22], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 39], [8, 44], [8, 47], [8, 48], [8, 52], [8, 53], [8, 54], [8, 56], [8, 57], [8, 59], [8, 62], [8, 68], [8, 69], [8, 71], [8, 72], [8, 73], [8, 75], [8, 76], [8, 77], [8, 83], [8, 85], [8, 86], [8, 87], [9, 10], [9, 11], [9, 13], [9, 16], [9, 20], [9, 22], [9, 23], [9, 26], [9, 27], [9, 28], [9, 31], [9, 32], [9, 33], [9, 36], [9, 37], [9, 39], [9, 44], [9, 45], [9, 46], [9, 49], [9, 51], [9, 52], [9, 55], [9, 56], [9, 57], [9, 58], [9, 61], [9, 66], [9, 67], [9, 70], [9, 72], [9, 75], [9, 76], [9, 77], [9, 78], [9, 81], [9, 82], [9, 83], [9, 85], [9, 87], [10, 11], [10, 12], [10, 13], [10, 15], [10, 16], [10, 18], [10, 21], [10, 25], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 35], [10, 36], [10, 37], [10, 38], [10, 40], [10, 41], [10, 42], [10, 45], [10, 46], [10, 48], [10, 49], [10, 51], [10, 52], [10, 53], [10, 57], [10, 58], [10, 59], [10, 61], [10, 63], [10, 65], [10, 66], [10, 67], [10, 69], [10, 70], [10, 73], [10, 74], [10, 76], [10, 77], [10, 78], [10, 79], [10, 80], [10, 81], [10, 83], [10, 85], [10, 86], [10, 88], [11, 13], [11, 16], [11, 17], [11, 18], [11, 21], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 34], [11, 36], [11, 38], [11, 40], [11, 41], [11, 42], [11, 43], [11, 44], [11, 47], [11, 48], [11, 50], [11, 51], [11, 52], [11, 55], [11, 56], [11, 57], [11, 58], [11, 60], [11, 62], [11, 63], [11, 64], [11, 67], [11, 68], [11, 72], [11, 73], [11, 77], [11, 78], [11, 82], [11, 84], [11, 86], [11, 87], [11, 89], [12, 15], [12, 16], [12, 18], [12, 19], [12, 23], [12, 24], [12, 26], [12, 28], [12, 29], [12, 30], [12, 32], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 42], [12, 44], [12, 46], [12, 47], [12, 49], [12, 53], [12, 54], [12, 55], [12, 57], [12, 59], [12, 60], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 68], [12, 71], [12, 75], [12, 77], [12, 79], [12, 80], [12, 81], [12, 82], [12, 85], [12, 86], [12, 88], [13, 15], [13, 16], [13, 18], [13, 19], [13, 23], [13, 25], [13, 28], [13, 30], [13, 31], [13, 33], [13, 34], [13, 36], [13, 38], [13, 39], [13, 41], [13, 42], [13, 46], [13, 47], [13, 49], [13, 52], [13, 53], [13, 58], [13, 59], [13, 62], [13, 63], [13, 65], [13, 66], [13, 67], [13, 70], [13, 71], [13, 73], [13, 76], [13, 81], [13, 82], [13, 86], [13, 89], [14, 17], [14, 18], [14, 19], [14, 24], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 32], [14, 34], [14, 35], [14, 36], [14, 40], [14, 41], [14, 44], [14, 45], [14, 47], [14, 50], [14, 53], [14, 56], [14, 59], [14, 62], [14, 66], [14, 67], [14, 68], [14, 69], [14, 72], [14, 73], [14, 74], [14, 75], [14, 77], [14, 81], [14, 83], [14, 85], [14, 87], [14, 88], [14, 89], [15, 16], [15, 17], [15, 25], [15, 30], [15, 31], [15, 32], [15, 34], [15, 35], [15, 36], [15, 37], [15, 40], [15, 41], [15, 43], [15, 46], [15, 48], [15, 50], [15, 52], [15, 57], [15, 59], [15, 61], [15, 63], [15, 64], [15, 65], [15, 67], [15, 71], [15, 74], [15, 75], [15, 78], [15, 79], [15, 82], [15, 83], [15, 89], [16, 19], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [16, 34], [16, 41], [16, 45], [16, 47], [16, 48], [16, 50], [16, 51], [16, 53], [16, 54], [16, 55], [16, 58], [16, 63], [16, 64], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 74], [16, 79], [16, 81], [16, 84], [16, 89], [17, 18], [17, 25], [17, 26], [17, 28], [17, 31], [17, 32], [17, 34], [17, 35], [17, 37], [17, 39], [17, 41], [17, 42], [17, 43], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 56], [17, 59], [17, 61], [17, 62], [17, 64], [17, 65], [17, 66], [17, 67], [17, 71], [17, 72], [17, 73], [17, 76], [17, 77], [17, 81], [17, 82], [17, 83], [17, 84], [17, 85], [17, 86], [17, 87], [17, 88], [18, 19], [18, 21], [18, 25], [18, 26], [18, 28], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 37], [18, 38], [18, 42], [18, 47], [18, 49], [18, 50], [18, 51], [18, 52], [18, 53], [18, 54], [18, 60], [18, 61], [18, 63], [18, 64], [18, 68], [18, 69], [18, 70], [18, 71], [18, 72], [18, 74], [18, 76], [18, 77], [18, 79], [18, 81], [18, 83], [18, 84], [18, 85], [19, 20], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 28], [19, 32], [19, 33], [19, 35], [19, 36], [19, 37], [19, 39], [19, 41], [19, 45], [19, 46], [19, 51], [19, 52], [19, 54], [19, 55], [19, 56], [19, 64], [19, 66], [19, 67], [19, 70], [19, 73], [19, 74], [19, 78], [19, 79], [19, 82], [19, 83], [19, 84], [19, 85], [19, 88], [20, 21], [20, 22], [20, 23], [20, 26], [20, 32], [20, 33], [20, 34], [20, 40], [20, 43], [20, 45], [20, 46], [20, 47], [20, 48], [20, 49], [20, 50], [20, 51], [20, 52], [20, 54], [20, 55], [20, 58], [20, 59], [20, 61], [20, 62], [20, 64], [20, 65], [20, 69], [20, 70], [20, 72], [20, 74], [20, 81], [20, 82], [20, 83], [20, 85], [20, 86], [20, 87], [20, 88], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 33], [21, 35], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 47], [21, 48], [21, 49], [21, 50], [21, 52], [21, 54], [21, 55], [21, 57], [21, 58], [21, 62], [21, 64], [21, 65], [21, 68], [21, 71], [21, 72], [21, 74], [21, 75], [21, 76], [21, 77], [21, 79], [21, 88], [22, 23], [22, 24], [22, 29], [22, 32], [22, 36], [22, 37], [22, 38], [22, 41], [22, 44], [22, 45], [22, 47], [22, 50], [22, 51], [22, 52], [22, 55], [22, 57], [22, 61], [22, 63], [22, 65], [22, 67], [22, 68], [22, 69], [22, 70], [22, 77], [22, 78], [22, 80], [22, 81], [22, 82], [22, 86], [23, 26], [23, 27], [23, 30], [23, 33], [23, 34], [23, 37], [23, 38], [23, 40], [23, 41], [23, 43], [23, 45], [23, 47], [23, 48], [23, 51], [23, 53], [23, 58], [23, 59], [23, 62], [23, 63], [23, 64], [23, 66], [23, 68], [23, 69], [23, 75], [23, 78], [23, 80], [23, 81], [23, 82], [23, 83], [23, 84], [23, 86], [23, 87], [23, 88], [24, 25], [24, 26], [24, 28], [24, 29], [24, 32], [24, 33], [24, 35], [24, 37], [24, 41], [24, 42], [24, 44], [24, 45], [24, 46], [24, 47], [24, 48], [24, 51], [24, 52], [24, 54], [24, 56], [24, 58], [24, 59], [24, 60], [24, 61], [24, 63], [24, 64], [24, 66], [24, 67], [24, 68], [24, 71], [24, 72], [24, 73], [24, 74], [24, 75], [24, 77], [24, 82], [24, 83], [24, 84], [24, 86], [24, 88], [24, 89], [25, 27], [25, 29], [25, 30], [25, 31], [25, 33], [25, 35], [25, 37], [25, 38], [25, 41], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 50], [25, 51], [25, 53], [25, 55], [25, 56], [25, 57], [25, 58], [25, 62], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 71], [25, 73], [25, 74], [25, 76], [25, 77], [25, 78], [25, 82], [25, 87], [25, 88], [25, 89], [26, 27], [26, 30], [26, 32], [26, 35], [26, 36], [26, 40], [26, 41], [26, 42], [26, 45], [26, 46], [26, 48], [26, 51], [26, 52], [26, 57], [26, 58], [26, 59], [26, 60], [26, 65], [26, 67], [26, 71], [26, 73], [26, 74], [26, 76], [26, 77], [26, 78], [26, 79], [26, 82], [26, 84], [26, 85], [26, 88], [26, 89], [27, 30], [27, 32], [27, 34], [27, 35], [27, 39], [27, 43], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 54], [27, 55], [27, 56], [27, 58], [27, 60], [27, 61], [27, 63], [27, 65], [27, 66], [27, 67], [27, 69], [27, 70], [27, 71], [27, 73], [27, 74], [27, 76], [27, 77], [27, 79], [27, 81], [27, 82], [27, 83], [27, 84], [27, 85], [27, 86], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 40], [28, 45], [28, 46], [28, 47], [28, 51], [28, 53], [28, 55], [28, 58], [28, 63], [28, 66], [28, 67], [28, 68], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [28, 77], [28, 78], [28, 83], [28, 84], [28, 85], [28, 86], [28, 87], [28, 88], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 42], [29, 43], [29, 45], [29, 47], [29, 49], [29, 50], [29, 54], [29, 55], [29, 56], [29, 57], [29, 58], [29, 64], [29, 66], [29, 67], [29, 68], [29, 71], [29, 73], [29, 75], [29, 76], [29, 77], [29, 79], [29, 80], [29, 84], [29, 86], [29, 88], [30, 32], [30, 33], [30, 35], [30, 38], [30, 41], [30, 42], [30, 44], [30, 45], [30, 46], [30, 47], [30, 49], [30, 50], [30, 53], [30, 54], [30, 58], [30, 59], [30, 60], [30, 62], [30, 63], [30, 64], [30, 68], [30, 69], [30, 70], [30, 71], [30, 73], [30, 74], [30, 75], [30, 76], [30, 79], [30, 80], [30, 82], [30, 87], [31, 32], [31, 33], [31, 35], [31, 37], [31, 38], [31, 40], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 48], [31, 49], [31, 57], [31, 58], [31, 62], [31, 63], [31, 67], [31, 68], [31, 71], [31, 72], [31, 76], [31, 78], [31, 79], [31, 83], [31, 85], [31, 87], [31, 88], [32, 35], [32, 36], [32, 39], [32, 42], [32, 43], [32, 46], [32, 48], [32, 50], [32, 51], [32, 52], [32, 55], [32, 57], [32, 58], [32, 60], [32, 64], [32, 66], [32, 68], [32, 69], [32, 70], [32, 71], [32, 72], [32, 74], [32, 75], [32, 79], [32, 80], [32, 81], [32, 84], [32, 87], [32, 88], [33, 36], [33, 37], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 44], [33, 45], [33, 46], [33, 47], [33, 51], [33, 54], [33, 58], [33, 60], [33, 61], [33, 62], [33, 63], [33, 66], [33, 68], [33, 69], [33, 72], [33, 73], [33, 75], [33, 76], [33, 78], [33, 79], [33, 80], [33, 82], [33, 83], [33, 85], [33, 87], [33, 88], [33, 89], [34, 36], [34, 40], [34, 44], [34, 45], [34, 46], [34, 48], [34, 49], [34, 53], [34, 54], [34, 58], [34, 59], [34, 62], [34, 63], [34, 66], [34, 67], [34, 68], [34, 69], [34, 70], [34, 74], [34, 75], [34, 77], [34, 80], [34, 81], [34, 82], [34, 84], [34, 86], [34, 87], [35, 36], [35, 37], [35, 38], [35, 41], [35, 46], [35, 48], [35, 51], [35, 53], [35, 55], [35, 58], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 66], [35, 68], [35, 71], [35, 74], [35, 77], [35, 78], [35, 82], [35, 84], [35, 85], [35, 88], [36, 37], [36, 38], [36, 40], [36, 45], [36, 46], [36, 51], [36, 54], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 65], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 71], [36, 76], [36, 77], [36, 79], [36, 82], [36, 84], [36, 85], [36, 86], [36, 89], [37, 40], [37, 41], [37, 43], [37, 44], [37, 45], [37, 48], [37, 51], [37, 52], [37, 53], [37, 55], [37, 56], [37, 60], [37, 61], [37, 62], [37, 65], [37, 66], [37, 71], [37, 73], [37, 76], [37, 77], [37, 78], [37, 83], [37, 84], [37, 85], [37, 88], [37, 89], [38, 43], [38, 45], [38, 48], [38, 49], [38, 52], [38, 54], [38, 55], [38, 56], [38, 57], [38, 58], [38, 61], [38, 62], [38, 64], [38, 65], [38, 66], [38, 74], [38, 76], [38, 77], [38, 80], [38, 82], [38, 83], [38, 85], [38, 86], [38, 87], [38, 89], [39, 40], [39, 41], [39, 42], [39, 53], [39, 56], [39, 58], [39, 60], [39, 61], [39, 62], [39, 63], [39, 64], [39, 66], [39, 67], [39, 71], [39, 74], [39, 77], [39, 79], [39, 80], [39, 82], [39, 83], [39, 84], [39, 85], [39, 86], [39, 87], [40, 42], [40, 43], [40, 45], [40, 48], [40, 52], [40, 54], [40, 55], [40, 56], [40, 57], [40, 59], [40, 61], [40, 62], [40, 64], [40, 66], [40, 70], [40, 71], [40, 72], [40, 73], [40, 74], [40, 75], [40, 76], [40, 79], [40, 80], [40, 81], [40, 83], [40, 85], [40, 87], [40, 88], [40, 89], [41, 42], [41, 43], [41, 44], [41, 45], [41, 46], [41, 48], [41, 49], [41, 50], [41, 53], [41, 57], [41, 59], [41, 60], [41, 63], [41, 64], [41, 66], [41, 68], [41, 69], [41, 71], [41, 73], [41, 77], [41, 78], [41, 79], [41, 80], [41, 81], [41, 84], [41, 85], [41, 88], [42, 46], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 55], [42, 58], [42, 62], [42, 64], [42, 67], [42, 68], [42, 69], [42, 70], [42, 72], [42, 74], [42, 75], [42, 76], [42, 78], [42, 79], [42, 80], [42, 85], [43, 44], [43, 45], [43, 46], [43, 48], [43, 53], [43, 54], [43, 55], [43, 56], [43, 58], [43, 62], [43, 64], [43, 67], [43, 72], [43, 73], [43, 74], [43, 75], [43, 79], [43, 80], [43, 82], [43, 84], [43, 85], [43, 88], [43, 89], [44, 45], [44, 46], [44, 48], [44, 52], [44, 53], [44, 55], [44, 56], [44, 58], [44, 60], [44, 61], [44, 64], [44, 65], [44, 75], [44, 76], [44, 77], [44, 78], [44, 79], [44, 80], [44, 82], [44, 85], [44, 88], [44, 89], [45, 46], [45, 47], [45, 48], [45, 55], [45, 58], [45, 59], [45, 60], [45, 64], [45, 65], [45, 66], [45, 68], [45, 69], [45, 74], [45, 76], [45, 77], [45, 78], [45, 82], [45, 85], [45, 86], [45, 88], [46, 47], [46, 49], [46, 50], [46, 52], [46, 54], [46, 56], [46, 57], [46, 59], [46, 60], [46, 61], [46, 63], [46, 64], [46, 65], [46, 66], [46, 68], [46, 75], [46, 77], [46, 78], [46, 81], [46, 85], [46, 87], [46, 88], [47, 50], [47, 51], [47, 52], [47, 57], [47, 58], [47, 61], [47, 63], [47, 66], [47, 67], [47, 68], [47, 73], [47, 74], [47, 76], [47, 77], [47, 79], [47, 81], [47, 82], [47, 84], [47, 87], [47, 88], [47, 89], [48, 49], [48, 52], [48, 54], [48, 56], [48, 57], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 67], [48, 69], [48, 70], [48, 71], [48, 74], [48, 78], [48, 79], [48, 81], [48, 83], [48, 84], [48, 85], [48, 87], [48, 88], [48, 89], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 58], [49, 59], [49, 61], [49, 63], [49, 64], [49, 67], [49, 68], [49, 70], [49, 74], [49, 82], [49, 84], [49, 85], [49, 87], [50, 52], [50, 61], [50, 62], [50, 64], [50, 66], [50, 69], [50, 71], [50, 76], [50, 77], [50, 78], [50, 80], [50, 81], [50, 82], [50, 88], [51, 52], [51, 53], [51, 56], [51, 57], [51, 59], [51, 60], [51, 61], [51, 66], [51, 67], [51, 68], [51, 69], [51, 72], [51, 73], [51, 75], [51, 78], [51, 82], [51, 85], [51, 86], [51, 87], [51, 88], [52, 54], [52, 55], [52, 56], [52, 58], [52, 60], [52, 62], [52, 65], [52, 67], [52, 70], [52, 71], [52, 72], [52, 73], [52, 74], [52, 75], [52, 79], [52, 81], [52, 82], [52, 84], [52, 86], [52, 87], [52, 88], [52, 89], [53, 55], [53, 56], [53, 57], [53, 59], [53, 60], [53, 61], [53, 62], [53, 65], [53, 66], [53, 67], [53, 71], [53, 72], [53, 74], [53, 75], [53, 77], [53, 81], [53, 82], [53, 83], [53, 87], [53, 89], [54, 55], [54, 57], [54, 63], [54, 64], [54, 65], [54, 66], [54, 68], [54, 73], [54, 75], [54, 76], [54, 77], [54, 80], [54, 83], [54, 87], [54, 88], [54, 89], [55, 58], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [55, 79], [55, 80], [55, 81], [55, 82], [55, 83], [55, 84], [55, 85], [55, 87], [55, 89], [56, 57], [56, 63], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 76], [56, 77], [56, 78], [56, 80], [56, 82], [56, 83], [56, 85], [56, 86], [56, 87], [56, 89], [57, 59], [57, 62], [57, 65], [57, 67], [57, 71], [57, 72], [57, 73], [57, 74], [57, 77], [57, 80], [57, 87], [57, 89], [58, 59], [58, 60], [58, 61], [58, 62], [58, 64], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 79], [58, 82], [58, 84], [58, 85], [58, 88], [59, 60], [59, 61], [59, 62], [59, 63], [59, 67], [59, 68], [59, 69], [59, 70], [59, 76], [59, 77], [59, 78], [59, 79], [59, 81], [59, 82], [59, 83], [59, 85], [59, 87], [59, 88], [60, 61], [60, 63], [60, 65], [60, 67], [60, 69], [60, 70], [60, 71], [60, 72], [60, 73], [60, 74], [60, 77], [60, 79], [60, 81], [60, 82], [60, 85], [60, 86], [60, 89], [61, 62], [61, 63], [61, 65], [61, 67], [61, 69], [61, 70], [61, 72], [61, 74], [61, 76], [61, 79], [61, 85], [61, 87], [61, 88], [62, 63], [62, 67], [62, 68], [62, 71], [62, 72], [62, 75], [62, 77], [62, 79], [62, 81], [62, 85], [62, 89], [63, 64], [63, 67], [63, 69], [63, 71], [63, 72], [63, 75], [63, 76], [63, 79], [63, 80], [63, 81], [63, 83], [63, 86], [63, 87], [63, 88], [63, 89], [64, 69], [64, 71], [64, 72], [64, 77], [64, 79], [64, 80], [64, 84], [64, 85], [64, 88], [64, 89], [65, 66], [65, 67], [65, 71], [65, 74], [65, 77], [65, 78], [65, 79], [65, 80], [65, 83], [65, 84], [65, 86], [65, 88], [65, 89], [66, 67], [66, 68], [66, 71], [66, 74], [66, 78], [66, 80], [66, 81], [66, 82], [66, 83], [66, 84], [66, 85], [66, 88], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [67, 75], [67, 77], [67, 78], [67, 80], [67, 81], [67, 82], [67, 84], [67, 86], [68, 71], [68, 73], [68, 74], [68, 75], [68, 76], [68, 77], [68, 78], [68, 80], [68, 81], [68, 82], [68, 84], [68, 86], [68, 88], [68, 89], [69, 74], [69, 75], [69, 76], [69, 77], [69, 78], [69, 80], [69, 84], [70, 71], [70, 72], [70, 73], [70, 74], [70, 76], [70, 77], [70, 79], [70, 81], [70, 82], [70, 85], [70, 86], [70, 87], [70, 88], [71, 72], [71, 75], [71, 77], [71, 78], [71, 79], [71, 80], [71, 81], [71, 82], [71, 86], [71, 88], [72, 75], [72, 77], [72, 80], [72, 81], [72, 83], [72, 85], [72, 87], [72, 88], [72, 89], [73, 75], [73, 76], [73, 77], [73, 79], [73, 80], [73, 81], [73, 84], [73, 85], [73, 89], [74, 76], [74, 77], [74, 78], [74, 80], [74, 82], [74, 83], [74, 84], [74, 85], [74, 86], [74, 89], [75, 77], [75, 79], [75, 81], [75, 86], [75, 87], [75, 88], [75, 89], [76, 77], [76, 78], [76, 79], [76, 81], [76, 83], [76, 86], [76, 88], [76, 89], [77, 79], [77, 81], [77, 82], [77, 84], [77, 86], [77, 87], [77, 88], [78, 79], [78, 80], [78, 82], [78, 84], [78, 85], [78, 86], [78, 88], [79, 81], [79, 82], [79, 83], [80, 82], [80, 83], [80, 85], [80, 88], [80, 89], [81, 82], [81, 83], [81, 84], [81, 85], [81, 86], [81, 87], [81, 89], [82, 84], [82, 87], [82, 88], [82, 89], [83, 88], [83, 89], [84, 85], [85, 87], [85, 88], [86, 88]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s5/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e8af6d4948d628bbb59804d9727e694bf3293e61 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 5, 24, 28, 29, 33, 45, 47, 58, 66, 68, 88]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s5/tests/check.py b/tasks/construct-mc-max-clique-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l5-s5/tests/instance.json b/tasks/construct-mc-max-clique-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..55fab1527eae50138bdc20eec13db3695f268ca5 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 5], [0, 8], [0, 12], [0, 13], [0, 14], [0, 15], [0, 17], [0, 20], [0, 24], [0, 27], [0, 29], [0, 36], [0, 41], [0, 43], [0, 44], [0, 46], [0, 49], [0, 50], [0, 51], [0, 52], [0, 53], [0, 55], [0, 56], [0, 62], [0, 63], [0, 65], [0, 68], [0, 69], [0, 70], [0, 75], [0, 76], [0, 78], [0, 80], [0, 82], [0, 88], [1, 2], [1, 3], [1, 4], [1, 5], [1, 9], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 17], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 31], [1, 33], [1, 35], [1, 36], [1, 39], [1, 40], [1, 41], [1, 43], [1, 44], [1, 45], [1, 47], [1, 48], [1, 49], [1, 50], [1, 52], [1, 58], [1, 59], [1, 60], [1, 61], [1, 63], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 72], [1, 75], [1, 77], [1, 82], [1, 83], [1, 86], [1, 87], [1, 88], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 16], [2, 19], [2, 25], [2, 26], [2, 27], [2, 28], [2, 30], [2, 33], [2, 38], [2, 44], [2, 47], [2, 50], [2, 52], [2, 53], [2, 56], [2, 58], [2, 60], [2, 63], [2, 64], [2, 66], [2, 69], [2, 71], [2, 73], [2, 74], [2, 75], [2, 76], [2, 77], [2, 79], [2, 83], [2, 84], [2, 85], [2, 86], [2, 87], [2, 89], [3, 5], [3, 7], [3, 8], [3, 9], [3, 12], [3, 13], [3, 17], [3, 18], [3, 19], [3, 21], [3, 26], [3, 28], [3, 29], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 41], [3, 42], [3, 43], [3, 47], [3, 48], [3, 49], [3, 50], [3, 55], [3, 60], [3, 61], [3, 62], [3, 67], [3, 68], [3, 72], [3, 75], [3, 77], [3, 80], [3, 81], [3, 86], [3, 87], [3, 88], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [4, 21], [4, 24], [4, 26], [4, 27], [4, 29], [4, 33], [4, 34], [4, 36], [4, 37], [4, 41], [4, 42], [4, 43], [4, 44], [4, 48], [4, 50], [4, 51], [4, 52], [4, 53], [4, 55], [4, 57], [4, 59], [4, 61], [4, 62], [4, 65], [4, 67], [4, 68], [4, 71], [4, 72], [4, 75], [4, 79], [4, 80], [4, 82], [4, 83], [4, 86], [4, 87], [4, 88], [5, 6], [5, 8], [5, 9], [5, 11], [5, 12], [5, 14], [5, 16], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 28], [5, 29], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 39], [5, 40], [5, 42], [5, 45], [5, 46], [5, 47], [5, 48], [5, 49], [5, 50], [5, 54], [5, 56], [5, 57], [5, 58], [5, 59], [5, 61], [5, 64], [5, 65], [5, 66], [5, 68], [5, 69], [5, 72], [5, 73], [5, 76], [5, 77], [5, 78], [5, 80], [5, 85], [5, 87], [5, 88], [6, 7], [6, 8], [6, 11], [6, 13], [6, 14], [6, 16], [6, 17], [6, 20], [6, 21], [6, 22], [6, 24], [6, 27], [6, 28], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 39], [6, 40], [6, 44], [6, 45], [6, 50], [6, 53], [6, 55], [6, 56], [6, 57], [6, 62], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 72], [6, 74], [6, 79], [6, 80], [6, 83], [6, 84], [6, 86], [6, 87], [6, 88], [6, 89], [7, 12], [7, 17], [7, 18], [7, 19], [7, 21], [7, 22], [7, 25], [7, 27], [7, 31], [7, 32], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 41], [7, 44], [7, 47], [7, 49], [7, 50], [7, 55], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 64], [7, 65], [7, 68], [7, 71], [7, 72], [7, 73], [7, 74], [7, 77], [7, 78], [7, 81], [7, 82], [7, 86], [7, 87], [7, 88], [8, 9], [8, 11], [8, 12], [8, 14], [8, 16], [8, 17], [8, 18], [8, 21], [8, 22], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 39], [8, 44], [8, 47], [8, 48], [8, 52], [8, 53], [8, 54], [8, 56], [8, 57], [8, 59], [8, 62], [8, 68], [8, 69], [8, 71], [8, 72], [8, 73], [8, 75], [8, 76], [8, 77], [8, 83], [8, 85], [8, 86], [8, 87], [9, 10], [9, 11], [9, 13], [9, 16], [9, 20], [9, 22], [9, 23], [9, 26], [9, 27], [9, 28], [9, 31], [9, 32], [9, 33], [9, 36], [9, 37], [9, 39], [9, 44], [9, 45], [9, 46], [9, 49], [9, 51], [9, 52], [9, 55], [9, 56], [9, 57], [9, 58], [9, 61], [9, 66], [9, 67], [9, 70], [9, 72], [9, 75], [9, 76], [9, 77], [9, 78], [9, 81], [9, 82], [9, 83], [9, 85], [9, 87], [10, 11], [10, 12], [10, 13], [10, 15], [10, 16], [10, 18], [10, 21], [10, 25], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 35], [10, 36], [10, 37], [10, 38], [10, 40], [10, 41], [10, 42], [10, 45], [10, 46], [10, 48], [10, 49], [10, 51], [10, 52], [10, 53], [10, 57], [10, 58], [10, 59], [10, 61], [10, 63], [10, 65], [10, 66], [10, 67], [10, 69], [10, 70], [10, 73], [10, 74], [10, 76], [10, 77], [10, 78], [10, 79], [10, 80], [10, 81], [10, 83], [10, 85], [10, 86], [10, 88], [11, 13], [11, 16], [11, 17], [11, 18], [11, 21], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 34], [11, 36], [11, 38], [11, 40], [11, 41], [11, 42], [11, 43], [11, 44], [11, 47], [11, 48], [11, 50], [11, 51], [11, 52], [11, 55], [11, 56], [11, 57], [11, 58], [11, 60], [11, 62], [11, 63], [11, 64], [11, 67], [11, 68], [11, 72], [11, 73], [11, 77], [11, 78], [11, 82], [11, 84], [11, 86], [11, 87], [11, 89], [12, 15], [12, 16], [12, 18], [12, 19], [12, 23], [12, 24], [12, 26], [12, 28], [12, 29], [12, 30], [12, 32], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 42], [12, 44], [12, 46], [12, 47], [12, 49], [12, 53], [12, 54], [12, 55], [12, 57], [12, 59], [12, 60], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 68], [12, 71], [12, 75], [12, 77], [12, 79], [12, 80], [12, 81], [12, 82], [12, 85], [12, 86], [12, 88], [13, 15], [13, 16], [13, 18], [13, 19], [13, 23], [13, 25], [13, 28], [13, 30], [13, 31], [13, 33], [13, 34], [13, 36], [13, 38], [13, 39], [13, 41], [13, 42], [13, 46], [13, 47], [13, 49], [13, 52], [13, 53], [13, 58], [13, 59], [13, 62], [13, 63], [13, 65], [13, 66], [13, 67], [13, 70], [13, 71], [13, 73], [13, 76], [13, 81], [13, 82], [13, 86], [13, 89], [14, 17], [14, 18], [14, 19], [14, 24], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 32], [14, 34], [14, 35], [14, 36], [14, 40], [14, 41], [14, 44], [14, 45], [14, 47], [14, 50], [14, 53], [14, 56], [14, 59], [14, 62], [14, 66], [14, 67], [14, 68], [14, 69], [14, 72], [14, 73], [14, 74], [14, 75], [14, 77], [14, 81], [14, 83], [14, 85], [14, 87], [14, 88], [14, 89], [15, 16], [15, 17], [15, 25], [15, 30], [15, 31], [15, 32], [15, 34], [15, 35], [15, 36], [15, 37], [15, 40], [15, 41], [15, 43], [15, 46], [15, 48], [15, 50], [15, 52], [15, 57], [15, 59], [15, 61], [15, 63], [15, 64], [15, 65], [15, 67], [15, 71], [15, 74], [15, 75], [15, 78], [15, 79], [15, 82], [15, 83], [15, 89], [16, 19], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [16, 34], [16, 41], [16, 45], [16, 47], [16, 48], [16, 50], [16, 51], [16, 53], [16, 54], [16, 55], [16, 58], [16, 63], [16, 64], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 74], [16, 79], [16, 81], [16, 84], [16, 89], [17, 18], [17, 25], [17, 26], [17, 28], [17, 31], [17, 32], [17, 34], [17, 35], [17, 37], [17, 39], [17, 41], [17, 42], [17, 43], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 56], [17, 59], [17, 61], [17, 62], [17, 64], [17, 65], [17, 66], [17, 67], [17, 71], [17, 72], [17, 73], [17, 76], [17, 77], [17, 81], [17, 82], [17, 83], [17, 84], [17, 85], [17, 86], [17, 87], [17, 88], [18, 19], [18, 21], [18, 25], [18, 26], [18, 28], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 37], [18, 38], [18, 42], [18, 47], [18, 49], [18, 50], [18, 51], [18, 52], [18, 53], [18, 54], [18, 60], [18, 61], [18, 63], [18, 64], [18, 68], [18, 69], [18, 70], [18, 71], [18, 72], [18, 74], [18, 76], [18, 77], [18, 79], [18, 81], [18, 83], [18, 84], [18, 85], [19, 20], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 28], [19, 32], [19, 33], [19, 35], [19, 36], [19, 37], [19, 39], [19, 41], [19, 45], [19, 46], [19, 51], [19, 52], [19, 54], [19, 55], [19, 56], [19, 64], [19, 66], [19, 67], [19, 70], [19, 73], [19, 74], [19, 78], [19, 79], [19, 82], [19, 83], [19, 84], [19, 85], [19, 88], [20, 21], [20, 22], [20, 23], [20, 26], [20, 32], [20, 33], [20, 34], [20, 40], [20, 43], [20, 45], [20, 46], [20, 47], [20, 48], [20, 49], [20, 50], [20, 51], [20, 52], [20, 54], [20, 55], [20, 58], [20, 59], [20, 61], [20, 62], [20, 64], [20, 65], [20, 69], [20, 70], [20, 72], [20, 74], [20, 81], [20, 82], [20, 83], [20, 85], [20, 86], [20, 87], [20, 88], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 33], [21, 35], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 47], [21, 48], [21, 49], [21, 50], [21, 52], [21, 54], [21, 55], [21, 57], [21, 58], [21, 62], [21, 64], [21, 65], [21, 68], [21, 71], [21, 72], [21, 74], [21, 75], [21, 76], [21, 77], [21, 79], [21, 88], [22, 23], [22, 24], [22, 29], [22, 32], [22, 36], [22, 37], [22, 38], [22, 41], [22, 44], [22, 45], [22, 47], [22, 50], [22, 51], [22, 52], [22, 55], [22, 57], [22, 61], [22, 63], [22, 65], [22, 67], [22, 68], [22, 69], [22, 70], [22, 77], [22, 78], [22, 80], [22, 81], [22, 82], [22, 86], [23, 26], [23, 27], [23, 30], [23, 33], [23, 34], [23, 37], [23, 38], [23, 40], [23, 41], [23, 43], [23, 45], [23, 47], [23, 48], [23, 51], [23, 53], [23, 58], [23, 59], [23, 62], [23, 63], [23, 64], [23, 66], [23, 68], [23, 69], [23, 75], [23, 78], [23, 80], [23, 81], [23, 82], [23, 83], [23, 84], [23, 86], [23, 87], [23, 88], [24, 25], [24, 26], [24, 28], [24, 29], [24, 32], [24, 33], [24, 35], [24, 37], [24, 41], [24, 42], [24, 44], [24, 45], [24, 46], [24, 47], [24, 48], [24, 51], [24, 52], [24, 54], [24, 56], [24, 58], [24, 59], [24, 60], [24, 61], [24, 63], [24, 64], [24, 66], [24, 67], [24, 68], [24, 71], [24, 72], [24, 73], [24, 74], [24, 75], [24, 77], [24, 82], [24, 83], [24, 84], [24, 86], [24, 88], [24, 89], [25, 27], [25, 29], [25, 30], [25, 31], [25, 33], [25, 35], [25, 37], [25, 38], [25, 41], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 50], [25, 51], [25, 53], [25, 55], [25, 56], [25, 57], [25, 58], [25, 62], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 71], [25, 73], [25, 74], [25, 76], [25, 77], [25, 78], [25, 82], [25, 87], [25, 88], [25, 89], [26, 27], [26, 30], [26, 32], [26, 35], [26, 36], [26, 40], [26, 41], [26, 42], [26, 45], [26, 46], [26, 48], [26, 51], [26, 52], [26, 57], [26, 58], [26, 59], [26, 60], [26, 65], [26, 67], [26, 71], [26, 73], [26, 74], [26, 76], [26, 77], [26, 78], [26, 79], [26, 82], [26, 84], [26, 85], [26, 88], [26, 89], [27, 30], [27, 32], [27, 34], [27, 35], [27, 39], [27, 43], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 54], [27, 55], [27, 56], [27, 58], [27, 60], [27, 61], [27, 63], [27, 65], [27, 66], [27, 67], [27, 69], [27, 70], [27, 71], [27, 73], [27, 74], [27, 76], [27, 77], [27, 79], [27, 81], [27, 82], [27, 83], [27, 84], [27, 85], [27, 86], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 40], [28, 45], [28, 46], [28, 47], [28, 51], [28, 53], [28, 55], [28, 58], [28, 63], [28, 66], [28, 67], [28, 68], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [28, 77], [28, 78], [28, 83], [28, 84], [28, 85], [28, 86], [28, 87], [28, 88], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 42], [29, 43], [29, 45], [29, 47], [29, 49], [29, 50], [29, 54], [29, 55], [29, 56], [29, 57], [29, 58], [29, 64], [29, 66], [29, 67], [29, 68], [29, 71], [29, 73], [29, 75], [29, 76], [29, 77], [29, 79], [29, 80], [29, 84], [29, 86], [29, 88], [30, 32], [30, 33], [30, 35], [30, 38], [30, 41], [30, 42], [30, 44], [30, 45], [30, 46], [30, 47], [30, 49], [30, 50], [30, 53], [30, 54], [30, 58], [30, 59], [30, 60], [30, 62], [30, 63], [30, 64], [30, 68], [30, 69], [30, 70], [30, 71], [30, 73], [30, 74], [30, 75], [30, 76], [30, 79], [30, 80], [30, 82], [30, 87], [31, 32], [31, 33], [31, 35], [31, 37], [31, 38], [31, 40], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 48], [31, 49], [31, 57], [31, 58], [31, 62], [31, 63], [31, 67], [31, 68], [31, 71], [31, 72], [31, 76], [31, 78], [31, 79], [31, 83], [31, 85], [31, 87], [31, 88], [32, 35], [32, 36], [32, 39], [32, 42], [32, 43], [32, 46], [32, 48], [32, 50], [32, 51], [32, 52], [32, 55], [32, 57], [32, 58], [32, 60], [32, 64], [32, 66], [32, 68], [32, 69], [32, 70], [32, 71], [32, 72], [32, 74], [32, 75], [32, 79], [32, 80], [32, 81], [32, 84], [32, 87], [32, 88], [33, 36], [33, 37], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 44], [33, 45], [33, 46], [33, 47], [33, 51], [33, 54], [33, 58], [33, 60], [33, 61], [33, 62], [33, 63], [33, 66], [33, 68], [33, 69], [33, 72], [33, 73], [33, 75], [33, 76], [33, 78], [33, 79], [33, 80], [33, 82], [33, 83], [33, 85], [33, 87], [33, 88], [33, 89], [34, 36], [34, 40], [34, 44], [34, 45], [34, 46], [34, 48], [34, 49], [34, 53], [34, 54], [34, 58], [34, 59], [34, 62], [34, 63], [34, 66], [34, 67], [34, 68], [34, 69], [34, 70], [34, 74], [34, 75], [34, 77], [34, 80], [34, 81], [34, 82], [34, 84], [34, 86], [34, 87], [35, 36], [35, 37], [35, 38], [35, 41], [35, 46], [35, 48], [35, 51], [35, 53], [35, 55], [35, 58], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 66], [35, 68], [35, 71], [35, 74], [35, 77], [35, 78], [35, 82], [35, 84], [35, 85], [35, 88], [36, 37], [36, 38], [36, 40], [36, 45], [36, 46], [36, 51], [36, 54], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 65], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 71], [36, 76], [36, 77], [36, 79], [36, 82], [36, 84], [36, 85], [36, 86], [36, 89], [37, 40], [37, 41], [37, 43], [37, 44], [37, 45], [37, 48], [37, 51], [37, 52], [37, 53], [37, 55], [37, 56], [37, 60], [37, 61], [37, 62], [37, 65], [37, 66], [37, 71], [37, 73], [37, 76], [37, 77], [37, 78], [37, 83], [37, 84], [37, 85], [37, 88], [37, 89], [38, 43], [38, 45], [38, 48], [38, 49], [38, 52], [38, 54], [38, 55], [38, 56], [38, 57], [38, 58], [38, 61], [38, 62], [38, 64], [38, 65], [38, 66], [38, 74], [38, 76], [38, 77], [38, 80], [38, 82], [38, 83], [38, 85], [38, 86], [38, 87], [38, 89], [39, 40], [39, 41], [39, 42], [39, 53], [39, 56], [39, 58], [39, 60], [39, 61], [39, 62], [39, 63], [39, 64], [39, 66], [39, 67], [39, 71], [39, 74], [39, 77], [39, 79], [39, 80], [39, 82], [39, 83], [39, 84], [39, 85], [39, 86], [39, 87], [40, 42], [40, 43], [40, 45], [40, 48], [40, 52], [40, 54], [40, 55], [40, 56], [40, 57], [40, 59], [40, 61], [40, 62], [40, 64], [40, 66], [40, 70], [40, 71], [40, 72], [40, 73], [40, 74], [40, 75], [40, 76], [40, 79], [40, 80], [40, 81], [40, 83], [40, 85], [40, 87], [40, 88], [40, 89], [41, 42], [41, 43], [41, 44], [41, 45], [41, 46], [41, 48], [41, 49], [41, 50], [41, 53], [41, 57], [41, 59], [41, 60], [41, 63], [41, 64], [41, 66], [41, 68], [41, 69], [41, 71], [41, 73], [41, 77], [41, 78], [41, 79], [41, 80], [41, 81], [41, 84], [41, 85], [41, 88], [42, 46], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 55], [42, 58], [42, 62], [42, 64], [42, 67], [42, 68], [42, 69], [42, 70], [42, 72], [42, 74], [42, 75], [42, 76], [42, 78], [42, 79], [42, 80], [42, 85], [43, 44], [43, 45], [43, 46], [43, 48], [43, 53], [43, 54], [43, 55], [43, 56], [43, 58], [43, 62], [43, 64], [43, 67], [43, 72], [43, 73], [43, 74], [43, 75], [43, 79], [43, 80], [43, 82], [43, 84], [43, 85], [43, 88], [43, 89], [44, 45], [44, 46], [44, 48], [44, 52], [44, 53], [44, 55], [44, 56], [44, 58], [44, 60], [44, 61], [44, 64], [44, 65], [44, 75], [44, 76], [44, 77], [44, 78], [44, 79], [44, 80], [44, 82], [44, 85], [44, 88], [44, 89], [45, 46], [45, 47], [45, 48], [45, 55], [45, 58], [45, 59], [45, 60], [45, 64], [45, 65], [45, 66], [45, 68], [45, 69], [45, 74], [45, 76], [45, 77], [45, 78], [45, 82], [45, 85], [45, 86], [45, 88], [46, 47], [46, 49], [46, 50], [46, 52], [46, 54], [46, 56], [46, 57], [46, 59], [46, 60], [46, 61], [46, 63], [46, 64], [46, 65], [46, 66], [46, 68], [46, 75], [46, 77], [46, 78], [46, 81], [46, 85], [46, 87], [46, 88], [47, 50], [47, 51], [47, 52], [47, 57], [47, 58], [47, 61], [47, 63], [47, 66], [47, 67], [47, 68], [47, 73], [47, 74], [47, 76], [47, 77], [47, 79], [47, 81], [47, 82], [47, 84], [47, 87], [47, 88], [47, 89], [48, 49], [48, 52], [48, 54], [48, 56], [48, 57], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 67], [48, 69], [48, 70], [48, 71], [48, 74], [48, 78], [48, 79], [48, 81], [48, 83], [48, 84], [48, 85], [48, 87], [48, 88], [48, 89], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 58], [49, 59], [49, 61], [49, 63], [49, 64], [49, 67], [49, 68], [49, 70], [49, 74], [49, 82], [49, 84], [49, 85], [49, 87], [50, 52], [50, 61], [50, 62], [50, 64], [50, 66], [50, 69], [50, 71], [50, 76], [50, 77], [50, 78], [50, 80], [50, 81], [50, 82], [50, 88], [51, 52], [51, 53], [51, 56], [51, 57], [51, 59], [51, 60], [51, 61], [51, 66], [51, 67], [51, 68], [51, 69], [51, 72], [51, 73], [51, 75], [51, 78], [51, 82], [51, 85], [51, 86], [51, 87], [51, 88], [52, 54], [52, 55], [52, 56], [52, 58], [52, 60], [52, 62], [52, 65], [52, 67], [52, 70], [52, 71], [52, 72], [52, 73], [52, 74], [52, 75], [52, 79], [52, 81], [52, 82], [52, 84], [52, 86], [52, 87], [52, 88], [52, 89], [53, 55], [53, 56], [53, 57], [53, 59], [53, 60], [53, 61], [53, 62], [53, 65], [53, 66], [53, 67], [53, 71], [53, 72], [53, 74], [53, 75], [53, 77], [53, 81], [53, 82], [53, 83], [53, 87], [53, 89], [54, 55], [54, 57], [54, 63], [54, 64], [54, 65], [54, 66], [54, 68], [54, 73], [54, 75], [54, 76], [54, 77], [54, 80], [54, 83], [54, 87], [54, 88], [54, 89], [55, 58], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [55, 79], [55, 80], [55, 81], [55, 82], [55, 83], [55, 84], [55, 85], [55, 87], [55, 89], [56, 57], [56, 63], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 76], [56, 77], [56, 78], [56, 80], [56, 82], [56, 83], [56, 85], [56, 86], [56, 87], [56, 89], [57, 59], [57, 62], [57, 65], [57, 67], [57, 71], [57, 72], [57, 73], [57, 74], [57, 77], [57, 80], [57, 87], [57, 89], [58, 59], [58, 60], [58, 61], [58, 62], [58, 64], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 79], [58, 82], [58, 84], [58, 85], [58, 88], [59, 60], [59, 61], [59, 62], [59, 63], [59, 67], [59, 68], [59, 69], [59, 70], [59, 76], [59, 77], [59, 78], [59, 79], [59, 81], [59, 82], [59, 83], [59, 85], [59, 87], [59, 88], [60, 61], [60, 63], [60, 65], [60, 67], [60, 69], [60, 70], [60, 71], [60, 72], [60, 73], [60, 74], [60, 77], [60, 79], [60, 81], [60, 82], [60, 85], [60, 86], [60, 89], [61, 62], [61, 63], [61, 65], [61, 67], [61, 69], [61, 70], [61, 72], [61, 74], [61, 76], [61, 79], [61, 85], [61, 87], [61, 88], [62, 63], [62, 67], [62, 68], [62, 71], [62, 72], [62, 75], [62, 77], [62, 79], [62, 81], [62, 85], [62, 89], [63, 64], [63, 67], [63, 69], [63, 71], [63, 72], [63, 75], [63, 76], [63, 79], [63, 80], [63, 81], [63, 83], [63, 86], [63, 87], [63, 88], [63, 89], [64, 69], [64, 71], [64, 72], [64, 77], [64, 79], [64, 80], [64, 84], [64, 85], [64, 88], [64, 89], [65, 66], [65, 67], [65, 71], [65, 74], [65, 77], [65, 78], [65, 79], [65, 80], [65, 83], [65, 84], [65, 86], [65, 88], [65, 89], [66, 67], [66, 68], [66, 71], [66, 74], [66, 78], [66, 80], [66, 81], [66, 82], [66, 83], [66, 84], [66, 85], [66, 88], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [67, 75], [67, 77], [67, 78], [67, 80], [67, 81], [67, 82], [67, 84], [67, 86], [68, 71], [68, 73], [68, 74], [68, 75], [68, 76], [68, 77], [68, 78], [68, 80], [68, 81], [68, 82], [68, 84], [68, 86], [68, 88], [68, 89], [69, 74], [69, 75], [69, 76], [69, 77], [69, 78], [69, 80], [69, 84], [70, 71], [70, 72], [70, 73], [70, 74], [70, 76], [70, 77], [70, 79], [70, 81], [70, 82], [70, 85], [70, 86], [70, 87], [70, 88], [71, 72], [71, 75], [71, 77], [71, 78], [71, 79], [71, 80], [71, 81], [71, 82], [71, 86], [71, 88], [72, 75], [72, 77], [72, 80], [72, 81], [72, 83], [72, 85], [72, 87], [72, 88], [72, 89], [73, 75], [73, 76], [73, 77], [73, 79], [73, 80], [73, 81], [73, 84], [73, 85], [73, 89], [74, 76], [74, 77], [74, 78], [74, 80], [74, 82], [74, 83], [74, 84], [74, 85], [74, 86], [74, 89], [75, 77], [75, 79], [75, 81], [75, 86], [75, 87], [75, 88], [75, 89], [76, 77], [76, 78], [76, 79], [76, 81], [76, 83], [76, 86], [76, 88], [76, 89], [77, 79], [77, 81], [77, 82], [77, 84], [77, 86], [77, 87], [77, 88], [78, 79], [78, 80], [78, 82], [78, 84], [78, 85], [78, 86], [78, 88], [79, 81], [79, 82], [79, 83], [80, 82], [80, 83], [80, 85], [80, 88], [80, 89], [81, 82], [81, 83], [81, 84], [81, 85], [81, 86], [81, 87], [81, 89], [82, 84], [82, 87], [82, 88], [82, 89], [83, 88], [83, 89], [84, 85], [85, 87], [85, 88], [86, 88]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s5/tests/run.py b/tasks/construct-mc-max-clique-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l5-s5/tests/test.sh b/tasks/construct-mc-max-clique-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l2-s6/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l2-s6/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e7f4dbf803438dd8e23dacec0464b0f85704c6d --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 3], [0, 4], [0, 5], [0, 12], [0, 14], [0, 21], [1, 9], [1, 15], [1, 19], [1, 22], [1, 23], [1, 29], [2, 10], [2, 15], [2, 17], [2, 19], [2, 24], [2, 27], [2, 28], [3, 7], [3, 14], [3, 19], [3, 22], [3, 23], [4, 6], [4, 7], [4, 8], [4, 16], [4, 17], [4, 19], [4, 28], [4, 29], [5, 6], [5, 7], [5, 8], [5, 13], [5, 14], [5, 15], [5, 16], [5, 21], [5, 22], [5, 24], [6, 11], [6, 13], [6, 15], [6, 25], [6, 28], [7, 10], [8, 12], [8, 21], [8, 25], [8, 26], [9, 12], [9, 16], [9, 19], [9, 20], [9, 22], [9, 26], [9, 29], [10, 11], [10, 14], [10, 16], [11, 12], [11, 13], [11, 26], [11, 27], [11, 28], [12, 14], [12, 15], [12, 16], [12, 26], [13, 15], [13, 19], [13, 20], [13, 21], [13, 22], [13, 25], [13, 27], [13, 28], [14, 15], [14, 16], [14, 17], [14, 18], [14, 21], [14, 26], [14, 27], [14, 29], [15, 21], [15, 24], [15, 27], [16, 17], [16, 21], [16, 22], [16, 23], [17, 19], [18, 19], [18, 22], [18, 23], [18, 26], [19, 22], [19, 24], [19, 27], [19, 28], [21, 23], [21, 26], [22, 24], [23, 29], [24, 25], [24, 26], [24, 28], [24, 29], [25, 28], [27, 28], [27, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s6/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c871326f8f1fc8e4bdd07bd212e7caba3c3aae50 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 6, 7, 8, 17, 20, 22, 23, 27]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s6/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l2-s6/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e7f4dbf803438dd8e23dacec0464b0f85704c6d --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 3], [0, 4], [0, 5], [0, 12], [0, 14], [0, 21], [1, 9], [1, 15], [1, 19], [1, 22], [1, 23], [1, 29], [2, 10], [2, 15], [2, 17], [2, 19], [2, 24], [2, 27], [2, 28], [3, 7], [3, 14], [3, 19], [3, 22], [3, 23], [4, 6], [4, 7], [4, 8], [4, 16], [4, 17], [4, 19], [4, 28], [4, 29], [5, 6], [5, 7], [5, 8], [5, 13], [5, 14], [5, 15], [5, 16], [5, 21], [5, 22], [5, 24], [6, 11], [6, 13], [6, 15], [6, 25], [6, 28], [7, 10], [8, 12], [8, 21], [8, 25], [8, 26], [9, 12], [9, 16], [9, 19], [9, 20], [9, 22], [9, 26], [9, 29], [10, 11], [10, 14], [10, 16], [11, 12], [11, 13], [11, 26], [11, 27], [11, 28], [12, 14], [12, 15], [12, 16], [12, 26], [13, 15], [13, 19], [13, 20], [13, 21], [13, 22], [13, 25], [13, 27], [13, 28], [14, 15], [14, 16], [14, 17], [14, 18], [14, 21], [14, 26], [14, 27], [14, 29], [15, 21], [15, 24], [15, 27], [16, 17], [16, 21], [16, 22], [16, 23], [17, 19], [18, 19], [18, 22], [18, 23], [18, 26], [19, 22], [19, 24], [19, 27], [19, 28], [21, 23], [21, 26], [22, 24], [23, 29], [24, 25], [24, 26], [24, 28], [24, 29], [25, 28], [27, 28], [27, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s6/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l2-s6/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l2-s8/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l2-s8/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c318cac4362d4e220fa81a30eae5b7c68cabda09 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 1], [0, 4], [0, 6], [0, 8], [0, 9], [0, 20], [0, 26], [0, 27], [1, 2], [1, 5], [1, 8], [1, 11], [1, 15], [1, 17], [1, 24], [1, 29], [2, 4], [2, 5], [2, 16], [2, 20], [2, 22], [2, 28], [3, 17], [3, 19], [3, 25], [4, 6], [4, 7], [4, 8], [4, 9], [4, 14], [4, 16], [4, 17], [4, 23], [4, 24], [4, 26], [4, 27], [5, 6], [5, 10], [5, 15], [5, 19], [5, 20], [5, 23], [5, 28], [5, 29], [6, 12], [6, 15], [6, 18], [6, 20], [6, 21], [6, 27], [6, 28], [6, 29], [7, 10], [7, 14], [7, 16], [7, 17], [7, 27], [7, 29], [8, 11], [8, 16], [8, 20], [9, 11], [9, 26], [9, 27], [10, 11], [10, 15], [10, 29], [11, 12], [11, 15], [11, 20], [11, 24], [11, 27], [11, 29], [12, 15], [12, 16], [12, 21], [12, 28], [13, 14], [13, 22], [13, 25], [13, 26], [14, 20], [14, 27], [15, 16], [15, 18], [15, 19], [15, 21], [15, 22], [15, 26], [15, 27], [15, 28], [16, 18], [16, 19], [17, 18], [17, 21], [17, 24], [17, 27], [18, 20], [18, 22], [18, 23], [18, 28], [19, 20], [19, 23], [19, 24], [19, 25], [20, 26], [20, 29], [21, 25], [21, 28], [21, 29], [22, 28], [22, 29], [23, 24], [23, 26], [23, 27], [24, 27], [25, 26], [25, 27], [25, 28], [25, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s8/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f9ac0f3f7f623e678138a910ec957d029c447dcd --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [2, 3, 8, 10, 12, 14, 18, 24, 26]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s8/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l2-s8/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c318cac4362d4e220fa81a30eae5b7c68cabda09 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 1], [0, 4], [0, 6], [0, 8], [0, 9], [0, 20], [0, 26], [0, 27], [1, 2], [1, 5], [1, 8], [1, 11], [1, 15], [1, 17], [1, 24], [1, 29], [2, 4], [2, 5], [2, 16], [2, 20], [2, 22], [2, 28], [3, 17], [3, 19], [3, 25], [4, 6], [4, 7], [4, 8], [4, 9], [4, 14], [4, 16], [4, 17], [4, 23], [4, 24], [4, 26], [4, 27], [5, 6], [5, 10], [5, 15], [5, 19], [5, 20], [5, 23], [5, 28], [5, 29], [6, 12], [6, 15], [6, 18], [6, 20], [6, 21], [6, 27], [6, 28], [6, 29], [7, 10], [7, 14], [7, 16], [7, 17], [7, 27], [7, 29], [8, 11], [8, 16], [8, 20], [9, 11], [9, 26], [9, 27], [10, 11], [10, 15], [10, 29], [11, 12], [11, 15], [11, 20], [11, 24], [11, 27], [11, 29], [12, 15], [12, 16], [12, 21], [12, 28], [13, 14], [13, 22], [13, 25], [13, 26], [14, 20], [14, 27], [15, 16], [15, 18], [15, 19], [15, 21], [15, 22], [15, 26], [15, 27], [15, 28], [16, 18], [16, 19], [17, 18], [17, 21], [17, 24], [17, 27], [18, 20], [18, 22], [18, 23], [18, 28], [19, 20], [19, 23], [19, 24], [19, 25], [20, 26], [20, 29], [21, 25], [21, 28], [21, 29], [22, 28], [22, 29], [23, 24], [23, 26], [23, 27], [24, 27], [25, 26], [25, 27], [25, 28], [25, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s8/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l2-s8/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s0/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s0/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cf2998adc0b435ff8fa37ca8bbd8c3113cdcafee --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 5], [0, 6], [0, 7], [0, 17], [0, 20], [0, 23], [0, 24], [0, 26], [0, 28], [0, 29], [0, 32], [0, 34], [0, 42], [0, 44], [0, 46], [0, 49], [0, 51], [0, 56], [0, 62], [0, 64], [0, 71], [0, 73], [0, 74], [0, 77], [0, 80], [0, 81], [0, 84], [0, 85], [0, 92], [0, 96], [0, 99], [0, 103], [0, 106], [0, 107], [0, 108], [0, 115], [0, 116], [0, 123], [0, 126], [0, 128], [1, 8], [1, 10], [1, 16], [1, 17], [1, 19], [1, 23], [1, 25], [1, 28], [1, 29], [1, 33], [1, 43], [1, 47], [1, 54], [1, 56], [1, 59], [1, 60], [1, 61], [1, 63], [1, 68], [1, 72], [1, 74], [1, 76], [1, 82], [1, 83], [1, 84], [1, 88], [1, 92], [1, 98], [1, 103], [1, 105], [1, 107], [1, 108], [1, 109], [1, 110], [1, 112], [1, 121], [1, 122], [1, 124], [1, 126], [1, 128], [1, 132], [1, 133], [1, 134], [1, 137], [1, 138], [1, 139], [2, 6], [2, 7], [2, 18], [2, 28], [2, 32], [2, 41], [2, 42], [2, 49], [2, 56], [2, 63], [2, 66], [2, 71], [2, 74], [2, 77], [2, 86], [2, 93], [2, 99], [2, 100], [2, 107], [2, 109], [2, 110], [2, 112], [2, 115], [2, 119], [2, 120], [2, 124], [2, 128], [2, 129], [2, 130], [2, 132], [2, 135], [2, 138], [3, 5], [3, 7], [3, 9], [3, 11], [3, 13], [3, 14], [3, 19], [3, 21], [3, 24], [3, 27], [3, 36], [3, 47], [3, 51], [3, 52], [3, 54], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 71], [3, 72], [3, 78], [3, 80], [3, 86], [3, 87], [3, 88], [3, 89], [3, 90], [3, 97], [3, 103], [3, 104], [3, 106], [3, 109], [3, 114], [3, 119], [3, 125], [3, 127], [3, 128], [3, 131], [3, 133], [3, 139], [4, 7], [4, 17], [4, 23], [4, 25], [4, 26], [4, 29], [4, 30], [4, 34], [4, 35], [4, 36], [4, 38], [4, 39], [4, 48], [4, 50], [4, 54], [4, 57], [4, 59], [4, 62], [4, 64], [4, 69], [4, 72], [4, 74], [4, 75], [4, 76], [4, 81], [4, 89], [4, 90], [4, 94], [4, 95], [4, 97], [4, 98], [4, 99], [4, 102], [4, 108], [4, 109], [4, 118], [4, 135], [4, 136], [5, 7], [5, 9], [5, 13], [5, 16], [5, 19], [5, 21], [5, 22], [5, 26], [5, 27], [5, 34], [5, 43], [5, 45], [5, 53], [5, 61], [5, 67], [5, 70], [5, 75], [5, 76], [5, 80], [5, 82], [5, 87], [5, 88], [5, 90], [5, 97], [5, 102], [5, 104], [5, 111], [5, 114], [5, 115], [5, 116], [5, 118], [5, 121], [5, 122], [5, 123], [5, 125], [5, 126], [5, 127], [5, 132], [5, 134], [5, 135], [6, 11], [6, 13], [6, 18], [6, 19], [6, 33], [6, 35], [6, 36], [6, 41], [6, 43], [6, 45], [6, 46], [6, 47], [6, 48], [6, 51], [6, 59], [6, 61], [6, 62], [6, 63], [6, 64], [6, 72], [6, 73], [6, 76], [6, 83], [6, 87], [6, 88], [6, 89], [6, 92], [6, 94], [6, 95], [6, 117], [6, 123], [6, 124], [6, 129], [6, 130], [6, 134], [6, 138], [7, 16], [7, 17], [7, 21], [7, 24], [7, 26], [7, 30], [7, 31], [7, 44], [7, 56], [7, 63], [7, 66], [7, 71], [7, 72], [7, 73], [7, 74], [7, 79], [7, 81], [7, 84], [7, 86], [7, 92], [7, 93], [7, 98], [7, 107], [7, 116], [7, 117], [7, 122], [7, 124], [7, 134], [7, 136], [8, 10], [8, 11], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 23], [8, 24], [8, 27], [8, 28], [8, 29], [8, 31], [8, 32], [8, 34], [8, 37], [8, 40], [8, 42], [8, 43], [8, 44], [8, 45], [8, 53], [8, 55], [8, 58], [8, 59], [8, 62], [8, 68], [8, 80], [8, 81], [8, 86], [8, 100], [8, 102], [8, 107], [8, 108], [8, 116], [8, 120], [8, 123], [8, 124], [8, 126], [8, 130], [8, 132], [8, 134], [9, 10], [9, 14], [9, 15], [9, 17], [9, 18], [9, 27], [9, 32], [9, 35], [9, 36], [9, 37], [9, 39], [9, 45], [9, 48], [9, 49], [9, 50], [9, 54], [9, 56], [9, 62], [9, 65], [9, 68], [9, 73], [9, 75], [9, 81], [9, 82], [9, 85], [9, 93], [9, 95], [9, 97], [9, 106], [9, 109], [9, 113], [9, 115], [9, 117], [9, 118], [9, 119], [9, 120], [9, 121], [9, 123], [9, 125], [9, 139], [10, 11], [10, 13], [10, 14], [10, 17], [10, 23], [10, 26], [10, 27], [10, 29], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 47], [10, 49], [10, 51], [10, 52], [10, 54], [10, 55], [10, 59], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 68], [10, 72], [10, 75], [10, 76], [10, 85], [10, 86], [10, 91], [10, 92], [10, 98], [10, 99], [10, 100], [10, 102], [10, 109], [10, 112], [10, 116], [10, 118], [10, 119], [10, 122], [10, 124], [10, 127], [10, 129], [10, 133], [10, 134], [11, 13], [11, 17], [11, 19], [11, 21], [11, 22], [11, 23], [11, 29], [11, 32], [11, 34], [11, 37], [11, 42], [11, 44], [11, 59], [11, 62], [11, 66], [11, 71], [11, 73], [11, 82], [11, 86], [11, 97], [11, 103], [11, 104], [11, 105], [11, 113], [11, 117], [11, 119], [11, 123], [11, 124], [11, 133], [11, 136], [11, 137], [12, 14], [12, 16], [12, 17], [12, 20], [12, 21], [12, 22], [12, 27], [12, 29], [12, 31], [12, 34], [12, 35], [12, 37], [12, 45], [12, 54], [12, 56], [12, 58], [12, 60], [12, 64], [12, 68], [12, 74], [12, 75], [12, 77], [12, 79], [12, 80], [12, 86], [12, 88], [12, 93], [12, 94], [12, 101], [12, 104], [12, 106], [12, 108], [12, 111], [12, 113], [12, 120], [12, 125], [12, 131], [12, 133], [13, 14], [13, 27], [13, 29], [13, 41], [13, 45], [13, 50], [13, 51], [13, 52], [13, 58], [13, 59], [13, 64], [13, 66], [13, 69], [13, 70], [13, 72], [13, 73], [13, 75], [13, 76], [13, 77], [13, 78], [13, 80], [13, 92], [13, 95], [13, 96], [13, 107], [13, 114], [13, 118], [13, 123], [13, 133], [13, 137], [14, 21], [14, 23], [14, 26], [14, 27], [14, 30], [14, 31], [14, 34], [14, 38], [14, 41], [14, 47], [14, 49], [14, 53], [14, 58], [14, 66], [14, 69], [14, 77], [14, 78], [14, 80], [14, 82], [14, 85], [14, 90], [14, 91], [14, 93], [14, 96], [14, 97], [14, 98], [14, 101], [14, 102], [14, 122], [14, 127], [14, 131], [14, 132], [14, 135], [14, 136], [14, 137], [14, 139], [15, 19], [15, 20], [15, 21], [15, 23], [15, 26], [15, 37], [15, 42], [15, 43], [15, 46], [15, 50], [15, 51], [15, 53], [15, 55], [15, 59], [15, 66], [15, 68], [15, 74], [15, 77], [15, 79], [15, 94], [15, 101], [15, 102], [15, 103], [15, 110], [15, 111], [15, 118], [15, 119], [15, 124], [15, 126], [15, 127], [15, 128], [15, 132], [15, 136], [15, 137], [16, 18], [16, 22], [16, 24], [16, 41], [16, 42], [16, 44], [16, 45], [16, 47], [16, 49], [16, 51], [16, 54], [16, 55], [16, 60], [16, 61], [16, 63], [16, 65], [16, 66], [16, 67], [16, 69], [16, 73], [16, 77], [16, 80], [16, 87], [16, 90], [16, 92], [16, 94], [16, 95], [16, 98], [16, 101], [16, 103], [16, 104], [16, 109], [16, 115], [16, 118], [16, 119], [16, 121], [16, 129], [16, 130], [16, 131], [16, 137], [17, 18], [17, 24], [17, 25], [17, 27], [17, 29], [17, 32], [17, 34], [17, 40], [17, 41], [17, 43], [17, 44], [17, 48], [17, 51], [17, 53], [17, 54], [17, 60], [17, 66], [17, 68], [17, 69], [17, 71], [17, 76], [17, 77], [17, 85], [17, 89], [17, 92], [17, 95], [17, 101], [17, 102], [17, 103], [17, 111], [17, 112], [17, 115], [17, 127], [17, 131], [17, 138], [18, 25], [18, 27], [18, 29], [18, 31], [18, 35], [18, 36], [18, 44], [18, 54], [18, 56], [18, 57], [18, 58], [18, 60], [18, 61], [18, 62], [18, 64], [18, 65], [18, 66], [18, 67], [18, 70], [18, 76], [18, 81], [18, 82], [18, 88], [18, 94], [18, 108], [18, 111], [18, 114], [18, 117], [18, 118], [18, 119], [18, 121], [18, 129], [18, 131], [18, 133], [18, 134], [18, 136], [18, 138], [19, 20], [19, 26], [19, 32], [19, 34], [19, 35], [19, 39], [19, 40], [19, 44], [19, 48], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 65], [19, 66], [19, 67], [19, 71], [19, 73], [19, 76], [19, 77], [19, 80], [19, 83], [19, 84], [19, 93], [19, 96], [19, 97], [19, 98], [19, 100], [19, 103], [19, 105], [19, 112], [19, 117], [19, 118], [19, 122], [19, 123], [19, 126], [19, 134], [19, 135], [20, 25], [20, 28], [20, 30], [20, 40], [20, 43], [20, 48], [20, 53], [20, 57], [20, 59], [20, 60], [20, 62], [20, 68], [20, 71], [20, 77], [20, 78], [20, 80], [20, 81], [20, 84], [20, 86], [20, 89], [20, 96], [20, 98], [20, 100], [20, 102], [20, 104], [20, 105], [20, 107], [20, 112], [20, 116], [20, 118], [20, 121], [20, 129], [20, 134], [20, 135], [20, 139], [21, 22], [21, 25], [21, 29], [21, 30], [21, 31], [21, 34], [21, 36], [21, 43], [21, 45], [21, 46], [21, 47], [21, 51], [21, 53], [21, 60], [21, 61], [21, 63], [21, 67], [21, 73], [21, 75], [21, 76], [21, 78], [21, 79], [21, 81], [21, 84], [21, 90], [21, 95], [21, 96], [21, 98], [21, 100], [21, 110], [21, 113], [21, 116], [21, 119], [21, 127], [21, 130], [21, 131], [21, 132], [21, 133], [22, 23], [22, 25], [22, 26], [22, 32], [22, 33], [22, 39], [22, 42], [22, 48], [22, 51], [22, 57], [22, 60], [22, 62], [22, 66], [22, 72], [22, 74], [22, 75], [22, 77], [22, 82], [22, 85], [22, 86], [22, 93], [22, 98], [22, 100], [22, 101], [22, 106], [22, 111], [22, 112], [22, 115], [22, 116], [22, 119], [22, 121], [22, 122], [22, 127], [22, 131], [22, 135], [22, 138], [23, 26], [23, 31], [23, 35], [23, 37], [23, 38], [23, 41], [23, 46], [23, 47], [23, 48], [23, 50], [23, 53], [23, 57], [23, 59], [23, 67], [23, 68], [23, 69], [23, 73], [23, 81], [23, 87], [23, 89], [23, 90], [23, 91], [23, 96], [23, 98], [23, 99], [23, 105], [23, 117], [23, 119], [23, 121], [23, 122], [23, 124], [23, 128], [23, 129], [23, 130], [23, 133], [23, 134], [23, 136], [24, 25], [24, 26], [24, 27], [24, 28], [24, 34], [24, 38], [24, 42], [24, 45], [24, 51], [24, 56], [24, 57], [24, 58], [24, 69], [24, 72], [24, 73], [24, 74], [24, 78], [24, 79], [24, 82], [24, 84], [24, 85], [24, 87], [24, 88], [24, 93], [24, 94], [24, 98], [24, 99], [24, 102], [24, 103], [24, 105], [24, 112], [24, 115], [24, 116], [24, 118], [24, 120], [24, 123], [24, 131], [25, 28], [25, 34], [25, 35], [25, 43], [25, 48], [25, 49], [25, 52], [25, 54], [25, 56], [25, 64], [25, 66], [25, 70], [25, 72], [25, 74], [25, 76], [25, 86], [25, 87], [25, 93], [25, 99], [25, 101], [25, 105], [25, 116], [25, 118], [25, 119], [25, 122], [25, 126], [25, 133], [25, 134], [26, 27], [26, 28], [26, 31], [26, 32], [26, 36], [26, 37], [26, 41], [26, 43], [26, 46], [26, 47], [26, 50], [26, 52], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 60], [26, 62], [26, 64], [26, 69], [26, 70], [26, 73], [26, 80], [26, 87], [26, 91], [26, 92], [26, 94], [26, 98], [26, 109], [26, 110], [26, 113], [26, 121], [26, 122], [26, 125], [26, 127], [26, 133], [26, 134], [26, 137], [26, 139], [27, 29], [27, 31], [27, 36], [27, 39], [27, 40], [27, 41], [27, 45], [27, 48], [27, 50], [27, 51], [27, 60], [27, 61], [27, 64], [27, 74], [27, 75], [27, 76], [27, 80], [27, 84], [27, 87], [27, 88], [27, 92], [27, 94], [27, 96], [27, 97], [27, 98], [27, 99], [27, 103], [27, 107], [27, 113], [27, 115], [27, 123], [27, 125], [27, 126], [27, 129], [27, 130], [27, 133], [28, 38], [28, 41], [28, 43], [28, 45], [28, 47], [28, 49], [28, 51], [28, 52], [28, 54], [28, 62], [28, 64], [28, 70], [28, 71], [28, 72], [28, 74], [28, 76], [28, 80], [28, 84], [28, 85], [28, 87], [28, 88], [28, 92], [28, 95], [28, 96], [28, 99], [28, 101], [28, 103], [28, 104], [28, 113], [28, 115], [28, 118], [28, 129], [28, 134], [28, 135], [29, 30], [29, 31], [29, 33], [29, 37], [29, 38], [29, 40], [29, 42], [29, 46], [29, 47], [29, 51], [29, 60], [29, 63], [29, 65], [29, 67], [29, 71], [29, 75], [29, 76], [29, 77], [29, 78], [29, 80], [29, 82], [29, 87], [29, 90], [29, 97], [29, 101], [29, 105], [29, 107], [29, 111], [29, 112], [29, 116], [29, 117], [29, 120], [29, 121], [29, 124], [29, 129], [30, 35], [30, 39], [30, 41], [30, 45], [30, 49], [30, 54], [30, 57], [30, 60], [30, 61], [30, 63], [30, 64], [30, 66], [30, 68], [30, 71], [30, 75], [30, 76], [30, 82], [30, 85], [30, 90], [30, 93], [30, 103], [30, 105], [30, 113], [30, 117], [30, 123], [30, 125], [30, 128], [30, 129], [30, 131], [30, 132], [30, 136], [30, 138], [30, 139], [31, 32], [31, 34], [31, 38], [31, 44], [31, 55], [31, 59], [31, 60], [31, 64], [31, 67], [31, 74], [31, 77], [31, 82], [31, 87], [31, 89], [31, 93], [31, 96], [31, 98], [31, 101], [31, 113], [31, 114], [31, 119], [31, 120], [31, 121], [31, 127], [31, 128], [31, 130], [31, 133], [31, 134], [31, 135], [31, 136], [31, 137], [31, 139], [32, 41], [32, 47], [32, 51], [32, 59], [32, 60], [32, 65], [32, 66], [32, 69], [32, 79], [32, 80], [32, 81], [32, 82], [32, 85], [32, 89], [32, 94], [32, 96], [32, 109], [32, 117], [32, 118], [32, 124], [32, 127], [32, 129], [32, 134], [33, 35], [33, 40], [33, 43], [33, 45], [33, 46], [33, 47], [33, 53], [33, 57], [33, 58], [33, 63], [33, 69], [33, 75], [33, 76], [33, 85], [33, 89], [33, 97], [33, 98], [33, 101], [33, 107], [33, 108], [33, 112], [33, 113], [33, 116], [33, 117], [33, 118], [33, 121], [33, 122], [33, 124], [33, 127], [33, 129], [33, 130], [33, 132], [33, 133], [33, 139], [34, 36], [34, 37], [34, 39], [34, 43], [34, 52], [34, 63], [34, 70], [34, 76], [34, 80], [34, 86], [34, 92], [34, 96], [34, 98], [34, 100], [34, 101], [34, 103], [34, 118], [34, 119], [34, 121], [34, 123], [34, 124], [34, 126], [34, 130], [34, 131], [34, 133], [34, 135], [35, 42], [35, 43], [35, 44], [35, 47], [35, 48], [35, 54], [35, 59], [35, 67], [35, 69], [35, 70], [35, 82], [35, 87], [35, 88], [35, 94], [35, 96], [35, 100], [35, 110], [35, 119], [35, 122], [35, 129], [35, 130], [35, 134], [35, 138], [36, 37], [36, 40], [36, 41], [36, 42], [36, 51], [36, 52], [36, 54], [36, 55], [36, 63], [36, 65], [36, 66], [36, 68], [36, 71], [36, 75], [36, 76], [36, 77], [36, 83], [36, 84], [36, 87], [36, 89], [36, 95], [36, 96], [36, 97], [36, 99], [36, 101], [36, 106], [36, 109], [36, 112], [36, 113], [36, 118], [36, 119], [36, 121], [36, 123], [36, 124], [36, 130], [36, 133], [36, 135], [37, 39], [37, 44], [37, 45], [37, 52], [37, 55], [37, 56], [37, 63], [37, 65], [37, 72], [37, 75], [37, 76], [37, 80], [37, 86], [37, 87], [37, 89], [37, 92], [37, 94], [37, 95], [37, 98], [37, 99], [37, 102], [37, 108], [37, 110], [37, 112], [37, 118], [37, 119], [37, 120], [37, 121], [37, 129], [37, 133], [37, 135], [37, 139], [38, 41], [38, 42], [38, 48], [38, 51], [38, 56], [38, 57], [38, 60], [38, 62], [38, 69], [38, 71], [38, 73], [38, 79], [38, 80], [38, 84], [38, 91], [38, 101], [38, 104], [38, 106], [38, 108], [38, 109], [38, 110], [38, 114], [38, 120], [38, 122], [38, 123], [38, 124], [38, 125], [38, 126], [38, 128], [38, 130], [38, 131], [38, 133], [38, 137], [38, 139], [39, 43], [39, 46], [39, 48], [39, 50], [39, 54], [39, 56], [39, 59], [39, 62], [39, 70], [39, 73], [39, 74], [39, 79], [39, 82], [39, 85], [39, 86], [39, 92], [39, 93], [39, 94], [39, 97], [39, 98], [39, 110], [39, 113], [39, 118], [39, 120], [39, 122], [39, 123], [39, 128], [39, 129], [39, 132], [39, 139], [40, 42], [40, 45], [40, 49], [40, 54], [40, 64], [40, 66], [40, 68], [40, 72], [40, 76], [40, 81], [40, 82], [40, 83], [40, 84], [40, 90], [40, 91], [40, 94], [40, 98], [40, 102], [40, 103], [40, 104], [40, 105], [40, 106], [40, 107], [40, 108], [40, 114], [40, 115], [40, 116], [40, 122], [41, 42], [41, 48], [41, 53], [41, 56], [41, 57], [41, 62], [41, 65], [41, 68], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [41, 94], [41, 96], [41, 98], [41, 103], [41, 112], [41, 115], [41, 119], [41, 126], [41, 127], [41, 130], [41, 131], [42, 48], [42, 49], [42, 51], [42, 69], [42, 71], [42, 77], [42, 80], [42, 96], [42, 97], [42, 98], [42, 100], [42, 103], [42, 105], [42, 111], [42, 113], [42, 114], [42, 115], [42, 127], [42, 133], [42, 135], [43, 45], [43, 54], [43, 57], [43, 58], [43, 60], [43, 61], [43, 65], [43, 69], [43, 89], [43, 90], [43, 91], [43, 92], [43, 97], [43, 101], [43, 102], [43, 103], [43, 108], [43, 110], [43, 112], [43, 114], [43, 121], [43, 123], [43, 125], [43, 126], [43, 130], [43, 133], [43, 139], [44, 45], [44, 48], [44, 49], [44, 50], [44, 51], [44, 59], [44, 80], [44, 81], [44, 83], [44, 84], [44, 87], [44, 94], [44, 96], [44, 104], [44, 111], [44, 115], [44, 117], [44, 118], [44, 120], [44, 122], [44, 129], [44, 130], [44, 136], [44, 138], [44, 139], [45, 46], [45, 47], [45, 49], [45, 53], [45, 55], [45, 60], [45, 65], [45, 67], [45, 69], [45, 71], [45, 76], [45, 77], [45, 84], [45, 85], [45, 89], [45, 90], [45, 94], [45, 95], [45, 96], [45, 98], [45, 101], [45, 104], [45, 108], [45, 112], [45, 117], [45, 123], [45, 127], [45, 131], [45, 138], [46, 52], [46, 54], [46, 56], [46, 57], [46, 59], [46, 61], [46, 64], [46, 66], [46, 69], [46, 70], [46, 75], [46, 77], [46, 80], [46, 83], [46, 85], [46, 87], [46, 91], [46, 93], [46, 96], [46, 97], [46, 98], [46, 100], [46, 101], [46, 102], [46, 107], [46, 109], [46, 110], [46, 111], [46, 119], [46, 123], [46, 124], [46, 129], [46, 133], [46, 136], [46, 137], [46, 139], [47, 50], [47, 51], [47, 62], [47, 64], [47, 71], [47, 72], [47, 75], [47, 76], [47, 77], [47, 79], [47, 88], [47, 89], [47, 90], [47, 95], [47, 98], [47, 101], [47, 105], [47, 110], [47, 111], [47, 115], [47, 120], [47, 127], [47, 131], [47, 136], [47, 137], [47, 138], [48, 53], [48, 59], [48, 67], [48, 70], [48, 71], [48, 74], [48, 83], [48, 84], [48, 91], [48, 93], [48, 96], [48, 97], [48, 100], [48, 102], [48, 103], [48, 109], [48, 110], [48, 112], [48, 113], [48, 114], [48, 116], [48, 120], [48, 124], [48, 125], [48, 130], [48, 132], [48, 135], [48, 138], [48, 139], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 57], [49, 59], [49, 61], [49, 63], [49, 64], [49, 67], [49, 74], [49, 81], [49, 83], [49, 85], [49, 86], [49, 95], [49, 100], [49, 101], [49, 103], [49, 106], [49, 109], [49, 112], [49, 114], [49, 123], [49, 124], [49, 126], [49, 132], [49, 135], [49, 137], [50, 51], [50, 64], [50, 66], [50, 67], [50, 73], [50, 76], [50, 77], [50, 85], [50, 86], [50, 87], [50, 93], [50, 94], [50, 96], [50, 99], [50, 101], [50, 102], [50, 103], [50, 105], [50, 106], [50, 118], [50, 121], [50, 123], [50, 124], [50, 132], [50, 134], [50, 136], [50, 137], [51, 54], [51, 55], [51, 57], [51, 58], [51, 59], [51, 61], [51, 65], [51, 66], [51, 71], [51, 73], [51, 75], [51, 78], [51, 79], [51, 80], [51, 82], [51, 84], [51, 85], [51, 86], [51, 94], [51, 100], [51, 103], [51, 106], [51, 107], [51, 109], [51, 111], [51, 115], [51, 117], [51, 118], [51, 119], [51, 120], [51, 128], [51, 130], [51, 131], [51, 138], [51, 139], [52, 54], [52, 61], [52, 62], [52, 64], [52, 68], [52, 80], [52, 85], [52, 86], [52, 88], [52, 89], [52, 93], [52, 94], [52, 97], [52, 98], [52, 99], [52, 100], [52, 106], [52, 108], [52, 109], [52, 118], [52, 123], [52, 124], [52, 131], [52, 132], [52, 138], [52, 139], [53, 59], [53, 62], [53, 64], [53, 65], [53, 66], [53, 78], [53, 81], [53, 86], [53, 87], [53, 89], [53, 92], [53, 95], [53, 98], [53, 99], [53, 109], [53, 110], [53, 111], [53, 112], [53, 120], [53, 124], [53, 125], [53, 126], [53, 127], [53, 128], [53, 129], [54, 57], [54, 63], [54, 64], [54, 67], [54, 68], [54, 70], [54, 72], [54, 83], [54, 91], [54, 97], [54, 99], [54, 102], [54, 103], [54, 108], [54, 113], [54, 115], [54, 116], [54, 117], [54, 118], [54, 119], [54, 120], [54, 122], [54, 125], [54, 129], [54, 131], [54, 133], [55, 56], [55, 57], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 67], [55, 72], [55, 73], [55, 79], [55, 80], [55, 88], [55, 96], [55, 99], [55, 100], [55, 102], [55, 107], [55, 114], [55, 119], [55, 123], [55, 124], [55, 132], [55, 133], [56, 57], [56, 61], [56, 64], [56, 66], [56, 73], [56, 79], [56, 81], [56, 83], [56, 88], [56, 90], [56, 99], [56, 107], [56, 117], [56, 125], [56, 126], [56, 128], [56, 132], [56, 137], [56, 138], [57, 59], [57, 61], [57, 63], [57, 64], [57, 75], [57, 82], [57, 87], [57, 89], [57, 90], [57, 99], [57, 100], [57, 102], [57, 103], [57, 106], [57, 114], [57, 120], [57, 126], [57, 127], [57, 129], [57, 133], [58, 64], [58, 67], [58, 70], [58, 71], [58, 78], [58, 79], [58, 82], [58, 84], [58, 85], [58, 91], [58, 92], [58, 95], [58, 98], [58, 99], [58, 100], [58, 107], [58, 112], [58, 115], [58, 118], [58, 126], [58, 132], [58, 134], [58, 139], [59, 61], [59, 62], [59, 69], [59, 70], [59, 74], [59, 76], [59, 77], [59, 104], [59, 107], [59, 115], [59, 117], [59, 120], [59, 122], [59, 129], [59, 130], [59, 133], [59, 136], [59, 139], [60, 62], [60, 69], [60, 72], [60, 74], [60, 81], [60, 97], [60, 101], [60, 106], [60, 108], [60, 110], [60, 113], [60, 114], [60, 118], [60, 119], [60, 122], [60, 130], [60, 133], [61, 62], [61, 65], [61, 68], [61, 70], [61, 74], [61, 75], [61, 81], [61, 82], [61, 84], [61, 91], [61, 98], [61, 103], [61, 106], [61, 112], [61, 116], [61, 119], [61, 122], [61, 126], [61, 131], [61, 133], [61, 135], [61, 136], [61, 137], [62, 63], [62, 64], [62, 70], [62, 71], [62, 73], [62, 76], [62, 80], [62, 81], [62, 83], [62, 87], [62, 100], [62, 101], [62, 103], [62, 105], [62, 109], [62, 110], [62, 111], [62, 112], [62, 117], [62, 120], [62, 122], [62, 123], [62, 124], [62, 126], [62, 134], [62, 139], [63, 69], [63, 71], [63, 74], [63, 79], [63, 80], [63, 81], [63, 82], [63, 83], [63, 85], [63, 90], [63, 93], [63, 96], [63, 97], [63, 100], [63, 106], [63, 107], [63, 111], [63, 114], [63, 120], [63, 124], [63, 125], [63, 126], [63, 129], [63, 137], [63, 139], [64, 67], [64, 71], [64, 75], [64, 76], [64, 77], [64, 78], [64, 87], [64, 88], [64, 89], [64, 91], [64, 97], [64, 99], [64, 112], [64, 118], [64, 120], [64, 129], [64, 134], [64, 138], [64, 139], [65, 67], [65, 70], [65, 71], [65, 73], [65, 74], [65, 75], [65, 79], [65, 85], [65, 87], [65, 97], [65, 99], [65, 102], [65, 106], [65, 111], [65, 114], [65, 123], [65, 126], [65, 128], [65, 139], [66, 69], [66, 71], [66, 74], [66, 75], [66, 79], [66, 81], [66, 83], [66, 84], [66, 88], [66, 89], [66, 94], [66, 95], [66, 97], [66, 98], [66, 122], [66, 124], [66, 125], [66, 126], [67, 70], [67, 71], [67, 75], [67, 77], [67, 78], [67, 79], [67, 82], [67, 84], [67, 87], [67, 94], [67, 96], [67, 103], [67, 111], [67, 113], [67, 116], [67, 118], [67, 120], [67, 124], [67, 125], [67, 126], [67, 131], [67, 135], [68, 69], [68, 71], [68, 75], [68, 77], [68, 82], [68, 83], [68, 86], [68, 89], [68, 91], [68, 92], [68, 93], [68, 98], [68, 101], [68, 102], [68, 103], [68, 107], [68, 109], [68, 117], [68, 119], [68, 121], [68, 122], [68, 127], [68, 129], [68, 131], [68, 133], [68, 134], [68, 136], [68, 137], [68, 138], [68, 139], [69, 71], [69, 75], [69, 78], [69, 80], [69, 84], [69, 86], [69, 89], [69, 91], [69, 98], [69, 99], [69, 100], [69, 101], [69, 102], [69, 104], [69, 109], [69, 110], [69, 111], [69, 114], [69, 116], [69, 120], [69, 123], [69, 124], [69, 126], [69, 128], [69, 129], [69, 132], [69, 133], [69, 134], [69, 138], [70, 71], [70, 76], [70, 77], [70, 78], [70, 91], [70, 93], [70, 95], [70, 103], [70, 105], [70, 106], [70, 109], [70, 111], [70, 122], [70, 123], [70, 130], [70, 139], [71, 72], [71, 77], [71, 82], [71, 83], [71, 93], [71, 94], [71, 98], [71, 99], [71, 102], [71, 103], [71, 104], [71, 117], [71, 118], [71, 119], [71, 120], [71, 121], [71, 126], [71, 130], [71, 131], [71, 136], [71, 138], [72, 75], [72, 77], [72, 81], [72, 86], [72, 90], [72, 94], [72, 95], [72, 96], [72, 97], [72, 105], [72, 108], [72, 110], [72, 113], [72, 114], [72, 115], [72, 125], [72, 126], [72, 132], [72, 138], [72, 139], [73, 76], [73, 83], [73, 84], [73, 88], [73, 91], [73, 92], [73, 95], [73, 98], [73, 99], [73, 100], [73, 101], [73, 108], [73, 117], [73, 119], [73, 120], [73, 127], [73, 128], [73, 135], [73, 136], [73, 138], [73, 139], [74, 78], [74, 79], [74, 89], [74, 91], [74, 94], [74, 96], [74, 98], [74, 101], [74, 102], [74, 104], [74, 106], [74, 108], [74, 109], [74, 110], [74, 114], [74, 116], [74, 117], [74, 119], [74, 121], [74, 122], [74, 123], [74, 127], [74, 129], [74, 131], [74, 132], [74, 133], [74, 137], [74, 139], [75, 83], [75, 85], [75, 89], [75, 90], [75, 91], [75, 97], [75, 98], [75, 99], [75, 102], [75, 110], [75, 111], [75, 116], [75, 121], [75, 126], [75, 130], [75, 131], [75, 133], [75, 135], [75, 137], [75, 138], [75, 139], [76, 77], [76, 78], [76, 81], [76, 85], [76, 91], [76, 93], [76, 102], [76, 103], [76, 109], [76, 110], [76, 113], [76, 118], [76, 123], [76, 130], [76, 136], [77, 81], [77, 82], [77, 84], [77, 91], [77, 95], [77, 98], [77, 100], [77, 102], [77, 103], [77, 107], [77, 112], [77, 116], [77, 119], [77, 120], [77, 124], [77, 128], [77, 131], [77, 133], [77, 136], [77, 138], [78, 80], [78, 83], [78, 86], [78, 88], [78, 96], [78, 97], [78, 99], [78, 103], [78, 105], [78, 108], [78, 112], [78, 113], [78, 114], [78, 116], [78, 117], [78, 122], [78, 125], [78, 129], [78, 131], [78, 137], [78, 138], [79, 80], [79, 90], [79, 92], [79, 93], [79, 98], [79, 109], [79, 112], [79, 119], [79, 122], [79, 123], [79, 127], [79, 130], [79, 132], [79, 134], [80, 83], [80, 84], [80, 91], [80, 93], [80, 94], [80, 97], [80, 102], [80, 110], [80, 113], [80, 118], [80, 121], [80, 124], [80, 129], [80, 130], [80, 131], [80, 132], [81, 85], [81, 87], [81, 92], [81, 94], [81, 95], [81, 104], [81, 107], [81, 108], [81, 119], [81, 121], [81, 124], [81, 132], [81, 134], [82, 84], [82, 87], [82, 98], [82, 111], [82, 112], [82, 113], [82, 114], [82, 120], [82, 121], [82, 124], [82, 128], [82, 132], [82, 136], [83, 89], [83, 90], [83, 91], [83, 93], [83, 94], [83, 97], [83, 102], [83, 106], [83, 112], [83, 128], [83, 130], [83, 131], [83, 132], [83, 133], [83, 134], [83, 137], [84, 86], [84, 87], [84, 101], [84, 108], [84, 113], [84, 114], [84, 119], [84, 120], [84, 123], [84, 129], [84, 130], [84, 136], [84, 139], [85, 89], [85, 103], [85, 104], [85, 107], [85, 108], [85, 111], [85, 114], [85, 118], [85, 119], [85, 120], [85, 127], [85, 132], [85, 138], [85, 139], [86, 87], [86, 90], [86, 91], [86, 96], [86, 99], [86, 102], [86, 108], [86, 110], [86, 112], [86, 119], [86, 120], [86, 122], [86, 123], [86, 126], [86, 133], [86, 136], [87, 88], [87, 90], [87, 91], [87, 96], [87, 100], [87, 102], [87, 107], [87, 108], [87, 115], [87, 120], [87, 121], [87, 122], [87, 123], [87, 126], [87, 137], [87, 138], [88, 91], [88, 93], [88, 96], [88, 100], [88, 101], [88, 104], [88, 106], [88, 109], [88, 110], [88, 114], [88, 116], [88, 118], [88, 120], [88, 123], [88, 129], [88, 134], [88, 139], [89, 90], [89, 91], [89, 93], [89, 96], [89, 100], [89, 101], [89, 103], [89, 104], [89, 107], [89, 112], [89, 116], [89, 118], [89, 121], [89, 129], [89, 130], [89, 132], [89, 135], [90, 93], [90, 97], [90, 98], [90, 104], [90, 107], [90, 108], [90, 112], [90, 116], [90, 117], [90, 121], [90, 123], [90, 127], [90, 130], [90, 133], [90, 134], [91, 98], [91, 104], [91, 105], [91, 107], [91, 112], [91, 113], [91, 121], [91, 123], [91, 125], [91, 126], [91, 131], [91, 132], [91, 133], [91, 136], [91, 138], [92, 98], [92, 101], [92, 102], [92, 103], [92, 104], [92, 109], [92, 113], [92, 118], [92, 120], [92, 121], [92, 122], [92, 126], [92, 130], [92, 135], [92, 137], [93, 96], [93, 97], [93, 99], [93, 102], [93, 103], [93, 106], [93, 111], [93, 123], [93, 124], [93, 130], [93, 134], [93, 135], [94, 101], [94, 102], [94, 103], [94, 107], [94, 113], [94, 118], [94, 125], [94, 132], [94, 133], [94, 138], [94, 139], [95, 96], [95, 97], [95, 104], [95, 107], [95, 108], [95, 113], [95, 115], [95, 120], [95, 123], [95, 124], [95, 126], [95, 127], [95, 128], [95, 130], [95, 133], [95, 134], [95, 138], [96, 99], [96, 100], [96, 103], [96, 105], [96, 106], [96, 109], [96, 110], [96, 117], [96, 125], [96, 127], [96, 132], [97, 98], [97, 103], [97, 109], [97, 118], [97, 119], [97, 120], [97, 125], [98, 101], [98, 107], [98, 108], [98, 110], [98, 111], [98, 112], [98, 115], [98, 119], [98, 125], [98, 126], [98, 127], [98, 130], [98, 132], [98, 134], [98, 138], [98, 139], [99, 103], [99, 105], [99, 108], [99, 111], [99, 122], [99, 125], [99, 126], [99, 127], [99, 129], [99, 131], [99, 136], [99, 138], [100, 101], [100, 102], [100, 115], [100, 127], [100, 131], [100, 132], [100, 133], [100, 139], [101, 103], [101, 104], [101, 106], [101, 107], [101, 110], [101, 112], [101, 113], [101, 115], [101, 122], [101, 137], [102, 104], [102, 106], [102, 113], [102, 116], [102, 122], [102, 125], [102, 131], [102, 134], [102, 135], [102, 136], [103, 106], [103, 113], [103, 114], [103, 115], [103, 118], [103, 119], [103, 126], [103, 129], [103, 133], [103, 134], [103, 137], [104, 105], [104, 106], [104, 108], [104, 111], [104, 115], [104, 116], [104, 121], [104, 126], [104, 127], [104, 129], [104, 130], [104, 131], [104, 133], [104, 139], [105, 108], [105, 113], [105, 123], [105, 127], [105, 130], [105, 131], [105, 132], [105, 136], [105, 137], [105, 138], [105, 139], [106, 116], [106, 119], [106, 120], [106, 123], [106, 124], [106, 125], [106, 126], [106, 129], [106, 130], [106, 132], [106, 133], [106, 139], [107, 112], [107, 115], [107, 119], [107, 124], [107, 128], [107, 129], [107, 134], [107, 136], [107, 137], [108, 110], [108, 112], [108, 124], [108, 127], [108, 128], [108, 136], [108, 138], [109, 111], [109, 113], [109, 115], [109, 118], [109, 120], [109, 125], [109, 126], [109, 128], [109, 129], [109, 130], [109, 133], [109, 134], [110, 115], [110, 122], [110, 132], [110, 137], [110, 139], [111, 112], [111, 113], [111, 119], [111, 121], [111, 122], [111, 125], [111, 131], [111, 134], [112, 114], [112, 117], [112, 122], [112, 123], [112, 125], [112, 130], [112, 132], [112, 134], [112, 136], [112, 139], [113, 114], [113, 115], [113, 118], [113, 119], [113, 127], [113, 128], [113, 129], [113, 131], [113, 135], [113, 138], [113, 139], [114, 118], [114, 123], [114, 124], [114, 131], [114, 134], [115, 116], [115, 121], [115, 126], [115, 129], [115, 132], [115, 135], [115, 136], [115, 137], [115, 138], [115, 139], [116, 117], [116, 121], [116, 122], [116, 124], [116, 126], [116, 127], [116, 130], [116, 133], [116, 137], [117, 119], [117, 120], [117, 132], [117, 133], [117, 136], [117, 137], [118, 121], [118, 123], [118, 124], [118, 131], [118, 134], [118, 137], [119, 120], [119, 121], [119, 125], [119, 130], [119, 133], [119, 134], [119, 136], [119, 137], [119, 138], [120, 126], [120, 127], [120, 128], [120, 129], [120, 135], [120, 138], [121, 124], [121, 126], [121, 135], [121, 136], [121, 139], [122, 123], [122, 124], [122, 127], [122, 134], [123, 125], [123, 129], [123, 133], [124, 125], [124, 126], [124, 127], [124, 130], [124, 134], [124, 135], [124, 136], [124, 139], [125, 127], [125, 129], [125, 131], [125, 133], [125, 134], [125, 139], [126, 134], [127, 130], [127, 131], [127, 135], [127, 137], [128, 129], [128, 130], [128, 131], [128, 135], [128, 138], [128, 139], [129, 136], [129, 138], [130, 132], [130, 134], [130, 137], [131, 132], [131, 133], [131, 137], [131, 138], [133, 136], [134, 137], [135, 138], [135, 139], [136, 139]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s0/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..26c4f93fb7429a0468e9cdcc9602b2c5b862960e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [2, 8, 14, 15, 35, 39, 52, 57, 60, 65, 76, 83, 84, 95, 105, 117, 121, 125]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s0/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l6-s0/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cf2998adc0b435ff8fa37ca8bbd8c3113cdcafee --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 5], [0, 6], [0, 7], [0, 17], [0, 20], [0, 23], [0, 24], [0, 26], [0, 28], [0, 29], [0, 32], [0, 34], [0, 42], [0, 44], [0, 46], [0, 49], [0, 51], [0, 56], [0, 62], [0, 64], [0, 71], [0, 73], [0, 74], [0, 77], [0, 80], [0, 81], [0, 84], [0, 85], [0, 92], [0, 96], [0, 99], [0, 103], [0, 106], [0, 107], [0, 108], [0, 115], [0, 116], [0, 123], [0, 126], [0, 128], [1, 8], [1, 10], [1, 16], [1, 17], [1, 19], [1, 23], [1, 25], [1, 28], [1, 29], [1, 33], [1, 43], [1, 47], [1, 54], [1, 56], [1, 59], [1, 60], [1, 61], [1, 63], [1, 68], [1, 72], [1, 74], [1, 76], [1, 82], [1, 83], [1, 84], [1, 88], [1, 92], [1, 98], [1, 103], [1, 105], [1, 107], [1, 108], [1, 109], [1, 110], [1, 112], [1, 121], [1, 122], [1, 124], [1, 126], [1, 128], [1, 132], [1, 133], [1, 134], [1, 137], [1, 138], [1, 139], [2, 6], [2, 7], [2, 18], [2, 28], [2, 32], [2, 41], [2, 42], [2, 49], [2, 56], [2, 63], [2, 66], [2, 71], [2, 74], [2, 77], [2, 86], [2, 93], [2, 99], [2, 100], [2, 107], [2, 109], [2, 110], [2, 112], [2, 115], [2, 119], [2, 120], [2, 124], [2, 128], [2, 129], [2, 130], [2, 132], [2, 135], [2, 138], [3, 5], [3, 7], [3, 9], [3, 11], [3, 13], [3, 14], [3, 19], [3, 21], [3, 24], [3, 27], [3, 36], [3, 47], [3, 51], [3, 52], [3, 54], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 71], [3, 72], [3, 78], [3, 80], [3, 86], [3, 87], [3, 88], [3, 89], [3, 90], [3, 97], [3, 103], [3, 104], [3, 106], [3, 109], [3, 114], [3, 119], [3, 125], [3, 127], [3, 128], [3, 131], [3, 133], [3, 139], [4, 7], [4, 17], [4, 23], [4, 25], [4, 26], [4, 29], [4, 30], [4, 34], [4, 35], [4, 36], [4, 38], [4, 39], [4, 48], [4, 50], [4, 54], [4, 57], [4, 59], [4, 62], [4, 64], [4, 69], [4, 72], [4, 74], [4, 75], [4, 76], [4, 81], [4, 89], [4, 90], [4, 94], [4, 95], [4, 97], [4, 98], [4, 99], [4, 102], [4, 108], [4, 109], [4, 118], [4, 135], [4, 136], [5, 7], [5, 9], [5, 13], [5, 16], [5, 19], [5, 21], [5, 22], [5, 26], [5, 27], [5, 34], [5, 43], [5, 45], [5, 53], [5, 61], [5, 67], [5, 70], [5, 75], [5, 76], [5, 80], [5, 82], [5, 87], [5, 88], [5, 90], [5, 97], [5, 102], [5, 104], [5, 111], [5, 114], [5, 115], [5, 116], [5, 118], [5, 121], [5, 122], [5, 123], [5, 125], [5, 126], [5, 127], [5, 132], [5, 134], [5, 135], [6, 11], [6, 13], [6, 18], [6, 19], [6, 33], [6, 35], [6, 36], [6, 41], [6, 43], [6, 45], [6, 46], [6, 47], [6, 48], [6, 51], [6, 59], [6, 61], [6, 62], [6, 63], [6, 64], [6, 72], [6, 73], [6, 76], [6, 83], [6, 87], [6, 88], [6, 89], [6, 92], [6, 94], [6, 95], [6, 117], [6, 123], [6, 124], [6, 129], [6, 130], [6, 134], [6, 138], [7, 16], [7, 17], [7, 21], [7, 24], [7, 26], [7, 30], [7, 31], [7, 44], [7, 56], [7, 63], [7, 66], [7, 71], [7, 72], [7, 73], [7, 74], [7, 79], [7, 81], [7, 84], [7, 86], [7, 92], [7, 93], [7, 98], [7, 107], [7, 116], [7, 117], [7, 122], [7, 124], [7, 134], [7, 136], [8, 10], [8, 11], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 23], [8, 24], [8, 27], [8, 28], [8, 29], [8, 31], [8, 32], [8, 34], [8, 37], [8, 40], [8, 42], [8, 43], [8, 44], [8, 45], [8, 53], [8, 55], [8, 58], [8, 59], [8, 62], [8, 68], [8, 80], [8, 81], [8, 86], [8, 100], [8, 102], [8, 107], [8, 108], [8, 116], [8, 120], [8, 123], [8, 124], [8, 126], [8, 130], [8, 132], [8, 134], [9, 10], [9, 14], [9, 15], [9, 17], [9, 18], [9, 27], [9, 32], [9, 35], [9, 36], [9, 37], [9, 39], [9, 45], [9, 48], [9, 49], [9, 50], [9, 54], [9, 56], [9, 62], [9, 65], [9, 68], [9, 73], [9, 75], [9, 81], [9, 82], [9, 85], [9, 93], [9, 95], [9, 97], [9, 106], [9, 109], [9, 113], [9, 115], [9, 117], [9, 118], [9, 119], [9, 120], [9, 121], [9, 123], [9, 125], [9, 139], [10, 11], [10, 13], [10, 14], [10, 17], [10, 23], [10, 26], [10, 27], [10, 29], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 47], [10, 49], [10, 51], [10, 52], [10, 54], [10, 55], [10, 59], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 68], [10, 72], [10, 75], [10, 76], [10, 85], [10, 86], [10, 91], [10, 92], [10, 98], [10, 99], [10, 100], [10, 102], [10, 109], [10, 112], [10, 116], [10, 118], [10, 119], [10, 122], [10, 124], [10, 127], [10, 129], [10, 133], [10, 134], [11, 13], [11, 17], [11, 19], [11, 21], [11, 22], [11, 23], [11, 29], [11, 32], [11, 34], [11, 37], [11, 42], [11, 44], [11, 59], [11, 62], [11, 66], [11, 71], [11, 73], [11, 82], [11, 86], [11, 97], [11, 103], [11, 104], [11, 105], [11, 113], [11, 117], [11, 119], [11, 123], [11, 124], [11, 133], [11, 136], [11, 137], [12, 14], [12, 16], [12, 17], [12, 20], [12, 21], [12, 22], [12, 27], [12, 29], [12, 31], [12, 34], [12, 35], [12, 37], [12, 45], [12, 54], [12, 56], [12, 58], [12, 60], [12, 64], [12, 68], [12, 74], [12, 75], [12, 77], [12, 79], [12, 80], [12, 86], [12, 88], [12, 93], [12, 94], [12, 101], [12, 104], [12, 106], [12, 108], [12, 111], [12, 113], [12, 120], [12, 125], [12, 131], [12, 133], [13, 14], [13, 27], [13, 29], [13, 41], [13, 45], [13, 50], [13, 51], [13, 52], [13, 58], [13, 59], [13, 64], [13, 66], [13, 69], [13, 70], [13, 72], [13, 73], [13, 75], [13, 76], [13, 77], [13, 78], [13, 80], [13, 92], [13, 95], [13, 96], [13, 107], [13, 114], [13, 118], [13, 123], [13, 133], [13, 137], [14, 21], [14, 23], [14, 26], [14, 27], [14, 30], [14, 31], [14, 34], [14, 38], [14, 41], [14, 47], [14, 49], [14, 53], [14, 58], [14, 66], [14, 69], [14, 77], [14, 78], [14, 80], [14, 82], [14, 85], [14, 90], [14, 91], [14, 93], [14, 96], [14, 97], [14, 98], [14, 101], [14, 102], [14, 122], [14, 127], [14, 131], [14, 132], [14, 135], [14, 136], [14, 137], [14, 139], [15, 19], [15, 20], [15, 21], [15, 23], [15, 26], [15, 37], [15, 42], [15, 43], [15, 46], [15, 50], [15, 51], [15, 53], [15, 55], [15, 59], [15, 66], [15, 68], [15, 74], [15, 77], [15, 79], [15, 94], [15, 101], [15, 102], [15, 103], [15, 110], [15, 111], [15, 118], [15, 119], [15, 124], [15, 126], [15, 127], [15, 128], [15, 132], [15, 136], [15, 137], [16, 18], [16, 22], [16, 24], [16, 41], [16, 42], [16, 44], [16, 45], [16, 47], [16, 49], [16, 51], [16, 54], [16, 55], [16, 60], [16, 61], [16, 63], [16, 65], [16, 66], [16, 67], [16, 69], [16, 73], [16, 77], [16, 80], [16, 87], [16, 90], [16, 92], [16, 94], [16, 95], [16, 98], [16, 101], [16, 103], [16, 104], [16, 109], [16, 115], [16, 118], [16, 119], [16, 121], [16, 129], [16, 130], [16, 131], [16, 137], [17, 18], [17, 24], [17, 25], [17, 27], [17, 29], [17, 32], [17, 34], [17, 40], [17, 41], [17, 43], [17, 44], [17, 48], [17, 51], [17, 53], [17, 54], [17, 60], [17, 66], [17, 68], [17, 69], [17, 71], [17, 76], [17, 77], [17, 85], [17, 89], [17, 92], [17, 95], [17, 101], [17, 102], [17, 103], [17, 111], [17, 112], [17, 115], [17, 127], [17, 131], [17, 138], [18, 25], [18, 27], [18, 29], [18, 31], [18, 35], [18, 36], [18, 44], [18, 54], [18, 56], [18, 57], [18, 58], [18, 60], [18, 61], [18, 62], [18, 64], [18, 65], [18, 66], [18, 67], [18, 70], [18, 76], [18, 81], [18, 82], [18, 88], [18, 94], [18, 108], [18, 111], [18, 114], [18, 117], [18, 118], [18, 119], [18, 121], [18, 129], [18, 131], [18, 133], [18, 134], [18, 136], [18, 138], [19, 20], [19, 26], [19, 32], [19, 34], [19, 35], [19, 39], [19, 40], [19, 44], [19, 48], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 65], [19, 66], [19, 67], [19, 71], [19, 73], [19, 76], [19, 77], [19, 80], [19, 83], [19, 84], [19, 93], [19, 96], [19, 97], [19, 98], [19, 100], [19, 103], [19, 105], [19, 112], [19, 117], [19, 118], [19, 122], [19, 123], [19, 126], [19, 134], [19, 135], [20, 25], [20, 28], [20, 30], [20, 40], [20, 43], [20, 48], [20, 53], [20, 57], [20, 59], [20, 60], [20, 62], [20, 68], [20, 71], [20, 77], [20, 78], [20, 80], [20, 81], [20, 84], [20, 86], [20, 89], [20, 96], [20, 98], [20, 100], [20, 102], [20, 104], [20, 105], [20, 107], [20, 112], [20, 116], [20, 118], [20, 121], [20, 129], [20, 134], [20, 135], [20, 139], [21, 22], [21, 25], [21, 29], [21, 30], [21, 31], [21, 34], [21, 36], [21, 43], [21, 45], [21, 46], [21, 47], [21, 51], [21, 53], [21, 60], [21, 61], [21, 63], [21, 67], [21, 73], [21, 75], [21, 76], [21, 78], [21, 79], [21, 81], [21, 84], [21, 90], [21, 95], [21, 96], [21, 98], [21, 100], [21, 110], [21, 113], [21, 116], [21, 119], [21, 127], [21, 130], [21, 131], [21, 132], [21, 133], [22, 23], [22, 25], [22, 26], [22, 32], [22, 33], [22, 39], [22, 42], [22, 48], [22, 51], [22, 57], [22, 60], [22, 62], [22, 66], [22, 72], [22, 74], [22, 75], [22, 77], [22, 82], [22, 85], [22, 86], [22, 93], [22, 98], [22, 100], [22, 101], [22, 106], [22, 111], [22, 112], [22, 115], [22, 116], [22, 119], [22, 121], [22, 122], [22, 127], [22, 131], [22, 135], [22, 138], [23, 26], [23, 31], [23, 35], [23, 37], [23, 38], [23, 41], [23, 46], [23, 47], [23, 48], [23, 50], [23, 53], [23, 57], [23, 59], [23, 67], [23, 68], [23, 69], [23, 73], [23, 81], [23, 87], [23, 89], [23, 90], [23, 91], [23, 96], [23, 98], [23, 99], [23, 105], [23, 117], [23, 119], [23, 121], [23, 122], [23, 124], [23, 128], [23, 129], [23, 130], [23, 133], [23, 134], [23, 136], [24, 25], [24, 26], [24, 27], [24, 28], [24, 34], [24, 38], [24, 42], [24, 45], [24, 51], [24, 56], [24, 57], [24, 58], [24, 69], [24, 72], [24, 73], [24, 74], [24, 78], [24, 79], [24, 82], [24, 84], [24, 85], [24, 87], [24, 88], [24, 93], [24, 94], [24, 98], [24, 99], [24, 102], [24, 103], [24, 105], [24, 112], [24, 115], [24, 116], [24, 118], [24, 120], [24, 123], [24, 131], [25, 28], [25, 34], [25, 35], [25, 43], [25, 48], [25, 49], [25, 52], [25, 54], [25, 56], [25, 64], [25, 66], [25, 70], [25, 72], [25, 74], [25, 76], [25, 86], [25, 87], [25, 93], [25, 99], [25, 101], [25, 105], [25, 116], [25, 118], [25, 119], [25, 122], [25, 126], [25, 133], [25, 134], [26, 27], [26, 28], [26, 31], [26, 32], [26, 36], [26, 37], [26, 41], [26, 43], [26, 46], [26, 47], [26, 50], [26, 52], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 60], [26, 62], [26, 64], [26, 69], [26, 70], [26, 73], [26, 80], [26, 87], [26, 91], [26, 92], [26, 94], [26, 98], [26, 109], [26, 110], [26, 113], [26, 121], [26, 122], [26, 125], [26, 127], [26, 133], [26, 134], [26, 137], [26, 139], [27, 29], [27, 31], [27, 36], [27, 39], [27, 40], [27, 41], [27, 45], [27, 48], [27, 50], [27, 51], [27, 60], [27, 61], [27, 64], [27, 74], [27, 75], [27, 76], [27, 80], [27, 84], [27, 87], [27, 88], [27, 92], [27, 94], [27, 96], [27, 97], [27, 98], [27, 99], [27, 103], [27, 107], [27, 113], [27, 115], [27, 123], [27, 125], [27, 126], [27, 129], [27, 130], [27, 133], [28, 38], [28, 41], [28, 43], [28, 45], [28, 47], [28, 49], [28, 51], [28, 52], [28, 54], [28, 62], [28, 64], [28, 70], [28, 71], [28, 72], [28, 74], [28, 76], [28, 80], [28, 84], [28, 85], [28, 87], [28, 88], [28, 92], [28, 95], [28, 96], [28, 99], [28, 101], [28, 103], [28, 104], [28, 113], [28, 115], [28, 118], [28, 129], [28, 134], [28, 135], [29, 30], [29, 31], [29, 33], [29, 37], [29, 38], [29, 40], [29, 42], [29, 46], [29, 47], [29, 51], [29, 60], [29, 63], [29, 65], [29, 67], [29, 71], [29, 75], [29, 76], [29, 77], [29, 78], [29, 80], [29, 82], [29, 87], [29, 90], [29, 97], [29, 101], [29, 105], [29, 107], [29, 111], [29, 112], [29, 116], [29, 117], [29, 120], [29, 121], [29, 124], [29, 129], [30, 35], [30, 39], [30, 41], [30, 45], [30, 49], [30, 54], [30, 57], [30, 60], [30, 61], [30, 63], [30, 64], [30, 66], [30, 68], [30, 71], [30, 75], [30, 76], [30, 82], [30, 85], [30, 90], [30, 93], [30, 103], [30, 105], [30, 113], [30, 117], [30, 123], [30, 125], [30, 128], [30, 129], [30, 131], [30, 132], [30, 136], [30, 138], [30, 139], [31, 32], [31, 34], [31, 38], [31, 44], [31, 55], [31, 59], [31, 60], [31, 64], [31, 67], [31, 74], [31, 77], [31, 82], [31, 87], [31, 89], [31, 93], [31, 96], [31, 98], [31, 101], [31, 113], [31, 114], [31, 119], [31, 120], [31, 121], [31, 127], [31, 128], [31, 130], [31, 133], [31, 134], [31, 135], [31, 136], [31, 137], [31, 139], [32, 41], [32, 47], [32, 51], [32, 59], [32, 60], [32, 65], [32, 66], [32, 69], [32, 79], [32, 80], [32, 81], [32, 82], [32, 85], [32, 89], [32, 94], [32, 96], [32, 109], [32, 117], [32, 118], [32, 124], [32, 127], [32, 129], [32, 134], [33, 35], [33, 40], [33, 43], [33, 45], [33, 46], [33, 47], [33, 53], [33, 57], [33, 58], [33, 63], [33, 69], [33, 75], [33, 76], [33, 85], [33, 89], [33, 97], [33, 98], [33, 101], [33, 107], [33, 108], [33, 112], [33, 113], [33, 116], [33, 117], [33, 118], [33, 121], [33, 122], [33, 124], [33, 127], [33, 129], [33, 130], [33, 132], [33, 133], [33, 139], [34, 36], [34, 37], [34, 39], [34, 43], [34, 52], [34, 63], [34, 70], [34, 76], [34, 80], [34, 86], [34, 92], [34, 96], [34, 98], [34, 100], [34, 101], [34, 103], [34, 118], [34, 119], [34, 121], [34, 123], [34, 124], [34, 126], [34, 130], [34, 131], [34, 133], [34, 135], [35, 42], [35, 43], [35, 44], [35, 47], [35, 48], [35, 54], [35, 59], [35, 67], [35, 69], [35, 70], [35, 82], [35, 87], [35, 88], [35, 94], [35, 96], [35, 100], [35, 110], [35, 119], [35, 122], [35, 129], [35, 130], [35, 134], [35, 138], [36, 37], [36, 40], [36, 41], [36, 42], [36, 51], [36, 52], [36, 54], [36, 55], [36, 63], [36, 65], [36, 66], [36, 68], [36, 71], [36, 75], [36, 76], [36, 77], [36, 83], [36, 84], [36, 87], [36, 89], [36, 95], [36, 96], [36, 97], [36, 99], [36, 101], [36, 106], [36, 109], [36, 112], [36, 113], [36, 118], [36, 119], [36, 121], [36, 123], [36, 124], [36, 130], [36, 133], [36, 135], [37, 39], [37, 44], [37, 45], [37, 52], [37, 55], [37, 56], [37, 63], [37, 65], [37, 72], [37, 75], [37, 76], [37, 80], [37, 86], [37, 87], [37, 89], [37, 92], [37, 94], [37, 95], [37, 98], [37, 99], [37, 102], [37, 108], [37, 110], [37, 112], [37, 118], [37, 119], [37, 120], [37, 121], [37, 129], [37, 133], [37, 135], [37, 139], [38, 41], [38, 42], [38, 48], [38, 51], [38, 56], [38, 57], [38, 60], [38, 62], [38, 69], [38, 71], [38, 73], [38, 79], [38, 80], [38, 84], [38, 91], [38, 101], [38, 104], [38, 106], [38, 108], [38, 109], [38, 110], [38, 114], [38, 120], [38, 122], [38, 123], [38, 124], [38, 125], [38, 126], [38, 128], [38, 130], [38, 131], [38, 133], [38, 137], [38, 139], [39, 43], [39, 46], [39, 48], [39, 50], [39, 54], [39, 56], [39, 59], [39, 62], [39, 70], [39, 73], [39, 74], [39, 79], [39, 82], [39, 85], [39, 86], [39, 92], [39, 93], [39, 94], [39, 97], [39, 98], [39, 110], [39, 113], [39, 118], [39, 120], [39, 122], [39, 123], [39, 128], [39, 129], [39, 132], [39, 139], [40, 42], [40, 45], [40, 49], [40, 54], [40, 64], [40, 66], [40, 68], [40, 72], [40, 76], [40, 81], [40, 82], [40, 83], [40, 84], [40, 90], [40, 91], [40, 94], [40, 98], [40, 102], [40, 103], [40, 104], [40, 105], [40, 106], [40, 107], [40, 108], [40, 114], [40, 115], [40, 116], [40, 122], [41, 42], [41, 48], [41, 53], [41, 56], [41, 57], [41, 62], [41, 65], [41, 68], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [41, 94], [41, 96], [41, 98], [41, 103], [41, 112], [41, 115], [41, 119], [41, 126], [41, 127], [41, 130], [41, 131], [42, 48], [42, 49], [42, 51], [42, 69], [42, 71], [42, 77], [42, 80], [42, 96], [42, 97], [42, 98], [42, 100], [42, 103], [42, 105], [42, 111], [42, 113], [42, 114], [42, 115], [42, 127], [42, 133], [42, 135], [43, 45], [43, 54], [43, 57], [43, 58], [43, 60], [43, 61], [43, 65], [43, 69], [43, 89], [43, 90], [43, 91], [43, 92], [43, 97], [43, 101], [43, 102], [43, 103], [43, 108], [43, 110], [43, 112], [43, 114], [43, 121], [43, 123], [43, 125], [43, 126], [43, 130], [43, 133], [43, 139], [44, 45], [44, 48], [44, 49], [44, 50], [44, 51], [44, 59], [44, 80], [44, 81], [44, 83], [44, 84], [44, 87], [44, 94], [44, 96], [44, 104], [44, 111], [44, 115], [44, 117], [44, 118], [44, 120], [44, 122], [44, 129], [44, 130], [44, 136], [44, 138], [44, 139], [45, 46], [45, 47], [45, 49], [45, 53], [45, 55], [45, 60], [45, 65], [45, 67], [45, 69], [45, 71], [45, 76], [45, 77], [45, 84], [45, 85], [45, 89], [45, 90], [45, 94], [45, 95], [45, 96], [45, 98], [45, 101], [45, 104], [45, 108], [45, 112], [45, 117], [45, 123], [45, 127], [45, 131], [45, 138], [46, 52], [46, 54], [46, 56], [46, 57], [46, 59], [46, 61], [46, 64], [46, 66], [46, 69], [46, 70], [46, 75], [46, 77], [46, 80], [46, 83], [46, 85], [46, 87], [46, 91], [46, 93], [46, 96], [46, 97], [46, 98], [46, 100], [46, 101], [46, 102], [46, 107], [46, 109], [46, 110], [46, 111], [46, 119], [46, 123], [46, 124], [46, 129], [46, 133], [46, 136], [46, 137], [46, 139], [47, 50], [47, 51], [47, 62], [47, 64], [47, 71], [47, 72], [47, 75], [47, 76], [47, 77], [47, 79], [47, 88], [47, 89], [47, 90], [47, 95], [47, 98], [47, 101], [47, 105], [47, 110], [47, 111], [47, 115], [47, 120], [47, 127], [47, 131], [47, 136], [47, 137], [47, 138], [48, 53], [48, 59], [48, 67], [48, 70], [48, 71], [48, 74], [48, 83], [48, 84], [48, 91], [48, 93], [48, 96], [48, 97], [48, 100], [48, 102], [48, 103], [48, 109], [48, 110], [48, 112], [48, 113], [48, 114], [48, 116], [48, 120], [48, 124], [48, 125], [48, 130], [48, 132], [48, 135], [48, 138], [48, 139], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 57], [49, 59], [49, 61], [49, 63], [49, 64], [49, 67], [49, 74], [49, 81], [49, 83], [49, 85], [49, 86], [49, 95], [49, 100], [49, 101], [49, 103], [49, 106], [49, 109], [49, 112], [49, 114], [49, 123], [49, 124], [49, 126], [49, 132], [49, 135], [49, 137], [50, 51], [50, 64], [50, 66], [50, 67], [50, 73], [50, 76], [50, 77], [50, 85], [50, 86], [50, 87], [50, 93], [50, 94], [50, 96], [50, 99], [50, 101], [50, 102], [50, 103], [50, 105], [50, 106], [50, 118], [50, 121], [50, 123], [50, 124], [50, 132], [50, 134], [50, 136], [50, 137], [51, 54], [51, 55], [51, 57], [51, 58], [51, 59], [51, 61], [51, 65], [51, 66], [51, 71], [51, 73], [51, 75], [51, 78], [51, 79], [51, 80], [51, 82], [51, 84], [51, 85], [51, 86], [51, 94], [51, 100], [51, 103], [51, 106], [51, 107], [51, 109], [51, 111], [51, 115], [51, 117], [51, 118], [51, 119], [51, 120], [51, 128], [51, 130], [51, 131], [51, 138], [51, 139], [52, 54], [52, 61], [52, 62], [52, 64], [52, 68], [52, 80], [52, 85], [52, 86], [52, 88], [52, 89], [52, 93], [52, 94], [52, 97], [52, 98], [52, 99], [52, 100], [52, 106], [52, 108], [52, 109], [52, 118], [52, 123], [52, 124], [52, 131], [52, 132], [52, 138], [52, 139], [53, 59], [53, 62], [53, 64], [53, 65], [53, 66], [53, 78], [53, 81], [53, 86], [53, 87], [53, 89], [53, 92], [53, 95], [53, 98], [53, 99], [53, 109], [53, 110], [53, 111], [53, 112], [53, 120], [53, 124], [53, 125], [53, 126], [53, 127], [53, 128], [53, 129], [54, 57], [54, 63], [54, 64], [54, 67], [54, 68], [54, 70], [54, 72], [54, 83], [54, 91], [54, 97], [54, 99], [54, 102], [54, 103], [54, 108], [54, 113], [54, 115], [54, 116], [54, 117], [54, 118], [54, 119], [54, 120], [54, 122], [54, 125], [54, 129], [54, 131], [54, 133], [55, 56], [55, 57], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 67], [55, 72], [55, 73], [55, 79], [55, 80], [55, 88], [55, 96], [55, 99], [55, 100], [55, 102], [55, 107], [55, 114], [55, 119], [55, 123], [55, 124], [55, 132], [55, 133], [56, 57], [56, 61], [56, 64], [56, 66], [56, 73], [56, 79], [56, 81], [56, 83], [56, 88], [56, 90], [56, 99], [56, 107], [56, 117], [56, 125], [56, 126], [56, 128], [56, 132], [56, 137], [56, 138], [57, 59], [57, 61], [57, 63], [57, 64], [57, 75], [57, 82], [57, 87], [57, 89], [57, 90], [57, 99], [57, 100], [57, 102], [57, 103], [57, 106], [57, 114], [57, 120], [57, 126], [57, 127], [57, 129], [57, 133], [58, 64], [58, 67], [58, 70], [58, 71], [58, 78], [58, 79], [58, 82], [58, 84], [58, 85], [58, 91], [58, 92], [58, 95], [58, 98], [58, 99], [58, 100], [58, 107], [58, 112], [58, 115], [58, 118], [58, 126], [58, 132], [58, 134], [58, 139], [59, 61], [59, 62], [59, 69], [59, 70], [59, 74], [59, 76], [59, 77], [59, 104], [59, 107], [59, 115], [59, 117], [59, 120], [59, 122], [59, 129], [59, 130], [59, 133], [59, 136], [59, 139], [60, 62], [60, 69], [60, 72], [60, 74], [60, 81], [60, 97], [60, 101], [60, 106], [60, 108], [60, 110], [60, 113], [60, 114], [60, 118], [60, 119], [60, 122], [60, 130], [60, 133], [61, 62], [61, 65], [61, 68], [61, 70], [61, 74], [61, 75], [61, 81], [61, 82], [61, 84], [61, 91], [61, 98], [61, 103], [61, 106], [61, 112], [61, 116], [61, 119], [61, 122], [61, 126], [61, 131], [61, 133], [61, 135], [61, 136], [61, 137], [62, 63], [62, 64], [62, 70], [62, 71], [62, 73], [62, 76], [62, 80], [62, 81], [62, 83], [62, 87], [62, 100], [62, 101], [62, 103], [62, 105], [62, 109], [62, 110], [62, 111], [62, 112], [62, 117], [62, 120], [62, 122], [62, 123], [62, 124], [62, 126], [62, 134], [62, 139], [63, 69], [63, 71], [63, 74], [63, 79], [63, 80], [63, 81], [63, 82], [63, 83], [63, 85], [63, 90], [63, 93], [63, 96], [63, 97], [63, 100], [63, 106], [63, 107], [63, 111], [63, 114], [63, 120], [63, 124], [63, 125], [63, 126], [63, 129], [63, 137], [63, 139], [64, 67], [64, 71], [64, 75], [64, 76], [64, 77], [64, 78], [64, 87], [64, 88], [64, 89], [64, 91], [64, 97], [64, 99], [64, 112], [64, 118], [64, 120], [64, 129], [64, 134], [64, 138], [64, 139], [65, 67], [65, 70], [65, 71], [65, 73], [65, 74], [65, 75], [65, 79], [65, 85], [65, 87], [65, 97], [65, 99], [65, 102], [65, 106], [65, 111], [65, 114], [65, 123], [65, 126], [65, 128], [65, 139], [66, 69], [66, 71], [66, 74], [66, 75], [66, 79], [66, 81], [66, 83], [66, 84], [66, 88], [66, 89], [66, 94], [66, 95], [66, 97], [66, 98], [66, 122], [66, 124], [66, 125], [66, 126], [67, 70], [67, 71], [67, 75], [67, 77], [67, 78], [67, 79], [67, 82], [67, 84], [67, 87], [67, 94], [67, 96], [67, 103], [67, 111], [67, 113], [67, 116], [67, 118], [67, 120], [67, 124], [67, 125], [67, 126], [67, 131], [67, 135], [68, 69], [68, 71], [68, 75], [68, 77], [68, 82], [68, 83], [68, 86], [68, 89], [68, 91], [68, 92], [68, 93], [68, 98], [68, 101], [68, 102], [68, 103], [68, 107], [68, 109], [68, 117], [68, 119], [68, 121], [68, 122], [68, 127], [68, 129], [68, 131], [68, 133], [68, 134], [68, 136], [68, 137], [68, 138], [68, 139], [69, 71], [69, 75], [69, 78], [69, 80], [69, 84], [69, 86], [69, 89], [69, 91], [69, 98], [69, 99], [69, 100], [69, 101], [69, 102], [69, 104], [69, 109], [69, 110], [69, 111], [69, 114], [69, 116], [69, 120], [69, 123], [69, 124], [69, 126], [69, 128], [69, 129], [69, 132], [69, 133], [69, 134], [69, 138], [70, 71], [70, 76], [70, 77], [70, 78], [70, 91], [70, 93], [70, 95], [70, 103], [70, 105], [70, 106], [70, 109], [70, 111], [70, 122], [70, 123], [70, 130], [70, 139], [71, 72], [71, 77], [71, 82], [71, 83], [71, 93], [71, 94], [71, 98], [71, 99], [71, 102], [71, 103], [71, 104], [71, 117], [71, 118], [71, 119], [71, 120], [71, 121], [71, 126], [71, 130], [71, 131], [71, 136], [71, 138], [72, 75], [72, 77], [72, 81], [72, 86], [72, 90], [72, 94], [72, 95], [72, 96], [72, 97], [72, 105], [72, 108], [72, 110], [72, 113], [72, 114], [72, 115], [72, 125], [72, 126], [72, 132], [72, 138], [72, 139], [73, 76], [73, 83], [73, 84], [73, 88], [73, 91], [73, 92], [73, 95], [73, 98], [73, 99], [73, 100], [73, 101], [73, 108], [73, 117], [73, 119], [73, 120], [73, 127], [73, 128], [73, 135], [73, 136], [73, 138], [73, 139], [74, 78], [74, 79], [74, 89], [74, 91], [74, 94], [74, 96], [74, 98], [74, 101], [74, 102], [74, 104], [74, 106], [74, 108], [74, 109], [74, 110], [74, 114], [74, 116], [74, 117], [74, 119], [74, 121], [74, 122], [74, 123], [74, 127], [74, 129], [74, 131], [74, 132], [74, 133], [74, 137], [74, 139], [75, 83], [75, 85], [75, 89], [75, 90], [75, 91], [75, 97], [75, 98], [75, 99], [75, 102], [75, 110], [75, 111], [75, 116], [75, 121], [75, 126], [75, 130], [75, 131], [75, 133], [75, 135], [75, 137], [75, 138], [75, 139], [76, 77], [76, 78], [76, 81], [76, 85], [76, 91], [76, 93], [76, 102], [76, 103], [76, 109], [76, 110], [76, 113], [76, 118], [76, 123], [76, 130], [76, 136], [77, 81], [77, 82], [77, 84], [77, 91], [77, 95], [77, 98], [77, 100], [77, 102], [77, 103], [77, 107], [77, 112], [77, 116], [77, 119], [77, 120], [77, 124], [77, 128], [77, 131], [77, 133], [77, 136], [77, 138], [78, 80], [78, 83], [78, 86], [78, 88], [78, 96], [78, 97], [78, 99], [78, 103], [78, 105], [78, 108], [78, 112], [78, 113], [78, 114], [78, 116], [78, 117], [78, 122], [78, 125], [78, 129], [78, 131], [78, 137], [78, 138], [79, 80], [79, 90], [79, 92], [79, 93], [79, 98], [79, 109], [79, 112], [79, 119], [79, 122], [79, 123], [79, 127], [79, 130], [79, 132], [79, 134], [80, 83], [80, 84], [80, 91], [80, 93], [80, 94], [80, 97], [80, 102], [80, 110], [80, 113], [80, 118], [80, 121], [80, 124], [80, 129], [80, 130], [80, 131], [80, 132], [81, 85], [81, 87], [81, 92], [81, 94], [81, 95], [81, 104], [81, 107], [81, 108], [81, 119], [81, 121], [81, 124], [81, 132], [81, 134], [82, 84], [82, 87], [82, 98], [82, 111], [82, 112], [82, 113], [82, 114], [82, 120], [82, 121], [82, 124], [82, 128], [82, 132], [82, 136], [83, 89], [83, 90], [83, 91], [83, 93], [83, 94], [83, 97], [83, 102], [83, 106], [83, 112], [83, 128], [83, 130], [83, 131], [83, 132], [83, 133], [83, 134], [83, 137], [84, 86], [84, 87], [84, 101], [84, 108], [84, 113], [84, 114], [84, 119], [84, 120], [84, 123], [84, 129], [84, 130], [84, 136], [84, 139], [85, 89], [85, 103], [85, 104], [85, 107], [85, 108], [85, 111], [85, 114], [85, 118], [85, 119], [85, 120], [85, 127], [85, 132], [85, 138], [85, 139], [86, 87], [86, 90], [86, 91], [86, 96], [86, 99], [86, 102], [86, 108], [86, 110], [86, 112], [86, 119], [86, 120], [86, 122], [86, 123], [86, 126], [86, 133], [86, 136], [87, 88], [87, 90], [87, 91], [87, 96], [87, 100], [87, 102], [87, 107], [87, 108], [87, 115], [87, 120], [87, 121], [87, 122], [87, 123], [87, 126], [87, 137], [87, 138], [88, 91], [88, 93], [88, 96], [88, 100], [88, 101], [88, 104], [88, 106], [88, 109], [88, 110], [88, 114], [88, 116], [88, 118], [88, 120], [88, 123], [88, 129], [88, 134], [88, 139], [89, 90], [89, 91], [89, 93], [89, 96], [89, 100], [89, 101], [89, 103], [89, 104], [89, 107], [89, 112], [89, 116], [89, 118], [89, 121], [89, 129], [89, 130], [89, 132], [89, 135], [90, 93], [90, 97], [90, 98], [90, 104], [90, 107], [90, 108], [90, 112], [90, 116], [90, 117], [90, 121], [90, 123], [90, 127], [90, 130], [90, 133], [90, 134], [91, 98], [91, 104], [91, 105], [91, 107], [91, 112], [91, 113], [91, 121], [91, 123], [91, 125], [91, 126], [91, 131], [91, 132], [91, 133], [91, 136], [91, 138], [92, 98], [92, 101], [92, 102], [92, 103], [92, 104], [92, 109], [92, 113], [92, 118], [92, 120], [92, 121], [92, 122], [92, 126], [92, 130], [92, 135], [92, 137], [93, 96], [93, 97], [93, 99], [93, 102], [93, 103], [93, 106], [93, 111], [93, 123], [93, 124], [93, 130], [93, 134], [93, 135], [94, 101], [94, 102], [94, 103], [94, 107], [94, 113], [94, 118], [94, 125], [94, 132], [94, 133], [94, 138], [94, 139], [95, 96], [95, 97], [95, 104], [95, 107], [95, 108], [95, 113], [95, 115], [95, 120], [95, 123], [95, 124], [95, 126], [95, 127], [95, 128], [95, 130], [95, 133], [95, 134], [95, 138], [96, 99], [96, 100], [96, 103], [96, 105], [96, 106], [96, 109], [96, 110], [96, 117], [96, 125], [96, 127], [96, 132], [97, 98], [97, 103], [97, 109], [97, 118], [97, 119], [97, 120], [97, 125], [98, 101], [98, 107], [98, 108], [98, 110], [98, 111], [98, 112], [98, 115], [98, 119], [98, 125], [98, 126], [98, 127], [98, 130], [98, 132], [98, 134], [98, 138], [98, 139], [99, 103], [99, 105], [99, 108], [99, 111], [99, 122], [99, 125], [99, 126], [99, 127], [99, 129], [99, 131], [99, 136], [99, 138], [100, 101], [100, 102], [100, 115], [100, 127], [100, 131], [100, 132], [100, 133], [100, 139], [101, 103], [101, 104], [101, 106], [101, 107], [101, 110], [101, 112], [101, 113], [101, 115], [101, 122], [101, 137], [102, 104], [102, 106], [102, 113], [102, 116], [102, 122], [102, 125], [102, 131], [102, 134], [102, 135], [102, 136], [103, 106], [103, 113], [103, 114], [103, 115], [103, 118], [103, 119], [103, 126], [103, 129], [103, 133], [103, 134], [103, 137], [104, 105], [104, 106], [104, 108], [104, 111], [104, 115], [104, 116], [104, 121], [104, 126], [104, 127], [104, 129], [104, 130], [104, 131], [104, 133], [104, 139], [105, 108], [105, 113], [105, 123], [105, 127], [105, 130], [105, 131], [105, 132], [105, 136], [105, 137], [105, 138], [105, 139], [106, 116], [106, 119], [106, 120], [106, 123], [106, 124], [106, 125], [106, 126], [106, 129], [106, 130], [106, 132], [106, 133], [106, 139], [107, 112], [107, 115], [107, 119], [107, 124], [107, 128], [107, 129], [107, 134], [107, 136], [107, 137], [108, 110], [108, 112], [108, 124], [108, 127], [108, 128], [108, 136], [108, 138], [109, 111], [109, 113], [109, 115], [109, 118], [109, 120], [109, 125], [109, 126], [109, 128], [109, 129], [109, 130], [109, 133], [109, 134], [110, 115], [110, 122], [110, 132], [110, 137], [110, 139], [111, 112], [111, 113], [111, 119], [111, 121], [111, 122], [111, 125], [111, 131], [111, 134], [112, 114], [112, 117], [112, 122], [112, 123], [112, 125], [112, 130], [112, 132], [112, 134], [112, 136], [112, 139], [113, 114], [113, 115], [113, 118], [113, 119], [113, 127], [113, 128], [113, 129], [113, 131], [113, 135], [113, 138], [113, 139], [114, 118], [114, 123], [114, 124], [114, 131], [114, 134], [115, 116], [115, 121], [115, 126], [115, 129], [115, 132], [115, 135], [115, 136], [115, 137], [115, 138], [115, 139], [116, 117], [116, 121], [116, 122], [116, 124], [116, 126], [116, 127], [116, 130], [116, 133], [116, 137], [117, 119], [117, 120], [117, 132], [117, 133], [117, 136], [117, 137], [118, 121], [118, 123], [118, 124], [118, 131], [118, 134], [118, 137], [119, 120], [119, 121], [119, 125], [119, 130], [119, 133], [119, 134], [119, 136], [119, 137], [119, 138], [120, 126], [120, 127], [120, 128], [120, 129], [120, 135], [120, 138], [121, 124], [121, 126], [121, 135], [121, 136], [121, 139], [122, 123], [122, 124], [122, 127], [122, 134], [123, 125], [123, 129], [123, 133], [124, 125], [124, 126], [124, 127], [124, 130], [124, 134], [124, 135], [124, 136], [124, 139], [125, 127], [125, 129], [125, 131], [125, 133], [125, 134], [125, 139], [126, 134], [127, 130], [127, 131], [127, 135], [127, 137], [128, 129], [128, 130], [128, 131], [128, 135], [128, 138], [128, 139], [129, 136], [129, 138], [130, 132], [130, 134], [130, 137], [131, 132], [131, 133], [131, 137], [131, 138], [133, 136], [134, 137], [135, 138], [135, 139], [136, 139]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s0/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s0/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s7/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s7/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b7ae7baec0548d12a72fbbea5bed8b8c7d5829f --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 5], [0, 9], [0, 14], [0, 16], [0, 21], [0, 29], [0, 34], [0, 37], [0, 46], [0, 47], [0, 54], [0, 56], [0, 61], [0, 68], [0, 70], [0, 71], [0, 75], [0, 77], [0, 79], [0, 86], [0, 90], [0, 96], [0, 104], [0, 108], [0, 109], [0, 124], [0, 125], [0, 126], [0, 127], [0, 129], [0, 131], [0, 133], [0, 137], [1, 2], [1, 6], [1, 7], [1, 11], [1, 12], [1, 14], [1, 17], [1, 20], [1, 23], [1, 24], [1, 27], [1, 32], [1, 33], [1, 34], [1, 38], [1, 47], [1, 50], [1, 51], [1, 53], [1, 55], [1, 69], [1, 72], [1, 77], [1, 78], [1, 79], [1, 82], [1, 86], [1, 87], [1, 90], [1, 91], [1, 96], [1, 98], [1, 99], [1, 113], [1, 114], [1, 117], [1, 120], [1, 122], [1, 128], [2, 6], [2, 7], [2, 9], [2, 11], [2, 12], [2, 13], [2, 16], [2, 24], [2, 32], [2, 43], [2, 44], [2, 48], [2, 49], [2, 50], [2, 51], [2, 54], [2, 56], [2, 65], [2, 66], [2, 69], [2, 75], [2, 80], [2, 83], [2, 85], [2, 89], [2, 90], [2, 98], [2, 99], [2, 107], [2, 111], [2, 112], [2, 122], [2, 125], [2, 127], [2, 131], [2, 134], [2, 135], [2, 136], [2, 139], [3, 4], [3, 5], [3, 8], [3, 11], [3, 12], [3, 13], [3, 22], [3, 29], [3, 32], [3, 36], [3, 49], [3, 52], [3, 56], [3, 61], [3, 69], [3, 70], [3, 75], [3, 77], [3, 79], [3, 84], [3, 86], [3, 91], [3, 97], [3, 99], [3, 101], [3, 106], [3, 107], [3, 112], [3, 113], [3, 116], [3, 124], [3, 126], [3, 127], [3, 131], [3, 133], [3, 136], [3, 138], [3, 139], [4, 9], [4, 10], [4, 12], [4, 22], [4, 23], [4, 28], [4, 42], [4, 45], [4, 48], [4, 53], [4, 54], [4, 60], [4, 61], [4, 69], [4, 72], [4, 73], [4, 74], [4, 76], [4, 77], [4, 78], [4, 79], [4, 80], [4, 87], [4, 88], [4, 89], [4, 93], [4, 97], [4, 98], [4, 102], [4, 106], [4, 120], [4, 124], [4, 125], [4, 133], [4, 134], [4, 139], [5, 8], [5, 12], [5, 14], [5, 17], [5, 21], [5, 24], [5, 28], [5, 29], [5, 30], [5, 32], [5, 37], [5, 39], [5, 41], [5, 45], [5, 47], [5, 48], [5, 59], [5, 60], [5, 68], [5, 73], [5, 75], [5, 76], [5, 82], [5, 93], [5, 94], [5, 95], [5, 99], [5, 101], [5, 102], [5, 106], [5, 110], [5, 114], [5, 115], [5, 118], [5, 122], [5, 123], [5, 125], [5, 127], [5, 132], [5, 137], [6, 7], [6, 12], [6, 14], [6, 15], [6, 16], [6, 18], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 28], [6, 29], [6, 31], [6, 35], [6, 40], [6, 41], [6, 43], [6, 47], [6, 48], [6, 49], [6, 50], [6, 52], [6, 53], [6, 55], [6, 57], [6, 59], [6, 61], [6, 66], [6, 67], [6, 68], [6, 70], [6, 75], [6, 78], [6, 79], [6, 80], [6, 81], [6, 82], [6, 83], [6, 95], [6, 96], [6, 105], [6, 108], [6, 113], [6, 119], [6, 121], [6, 129], [6, 136], [6, 138], [7, 11], [7, 12], [7, 18], [7, 23], [7, 24], [7, 25], [7, 31], [7, 33], [7, 42], [7, 47], [7, 51], [7, 55], [7, 56], [7, 58], [7, 59], [7, 61], [7, 72], [7, 73], [7, 74], [7, 76], [7, 79], [7, 86], [7, 88], [7, 91], [7, 93], [7, 96], [7, 111], [7, 112], [7, 115], [7, 117], [7, 125], [7, 130], [7, 132], [7, 133], [7, 135], [7, 138], [8, 10], [8, 15], [8, 18], [8, 19], [8, 24], [8, 25], [8, 28], [8, 29], [8, 31], [8, 32], [8, 36], [8, 39], [8, 41], [8, 42], [8, 55], [8, 56], [8, 58], [8, 59], [8, 60], [8, 61], [8, 64], [8, 68], [8, 69], [8, 71], [8, 76], [8, 81], [8, 84], [8, 85], [8, 90], [8, 92], [8, 100], [8, 101], [8, 104], [8, 105], [8, 106], [8, 110], [8, 111], [8, 112], [8, 115], [8, 118], [8, 119], [8, 121], [8, 122], [8, 123], [8, 125], [8, 126], [8, 131], [8, 132], [8, 134], [8, 137], [8, 138], [9, 11], [9, 13], [9, 15], [9, 16], [9, 20], [9, 28], [9, 31], [9, 33], [9, 35], [9, 36], [9, 37], [9, 40], [9, 41], [9, 43], [9, 48], [9, 49], [9, 50], [9, 54], [9, 57], [9, 58], [9, 61], [9, 62], [9, 67], [9, 69], [9, 70], [9, 79], [9, 80], [9, 91], [9, 104], [9, 106], [9, 110], [9, 113], [9, 135], [9, 138], [9, 139], [10, 33], [10, 36], [10, 42], [10, 44], [10, 48], [10, 54], [10, 55], [10, 56], [10, 60], [10, 61], [10, 72], [10, 73], [10, 74], [10, 75], [10, 76], [10, 78], [10, 80], [10, 81], [10, 83], [10, 89], [10, 94], [10, 97], [10, 102], [10, 105], [10, 108], [10, 112], [10, 115], [10, 116], [10, 126], [10, 134], [10, 135], [10, 136], [11, 12], [11, 14], [11, 16], [11, 17], [11, 18], [11, 26], [11, 27], [11, 32], [11, 34], [11, 35], [11, 41], [11, 42], [11, 44], [11, 49], [11, 53], [11, 54], [11, 55], [11, 60], [11, 63], [11, 74], [11, 75], [11, 85], [11, 94], [11, 95], [11, 97], [11, 102], [11, 109], [11, 117], [11, 118], [11, 119], [11, 122], [11, 123], [11, 125], [11, 134], [11, 139], [12, 24], [12, 29], [12, 39], [12, 43], [12, 45], [12, 54], [12, 55], [12, 56], [12, 58], [12, 59], [12, 62], [12, 63], [12, 64], [12, 67], [12, 72], [12, 74], [12, 76], [12, 77], [12, 78], [12, 84], [12, 88], [12, 90], [12, 96], [12, 100], [12, 104], [12, 106], [12, 109], [12, 114], [12, 118], [12, 124], [12, 130], [12, 131], [12, 133], [12, 135], [12, 137], [12, 139], [13, 14], [13, 18], [13, 20], [13, 24], [13, 25], [13, 29], [13, 30], [13, 31], [13, 33], [13, 43], [13, 45], [13, 50], [13, 57], [13, 58], [13, 62], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 75], [13, 76], [13, 82], [13, 83], [13, 84], [13, 89], [13, 92], [13, 98], [13, 100], [13, 101], [13, 104], [13, 111], [13, 114], [13, 116], [13, 118], [13, 121], [13, 131], [13, 137], [13, 138], [13, 139], [14, 15], [14, 16], [14, 19], [14, 21], [14, 24], [14, 29], [14, 31], [14, 33], [14, 34], [14, 38], [14, 39], [14, 45], [14, 46], [14, 47], [14, 48], [14, 52], [14, 54], [14, 55], [14, 60], [14, 63], [14, 68], [14, 72], [14, 75], [14, 78], [14, 80], [14, 84], [14, 85], [14, 86], [14, 88], [14, 97], [14, 99], [14, 101], [14, 102], [14, 103], [14, 104], [14, 109], [14, 110], [14, 111], [14, 126], [14, 129], [14, 132], [14, 136], [15, 17], [15, 19], [15, 20], [15, 22], [15, 23], [15, 27], [15, 28], [15, 35], [15, 38], [15, 39], [15, 42], [15, 43], [15, 44], [15, 51], [15, 52], [15, 57], [15, 59], [15, 63], [15, 64], [15, 66], [15, 71], [15, 75], [15, 79], [15, 80], [15, 81], [15, 82], [15, 90], [15, 92], [15, 93], [15, 94], [15, 98], [15, 103], [15, 104], [15, 107], [15, 108], [15, 115], [15, 119], [15, 121], [15, 124], [15, 125], [15, 126], [15, 127], [15, 134], [16, 17], [16, 19], [16, 20], [16, 23], [16, 28], [16, 29], [16, 31], [16, 33], [16, 35], [16, 37], [16, 38], [16, 41], [16, 51], [16, 54], [16, 56], [16, 57], [16, 59], [16, 63], [16, 66], [16, 73], [16, 74], [16, 78], [16, 81], [16, 87], [16, 91], [16, 101], [16, 107], [16, 108], [16, 114], [16, 115], [16, 116], [16, 117], [16, 118], [16, 124], [16, 131], [16, 133], [16, 134], [17, 18], [17, 20], [17, 24], [17, 25], [17, 28], [17, 30], [17, 33], [17, 35], [17, 38], [17, 39], [17, 46], [17, 54], [17, 55], [17, 69], [17, 74], [17, 77], [17, 80], [17, 81], [17, 85], [17, 88], [17, 89], [17, 91], [17, 94], [17, 97], [17, 103], [17, 107], [17, 108], [17, 109], [17, 118], [17, 123], [17, 124], [17, 132], [17, 137], [17, 138], [18, 20], [18, 24], [18, 26], [18, 27], [18, 31], [18, 36], [18, 51], [18, 52], [18, 58], [18, 59], [18, 63], [18, 64], [18, 76], [18, 77], [18, 79], [18, 84], [18, 88], [18, 96], [18, 99], [18, 100], [18, 102], [18, 107], [18, 108], [18, 109], [18, 116], [18, 118], [18, 122], [18, 125], [18, 126], [18, 130], [18, 138], [19, 20], [19, 21], [19, 24], [19, 36], [19, 41], [19, 42], [19, 43], [19, 44], [19, 46], [19, 47], [19, 48], [19, 53], [19, 54], [19, 56], [19, 58], [19, 64], [19, 70], [19, 71], [19, 72], [19, 86], [19, 87], [19, 89], [19, 90], [19, 92], [19, 97], [19, 101], [19, 102], [19, 104], [19, 108], [19, 109], [19, 110], [19, 115], [19, 116], [19, 117], [19, 118], [19, 120], [19, 127], [19, 128], [19, 129], [19, 133], [19, 137], [19, 139], [20, 21], [20, 24], [20, 26], [20, 30], [20, 35], [20, 45], [20, 51], [20, 56], [20, 57], [20, 60], [20, 61], [20, 63], [20, 65], [20, 71], [20, 72], [20, 80], [20, 85], [20, 94], [20, 102], [20, 113], [20, 115], [20, 118], [20, 123], [20, 125], [20, 135], [21, 22], [21, 23], [21, 30], [21, 37], [21, 38], [21, 40], [21, 43], [21, 45], [21, 47], [21, 58], [21, 59], [21, 63], [21, 64], [21, 65], [21, 71], [21, 73], [21, 75], [21, 77], [21, 81], [21, 84], [21, 85], [21, 87], [21, 98], [21, 101], [21, 105], [21, 107], [21, 117], [21, 119], [21, 121], [21, 124], [21, 128], [21, 130], [21, 133], [21, 135], [21, 136], [21, 137], [21, 138], [22, 26], [22, 33], [22, 39], [22, 46], [22, 56], [22, 59], [22, 62], [22, 63], [22, 64], [22, 65], [22, 66], [22, 67], [22, 69], [22, 70], [22, 71], [22, 72], [22, 77], [22, 78], [22, 79], [22, 80], [22, 82], [22, 83], [22, 84], [22, 87], [22, 88], [22, 90], [22, 92], [22, 93], [22, 95], [22, 98], [22, 99], [22, 101], [22, 102], [22, 106], [22, 111], [22, 113], [22, 114], [22, 120], [22, 122], [22, 124], [22, 131], [22, 132], [22, 134], [22, 136], [23, 27], [23, 30], [23, 31], [23, 35], [23, 38], [23, 39], [23, 42], [23, 44], [23, 61], [23, 65], [23, 66], [23, 68], [23, 71], [23, 73], [23, 74], [23, 80], [23, 87], [23, 88], [23, 89], [23, 90], [23, 91], [23, 97], [23, 99], [23, 104], [23, 106], [23, 108], [23, 111], [23, 114], [23, 116], [23, 117], [23, 120], [23, 130], [23, 131], [23, 133], [23, 135], [23, 136], [24, 26], [24, 33], [24, 35], [24, 39], [24, 56], [24, 57], [24, 58], [24, 61], [24, 62], [24, 71], [24, 72], [24, 79], [24, 80], [24, 86], [24, 88], [24, 91], [24, 93], [24, 96], [24, 98], [24, 104], [24, 105], [24, 106], [24, 108], [24, 109], [24, 110], [24, 120], [24, 122], [24, 124], [24, 125], [24, 132], [24, 133], [24, 139], [25, 28], [25, 34], [25, 45], [25, 46], [25, 58], [25, 63], [25, 68], [25, 72], [25, 74], [25, 80], [25, 81], [25, 82], [25, 88], [25, 89], [25, 90], [25, 91], [25, 95], [25, 96], [25, 106], [25, 108], [25, 111], [25, 115], [25, 116], [25, 118], [25, 131], [25, 135], [25, 138], [26, 29], [26, 32], [26, 40], [26, 42], [26, 46], [26, 48], [26, 49], [26, 50], [26, 53], [26, 59], [26, 61], [26, 64], [26, 67], [26, 68], [26, 69], [26, 71], [26, 72], [26, 75], [26, 76], [26, 78], [26, 81], [26, 85], [26, 86], [26, 90], [26, 92], [26, 93], [26, 98], [26, 99], [26, 104], [26, 105], [26, 106], [26, 107], [26, 111], [26, 120], [26, 121], [26, 124], [26, 126], [26, 136], [27, 32], [27, 39], [27, 40], [27, 41], [27, 47], [27, 48], [27, 49], [27, 54], [27, 55], [27, 57], [27, 64], [27, 66], [27, 67], [27, 69], [27, 74], [27, 76], [27, 80], [27, 100], [27, 101], [27, 102], [27, 103], [27, 104], [27, 107], [27, 108], [27, 110], [27, 111], [27, 129], [27, 130], [27, 135], [28, 30], [28, 36], [28, 39], [28, 46], [28, 50], [28, 53], [28, 60], [28, 62], [28, 63], [28, 67], [28, 70], [28, 72], [28, 75], [28, 79], [28, 81], [28, 84], [28, 86], [28, 87], [28, 89], [28, 91], [28, 94], [28, 95], [28, 99], [28, 105], [28, 108], [28, 115], [28, 119], [28, 128], [28, 131], [28, 133], [28, 134], [28, 138], [28, 139], [29, 53], [29, 55], [29, 64], [29, 68], [29, 72], [29, 73], [29, 75], [29, 77], [29, 78], [29, 79], [29, 86], [29, 92], [29, 94], [29, 98], [29, 103], [29, 111], [29, 115], [29, 118], [29, 129], [29, 133], [29, 134], [29, 136], [29, 139], [30, 34], [30, 36], [30, 37], [30, 40], [30, 48], [30, 49], [30, 51], [30, 61], [30, 66], [30, 70], [30, 72], [30, 73], [30, 75], [30, 77], [30, 79], [30, 84], [30, 86], [30, 91], [30, 92], [30, 97], [30, 98], [30, 100], [30, 113], [30, 114], [30, 118], [30, 121], [30, 126], [30, 135], [30, 137], [30, 139], [31, 34], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 50], [31, 52], [31, 55], [31, 57], [31, 58], [31, 59], [31, 62], [31, 65], [31, 68], [31, 70], [31, 76], [31, 77], [31, 82], [31, 89], [31, 98], [31, 100], [31, 101], [31, 104], [31, 113], [31, 118], [32, 33], [32, 34], [32, 38], [32, 43], [32, 47], [32, 51], [32, 58], [32, 59], [32, 61], [32, 62], [32, 63], [32, 66], [32, 70], [32, 85], [32, 87], [32, 93], [32, 95], [32, 101], [32, 108], [32, 113], [32, 118], [32, 120], [32, 121], [32, 124], [32, 125], [32, 130], [32, 132], [32, 136], [32, 138], [33, 36], [33, 38], [33, 39], [33, 51], [33, 60], [33, 62], [33, 63], [33, 65], [33, 69], [33, 71], [33, 78], [33, 81], [33, 92], [33, 94], [33, 96], [33, 100], [33, 103], [33, 104], [33, 105], [33, 109], [33, 112], [33, 114], [33, 115], [33, 123], [33, 125], [33, 131], [34, 36], [34, 38], [34, 39], [34, 40], [34, 41], [34, 44], [34, 51], [34, 60], [34, 61], [34, 63], [34, 66], [34, 70], [34, 73], [34, 78], [34, 90], [34, 92], [34, 95], [34, 98], [34, 99], [34, 102], [34, 116], [34, 118], [34, 119], [34, 120], [34, 121], [34, 122], [34, 123], [34, 129], [34, 132], [34, 133], [34, 135], [34, 136], [34, 137], [35, 39], [35, 40], [35, 41], [35, 45], [35, 53], [35, 63], [35, 66], [35, 69], [35, 70], [35, 76], [35, 78], [35, 79], [35, 82], [35, 90], [35, 95], [35, 97], [35, 98], [35, 102], [35, 105], [35, 108], [35, 117], [35, 118], [35, 120], [35, 124], [35, 125], [35, 126], [35, 131], [35, 137], [36, 37], [36, 39], [36, 43], [36, 44], [36, 46], [36, 53], [36, 57], [36, 64], [36, 67], [36, 71], [36, 72], [36, 76], [36, 77], [36, 78], [36, 80], [36, 83], [36, 86], [36, 89], [36, 100], [36, 102], [36, 103], [36, 105], [36, 107], [36, 109], [36, 115], [36, 122], [36, 125], [36, 126], [36, 127], [36, 130], [36, 138], [36, 139], [37, 38], [37, 39], [37, 41], [37, 42], [37, 48], [37, 52], [37, 54], [37, 56], [37, 61], [37, 62], [37, 66], [37, 73], [37, 83], [37, 88], [37, 89], [37, 90], [37, 91], [37, 93], [37, 96], [37, 97], [37, 100], [37, 103], [37, 106], [37, 111], [37, 120], [37, 121], [37, 123], [37, 124], [37, 126], [37, 136], [37, 139], [38, 39], [38, 40], [38, 43], [38, 45], [38, 47], [38, 48], [38, 57], [38, 59], [38, 63], [38, 67], [38, 76], [38, 82], [38, 88], [38, 89], [38, 92], [38, 95], [38, 99], [38, 102], [38, 103], [38, 104], [38, 106], [38, 108], [38, 110], [38, 111], [38, 113], [38, 114], [38, 117], [38, 119], [38, 126], [38, 129], [38, 132], [38, 139], [39, 40], [39, 43], [39, 46], [39, 47], [39, 49], [39, 50], [39, 52], [39, 53], [39, 54], [39, 55], [39, 56], [39, 59], [39, 60], [39, 62], [39, 63], [39, 75], [39, 81], [39, 83], [39, 89], [39, 92], [39, 94], [39, 105], [39, 108], [39, 113], [39, 117], [39, 119], [39, 123], [39, 124], [39, 125], [39, 127], [39, 130], [39, 135], [39, 138], [40, 42], [40, 43], [40, 49], [40, 52], [40, 54], [40, 57], [40, 58], [40, 62], [40, 64], [40, 68], [40, 78], [40, 80], [40, 82], [40, 86], [40, 87], [40, 97], [40, 99], [40, 102], [40, 108], [40, 110], [40, 114], [40, 117], [40, 121], [40, 122], [40, 123], [40, 124], [40, 128], [40, 129], [40, 130], [40, 132], [40, 133], [40, 136], [40, 137], [41, 42], [41, 43], [41, 45], [41, 46], [41, 50], [41, 51], [41, 56], [41, 57], [41, 59], [41, 62], [41, 64], [41, 65], [41, 67], [41, 68], [41, 71], [41, 78], [41, 79], [41, 87], [41, 91], [41, 96], [41, 99], [41, 101], [41, 106], [41, 110], [41, 122], [41, 127], [41, 128], [41, 130], [41, 133], [41, 135], [41, 138], [41, 139], [42, 47], [42, 49], [42, 51], [42, 57], [42, 58], [42, 59], [42, 61], [42, 66], [42, 73], [42, 75], [42, 76], [42, 77], [42, 78], [42, 79], [42, 84], [42, 85], [42, 86], [42, 88], [42, 92], [42, 93], [42, 96], [42, 99], [42, 107], [42, 120], [42, 123], [42, 127], [42, 137], [42, 138], [43, 49], [43, 52], [43, 53], [43, 55], [43, 56], [43, 57], [43, 58], [43, 61], [43, 66], [43, 69], [43, 73], [43, 85], [43, 86], [43, 87], [43, 88], [43, 90], [43, 100], [43, 101], [43, 107], [43, 109], [43, 111], [43, 114], [43, 115], [43, 117], [43, 118], [43, 124], [43, 127], [43, 132], [43, 137], [43, 138], [43, 139], [44, 47], [44, 49], [44, 55], [44, 57], [44, 58], [44, 71], [44, 73], [44, 76], [44, 77], [44, 78], [44, 87], [44, 90], [44, 91], [44, 92], [44, 93], [44, 96], [44, 99], [44, 102], [44, 104], [44, 111], [44, 112], [44, 114], [44, 115], [44, 116], [44, 119], [44, 120], [44, 122], [44, 125], [44, 128], [44, 129], [44, 130], [44, 133], [44, 138], [45, 49], [45, 55], [45, 59], [45, 60], [45, 64], [45, 65], [45, 68], [45, 76], [45, 77], [45, 78], [45, 85], [45, 89], [45, 90], [45, 95], [45, 99], [45, 102], [45, 104], [45, 108], [45, 111], [45, 118], [45, 119], [45, 124], [45, 125], [45, 128], [45, 129], [45, 132], [45, 134], [45, 139], [46, 47], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 57], [46, 58], [46, 61], [46, 68], [46, 77], [46, 80], [46, 84], [46, 85], [46, 88], [46, 91], [46, 92], [46, 97], [46, 100], [46, 102], [46, 108], [46, 111], [46, 112], [46, 114], [46, 115], [46, 118], [46, 134], [46, 136], [46, 138], [47, 50], [47, 51], [47, 52], [47, 54], [47, 56], [47, 57], [47, 58], [47, 63], [47, 68], [47, 69], [47, 70], [47, 76], [47, 77], [47, 78], [47, 79], [47, 82], [47, 83], [47, 84], [47, 87], [47, 89], [47, 92], [47, 97], [47, 100], [47, 102], [47, 105], [47, 106], [47, 108], [47, 109], [47, 110], [47, 111], [47, 112], [47, 114], [47, 116], [47, 119], [47, 121], [47, 126], [47, 127], [47, 128], [47, 129], [47, 137], [48, 59], [48, 63], [48, 64], [48, 65], [48, 67], [48, 71], [48, 75], [48, 80], [48, 83], [48, 91], [48, 93], [48, 96], [48, 97], [48, 103], [48, 106], [48, 113], [48, 116], [48, 118], [48, 123], [48, 126], [48, 135], [48, 136], [48, 137], [49, 51], [49, 53], [49, 62], [49, 65], [49, 66], [49, 70], [49, 77], [49, 80], [49, 82], [49, 83], [49, 84], [49, 92], [49, 93], [49, 100], [49, 101], [49, 102], [49, 103], [49, 108], [49, 112], [49, 118], [49, 119], [49, 121], [49, 123], [49, 124], [49, 126], [49, 127], [49, 128], [49, 132], [49, 133], [49, 136], [49, 139], [50, 51], [50, 52], [50, 53], [50, 56], [50, 60], [50, 61], [50, 62], [50, 67], [50, 73], [50, 79], [50, 82], [50, 85], [50, 86], [50, 88], [50, 91], [50, 94], [50, 96], [50, 97], [50, 102], [50, 107], [50, 114], [50, 116], [50, 121], [50, 126], [50, 128], [50, 131], [50, 132], [50, 133], [51, 53], [51, 63], [51, 66], [51, 67], [51, 72], [51, 80], [51, 83], [51, 85], [51, 87], [51, 91], [51, 97], [51, 113], [51, 114], [51, 128], [51, 131], [51, 134], [52, 57], [52, 58], [52, 59], [52, 61], [52, 68], [52, 72], [52, 73], [52, 74], [52, 83], [52, 89], [52, 91], [52, 97], [52, 98], [52, 101], [52, 104], [52, 108], [52, 111], [52, 118], [52, 122], [52, 125], [52, 131], [52, 134], [52, 137], [52, 139], [53, 57], [53, 58], [53, 59], [53, 60], [53, 63], [53, 64], [53, 69], [53, 71], [53, 82], [53, 92], [53, 99], [53, 101], [53, 103], [53, 111], [53, 117], [53, 119], [53, 122], [53, 125], [53, 127], [53, 129], [53, 132], [53, 133], [53, 134], [54, 59], [54, 60], [54, 62], [54, 63], [54, 66], [54, 67], [54, 68], [54, 72], [54, 74], [54, 78], [54, 80], [54, 81], [54, 82], [54, 86], [54, 87], [54, 89], [54, 90], [54, 92], [54, 96], [54, 100], [54, 103], [54, 105], [54, 107], [54, 108], [54, 109], [54, 112], [54, 113], [54, 120], [54, 122], [54, 127], [54, 129], [54, 131], [54, 135], [55, 57], [55, 61], [55, 64], [55, 66], [55, 70], [55, 72], [55, 73], [55, 74], [55, 83], [55, 84], [55, 85], [55, 86], [55, 88], [55, 94], [55, 95], [55, 101], [55, 102], [55, 105], [55, 106], [55, 107], [55, 110], [55, 115], [55, 118], [55, 119], [55, 126], [55, 131], [56, 57], [56, 58], [56, 65], [56, 74], [56, 80], [56, 85], [56, 86], [56, 88], [56, 90], [56, 93], [56, 100], [56, 105], [56, 108], [56, 109], [56, 115], [56, 123], [56, 126], [56, 127], [56, 131], [56, 135], [56, 137], [56, 138], [57, 60], [57, 65], [57, 69], [57, 73], [57, 77], [57, 78], [57, 81], [57, 83], [57, 87], [57, 88], [57, 90], [57, 94], [57, 96], [57, 97], [57, 98], [57, 101], [57, 102], [57, 104], [57, 106], [57, 110], [57, 111], [57, 113], [57, 115], [57, 121], [57, 125], [57, 126], [57, 130], [57, 132], [57, 139], [58, 59], [58, 62], [58, 64], [58, 67], [58, 72], [58, 75], [58, 78], [58, 80], [58, 81], [58, 86], [58, 89], [58, 95], [58, 96], [58, 97], [58, 101], [58, 103], [58, 107], [58, 111], [58, 126], [58, 127], [59, 63], [59, 66], [59, 82], [59, 87], [59, 90], [59, 92], [59, 93], [59, 96], [59, 101], [59, 102], [59, 103], [59, 112], [59, 114], [59, 119], [59, 123], [59, 134], [59, 137], [60, 69], [60, 74], [60, 76], [60, 85], [60, 86], [60, 87], [60, 88], [60, 89], [60, 94], [60, 97], [60, 98], [60, 100], [60, 101], [60, 102], [60, 103], [60, 104], [60, 105], [60, 106], [60, 109], [60, 111], [60, 113], [60, 117], [60, 120], [60, 121], [60, 126], [60, 127], [60, 133], [60, 135], [61, 62], [61, 63], [61, 64], [61, 66], [61, 67], [61, 70], [61, 71], [61, 74], [61, 81], [61, 82], [61, 85], [61, 86], [61, 89], [61, 94], [61, 101], [61, 103], [61, 109], [61, 121], [61, 131], [61, 133], [61, 137], [62, 63], [62, 66], [62, 72], [62, 75], [62, 77], [62, 80], [62, 84], [62, 87], [62, 88], [62, 89], [62, 91], [62, 93], [62, 98], [62, 100], [62, 101], [62, 102], [62, 109], [62, 110], [62, 116], [62, 117], [62, 118], [62, 127], [62, 130], [62, 132], [63, 64], [63, 68], [63, 77], [63, 81], [63, 89], [63, 91], [63, 95], [63, 96], [63, 99], [63, 100], [63, 104], [63, 105], [63, 108], [63, 112], [63, 116], [63, 120], [63, 122], [63, 128], [63, 129], [63, 132], [63, 135], [63, 137], [64, 66], [64, 72], [64, 81], [64, 83], [64, 85], [64, 88], [64, 90], [64, 91], [64, 92], [64, 94], [64, 95], [64, 97], [64, 101], [64, 103], [64, 104], [64, 107], [64, 110], [64, 111], [64, 116], [64, 117], [64, 119], [64, 123], [64, 128], [64, 133], [64, 134], [64, 135], [65, 67], [65, 69], [65, 72], [65, 75], [65, 79], [65, 81], [65, 86], [65, 89], [65, 90], [65, 97], [65, 106], [65, 107], [65, 113], [65, 116], [65, 117], [65, 128], [65, 131], [65, 132], [65, 134], [65, 135], [65, 139], [66, 72], [66, 76], [66, 83], [66, 84], [66, 85], [66, 86], [66, 93], [66, 94], [66, 105], [66, 117], [66, 119], [66, 122], [66, 139], [67, 68], [67, 71], [67, 72], [67, 76], [67, 78], [67, 83], [67, 85], [67, 89], [67, 93], [67, 95], [67, 101], [67, 104], [67, 109], [67, 113], [67, 116], [67, 118], [67, 123], [67, 128], [67, 133], [67, 136], [68, 69], [68, 74], [68, 75], [68, 82], [68, 83], [68, 85], [68, 87], [68, 90], [68, 94], [68, 103], [68, 105], [68, 106], [68, 107], [68, 109], [68, 111], [68, 115], [68, 116], [68, 117], [68, 123], [68, 124], [68, 128], [68, 129], [68, 133], [68, 139], [69, 70], [69, 79], [69, 81], [69, 83], [69, 86], [69, 89], [69, 92], [69, 93], [69, 95], [69, 98], [69, 106], [69, 120], [69, 128], [69, 129], [69, 130], [70, 72], [70, 75], [70, 79], [70, 88], [70, 91], [70, 92], [70, 95], [70, 97], [70, 99], [70, 102], [70, 105], [70, 106], [70, 107], [70, 108], [70, 110], [70, 114], [70, 119], [70, 120], [70, 122], [70, 132], [70, 133], [70, 137], [71, 77], [71, 78], [71, 79], [71, 80], [71, 81], [71, 82], [71, 84], [71, 85], [71, 91], [71, 94], [71, 97], [71, 99], [71, 100], [71, 104], [71, 107], [71, 116], [71, 117], [71, 118], [71, 124], [71, 129], [71, 130], [71, 132], [71, 134], [72, 73], [72, 74], [72, 75], [72, 76], [72, 79], [72, 80], [72, 81], [72, 91], [72, 92], [72, 93], [72, 94], [72, 98], [72, 103], [72, 104], [72, 105], [72, 107], [72, 113], [72, 114], [72, 116], [72, 132], [72, 135], [73, 78], [73, 81], [73, 88], [73, 96], [73, 97], [73, 98], [73, 99], [73, 100], [73, 101], [73, 120], [73, 124], [73, 126], [73, 127], [73, 131], [73, 132], [73, 137], [74, 76], [74, 81], [74, 90], [74, 91], [74, 92], [74, 94], [74, 98], [74, 99], [74, 108], [74, 109], [74, 118], [74, 121], [74, 126], [74, 133], [74, 135], [74, 139], [75, 83], [75, 86], [75, 92], [75, 94], [75, 96], [75, 100], [75, 101], [75, 104], [75, 105], [75, 111], [75, 119], [75, 121], [75, 123], [75, 124], [76, 78], [76, 88], [76, 89], [76, 92], [76, 100], [76, 101], [76, 102], [76, 112], [76, 114], [76, 118], [76, 120], [76, 121], [76, 131], [76, 135], [77, 78], [77, 80], [77, 82], [77, 86], [77, 90], [77, 91], [77, 97], [77, 106], [77, 111], [77, 119], [77, 123], [77, 124], [77, 126], [77, 127], [77, 132], [77, 134], [77, 139], [78, 81], [78, 86], [78, 89], [78, 95], [78, 96], [78, 98], [78, 99], [78, 101], [78, 108], [78, 110], [78, 111], [78, 112], [78, 126], [78, 128], [78, 132], [78, 136], [78, 138], [79, 81], [79, 84], [79, 89], [79, 90], [79, 92], [79, 94], [79, 101], [79, 104], [79, 109], [79, 110], [79, 112], [79, 113], [79, 115], [79, 118], [79, 122], [79, 123], [79, 126], [79, 127], [79, 128], [79, 133], [80, 82], [80, 84], [80, 94], [80, 96], [80, 110], [80, 113], [80, 116], [80, 118], [80, 120], [80, 133], [80, 134], [81, 83], [81, 87], [81, 93], [81, 98], [81, 99], [81, 100], [81, 101], [81, 103], [81, 105], [81, 113], [81, 118], [81, 124], [81, 127], [81, 129], [81, 136], [81, 138], [82, 85], [82, 88], [82, 91], [82, 93], [82, 94], [82, 95], [82, 97], [82, 99], [82, 101], [82, 104], [82, 108], [82, 110], [82, 111], [82, 119], [82, 120], [82, 122], [82, 125], [82, 127], [82, 129], [82, 130], [82, 133], [82, 137], [83, 86], [83, 89], [83, 92], [83, 93], [83, 94], [83, 96], [83, 101], [83, 102], [83, 114], [83, 116], [83, 125], [83, 132], [83, 134], [83, 137], [84, 85], [84, 95], [84, 97], [84, 98], [84, 103], [84, 106], [84, 109], [84, 111], [84, 119], [84, 122], [84, 125], [84, 126], [84, 127], [84, 131], [84, 135], [85, 92], [85, 94], [85, 95], [85, 97], [85, 98], [85, 102], [85, 104], [85, 112], [85, 117], [85, 123], [85, 132], [85, 135], [85, 136], [86, 87], [86, 99], [86, 100], [86, 101], [86, 102], [86, 103], [86, 107], [86, 109], [86, 116], [86, 118], [86, 124], [86, 126], [86, 127], [86, 133], [86, 135], [86, 139], [87, 93], [87, 94], [87, 98], [87, 101], [87, 112], [87, 116], [87, 119], [87, 123], [87, 130], [88, 101], [88, 105], [88, 115], [88, 118], [88, 127], [88, 128], [88, 133], [88, 135], [89, 94], [89, 97], [89, 99], [89, 102], [89, 107], [89, 108], [89, 110], [89, 115], [89, 116], [89, 117], [89, 120], [89, 123], [89, 130], [89, 131], [89, 132], [89, 133], [90, 95], [90, 96], [90, 97], [90, 99], [90, 101], [90, 102], [90, 103], [90, 111], [90, 113], [90, 116], [90, 118], [90, 120], [90, 124], [90, 125], [90, 128], [90, 132], [90, 133], [90, 134], [90, 136], [91, 96], [91, 99], [91, 107], [91, 108], [91, 111], [91, 113], [91, 116], [91, 117], [91, 121], [91, 128], [91, 130], [91, 134], [91, 138], [92, 93], [92, 96], [92, 97], [92, 103], [92, 105], [92, 106], [92, 111], [92, 115], [92, 116], [92, 117], [92, 118], [92, 123], [92, 133], [92, 134], [92, 135], [92, 137], [93, 103], [93, 105], [93, 112], [93, 116], [93, 117], [93, 121], [93, 122], [93, 132], [93, 136], [93, 137], [94, 100], [94, 104], [94, 105], [94, 106], [94, 114], [94, 116], [94, 118], [94, 119], [94, 124], [94, 128], [94, 133], [95, 98], [95, 100], [95, 103], [95, 108], [95, 110], [95, 114], [95, 128], [95, 130], [95, 132], [95, 139], [96, 98], [96, 102], [96, 108], [96, 109], [96, 113], [96, 119], [96, 122], [96, 128], [96, 131], [96, 132], [96, 138], [97, 99], [97, 100], [97, 106], [97, 108], [97, 113], [97, 114], [97, 115], [97, 117], [97, 124], [97, 135], [97, 139], [98, 109], [98, 110], [98, 111], [98, 116], [98, 122], [98, 125], [98, 127], [98, 132], [98, 134], [98, 138], [99, 109], [99, 110], [99, 112], [99, 118], [99, 119], [99, 124], [99, 132], [100, 104], [100, 105], [100, 106], [100, 108], [100, 110], [100, 111], [100, 118], [100, 124], [100, 125], [100, 126], [100, 127], [100, 130], [100, 131], [100, 133], [100, 138], [101, 104], [101, 107], [101, 108], [101, 110], [101, 119], [101, 126], [101, 134], [101, 135], [102, 104], [102, 109], [102, 110], [102, 113], [102, 114], [102, 117], [102, 119], [102, 120], [102, 123], [102, 135], [102, 136], [102, 137], [102, 138], [103, 108], [103, 110], [103, 112], [103, 115], [103, 116], [103, 118], [103, 124], [103, 131], [103, 136], [103, 138], [104, 108], [104, 110], [104, 111], [104, 115], [104, 117], [104, 122], [104, 126], [104, 128], [104, 129], [104, 130], [104, 133], [105, 107], [105, 108], [105, 113], [105, 114], [105, 115], [105, 116], [105, 129], [105, 130], [105, 135], [105, 139], [106, 109], [106, 112], [106, 113], [106, 115], [106, 116], [106, 119], [106, 124], [106, 126], [106, 132], [106, 134], [107, 115], [107, 118], [107, 121], [107, 122], [107, 123], [107, 126], [107, 127], [107, 133], [107, 136], [107, 139], [108, 117], [108, 118], [108, 120], [108, 121], [108, 122], [108, 123], [108, 130], [108, 131], [108, 134], [108, 137], [109, 122], [109, 132], [109, 134], [109, 135], [109, 139], [110, 112], [110, 117], [110, 118], [110, 122], [110, 126], [110, 127], [110, 128], [110, 129], [110, 130], [110, 131], [110, 133], [110, 137], [110, 138], [111, 113], [111, 115], [111, 116], [111, 123], [111, 128], [111, 132], [111, 134], [111, 135], [111, 136], [111, 139], [112, 114], [112, 119], [112, 123], [112, 125], [112, 130], [112, 135], [112, 137], [112, 138], [113, 121], [113, 123], [113, 125], [113, 126], [113, 127], [113, 129], [113, 130], [113, 135], [113, 136], [114, 115], [114, 122], [114, 127], [114, 130], [114, 133], [114, 138], [114, 139], [115, 119], [115, 121], [115, 122], [115, 129], [115, 133], [116, 117], [116, 118], [116, 119], [116, 128], [116, 133], [116, 134], [116, 136], [116, 137], [116, 138], [117, 118], [117, 119], [117, 120], [117, 122], [117, 132], [117, 134], [117, 135], [117, 136], [118, 132], [118, 133], [118, 136], [118, 139], [119, 120], [119, 123], [119, 124], [119, 133], [119, 135], [119, 138], [119, 139], [120, 121], [120, 123], [120, 124], [120, 129], [120, 130], [120, 134], [121, 122], [121, 126], [121, 133], [121, 134], [121, 137], [121, 139], [122, 125], [122, 129], [122, 132], [122, 135], [122, 136], [123, 125], [123, 126], [123, 128], [123, 131], [123, 132], [124, 127], [124, 129], [124, 131], [124, 132], [124, 135], [124, 137], [125, 129], [125, 131], [125, 137], [126, 127], [126, 130], [126, 131], [126, 133], [127, 128], [127, 132], [127, 133], [127, 139], [128, 130], [128, 135], [128, 137], [129, 132], [129, 138], [130, 132], [130, 134], [131, 134], [131, 135], [131, 137], [133, 138], [135, 138], [135, 139], [136, 139]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s7/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..994c2070154e71454d07b828ebf9d500291e0342 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [10, 11, 20, 31, 39, 66, 67, 79, 87, 88, 96, 99, 103, 106, 111, 114, 121, 129]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s7/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l6-s7/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b7ae7baec0548d12a72fbbea5bed8b8c7d5829f --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 5], [0, 9], [0, 14], [0, 16], [0, 21], [0, 29], [0, 34], [0, 37], [0, 46], [0, 47], [0, 54], [0, 56], [0, 61], [0, 68], [0, 70], [0, 71], [0, 75], [0, 77], [0, 79], [0, 86], [0, 90], [0, 96], [0, 104], [0, 108], [0, 109], [0, 124], [0, 125], [0, 126], [0, 127], [0, 129], [0, 131], [0, 133], [0, 137], [1, 2], [1, 6], [1, 7], [1, 11], [1, 12], [1, 14], [1, 17], [1, 20], [1, 23], [1, 24], [1, 27], [1, 32], [1, 33], [1, 34], [1, 38], [1, 47], [1, 50], [1, 51], [1, 53], [1, 55], [1, 69], [1, 72], [1, 77], [1, 78], [1, 79], [1, 82], [1, 86], [1, 87], [1, 90], [1, 91], [1, 96], [1, 98], [1, 99], [1, 113], [1, 114], [1, 117], [1, 120], [1, 122], [1, 128], [2, 6], [2, 7], [2, 9], [2, 11], [2, 12], [2, 13], [2, 16], [2, 24], [2, 32], [2, 43], [2, 44], [2, 48], [2, 49], [2, 50], [2, 51], [2, 54], [2, 56], [2, 65], [2, 66], [2, 69], [2, 75], [2, 80], [2, 83], [2, 85], [2, 89], [2, 90], [2, 98], [2, 99], [2, 107], [2, 111], [2, 112], [2, 122], [2, 125], [2, 127], [2, 131], [2, 134], [2, 135], [2, 136], [2, 139], [3, 4], [3, 5], [3, 8], [3, 11], [3, 12], [3, 13], [3, 22], [3, 29], [3, 32], [3, 36], [3, 49], [3, 52], [3, 56], [3, 61], [3, 69], [3, 70], [3, 75], [3, 77], [3, 79], [3, 84], [3, 86], [3, 91], [3, 97], [3, 99], [3, 101], [3, 106], [3, 107], [3, 112], [3, 113], [3, 116], [3, 124], [3, 126], [3, 127], [3, 131], [3, 133], [3, 136], [3, 138], [3, 139], [4, 9], [4, 10], [4, 12], [4, 22], [4, 23], [4, 28], [4, 42], [4, 45], [4, 48], [4, 53], [4, 54], [4, 60], [4, 61], [4, 69], [4, 72], [4, 73], [4, 74], [4, 76], [4, 77], [4, 78], [4, 79], [4, 80], [4, 87], [4, 88], [4, 89], [4, 93], [4, 97], [4, 98], [4, 102], [4, 106], [4, 120], [4, 124], [4, 125], [4, 133], [4, 134], [4, 139], [5, 8], [5, 12], [5, 14], [5, 17], [5, 21], [5, 24], [5, 28], [5, 29], [5, 30], [5, 32], [5, 37], [5, 39], [5, 41], [5, 45], [5, 47], [5, 48], [5, 59], [5, 60], [5, 68], [5, 73], [5, 75], [5, 76], [5, 82], [5, 93], [5, 94], [5, 95], [5, 99], [5, 101], [5, 102], [5, 106], [5, 110], [5, 114], [5, 115], [5, 118], [5, 122], [5, 123], [5, 125], [5, 127], [5, 132], [5, 137], [6, 7], [6, 12], [6, 14], [6, 15], [6, 16], [6, 18], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 28], [6, 29], [6, 31], [6, 35], [6, 40], [6, 41], [6, 43], [6, 47], [6, 48], [6, 49], [6, 50], [6, 52], [6, 53], [6, 55], [6, 57], [6, 59], [6, 61], [6, 66], [6, 67], [6, 68], [6, 70], [6, 75], [6, 78], [6, 79], [6, 80], [6, 81], [6, 82], [6, 83], [6, 95], [6, 96], [6, 105], [6, 108], [6, 113], [6, 119], [6, 121], [6, 129], [6, 136], [6, 138], [7, 11], [7, 12], [7, 18], [7, 23], [7, 24], [7, 25], [7, 31], [7, 33], [7, 42], [7, 47], [7, 51], [7, 55], [7, 56], [7, 58], [7, 59], [7, 61], [7, 72], [7, 73], [7, 74], [7, 76], [7, 79], [7, 86], [7, 88], [7, 91], [7, 93], [7, 96], [7, 111], [7, 112], [7, 115], [7, 117], [7, 125], [7, 130], [7, 132], [7, 133], [7, 135], [7, 138], [8, 10], [8, 15], [8, 18], [8, 19], [8, 24], [8, 25], [8, 28], [8, 29], [8, 31], [8, 32], [8, 36], [8, 39], [8, 41], [8, 42], [8, 55], [8, 56], [8, 58], [8, 59], [8, 60], [8, 61], [8, 64], [8, 68], [8, 69], [8, 71], [8, 76], [8, 81], [8, 84], [8, 85], [8, 90], [8, 92], [8, 100], [8, 101], [8, 104], [8, 105], [8, 106], [8, 110], [8, 111], [8, 112], [8, 115], [8, 118], [8, 119], [8, 121], [8, 122], [8, 123], [8, 125], [8, 126], [8, 131], [8, 132], [8, 134], [8, 137], [8, 138], [9, 11], [9, 13], [9, 15], [9, 16], [9, 20], [9, 28], [9, 31], [9, 33], [9, 35], [9, 36], [9, 37], [9, 40], [9, 41], [9, 43], [9, 48], [9, 49], [9, 50], [9, 54], [9, 57], [9, 58], [9, 61], [9, 62], [9, 67], [9, 69], [9, 70], [9, 79], [9, 80], [9, 91], [9, 104], [9, 106], [9, 110], [9, 113], [9, 135], [9, 138], [9, 139], [10, 33], [10, 36], [10, 42], [10, 44], [10, 48], [10, 54], [10, 55], [10, 56], [10, 60], [10, 61], [10, 72], [10, 73], [10, 74], [10, 75], [10, 76], [10, 78], [10, 80], [10, 81], [10, 83], [10, 89], [10, 94], [10, 97], [10, 102], [10, 105], [10, 108], [10, 112], [10, 115], [10, 116], [10, 126], [10, 134], [10, 135], [10, 136], [11, 12], [11, 14], [11, 16], [11, 17], [11, 18], [11, 26], [11, 27], [11, 32], [11, 34], [11, 35], [11, 41], [11, 42], [11, 44], [11, 49], [11, 53], [11, 54], [11, 55], [11, 60], [11, 63], [11, 74], [11, 75], [11, 85], [11, 94], [11, 95], [11, 97], [11, 102], [11, 109], [11, 117], [11, 118], [11, 119], [11, 122], [11, 123], [11, 125], [11, 134], [11, 139], [12, 24], [12, 29], [12, 39], [12, 43], [12, 45], [12, 54], [12, 55], [12, 56], [12, 58], [12, 59], [12, 62], [12, 63], [12, 64], [12, 67], [12, 72], [12, 74], [12, 76], [12, 77], [12, 78], [12, 84], [12, 88], [12, 90], [12, 96], [12, 100], [12, 104], [12, 106], [12, 109], [12, 114], [12, 118], [12, 124], [12, 130], [12, 131], [12, 133], [12, 135], [12, 137], [12, 139], [13, 14], [13, 18], [13, 20], [13, 24], [13, 25], [13, 29], [13, 30], [13, 31], [13, 33], [13, 43], [13, 45], [13, 50], [13, 57], [13, 58], [13, 62], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 75], [13, 76], [13, 82], [13, 83], [13, 84], [13, 89], [13, 92], [13, 98], [13, 100], [13, 101], [13, 104], [13, 111], [13, 114], [13, 116], [13, 118], [13, 121], [13, 131], [13, 137], [13, 138], [13, 139], [14, 15], [14, 16], [14, 19], [14, 21], [14, 24], [14, 29], [14, 31], [14, 33], [14, 34], [14, 38], [14, 39], [14, 45], [14, 46], [14, 47], [14, 48], [14, 52], [14, 54], [14, 55], [14, 60], [14, 63], [14, 68], [14, 72], [14, 75], [14, 78], [14, 80], [14, 84], [14, 85], [14, 86], [14, 88], [14, 97], [14, 99], [14, 101], [14, 102], [14, 103], [14, 104], [14, 109], [14, 110], [14, 111], [14, 126], [14, 129], [14, 132], [14, 136], [15, 17], [15, 19], [15, 20], [15, 22], [15, 23], [15, 27], [15, 28], [15, 35], [15, 38], [15, 39], [15, 42], [15, 43], [15, 44], [15, 51], [15, 52], [15, 57], [15, 59], [15, 63], [15, 64], [15, 66], [15, 71], [15, 75], [15, 79], [15, 80], [15, 81], [15, 82], [15, 90], [15, 92], [15, 93], [15, 94], [15, 98], [15, 103], [15, 104], [15, 107], [15, 108], [15, 115], [15, 119], [15, 121], [15, 124], [15, 125], [15, 126], [15, 127], [15, 134], [16, 17], [16, 19], [16, 20], [16, 23], [16, 28], [16, 29], [16, 31], [16, 33], [16, 35], [16, 37], [16, 38], [16, 41], [16, 51], [16, 54], [16, 56], [16, 57], [16, 59], [16, 63], [16, 66], [16, 73], [16, 74], [16, 78], [16, 81], [16, 87], [16, 91], [16, 101], [16, 107], [16, 108], [16, 114], [16, 115], [16, 116], [16, 117], [16, 118], [16, 124], [16, 131], [16, 133], [16, 134], [17, 18], [17, 20], [17, 24], [17, 25], [17, 28], [17, 30], [17, 33], [17, 35], [17, 38], [17, 39], [17, 46], [17, 54], [17, 55], [17, 69], [17, 74], [17, 77], [17, 80], [17, 81], [17, 85], [17, 88], [17, 89], [17, 91], [17, 94], [17, 97], [17, 103], [17, 107], [17, 108], [17, 109], [17, 118], [17, 123], [17, 124], [17, 132], [17, 137], [17, 138], [18, 20], [18, 24], [18, 26], [18, 27], [18, 31], [18, 36], [18, 51], [18, 52], [18, 58], [18, 59], [18, 63], [18, 64], [18, 76], [18, 77], [18, 79], [18, 84], [18, 88], [18, 96], [18, 99], [18, 100], [18, 102], [18, 107], [18, 108], [18, 109], [18, 116], [18, 118], [18, 122], [18, 125], [18, 126], [18, 130], [18, 138], [19, 20], [19, 21], [19, 24], [19, 36], [19, 41], [19, 42], [19, 43], [19, 44], [19, 46], [19, 47], [19, 48], [19, 53], [19, 54], [19, 56], [19, 58], [19, 64], [19, 70], [19, 71], [19, 72], [19, 86], [19, 87], [19, 89], [19, 90], [19, 92], [19, 97], [19, 101], [19, 102], [19, 104], [19, 108], [19, 109], [19, 110], [19, 115], [19, 116], [19, 117], [19, 118], [19, 120], [19, 127], [19, 128], [19, 129], [19, 133], [19, 137], [19, 139], [20, 21], [20, 24], [20, 26], [20, 30], [20, 35], [20, 45], [20, 51], [20, 56], [20, 57], [20, 60], [20, 61], [20, 63], [20, 65], [20, 71], [20, 72], [20, 80], [20, 85], [20, 94], [20, 102], [20, 113], [20, 115], [20, 118], [20, 123], [20, 125], [20, 135], [21, 22], [21, 23], [21, 30], [21, 37], [21, 38], [21, 40], [21, 43], [21, 45], [21, 47], [21, 58], [21, 59], [21, 63], [21, 64], [21, 65], [21, 71], [21, 73], [21, 75], [21, 77], [21, 81], [21, 84], [21, 85], [21, 87], [21, 98], [21, 101], [21, 105], [21, 107], [21, 117], [21, 119], [21, 121], [21, 124], [21, 128], [21, 130], [21, 133], [21, 135], [21, 136], [21, 137], [21, 138], [22, 26], [22, 33], [22, 39], [22, 46], [22, 56], [22, 59], [22, 62], [22, 63], [22, 64], [22, 65], [22, 66], [22, 67], [22, 69], [22, 70], [22, 71], [22, 72], [22, 77], [22, 78], [22, 79], [22, 80], [22, 82], [22, 83], [22, 84], [22, 87], [22, 88], [22, 90], [22, 92], [22, 93], [22, 95], [22, 98], [22, 99], [22, 101], [22, 102], [22, 106], [22, 111], [22, 113], [22, 114], [22, 120], [22, 122], [22, 124], [22, 131], [22, 132], [22, 134], [22, 136], [23, 27], [23, 30], [23, 31], [23, 35], [23, 38], [23, 39], [23, 42], [23, 44], [23, 61], [23, 65], [23, 66], [23, 68], [23, 71], [23, 73], [23, 74], [23, 80], [23, 87], [23, 88], [23, 89], [23, 90], [23, 91], [23, 97], [23, 99], [23, 104], [23, 106], [23, 108], [23, 111], [23, 114], [23, 116], [23, 117], [23, 120], [23, 130], [23, 131], [23, 133], [23, 135], [23, 136], [24, 26], [24, 33], [24, 35], [24, 39], [24, 56], [24, 57], [24, 58], [24, 61], [24, 62], [24, 71], [24, 72], [24, 79], [24, 80], [24, 86], [24, 88], [24, 91], [24, 93], [24, 96], [24, 98], [24, 104], [24, 105], [24, 106], [24, 108], [24, 109], [24, 110], [24, 120], [24, 122], [24, 124], [24, 125], [24, 132], [24, 133], [24, 139], [25, 28], [25, 34], [25, 45], [25, 46], [25, 58], [25, 63], [25, 68], [25, 72], [25, 74], [25, 80], [25, 81], [25, 82], [25, 88], [25, 89], [25, 90], [25, 91], [25, 95], [25, 96], [25, 106], [25, 108], [25, 111], [25, 115], [25, 116], [25, 118], [25, 131], [25, 135], [25, 138], [26, 29], [26, 32], [26, 40], [26, 42], [26, 46], [26, 48], [26, 49], [26, 50], [26, 53], [26, 59], [26, 61], [26, 64], [26, 67], [26, 68], [26, 69], [26, 71], [26, 72], [26, 75], [26, 76], [26, 78], [26, 81], [26, 85], [26, 86], [26, 90], [26, 92], [26, 93], [26, 98], [26, 99], [26, 104], [26, 105], [26, 106], [26, 107], [26, 111], [26, 120], [26, 121], [26, 124], [26, 126], [26, 136], [27, 32], [27, 39], [27, 40], [27, 41], [27, 47], [27, 48], [27, 49], [27, 54], [27, 55], [27, 57], [27, 64], [27, 66], [27, 67], [27, 69], [27, 74], [27, 76], [27, 80], [27, 100], [27, 101], [27, 102], [27, 103], [27, 104], [27, 107], [27, 108], [27, 110], [27, 111], [27, 129], [27, 130], [27, 135], [28, 30], [28, 36], [28, 39], [28, 46], [28, 50], [28, 53], [28, 60], [28, 62], [28, 63], [28, 67], [28, 70], [28, 72], [28, 75], [28, 79], [28, 81], [28, 84], [28, 86], [28, 87], [28, 89], [28, 91], [28, 94], [28, 95], [28, 99], [28, 105], [28, 108], [28, 115], [28, 119], [28, 128], [28, 131], [28, 133], [28, 134], [28, 138], [28, 139], [29, 53], [29, 55], [29, 64], [29, 68], [29, 72], [29, 73], [29, 75], [29, 77], [29, 78], [29, 79], [29, 86], [29, 92], [29, 94], [29, 98], [29, 103], [29, 111], [29, 115], [29, 118], [29, 129], [29, 133], [29, 134], [29, 136], [29, 139], [30, 34], [30, 36], [30, 37], [30, 40], [30, 48], [30, 49], [30, 51], [30, 61], [30, 66], [30, 70], [30, 72], [30, 73], [30, 75], [30, 77], [30, 79], [30, 84], [30, 86], [30, 91], [30, 92], [30, 97], [30, 98], [30, 100], [30, 113], [30, 114], [30, 118], [30, 121], [30, 126], [30, 135], [30, 137], [30, 139], [31, 34], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 50], [31, 52], [31, 55], [31, 57], [31, 58], [31, 59], [31, 62], [31, 65], [31, 68], [31, 70], [31, 76], [31, 77], [31, 82], [31, 89], [31, 98], [31, 100], [31, 101], [31, 104], [31, 113], [31, 118], [32, 33], [32, 34], [32, 38], [32, 43], [32, 47], [32, 51], [32, 58], [32, 59], [32, 61], [32, 62], [32, 63], [32, 66], [32, 70], [32, 85], [32, 87], [32, 93], [32, 95], [32, 101], [32, 108], [32, 113], [32, 118], [32, 120], [32, 121], [32, 124], [32, 125], [32, 130], [32, 132], [32, 136], [32, 138], [33, 36], [33, 38], [33, 39], [33, 51], [33, 60], [33, 62], [33, 63], [33, 65], [33, 69], [33, 71], [33, 78], [33, 81], [33, 92], [33, 94], [33, 96], [33, 100], [33, 103], [33, 104], [33, 105], [33, 109], [33, 112], [33, 114], [33, 115], [33, 123], [33, 125], [33, 131], [34, 36], [34, 38], [34, 39], [34, 40], [34, 41], [34, 44], [34, 51], [34, 60], [34, 61], [34, 63], [34, 66], [34, 70], [34, 73], [34, 78], [34, 90], [34, 92], [34, 95], [34, 98], [34, 99], [34, 102], [34, 116], [34, 118], [34, 119], [34, 120], [34, 121], [34, 122], [34, 123], [34, 129], [34, 132], [34, 133], [34, 135], [34, 136], [34, 137], [35, 39], [35, 40], [35, 41], [35, 45], [35, 53], [35, 63], [35, 66], [35, 69], [35, 70], [35, 76], [35, 78], [35, 79], [35, 82], [35, 90], [35, 95], [35, 97], [35, 98], [35, 102], [35, 105], [35, 108], [35, 117], [35, 118], [35, 120], [35, 124], [35, 125], [35, 126], [35, 131], [35, 137], [36, 37], [36, 39], [36, 43], [36, 44], [36, 46], [36, 53], [36, 57], [36, 64], [36, 67], [36, 71], [36, 72], [36, 76], [36, 77], [36, 78], [36, 80], [36, 83], [36, 86], [36, 89], [36, 100], [36, 102], [36, 103], [36, 105], [36, 107], [36, 109], [36, 115], [36, 122], [36, 125], [36, 126], [36, 127], [36, 130], [36, 138], [36, 139], [37, 38], [37, 39], [37, 41], [37, 42], [37, 48], [37, 52], [37, 54], [37, 56], [37, 61], [37, 62], [37, 66], [37, 73], [37, 83], [37, 88], [37, 89], [37, 90], [37, 91], [37, 93], [37, 96], [37, 97], [37, 100], [37, 103], [37, 106], [37, 111], [37, 120], [37, 121], [37, 123], [37, 124], [37, 126], [37, 136], [37, 139], [38, 39], [38, 40], [38, 43], [38, 45], [38, 47], [38, 48], [38, 57], [38, 59], [38, 63], [38, 67], [38, 76], [38, 82], [38, 88], [38, 89], [38, 92], [38, 95], [38, 99], [38, 102], [38, 103], [38, 104], [38, 106], [38, 108], [38, 110], [38, 111], [38, 113], [38, 114], [38, 117], [38, 119], [38, 126], [38, 129], [38, 132], [38, 139], [39, 40], [39, 43], [39, 46], [39, 47], [39, 49], [39, 50], [39, 52], [39, 53], [39, 54], [39, 55], [39, 56], [39, 59], [39, 60], [39, 62], [39, 63], [39, 75], [39, 81], [39, 83], [39, 89], [39, 92], [39, 94], [39, 105], [39, 108], [39, 113], [39, 117], [39, 119], [39, 123], [39, 124], [39, 125], [39, 127], [39, 130], [39, 135], [39, 138], [40, 42], [40, 43], [40, 49], [40, 52], [40, 54], [40, 57], [40, 58], [40, 62], [40, 64], [40, 68], [40, 78], [40, 80], [40, 82], [40, 86], [40, 87], [40, 97], [40, 99], [40, 102], [40, 108], [40, 110], [40, 114], [40, 117], [40, 121], [40, 122], [40, 123], [40, 124], [40, 128], [40, 129], [40, 130], [40, 132], [40, 133], [40, 136], [40, 137], [41, 42], [41, 43], [41, 45], [41, 46], [41, 50], [41, 51], [41, 56], [41, 57], [41, 59], [41, 62], [41, 64], [41, 65], [41, 67], [41, 68], [41, 71], [41, 78], [41, 79], [41, 87], [41, 91], [41, 96], [41, 99], [41, 101], [41, 106], [41, 110], [41, 122], [41, 127], [41, 128], [41, 130], [41, 133], [41, 135], [41, 138], [41, 139], [42, 47], [42, 49], [42, 51], [42, 57], [42, 58], [42, 59], [42, 61], [42, 66], [42, 73], [42, 75], [42, 76], [42, 77], [42, 78], [42, 79], [42, 84], [42, 85], [42, 86], [42, 88], [42, 92], [42, 93], [42, 96], [42, 99], [42, 107], [42, 120], [42, 123], [42, 127], [42, 137], [42, 138], [43, 49], [43, 52], [43, 53], [43, 55], [43, 56], [43, 57], [43, 58], [43, 61], [43, 66], [43, 69], [43, 73], [43, 85], [43, 86], [43, 87], [43, 88], [43, 90], [43, 100], [43, 101], [43, 107], [43, 109], [43, 111], [43, 114], [43, 115], [43, 117], [43, 118], [43, 124], [43, 127], [43, 132], [43, 137], [43, 138], [43, 139], [44, 47], [44, 49], [44, 55], [44, 57], [44, 58], [44, 71], [44, 73], [44, 76], [44, 77], [44, 78], [44, 87], [44, 90], [44, 91], [44, 92], [44, 93], [44, 96], [44, 99], [44, 102], [44, 104], [44, 111], [44, 112], [44, 114], [44, 115], [44, 116], [44, 119], [44, 120], [44, 122], [44, 125], [44, 128], [44, 129], [44, 130], [44, 133], [44, 138], [45, 49], [45, 55], [45, 59], [45, 60], [45, 64], [45, 65], [45, 68], [45, 76], [45, 77], [45, 78], [45, 85], [45, 89], [45, 90], [45, 95], [45, 99], [45, 102], [45, 104], [45, 108], [45, 111], [45, 118], [45, 119], [45, 124], [45, 125], [45, 128], [45, 129], [45, 132], [45, 134], [45, 139], [46, 47], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 57], [46, 58], [46, 61], [46, 68], [46, 77], [46, 80], [46, 84], [46, 85], [46, 88], [46, 91], [46, 92], [46, 97], [46, 100], [46, 102], [46, 108], [46, 111], [46, 112], [46, 114], [46, 115], [46, 118], [46, 134], [46, 136], [46, 138], [47, 50], [47, 51], [47, 52], [47, 54], [47, 56], [47, 57], [47, 58], [47, 63], [47, 68], [47, 69], [47, 70], [47, 76], [47, 77], [47, 78], [47, 79], [47, 82], [47, 83], [47, 84], [47, 87], [47, 89], [47, 92], [47, 97], [47, 100], [47, 102], [47, 105], [47, 106], [47, 108], [47, 109], [47, 110], [47, 111], [47, 112], [47, 114], [47, 116], [47, 119], [47, 121], [47, 126], [47, 127], [47, 128], [47, 129], [47, 137], [48, 59], [48, 63], [48, 64], [48, 65], [48, 67], [48, 71], [48, 75], [48, 80], [48, 83], [48, 91], [48, 93], [48, 96], [48, 97], [48, 103], [48, 106], [48, 113], [48, 116], [48, 118], [48, 123], [48, 126], [48, 135], [48, 136], [48, 137], [49, 51], [49, 53], [49, 62], [49, 65], [49, 66], [49, 70], [49, 77], [49, 80], [49, 82], [49, 83], [49, 84], [49, 92], [49, 93], [49, 100], [49, 101], [49, 102], [49, 103], [49, 108], [49, 112], [49, 118], [49, 119], [49, 121], [49, 123], [49, 124], [49, 126], [49, 127], [49, 128], [49, 132], [49, 133], [49, 136], [49, 139], [50, 51], [50, 52], [50, 53], [50, 56], [50, 60], [50, 61], [50, 62], [50, 67], [50, 73], [50, 79], [50, 82], [50, 85], [50, 86], [50, 88], [50, 91], [50, 94], [50, 96], [50, 97], [50, 102], [50, 107], [50, 114], [50, 116], [50, 121], [50, 126], [50, 128], [50, 131], [50, 132], [50, 133], [51, 53], [51, 63], [51, 66], [51, 67], [51, 72], [51, 80], [51, 83], [51, 85], [51, 87], [51, 91], [51, 97], [51, 113], [51, 114], [51, 128], [51, 131], [51, 134], [52, 57], [52, 58], [52, 59], [52, 61], [52, 68], [52, 72], [52, 73], [52, 74], [52, 83], [52, 89], [52, 91], [52, 97], [52, 98], [52, 101], [52, 104], [52, 108], [52, 111], [52, 118], [52, 122], [52, 125], [52, 131], [52, 134], [52, 137], [52, 139], [53, 57], [53, 58], [53, 59], [53, 60], [53, 63], [53, 64], [53, 69], [53, 71], [53, 82], [53, 92], [53, 99], [53, 101], [53, 103], [53, 111], [53, 117], [53, 119], [53, 122], [53, 125], [53, 127], [53, 129], [53, 132], [53, 133], [53, 134], [54, 59], [54, 60], [54, 62], [54, 63], [54, 66], [54, 67], [54, 68], [54, 72], [54, 74], [54, 78], [54, 80], [54, 81], [54, 82], [54, 86], [54, 87], [54, 89], [54, 90], [54, 92], [54, 96], [54, 100], [54, 103], [54, 105], [54, 107], [54, 108], [54, 109], [54, 112], [54, 113], [54, 120], [54, 122], [54, 127], [54, 129], [54, 131], [54, 135], [55, 57], [55, 61], [55, 64], [55, 66], [55, 70], [55, 72], [55, 73], [55, 74], [55, 83], [55, 84], [55, 85], [55, 86], [55, 88], [55, 94], [55, 95], [55, 101], [55, 102], [55, 105], [55, 106], [55, 107], [55, 110], [55, 115], [55, 118], [55, 119], [55, 126], [55, 131], [56, 57], [56, 58], [56, 65], [56, 74], [56, 80], [56, 85], [56, 86], [56, 88], [56, 90], [56, 93], [56, 100], [56, 105], [56, 108], [56, 109], [56, 115], [56, 123], [56, 126], [56, 127], [56, 131], [56, 135], [56, 137], [56, 138], [57, 60], [57, 65], [57, 69], [57, 73], [57, 77], [57, 78], [57, 81], [57, 83], [57, 87], [57, 88], [57, 90], [57, 94], [57, 96], [57, 97], [57, 98], [57, 101], [57, 102], [57, 104], [57, 106], [57, 110], [57, 111], [57, 113], [57, 115], [57, 121], [57, 125], [57, 126], [57, 130], [57, 132], [57, 139], [58, 59], [58, 62], [58, 64], [58, 67], [58, 72], [58, 75], [58, 78], [58, 80], [58, 81], [58, 86], [58, 89], [58, 95], [58, 96], [58, 97], [58, 101], [58, 103], [58, 107], [58, 111], [58, 126], [58, 127], [59, 63], [59, 66], [59, 82], [59, 87], [59, 90], [59, 92], [59, 93], [59, 96], [59, 101], [59, 102], [59, 103], [59, 112], [59, 114], [59, 119], [59, 123], [59, 134], [59, 137], [60, 69], [60, 74], [60, 76], [60, 85], [60, 86], [60, 87], [60, 88], [60, 89], [60, 94], [60, 97], [60, 98], [60, 100], [60, 101], [60, 102], [60, 103], [60, 104], [60, 105], [60, 106], [60, 109], [60, 111], [60, 113], [60, 117], [60, 120], [60, 121], [60, 126], [60, 127], [60, 133], [60, 135], [61, 62], [61, 63], [61, 64], [61, 66], [61, 67], [61, 70], [61, 71], [61, 74], [61, 81], [61, 82], [61, 85], [61, 86], [61, 89], [61, 94], [61, 101], [61, 103], [61, 109], [61, 121], [61, 131], [61, 133], [61, 137], [62, 63], [62, 66], [62, 72], [62, 75], [62, 77], [62, 80], [62, 84], [62, 87], [62, 88], [62, 89], [62, 91], [62, 93], [62, 98], [62, 100], [62, 101], [62, 102], [62, 109], [62, 110], [62, 116], [62, 117], [62, 118], [62, 127], [62, 130], [62, 132], [63, 64], [63, 68], [63, 77], [63, 81], [63, 89], [63, 91], [63, 95], [63, 96], [63, 99], [63, 100], [63, 104], [63, 105], [63, 108], [63, 112], [63, 116], [63, 120], [63, 122], [63, 128], [63, 129], [63, 132], [63, 135], [63, 137], [64, 66], [64, 72], [64, 81], [64, 83], [64, 85], [64, 88], [64, 90], [64, 91], [64, 92], [64, 94], [64, 95], [64, 97], [64, 101], [64, 103], [64, 104], [64, 107], [64, 110], [64, 111], [64, 116], [64, 117], [64, 119], [64, 123], [64, 128], [64, 133], [64, 134], [64, 135], [65, 67], [65, 69], [65, 72], [65, 75], [65, 79], [65, 81], [65, 86], [65, 89], [65, 90], [65, 97], [65, 106], [65, 107], [65, 113], [65, 116], [65, 117], [65, 128], [65, 131], [65, 132], [65, 134], [65, 135], [65, 139], [66, 72], [66, 76], [66, 83], [66, 84], [66, 85], [66, 86], [66, 93], [66, 94], [66, 105], [66, 117], [66, 119], [66, 122], [66, 139], [67, 68], [67, 71], [67, 72], [67, 76], [67, 78], [67, 83], [67, 85], [67, 89], [67, 93], [67, 95], [67, 101], [67, 104], [67, 109], [67, 113], [67, 116], [67, 118], [67, 123], [67, 128], [67, 133], [67, 136], [68, 69], [68, 74], [68, 75], [68, 82], [68, 83], [68, 85], [68, 87], [68, 90], [68, 94], [68, 103], [68, 105], [68, 106], [68, 107], [68, 109], [68, 111], [68, 115], [68, 116], [68, 117], [68, 123], [68, 124], [68, 128], [68, 129], [68, 133], [68, 139], [69, 70], [69, 79], [69, 81], [69, 83], [69, 86], [69, 89], [69, 92], [69, 93], [69, 95], [69, 98], [69, 106], [69, 120], [69, 128], [69, 129], [69, 130], [70, 72], [70, 75], [70, 79], [70, 88], [70, 91], [70, 92], [70, 95], [70, 97], [70, 99], [70, 102], [70, 105], [70, 106], [70, 107], [70, 108], [70, 110], [70, 114], [70, 119], [70, 120], [70, 122], [70, 132], [70, 133], [70, 137], [71, 77], [71, 78], [71, 79], [71, 80], [71, 81], [71, 82], [71, 84], [71, 85], [71, 91], [71, 94], [71, 97], [71, 99], [71, 100], [71, 104], [71, 107], [71, 116], [71, 117], [71, 118], [71, 124], [71, 129], [71, 130], [71, 132], [71, 134], [72, 73], [72, 74], [72, 75], [72, 76], [72, 79], [72, 80], [72, 81], [72, 91], [72, 92], [72, 93], [72, 94], [72, 98], [72, 103], [72, 104], [72, 105], [72, 107], [72, 113], [72, 114], [72, 116], [72, 132], [72, 135], [73, 78], [73, 81], [73, 88], [73, 96], [73, 97], [73, 98], [73, 99], [73, 100], [73, 101], [73, 120], [73, 124], [73, 126], [73, 127], [73, 131], [73, 132], [73, 137], [74, 76], [74, 81], [74, 90], [74, 91], [74, 92], [74, 94], [74, 98], [74, 99], [74, 108], [74, 109], [74, 118], [74, 121], [74, 126], [74, 133], [74, 135], [74, 139], [75, 83], [75, 86], [75, 92], [75, 94], [75, 96], [75, 100], [75, 101], [75, 104], [75, 105], [75, 111], [75, 119], [75, 121], [75, 123], [75, 124], [76, 78], [76, 88], [76, 89], [76, 92], [76, 100], [76, 101], [76, 102], [76, 112], [76, 114], [76, 118], [76, 120], [76, 121], [76, 131], [76, 135], [77, 78], [77, 80], [77, 82], [77, 86], [77, 90], [77, 91], [77, 97], [77, 106], [77, 111], [77, 119], [77, 123], [77, 124], [77, 126], [77, 127], [77, 132], [77, 134], [77, 139], [78, 81], [78, 86], [78, 89], [78, 95], [78, 96], [78, 98], [78, 99], [78, 101], [78, 108], [78, 110], [78, 111], [78, 112], [78, 126], [78, 128], [78, 132], [78, 136], [78, 138], [79, 81], [79, 84], [79, 89], [79, 90], [79, 92], [79, 94], [79, 101], [79, 104], [79, 109], [79, 110], [79, 112], [79, 113], [79, 115], [79, 118], [79, 122], [79, 123], [79, 126], [79, 127], [79, 128], [79, 133], [80, 82], [80, 84], [80, 94], [80, 96], [80, 110], [80, 113], [80, 116], [80, 118], [80, 120], [80, 133], [80, 134], [81, 83], [81, 87], [81, 93], [81, 98], [81, 99], [81, 100], [81, 101], [81, 103], [81, 105], [81, 113], [81, 118], [81, 124], [81, 127], [81, 129], [81, 136], [81, 138], [82, 85], [82, 88], [82, 91], [82, 93], [82, 94], [82, 95], [82, 97], [82, 99], [82, 101], [82, 104], [82, 108], [82, 110], [82, 111], [82, 119], [82, 120], [82, 122], [82, 125], [82, 127], [82, 129], [82, 130], [82, 133], [82, 137], [83, 86], [83, 89], [83, 92], [83, 93], [83, 94], [83, 96], [83, 101], [83, 102], [83, 114], [83, 116], [83, 125], [83, 132], [83, 134], [83, 137], [84, 85], [84, 95], [84, 97], [84, 98], [84, 103], [84, 106], [84, 109], [84, 111], [84, 119], [84, 122], [84, 125], [84, 126], [84, 127], [84, 131], [84, 135], [85, 92], [85, 94], [85, 95], [85, 97], [85, 98], [85, 102], [85, 104], [85, 112], [85, 117], [85, 123], [85, 132], [85, 135], [85, 136], [86, 87], [86, 99], [86, 100], [86, 101], [86, 102], [86, 103], [86, 107], [86, 109], [86, 116], [86, 118], [86, 124], [86, 126], [86, 127], [86, 133], [86, 135], [86, 139], [87, 93], [87, 94], [87, 98], [87, 101], [87, 112], [87, 116], [87, 119], [87, 123], [87, 130], [88, 101], [88, 105], [88, 115], [88, 118], [88, 127], [88, 128], [88, 133], [88, 135], [89, 94], [89, 97], [89, 99], [89, 102], [89, 107], [89, 108], [89, 110], [89, 115], [89, 116], [89, 117], [89, 120], [89, 123], [89, 130], [89, 131], [89, 132], [89, 133], [90, 95], [90, 96], [90, 97], [90, 99], [90, 101], [90, 102], [90, 103], [90, 111], [90, 113], [90, 116], [90, 118], [90, 120], [90, 124], [90, 125], [90, 128], [90, 132], [90, 133], [90, 134], [90, 136], [91, 96], [91, 99], [91, 107], [91, 108], [91, 111], [91, 113], [91, 116], [91, 117], [91, 121], [91, 128], [91, 130], [91, 134], [91, 138], [92, 93], [92, 96], [92, 97], [92, 103], [92, 105], [92, 106], [92, 111], [92, 115], [92, 116], [92, 117], [92, 118], [92, 123], [92, 133], [92, 134], [92, 135], [92, 137], [93, 103], [93, 105], [93, 112], [93, 116], [93, 117], [93, 121], [93, 122], [93, 132], [93, 136], [93, 137], [94, 100], [94, 104], [94, 105], [94, 106], [94, 114], [94, 116], [94, 118], [94, 119], [94, 124], [94, 128], [94, 133], [95, 98], [95, 100], [95, 103], [95, 108], [95, 110], [95, 114], [95, 128], [95, 130], [95, 132], [95, 139], [96, 98], [96, 102], [96, 108], [96, 109], [96, 113], [96, 119], [96, 122], [96, 128], [96, 131], [96, 132], [96, 138], [97, 99], [97, 100], [97, 106], [97, 108], [97, 113], [97, 114], [97, 115], [97, 117], [97, 124], [97, 135], [97, 139], [98, 109], [98, 110], [98, 111], [98, 116], [98, 122], [98, 125], [98, 127], [98, 132], [98, 134], [98, 138], [99, 109], [99, 110], [99, 112], [99, 118], [99, 119], [99, 124], [99, 132], [100, 104], [100, 105], [100, 106], [100, 108], [100, 110], [100, 111], [100, 118], [100, 124], [100, 125], [100, 126], [100, 127], [100, 130], [100, 131], [100, 133], [100, 138], [101, 104], [101, 107], [101, 108], [101, 110], [101, 119], [101, 126], [101, 134], [101, 135], [102, 104], [102, 109], [102, 110], [102, 113], [102, 114], [102, 117], [102, 119], [102, 120], [102, 123], [102, 135], [102, 136], [102, 137], [102, 138], [103, 108], [103, 110], [103, 112], [103, 115], [103, 116], [103, 118], [103, 124], [103, 131], [103, 136], [103, 138], [104, 108], [104, 110], [104, 111], [104, 115], [104, 117], [104, 122], [104, 126], [104, 128], [104, 129], [104, 130], [104, 133], [105, 107], [105, 108], [105, 113], [105, 114], [105, 115], [105, 116], [105, 129], [105, 130], [105, 135], [105, 139], [106, 109], [106, 112], [106, 113], [106, 115], [106, 116], [106, 119], [106, 124], [106, 126], [106, 132], [106, 134], [107, 115], [107, 118], [107, 121], [107, 122], [107, 123], [107, 126], [107, 127], [107, 133], [107, 136], [107, 139], [108, 117], [108, 118], [108, 120], [108, 121], [108, 122], [108, 123], [108, 130], [108, 131], [108, 134], [108, 137], [109, 122], [109, 132], [109, 134], [109, 135], [109, 139], [110, 112], [110, 117], [110, 118], [110, 122], [110, 126], [110, 127], [110, 128], [110, 129], [110, 130], [110, 131], [110, 133], [110, 137], [110, 138], [111, 113], [111, 115], [111, 116], [111, 123], [111, 128], [111, 132], [111, 134], [111, 135], [111, 136], [111, 139], [112, 114], [112, 119], [112, 123], [112, 125], [112, 130], [112, 135], [112, 137], [112, 138], [113, 121], [113, 123], [113, 125], [113, 126], [113, 127], [113, 129], [113, 130], [113, 135], [113, 136], [114, 115], [114, 122], [114, 127], [114, 130], [114, 133], [114, 138], [114, 139], [115, 119], [115, 121], [115, 122], [115, 129], [115, 133], [116, 117], [116, 118], [116, 119], [116, 128], [116, 133], [116, 134], [116, 136], [116, 137], [116, 138], [117, 118], [117, 119], [117, 120], [117, 122], [117, 132], [117, 134], [117, 135], [117, 136], [118, 132], [118, 133], [118, 136], [118, 139], [119, 120], [119, 123], [119, 124], [119, 133], [119, 135], [119, 138], [119, 139], [120, 121], [120, 123], [120, 124], [120, 129], [120, 130], [120, 134], [121, 122], [121, 126], [121, 133], [121, 134], [121, 137], [121, 139], [122, 125], [122, 129], [122, 132], [122, 135], [122, 136], [123, 125], [123, 126], [123, 128], [123, 131], [123, 132], [124, 127], [124, 129], [124, 131], [124, 132], [124, 135], [124, 137], [125, 129], [125, 131], [125, 137], [126, 127], [126, 130], [126, 131], [126, 133], [127, 128], [127, 132], [127, 133], [127, 139], [128, 130], [128, 135], [128, 137], [129, 132], [129, 138], [130, 132], [130, 134], [131, 134], [131, 135], [131, 137], [133, 138], [135, 138], [135, 139], [136, 139]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s7/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s7/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s9/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s9/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ddf0cc8fb2298e9bbeaf1b013b19706fe611a85 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 10], [0, 14], [0, 21], [0, 24], [0, 26], [0, 27], [0, 33], [0, 34], [0, 44], [0, 50], [0, 55], [0, 56], [0, 57], [0, 65], [0, 66], [0, 69], [0, 70], [0, 71], [0, 76], [0, 81], [0, 88], [0, 93], [0, 95], [0, 96], [0, 102], [0, 103], [0, 104], [0, 106], [0, 107], [0, 109], [0, 113], [0, 115], [0, 116], [0, 122], [0, 123], [0, 128], [0, 132], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 22], [1, 27], [1, 28], [1, 30], [1, 31], [1, 41], [1, 42], [1, 45], [1, 55], [1, 64], [1, 66], [1, 70], [1, 71], [1, 74], [1, 83], [1, 84], [1, 85], [1, 91], [1, 95], [1, 98], [1, 104], [1, 107], [1, 111], [1, 113], [1, 114], [1, 118], [1, 123], [1, 125], [1, 128], [1, 129], [1, 132], [1, 136], [2, 3], [2, 4], [2, 9], [2, 10], [2, 15], [2, 19], [2, 29], [2, 31], [2, 32], [2, 34], [2, 36], [2, 47], [2, 52], [2, 53], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 63], [2, 64], [2, 65], [2, 74], [2, 78], [2, 91], [2, 95], [2, 96], [2, 102], [2, 105], [2, 106], [2, 108], [2, 109], [2, 111], [2, 114], [2, 115], [2, 117], [2, 122], [2, 125], [2, 126], [2, 129], [2, 135], [2, 139], [3, 4], [3, 9], [3, 11], [3, 15], [3, 17], [3, 20], [3, 24], [3, 30], [3, 33], [3, 34], [3, 41], [3, 42], [3, 44], [3, 46], [3, 48], [3, 49], [3, 52], [3, 54], [3, 59], [3, 67], [3, 68], [3, 72], [3, 85], [3, 92], [3, 99], [3, 101], [3, 107], [3, 111], [3, 113], [3, 115], [3, 116], [3, 117], [3, 119], [3, 120], [3, 122], [3, 125], [3, 126], [3, 127], [3, 134], [3, 135], [3, 138], [3, 139], [4, 10], [4, 11], [4, 13], [4, 14], [4, 15], [4, 19], [4, 20], [4, 21], [4, 25], [4, 30], [4, 34], [4, 35], [4, 36], [4, 38], [4, 42], [4, 44], [4, 51], [4, 52], [4, 54], [4, 56], [4, 61], [4, 68], [4, 69], [4, 73], [4, 78], [4, 79], [4, 87], [4, 90], [4, 91], [4, 97], [4, 99], [4, 100], [4, 101], [4, 102], [4, 108], [4, 114], [4, 121], [4, 128], [4, 130], [4, 132], [4, 135], [5, 14], [5, 18], [5, 20], [5, 26], [5, 30], [5, 31], [5, 35], [5, 44], [5, 48], [5, 52], [5, 62], [5, 64], [5, 69], [5, 70], [5, 72], [5, 77], [5, 81], [5, 86], [5, 90], [5, 92], [5, 94], [5, 96], [5, 97], [5, 98], [5, 99], [5, 109], [5, 110], [5, 113], [5, 114], [5, 122], [5, 123], [5, 126], [5, 127], [5, 132], [5, 133], [5, 137], [5, 139], [6, 7], [6, 8], [6, 9], [6, 13], [6, 18], [6, 23], [6, 24], [6, 30], [6, 32], [6, 33], [6, 36], [6, 50], [6, 51], [6, 55], [6, 57], [6, 66], [6, 70], [6, 77], [6, 78], [6, 82], [6, 86], [6, 91], [6, 92], [6, 93], [6, 96], [6, 99], [6, 106], [6, 109], [6, 110], [6, 112], [6, 115], [6, 117], [6, 119], [6, 121], [6, 123], [6, 128], [6, 132], [6, 134], [6, 138], [6, 139], [7, 21], [7, 22], [7, 24], [7, 26], [7, 28], [7, 34], [7, 35], [7, 36], [7, 37], [7, 43], [7, 44], [7, 54], [7, 58], [7, 63], [7, 69], [7, 70], [7, 72], [7, 77], [7, 81], [7, 83], [7, 90], [7, 94], [7, 96], [7, 97], [7, 99], [7, 101], [7, 103], [7, 105], [7, 108], [7, 111], [7, 114], [7, 124], [7, 125], [7, 126], [7, 127], [7, 129], [7, 131], [7, 136], [8, 11], [8, 12], [8, 13], [8, 17], [8, 18], [8, 21], [8, 23], [8, 30], [8, 34], [8, 37], [8, 38], [8, 40], [8, 43], [8, 45], [8, 46], [8, 52], [8, 54], [8, 56], [8, 57], [8, 59], [8, 60], [8, 61], [8, 65], [8, 71], [8, 72], [8, 75], [8, 77], [8, 82], [8, 83], [8, 84], [8, 85], [8, 86], [8, 90], [8, 92], [8, 93], [8, 97], [8, 99], [8, 105], [8, 107], [8, 110], [8, 111], [8, 112], [8, 114], [8, 115], [8, 116], [8, 122], [8, 123], [8, 125], [8, 127], [8, 130], [8, 139], [9, 11], [9, 15], [9, 17], [9, 22], [9, 27], [9, 34], [9, 38], [9, 41], [9, 49], [9, 59], [9, 62], [9, 64], [9, 65], [9, 68], [9, 69], [9, 73], [9, 78], [9, 79], [9, 83], [9, 89], [9, 95], [9, 100], [9, 101], [9, 105], [9, 108], [9, 111], [9, 116], [9, 119], [9, 123], [9, 125], [9, 127], [9, 132], [10, 11], [10, 13], [10, 16], [10, 17], [10, 23], [10, 24], [10, 32], [10, 33], [10, 35], [10, 38], [10, 42], [10, 47], [10, 48], [10, 52], [10, 56], [10, 57], [10, 59], [10, 60], [10, 61], [10, 73], [10, 82], [10, 84], [10, 85], [10, 86], [10, 89], [10, 90], [10, 92], [10, 93], [10, 101], [10, 102], [10, 103], [10, 109], [10, 111], [10, 112], [10, 113], [10, 115], [10, 117], [10, 122], [10, 124], [10, 127], [10, 134], [10, 136], [11, 12], [11, 15], [11, 23], [11, 24], [11, 29], [11, 31], [11, 32], [11, 34], [11, 38], [11, 42], [11, 45], [11, 50], [11, 51], [11, 53], [11, 55], [11, 57], [11, 63], [11, 65], [11, 71], [11, 72], [11, 74], [11, 76], [11, 77], [11, 78], [11, 79], [11, 82], [11, 85], [11, 86], [11, 88], [11, 90], [11, 91], [11, 94], [11, 103], [11, 111], [11, 124], [11, 125], [11, 127], [11, 128], [11, 132], [11, 133], [11, 137], [12, 14], [12, 23], [12, 25], [12, 28], [12, 29], [12, 38], [12, 42], [12, 56], [12, 59], [12, 60], [12, 64], [12, 66], [12, 67], [12, 69], [12, 78], [12, 79], [12, 84], [12, 86], [12, 92], [12, 96], [12, 98], [12, 99], [12, 101], [12, 108], [12, 110], [12, 115], [12, 119], [12, 122], [12, 124], [12, 130], [12, 132], [12, 134], [12, 136], [12, 138], [13, 14], [13, 19], [13, 23], [13, 24], [13, 30], [13, 31], [13, 35], [13, 39], [13, 40], [13, 41], [13, 43], [13, 55], [13, 57], [13, 61], [13, 63], [13, 68], [13, 71], [13, 74], [13, 76], [13, 83], [13, 86], [13, 89], [13, 90], [13, 91], [13, 94], [13, 100], [13, 106], [13, 108], [13, 112], [13, 113], [13, 124], [13, 127], [13, 129], [13, 130], [13, 131], [13, 133], [14, 16], [14, 26], [14, 29], [14, 34], [14, 35], [14, 41], [14, 49], [14, 50], [14, 51], [14, 53], [14, 54], [14, 58], [14, 60], [14, 65], [14, 67], [14, 68], [14, 69], [14, 71], [14, 82], [14, 87], [14, 89], [14, 92], [14, 93], [14, 95], [14, 98], [14, 100], [14, 104], [14, 106], [14, 108], [14, 109], [14, 112], [14, 115], [14, 116], [14, 118], [14, 120], [14, 127], [14, 132], [14, 136], [15, 18], [15, 20], [15, 22], [15, 23], [15, 26], [15, 33], [15, 34], [15, 37], [15, 40], [15, 42], [15, 43], [15, 51], [15, 54], [15, 55], [15, 56], [15, 63], [15, 71], [15, 76], [15, 80], [15, 82], [15, 83], [15, 89], [15, 92], [15, 99], [15, 102], [15, 105], [15, 107], [15, 111], [15, 112], [15, 118], [15, 131], [15, 134], [15, 136], [15, 138], [16, 21], [16, 22], [16, 24], [16, 29], [16, 31], [16, 34], [16, 35], [16, 37], [16, 38], [16, 43], [16, 44], [16, 45], [16, 49], [16, 53], [16, 61], [16, 62], [16, 66], [16, 67], [16, 70], [16, 72], [16, 74], [16, 75], [16, 82], [16, 86], [16, 87], [16, 88], [16, 91], [16, 94], [16, 101], [16, 108], [16, 109], [16, 116], [16, 118], [16, 119], [16, 125], [16, 128], [16, 130], [16, 132], [17, 20], [17, 21], [17, 23], [17, 26], [17, 31], [17, 34], [17, 36], [17, 37], [17, 38], [17, 39], [17, 41], [17, 43], [17, 44], [17, 45], [17, 48], [17, 52], [17, 53], [17, 57], [17, 59], [17, 60], [17, 61], [17, 65], [17, 68], [17, 69], [17, 76], [17, 77], [17, 80], [17, 81], [17, 87], [17, 93], [17, 101], [17, 106], [17, 112], [17, 117], [17, 118], [17, 120], [17, 125], [17, 130], [17, 132], [17, 135], [18, 19], [18, 20], [18, 21], [18, 22], [18, 25], [18, 31], [18, 32], [18, 33], [18, 36], [18, 38], [18, 41], [18, 42], [18, 46], [18, 48], [18, 53], [18, 56], [18, 59], [18, 61], [18, 62], [18, 68], [18, 69], [18, 71], [18, 74], [18, 78], [18, 81], [18, 83], [18, 92], [18, 93], [18, 95], [18, 100], [18, 101], [18, 102], [18, 105], [18, 106], [18, 107], [18, 109], [18, 114], [18, 117], [18, 120], [18, 128], [18, 129], [18, 132], [18, 134], [18, 135], [19, 22], [19, 26], [19, 34], [19, 38], [19, 51], [19, 58], [19, 65], [19, 68], [19, 71], [19, 76], [19, 79], [19, 80], [19, 83], [19, 84], [19, 87], [19, 95], [19, 96], [19, 99], [19, 104], [19, 108], [19, 111], [19, 112], [19, 116], [19, 117], [19, 125], [19, 130], [19, 131], [19, 133], [19, 135], [19, 138], [20, 26], [20, 27], [20, 28], [20, 31], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [20, 39], [20, 41], [20, 45], [20, 48], [20, 49], [20, 54], [20, 57], [20, 59], [20, 60], [20, 64], [20, 65], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 74], [20, 80], [20, 85], [20, 88], [20, 89], [20, 90], [20, 95], [20, 96], [20, 100], [20, 101], [20, 107], [20, 110], [20, 114], [20, 115], [20, 116], [20, 128], [20, 134], [20, 137], [21, 25], [21, 28], [21, 33], [21, 38], [21, 42], [21, 43], [21, 48], [21, 51], [21, 52], [21, 56], [21, 62], [21, 64], [21, 67], [21, 68], [21, 76], [21, 78], [21, 86], [21, 87], [21, 88], [21, 89], [21, 90], [21, 98], [21, 100], [21, 105], [21, 106], [21, 110], [21, 113], [21, 116], [21, 118], [21, 124], [21, 125], [21, 126], [22, 31], [22, 32], [22, 33], [22, 35], [22, 36], [22, 41], [22, 42], [22, 45], [22, 46], [22, 47], [22, 49], [22, 50], [22, 55], [22, 56], [22, 59], [22, 60], [22, 66], [22, 67], [22, 73], [22, 77], [22, 78], [22, 79], [22, 80], [22, 85], [22, 86], [22, 89], [22, 90], [22, 92], [22, 94], [22, 106], [22, 109], [22, 113], [22, 115], [22, 116], [22, 117], [22, 126], [22, 129], [22, 133], [22, 134], [22, 137], [22, 139], [23, 27], [23, 29], [23, 31], [23, 33], [23, 37], [23, 40], [23, 46], [23, 55], [23, 56], [23, 60], [23, 62], [23, 69], [23, 74], [23, 76], [23, 77], [23, 79], [23, 80], [23, 82], [23, 85], [23, 87], [23, 91], [23, 93], [23, 98], [23, 99], [23, 100], [23, 103], [23, 105], [23, 106], [23, 107], [23, 112], [23, 113], [23, 114], [23, 119], [23, 120], [23, 121], [23, 122], [23, 126], [23, 132], [23, 133], [23, 135], [23, 136], [23, 139], [24, 28], [24, 29], [24, 36], [24, 37], [24, 39], [24, 41], [24, 45], [24, 49], [24, 52], [24, 59], [24, 66], [24, 72], [24, 78], [24, 84], [24, 89], [24, 92], [24, 93], [24, 95], [24, 103], [24, 104], [24, 105], [24, 110], [24, 112], [24, 116], [24, 121], [24, 127], [24, 128], [25, 26], [25, 27], [25, 28], [25, 30], [25, 35], [25, 42], [25, 47], [25, 49], [25, 52], [25, 53], [25, 58], [25, 62], [25, 69], [25, 70], [25, 75], [25, 77], [25, 91], [25, 92], [25, 93], [25, 97], [25, 98], [25, 100], [25, 104], [25, 111], [25, 112], [25, 118], [25, 124], [25, 132], [25, 135], [26, 27], [26, 34], [26, 36], [26, 37], [26, 41], [26, 45], [26, 46], [26, 47], [26, 52], [26, 58], [26, 61], [26, 62], [26, 67], [26, 68], [26, 71], [26, 78], [26, 79], [26, 81], [26, 85], [26, 87], [26, 90], [26, 93], [26, 94], [26, 95], [26, 96], [26, 97], [26, 100], [26, 101], [26, 102], [26, 105], [26, 108], [26, 111], [26, 113], [26, 114], [26, 116], [26, 118], [26, 119], [26, 123], [26, 130], [26, 131], [26, 133], [26, 137], [27, 30], [27, 38], [27, 39], [27, 41], [27, 42], [27, 51], [27, 56], [27, 57], [27, 60], [27, 61], [27, 62], [27, 64], [27, 66], [27, 68], [27, 75], [27, 79], [27, 83], [27, 85], [27, 86], [27, 88], [27, 89], [27, 91], [27, 97], [27, 104], [27, 107], [27, 110], [27, 117], [27, 119], [27, 124], [27, 126], [27, 131], [27, 133], [27, 136], [27, 138], [28, 31], [28, 36], [28, 39], [28, 42], [28, 47], [28, 49], [28, 52], [28, 57], [28, 59], [28, 61], [28, 64], [28, 65], [28, 66], [28, 68], [28, 69], [28, 74], [28, 80], [28, 84], [28, 91], [28, 92], [28, 93], [28, 94], [28, 96], [28, 98], [28, 100], [28, 102], [28, 103], [28, 112], [28, 129], [28, 134], [28, 137], [29, 35], [29, 36], [29, 40], [29, 43], [29, 44], [29, 47], [29, 48], [29, 49], [29, 53], [29, 60], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 70], [29, 76], [29, 78], [29, 91], [29, 97], [29, 109], [29, 110], [29, 112], [29, 113], [29, 119], [29, 120], [29, 122], [29, 123], [29, 127], [29, 129], [29, 133], [29, 136], [30, 39], [30, 41], [30, 47], [30, 52], [30, 55], [30, 56], [30, 57], [30, 61], [30, 67], [30, 68], [30, 69], [30, 71], [30, 74], [30, 76], [30, 86], [30, 92], [30, 97], [30, 98], [30, 99], [30, 100], [30, 102], [30, 103], [30, 106], [30, 107], [30, 108], [30, 113], [30, 117], [30, 118], [30, 122], [30, 123], [30, 125], [30, 128], [30, 133], [30, 137], [31, 32], [31, 34], [31, 35], [31, 37], [31, 40], [31, 42], [31, 47], [31, 48], [31, 49], [31, 51], [31, 57], [31, 59], [31, 61], [31, 62], [31, 65], [31, 68], [31, 73], [31, 74], [31, 76], [31, 79], [31, 80], [31, 83], [31, 85], [31, 86], [31, 95], [31, 100], [31, 112], [31, 113], [31, 114], [31, 115], [31, 118], [31, 125], [31, 134], [31, 139], [32, 33], [32, 36], [32, 37], [32, 39], [32, 40], [32, 42], [32, 48], [32, 66], [32, 70], [32, 71], [32, 73], [32, 80], [32, 82], [32, 90], [32, 91], [32, 92], [32, 95], [32, 98], [32, 99], [32, 100], [32, 101], [32, 102], [32, 105], [32, 109], [32, 115], [32, 117], [32, 119], [32, 121], [32, 122], [32, 123], [32, 127], [32, 128], [32, 129], [32, 130], [32, 136], [33, 34], [33, 37], [33, 39], [33, 42], [33, 43], [33, 48], [33, 51], [33, 52], [33, 54], [33, 55], [33, 56], [33, 57], [33, 58], [33, 63], [33, 66], [33, 67], [33, 75], [33, 80], [33, 81], [33, 86], [33, 89], [33, 92], [33, 93], [33, 95], [33, 97], [33, 99], [33, 100], [33, 101], [33, 110], [33, 111], [33, 116], [33, 119], [33, 124], [33, 130], [33, 132], [33, 133], [33, 135], [33, 136], [33, 137], [33, 138], [34, 37], [34, 38], [34, 40], [34, 41], [34, 43], [34, 48], [34, 54], [34, 58], [34, 62], [34, 64], [34, 71], [34, 81], [34, 83], [34, 95], [34, 96], [34, 97], [34, 99], [34, 100], [34, 102], [34, 108], [34, 109], [34, 110], [34, 115], [34, 117], [34, 122], [34, 124], [34, 126], [34, 134], [35, 38], [35, 42], [35, 43], [35, 45], [35, 48], [35, 49], [35, 50], [35, 58], [35, 61], [35, 62], [35, 65], [35, 66], [35, 68], [35, 69], [35, 70], [35, 72], [35, 73], [35, 74], [35, 75], [35, 78], [35, 85], [35, 88], [35, 89], [35, 91], [35, 97], [35, 98], [35, 104], [35, 108], [35, 112], [35, 113], [35, 116], [35, 117], [35, 121], [35, 126], [35, 127], [35, 132], [35, 134], [35, 137], [35, 139], [36, 38], [36, 39], [36, 40], [36, 41], [36, 49], [36, 52], [36, 54], [36, 58], [36, 59], [36, 65], [36, 66], [36, 70], [36, 72], [36, 77], [36, 81], [36, 84], [36, 88], [36, 89], [36, 91], [36, 92], [36, 96], [36, 97], [36, 101], [36, 103], [36, 104], [36, 109], [36, 111], [36, 113], [36, 114], [36, 118], [36, 124], [36, 128], [36, 130], [36, 133], [36, 134], [36, 135], [36, 136], [37, 40], [37, 44], [37, 45], [37, 48], [37, 49], [37, 59], [37, 61], [37, 62], [37, 65], [37, 69], [37, 72], [37, 73], [37, 80], [37, 81], [37, 83], [37, 88], [37, 90], [37, 93], [37, 96], [37, 97], [37, 100], [37, 101], [37, 104], [37, 106], [37, 108], [37, 111], [37, 118], [37, 125], [37, 128], [37, 130], [37, 132], [37, 134], [37, 135], [38, 39], [38, 41], [38, 47], [38, 49], [38, 50], [38, 51], [38, 53], [38, 56], [38, 58], [38, 62], [38, 69], [38, 70], [38, 74], [38, 75], [38, 78], [38, 85], [38, 86], [38, 94], [38, 97], [38, 101], [38, 103], [38, 107], [38, 108], [38, 110], [38, 111], [38, 114], [38, 116], [38, 121], [38, 123], [38, 127], [38, 132], [38, 133], [38, 134], [38, 135], [38, 136], [38, 137], [39, 52], [39, 59], [39, 61], [39, 63], [39, 67], [39, 69], [39, 71], [39, 72], [39, 73], [39, 76], [39, 77], [39, 79], [39, 84], [39, 85], [39, 90], [39, 95], [39, 97], [39, 98], [39, 102], [39, 105], [39, 106], [39, 119], [39, 123], [39, 128], [39, 131], [39, 132], [39, 134], [39, 138], [39, 139], [40, 42], [40, 47], [40, 48], [40, 49], [40, 53], [40, 59], [40, 61], [40, 63], [40, 66], [40, 70], [40, 74], [40, 78], [40, 80], [40, 83], [40, 90], [40, 94], [40, 96], [40, 101], [40, 103], [40, 105], [40, 111], [40, 112], [40, 116], [40, 117], [40, 118], [40, 126], [40, 137], [40, 139], [41, 42], [41, 43], [41, 47], [41, 54], [41, 56], [41, 66], [41, 67], [41, 69], [41, 70], [41, 73], [41, 75], [41, 77], [41, 79], [41, 80], [41, 81], [41, 82], [41, 92], [41, 94], [41, 96], [41, 101], [41, 104], [41, 107], [41, 109], [41, 119], [41, 121], [41, 125], [41, 126], [41, 130], [41, 136], [42, 43], [42, 47], [42, 51], [42, 52], [42, 57], [42, 59], [42, 61], [42, 63], [42, 64], [42, 75], [42, 92], [42, 93], [42, 103], [42, 110], [42, 113], [42, 119], [42, 121], [42, 124], [42, 126], [42, 127], [42, 128], [42, 129], [42, 131], [42, 132], [42, 133], [43, 44], [43, 51], [43, 55], [43, 60], [43, 61], [43, 64], [43, 65], [43, 69], [43, 76], [43, 84], [43, 92], [43, 93], [43, 96], [43, 106], [43, 107], [43, 111], [43, 112], [43, 113], [43, 117], [43, 120], [43, 123], [43, 125], [43, 127], [43, 138], [43, 139], [44, 45], [44, 51], [44, 54], [44, 55], [44, 56], [44, 57], [44, 59], [44, 61], [44, 64], [44, 68], [44, 69], [44, 71], [44, 72], [44, 73], [44, 74], [44, 78], [44, 82], [44, 85], [44, 89], [44, 92], [44, 94], [44, 95], [44, 103], [44, 105], [44, 106], [44, 107], [44, 116], [44, 122], [44, 125], [44, 126], [44, 127], [44, 128], [44, 130], [44, 132], [45, 52], [45, 54], [45, 58], [45, 62], [45, 63], [45, 65], [45, 66], [45, 69], [45, 70], [45, 81], [45, 88], [45, 91], [45, 103], [45, 108], [45, 109], [45, 120], [45, 122], [45, 130], [45, 131], [45, 134], [45, 138], [45, 139], [46, 51], [46, 55], [46, 56], [46, 57], [46, 60], [46, 62], [46, 66], [46, 68], [46, 76], [46, 77], [46, 78], [46, 79], [46, 80], [46, 84], [46, 93], [46, 95], [46, 99], [46, 103], [46, 104], [46, 105], [46, 112], [46, 118], [46, 120], [46, 125], [46, 131], [46, 138], [47, 50], [47, 52], [47, 53], [47, 58], [47, 62], [47, 65], [47, 69], [47, 71], [47, 79], [47, 80], [47, 89], [47, 92], [47, 93], [47, 94], [47, 98], [47, 99], [47, 100], [47, 102], [47, 114], [47, 115], [47, 118], [47, 120], [47, 124], [47, 126], [47, 133], [47, 135], [47, 139], [48, 51], [48, 53], [48, 55], [48, 56], [48, 57], [48, 64], [48, 65], [48, 67], [48, 73], [48, 80], [48, 82], [48, 98], [48, 99], [48, 101], [48, 108], [48, 110], [48, 117], [48, 120], [48, 123], [48, 124], [48, 125], [48, 136], [48, 138], [48, 139], [49, 52], [49, 54], [49, 60], [49, 61], [49, 62], [49, 66], [49, 74], [49, 77], [49, 82], [49, 92], [49, 94], [49, 95], [49, 97], [49, 103], [49, 107], [49, 116], [49, 117], [49, 120], [49, 123], [49, 124], [49, 126], [49, 127], [49, 128], [49, 129], [49, 130], [49, 132], [50, 51], [50, 54], [50, 58], [50, 64], [50, 65], [50, 67], [50, 69], [50, 71], [50, 73], [50, 76], [50, 77], [50, 81], [50, 83], [50, 87], [50, 92], [50, 97], [50, 98], [50, 102], [50, 107], [50, 109], [50, 114], [50, 120], [50, 121], [50, 129], [50, 130], [50, 131], [50, 137], [51, 53], [51, 57], [51, 61], [51, 68], [51, 72], [51, 75], [51, 77], [51, 81], [51, 86], [51, 90], [51, 91], [51, 93], [51, 94], [51, 95], [51, 97], [51, 98], [51, 99], [51, 104], [51, 107], [51, 109], [51, 110], [51, 128], [51, 129], [51, 132], [51, 133], [51, 138], [52, 54], [52, 55], [52, 58], [52, 61], [52, 65], [52, 67], [52, 68], [52, 69], [52, 71], [52, 73], [52, 88], [52, 97], [52, 100], [52, 104], [52, 106], [52, 108], [52, 109], [52, 110], [52, 112], [52, 113], [52, 116], [52, 117], [52, 124], [52, 127], [52, 132], [52, 135], [52, 137], [52, 138], [53, 54], [53, 59], [53, 63], [53, 67], [53, 70], [53, 72], [53, 73], [53, 77], [53, 83], [53, 87], [53, 88], [53, 91], [53, 93], [53, 95], [53, 100], [53, 101], [53, 117], [53, 125], [53, 128], [53, 133], [53, 135], [54, 56], [54, 57], [54, 61], [54, 62], [54, 66], [54, 70], [54, 72], [54, 74], [54, 78], [54, 79], [54, 82], [54, 87], [54, 90], [54, 94], [54, 96], [54, 100], [54, 106], [54, 109], [54, 114], [54, 120], [54, 121], [54, 124], [54, 125], [54, 127], [54, 129], [54, 130], [54, 132], [54, 137], [55, 58], [55, 61], [55, 62], [55, 65], [55, 66], [55, 68], [55, 70], [55, 74], [55, 78], [55, 79], [55, 85], [55, 86], [55, 89], [55, 90], [55, 92], [55, 97], [55, 99], [55, 101], [55, 103], [55, 105], [55, 109], [55, 112], [55, 121], [55, 125], [55, 135], [55, 136], [55, 137], [55, 139], [56, 59], [56, 61], [56, 62], [56, 64], [56, 66], [56, 68], [56, 72], [56, 73], [56, 77], [56, 80], [56, 82], [56, 83], [56, 85], [56, 87], [56, 93], [56, 95], [56, 96], [56, 99], [56, 100], [56, 104], [56, 105], [56, 110], [56, 111], [56, 112], [56, 120], [56, 121], [56, 129], [56, 134], [56, 137], [57, 59], [57, 60], [57, 61], [57, 66], [57, 74], [57, 77], [57, 87], [57, 88], [57, 89], [57, 96], [57, 98], [57, 99], [57, 103], [57, 105], [57, 109], [57, 110], [57, 113], [57, 115], [57, 117], [57, 121], [57, 123], [57, 128], [57, 137], [58, 64], [58, 66], [58, 76], [58, 81], [58, 85], [58, 91], [58, 101], [58, 102], [58, 103], [58, 104], [58, 110], [58, 114], [58, 115], [58, 123], [58, 124], [58, 125], [58, 127], [59, 60], [59, 66], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [59, 80], [59, 85], [59, 88], [59, 95], [59, 100], [59, 104], [59, 107], [59, 109], [59, 114], [59, 118], [59, 119], [59, 120], [59, 126], [59, 129], [59, 130], [59, 131], [59, 137], [60, 63], [60, 66], [60, 69], [60, 71], [60, 77], [60, 78], [60, 79], [60, 83], [60, 84], [60, 85], [60, 90], [60, 92], [60, 95], [60, 99], [60, 104], [60, 111], [60, 115], [60, 122], [60, 127], [60, 130], [60, 135], [61, 64], [61, 80], [61, 82], [61, 83], [61, 89], [61, 95], [61, 99], [61, 100], [61, 102], [61, 104], [61, 106], [61, 111], [61, 114], [61, 118], [61, 122], [61, 126], [61, 128], [61, 129], [61, 130], [61, 133], [61, 134], [61, 138], [62, 63], [62, 67], [62, 68], [62, 75], [62, 78], [62, 84], [62, 91], [62, 94], [62, 98], [62, 100], [62, 108], [62, 112], [62, 114], [62, 115], [62, 116], [62, 120], [62, 125], [62, 132], [62, 133], [62, 134], [63, 64], [63, 78], [63, 85], [63, 86], [63, 87], [63, 96], [63, 98], [63, 101], [63, 106], [63, 116], [63, 118], [63, 120], [63, 121], [63, 126], [63, 129], [64, 65], [64, 66], [64, 67], [64, 71], [64, 72], [64, 76], [64, 84], [64, 88], [64, 89], [64, 90], [64, 93], [64, 94], [64, 102], [64, 103], [64, 104], [64, 105], [64, 106], [64, 107], [64, 110], [64, 116], [64, 118], [64, 119], [64, 120], [64, 121], [64, 123], [64, 127], [64, 128], [64, 132], [64, 134], [64, 139], [65, 71], [65, 78], [65, 82], [65, 85], [65, 86], [65, 87], [65, 91], [65, 93], [65, 97], [65, 99], [65, 101], [65, 103], [65, 105], [65, 106], [65, 115], [65, 116], [65, 118], [65, 119], [65, 120], [65, 123], [65, 125], [65, 128], [65, 129], [65, 133], [65, 135], [65, 136], [66, 71], [66, 74], [66, 78], [66, 83], [66, 89], [66, 90], [66, 91], [66, 100], [66, 101], [66, 106], [66, 108], [66, 112], [66, 116], [66, 124], [66, 125], [66, 128], [66, 132], [66, 134], [66, 136], [66, 139], [67, 73], [67, 75], [67, 77], [67, 79], [67, 80], [67, 87], [67, 89], [67, 91], [67, 92], [67, 94], [67, 96], [67, 98], [67, 99], [67, 100], [67, 112], [67, 118], [67, 123], [67, 129], [67, 134], [67, 136], [67, 139], [68, 75], [68, 77], [68, 92], [68, 96], [68, 102], [68, 106], [68, 108], [68, 109], [68, 110], [68, 111], [68, 114], [68, 116], [68, 118], [68, 119], [68, 120], [68, 127], [68, 130], [68, 131], [68, 132], [68, 134], [68, 135], [69, 73], [69, 74], [69, 77], [69, 78], [69, 89], [69, 93], [69, 100], [69, 105], [69, 106], [69, 109], [69, 112], [69, 118], [69, 120], [69, 124], [69, 127], [69, 138], [69, 139], [70, 71], [70, 72], [70, 73], [70, 76], [70, 77], [70, 81], [70, 83], [70, 87], [70, 90], [70, 93], [70, 99], [70, 100], [70, 101], [70, 106], [70, 108], [70, 109], [70, 113], [70, 114], [70, 115], [70, 125], [70, 131], [70, 132], [71, 73], [71, 76], [71, 77], [71, 85], [71, 86], [71, 87], [71, 89], [71, 93], [71, 102], [71, 104], [71, 105], [71, 112], [71, 114], [71, 127], [71, 132], [71, 135], [72, 75], [72, 76], [72, 77], [72, 85], [72, 98], [72, 99], [72, 104], [72, 110], [72, 115], [72, 116], [72, 118], [72, 119], [72, 120], [72, 134], [72, 137], [72, 138], [72, 139], [73, 74], [73, 76], [73, 85], [73, 86], [73, 87], [73, 90], [73, 91], [73, 92], [73, 93], [73, 96], [73, 99], [73, 100], [73, 101], [73, 103], [73, 105], [73, 107], [73, 112], [73, 113], [73, 114], [73, 116], [73, 123], [73, 124], [73, 127], [73, 128], [73, 130], [73, 131], [74, 77], [74, 78], [74, 79], [74, 80], [74, 82], [74, 84], [74, 85], [74, 87], [74, 88], [74, 95], [74, 100], [74, 105], [74, 106], [74, 108], [74, 110], [74, 114], [74, 118], [74, 128], [74, 129], [74, 130], [74, 131], [74, 136], [74, 138], [74, 139], [75, 84], [75, 94], [75, 95], [75, 102], [75, 104], [75, 105], [75, 116], [75, 119], [75, 123], [75, 127], [75, 130], [75, 134], [76, 78], [76, 81], [76, 86], [76, 89], [76, 93], [76, 94], [76, 97], [76, 105], [76, 108], [76, 109], [76, 110], [76, 114], [76, 119], [76, 122], [76, 123], [76, 126], [76, 129], [76, 133], [76, 136], [76, 137], [77, 78], [77, 81], [77, 83], [77, 86], [77, 88], [77, 93], [77, 95], [77, 99], [77, 109], [77, 110], [77, 116], [77, 121], [77, 122], [77, 123], [77, 127], [77, 130], [77, 132], [78, 80], [78, 82], [78, 83], [78, 85], [78, 86], [78, 87], [78, 91], [78, 94], [78, 102], [78, 104], [78, 105], [78, 106], [78, 109], [78, 116], [78, 118], [78, 119], [78, 125], [78, 126], [78, 128], [78, 137], [78, 138], [78, 139], [79, 89], [79, 95], [79, 96], [79, 99], [79, 101], [79, 102], [79, 112], [79, 115], [79, 117], [79, 118], [79, 124], [79, 125], [79, 130], [79, 131], [79, 138], [80, 82], [80, 84], [80, 86], [80, 88], [80, 92], [80, 94], [80, 97], [80, 103], [80, 107], [80, 109], [80, 117], [80, 123], [80, 125], [80, 128], [80, 131], [80, 133], [80, 136], [80, 138], [80, 139], [81, 85], [81, 87], [81, 92], [81, 94], [81, 105], [81, 109], [81, 110], [81, 111], [81, 112], [81, 113], [81, 115], [81, 118], [81, 123], [81, 130], [81, 131], [81, 132], [81, 133], [81, 136], [81, 138], [82, 88], [82, 94], [82, 98], [82, 112], [82, 114], [82, 115], [82, 117], [82, 118], [82, 119], [82, 123], [82, 129], [82, 131], [82, 138], [83, 87], [83, 93], [83, 95], [83, 99], [83, 106], [83, 110], [83, 120], [83, 121], [83, 125], [83, 133], [83, 135], [83, 137], [83, 138], [84, 85], [84, 87], [84, 88], [84, 89], [84, 96], [84, 97], [84, 107], [84, 110], [84, 112], [84, 114], [84, 115], [84, 117], [84, 121], [84, 122], [84, 126], [84, 128], [84, 129], [84, 133], [84, 137], [84, 138], [84, 139], [85, 91], [85, 93], [85, 94], [85, 101], [85, 102], [85, 104], [85, 111], [85, 112], [85, 113], [85, 114], [85, 118], [85, 126], [85, 133], [85, 137], [86, 89], [86, 90], [86, 91], [86, 94], [86, 96], [86, 98], [86, 102], [86, 108], [86, 110], [86, 114], [86, 119], [86, 120], [86, 122], [86, 124], [86, 129], [86, 139], [87, 90], [87, 91], [87, 92], [87, 93], [87, 99], [87, 100], [87, 104], [87, 108], [87, 110], [87, 119], [87, 120], [87, 124], [87, 131], [87, 133], [87, 135], [87, 138], [88, 89], [88, 93], [88, 97], [88, 98], [88, 102], [88, 103], [88, 106], [88, 108], [88, 110], [88, 111], [88, 117], [88, 126], [88, 127], [88, 133], [88, 134], [89, 91], [89, 92], [89, 93], [89, 95], [89, 97], [89, 103], [89, 110], [89, 112], [89, 119], [89, 123], [89, 125], [89, 126], [89, 129], [89, 134], [89, 135], [89, 136], [89, 137], [90, 93], [90, 95], [90, 99], [90, 103], [90, 108], [90, 111], [90, 116], [90, 118], [90, 124], [90, 138], [91, 97], [91, 98], [91, 99], [91, 100], [91, 101], [91, 116], [91, 120], [91, 121], [91, 125], [91, 130], [91, 137], [91, 138], [92, 94], [92, 97], [92, 98], [92, 101], [92, 106], [92, 109], [92, 110], [92, 117], [92, 121], [92, 127], [92, 128], [92, 133], [92, 136], [92, 138], [92, 139], [93, 104], [93, 106], [93, 107], [93, 108], [93, 111], [93, 114], [93, 117], [93, 118], [93, 120], [93, 122], [93, 125], [93, 128], [93, 129], [93, 135], [94, 97], [94, 104], [94, 107], [94, 110], [94, 114], [94, 115], [94, 125], [94, 132], [94, 133], [94, 135], [94, 137], [94, 139], [95, 108], [95, 114], [95, 115], [95, 116], [95, 120], [95, 121], [95, 124], [95, 127], [95, 131], [95, 138], [96, 98], [96, 101], [96, 106], [96, 112], [96, 114], [96, 117], [96, 118], [96, 121], [96, 133], [96, 137], [97, 98], [97, 99], [97, 103], [97, 110], [97, 112], [97, 114], [97, 115], [97, 122], [97, 125], [97, 130], [97, 131], [97, 134], [97, 135], [97, 136], [98, 99], [98, 104], [98, 106], [98, 107], [98, 112], [98, 114], [98, 116], [98, 118], [98, 122], [98, 124], [98, 127], [98, 131], [98, 132], [98, 133], [98, 135], [99, 100], [99, 101], [99, 102], [99, 109], [99, 110], [99, 112], [99, 113], [99, 118], [99, 121], [99, 124], [99, 127], [99, 128], [99, 130], [99, 133], [99, 136], [99, 137], [99, 138], [100, 103], [100, 105], [100, 108], [100, 110], [100, 111], [100, 122], [100, 126], [100, 136], [100, 137], [101, 103], [101, 107], [101, 109], [101, 111], [101, 112], [101, 120], [101, 137], [101, 139], [102, 105], [102, 106], [102, 108], [102, 111], [102, 115], [102, 117], [102, 118], [102, 119], [102, 123], [102, 125], [102, 126], [102, 136], [102, 139], [103, 104], [103, 106], [103, 113], [103, 114], [103, 122], [103, 125], [103, 129], [103, 130], [103, 133], [103, 134], [103, 136], [103, 137], [104, 106], [104, 108], [104, 116], [104, 119], [104, 126], [104, 127], [104, 128], [104, 131], [104, 132], [104, 133], [104, 135], [104, 137], [104, 138], [105, 107], [105, 109], [105, 111], [105, 115], [105, 117], [105, 121], [105, 123], [105, 135], [105, 136], [105, 138], [106, 108], [106, 110], [106, 111], [106, 120], [106, 122], [106, 124], [106, 127], [106, 130], [106, 134], [106, 138], [107, 108], [107, 112], [107, 113], [107, 114], [107, 120], [107, 121], [107, 128], [107, 130], [107, 135], [108, 114], [108, 115], [108, 116], [108, 117], [108, 118], [108, 123], [108, 124], [108, 127], [108, 132], [108, 134], [108, 135], [108, 136], [108, 139], [109, 115], [109, 119], [109, 123], [109, 125], [109, 127], [109, 131], [109, 132], [109, 134], [110, 111], [110, 113], [110, 115], [110, 119], [110, 120], [110, 121], [110, 123], [110, 128], [110, 129], [110, 130], [110, 132], [110, 133], [110, 134], [110, 135], [110, 136], [111, 116], [111, 117], [111, 120], [111, 125], [111, 131], [111, 138], [112, 117], [112, 118], [112, 124], [112, 126], [112, 127], [112, 129], [112, 130], [112, 132], [112, 133], [112, 134], [112, 135], [112, 139], [113, 114], [113, 121], [113, 123], [113, 129], [113, 139], [114, 115], [114, 120], [114, 125], [114, 129], [114, 135], [114, 136], [114, 137], [115, 116], [115, 119], [115, 124], [115, 127], [115, 128], [115, 138], [115, 139], [116, 120], [116, 121], [116, 124], [116, 126], [116, 128], [116, 132], [116, 136], [117, 119], [117, 122], [117, 123], [117, 124], [117, 128], [117, 139], [118, 120], [118, 121], [118, 122], [118, 123], [118, 125], [118, 129], [118, 130], [118, 131], [118, 132], [119, 120], [119, 129], [119, 132], [119, 133], [119, 135], [119, 139], [120, 121], [120, 123], [120, 124], [120, 125], [120, 131], [120, 137], [121, 122], [121, 125], [121, 129], [121, 133], [121, 136], [121, 138], [122, 134], [123, 124], [123, 125], [123, 126], [123, 129], [123, 130], [123, 132], [123, 136], [123, 137], [124, 127], [124, 132], [124, 133], [124, 135], [125, 126], [125, 131], [125, 135], [126, 128], [126, 130], [127, 136], [128, 129], [128, 134], [128, 139], [129, 130], [129, 131], [129, 132], [129, 134], [129, 136], [130, 133], [130, 135], [130, 137], [130, 138], [130, 139], [131, 136], [131, 137], [132, 136], [133, 136], [133, 138]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s9/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ca57e417eecb5b105393e77a77671b5668b8971e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [9, 12, 24, 31, 46, 58, 71, 75, 90, 97, 106, 107, 109, 117, 126, 129, 133, 137]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s9/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l6-s9/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ddf0cc8fb2298e9bbeaf1b013b19706fe611a85 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 10], [0, 14], [0, 21], [0, 24], [0, 26], [0, 27], [0, 33], [0, 34], [0, 44], [0, 50], [0, 55], [0, 56], [0, 57], [0, 65], [0, 66], [0, 69], [0, 70], [0, 71], [0, 76], [0, 81], [0, 88], [0, 93], [0, 95], [0, 96], [0, 102], [0, 103], [0, 104], [0, 106], [0, 107], [0, 109], [0, 113], [0, 115], [0, 116], [0, 122], [0, 123], [0, 128], [0, 132], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 22], [1, 27], [1, 28], [1, 30], [1, 31], [1, 41], [1, 42], [1, 45], [1, 55], [1, 64], [1, 66], [1, 70], [1, 71], [1, 74], [1, 83], [1, 84], [1, 85], [1, 91], [1, 95], [1, 98], [1, 104], [1, 107], [1, 111], [1, 113], [1, 114], [1, 118], [1, 123], [1, 125], [1, 128], [1, 129], [1, 132], [1, 136], [2, 3], [2, 4], [2, 9], [2, 10], [2, 15], [2, 19], [2, 29], [2, 31], [2, 32], [2, 34], [2, 36], [2, 47], [2, 52], [2, 53], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 63], [2, 64], [2, 65], [2, 74], [2, 78], [2, 91], [2, 95], [2, 96], [2, 102], [2, 105], [2, 106], [2, 108], [2, 109], [2, 111], [2, 114], [2, 115], [2, 117], [2, 122], [2, 125], [2, 126], [2, 129], [2, 135], [2, 139], [3, 4], [3, 9], [3, 11], [3, 15], [3, 17], [3, 20], [3, 24], [3, 30], [3, 33], [3, 34], [3, 41], [3, 42], [3, 44], [3, 46], [3, 48], [3, 49], [3, 52], [3, 54], [3, 59], [3, 67], [3, 68], [3, 72], [3, 85], [3, 92], [3, 99], [3, 101], [3, 107], [3, 111], [3, 113], [3, 115], [3, 116], [3, 117], [3, 119], [3, 120], [3, 122], [3, 125], [3, 126], [3, 127], [3, 134], [3, 135], [3, 138], [3, 139], [4, 10], [4, 11], [4, 13], [4, 14], [4, 15], [4, 19], [4, 20], [4, 21], [4, 25], [4, 30], [4, 34], [4, 35], [4, 36], [4, 38], [4, 42], [4, 44], [4, 51], [4, 52], [4, 54], [4, 56], [4, 61], [4, 68], [4, 69], [4, 73], [4, 78], [4, 79], [4, 87], [4, 90], [4, 91], [4, 97], [4, 99], [4, 100], [4, 101], [4, 102], [4, 108], [4, 114], [4, 121], [4, 128], [4, 130], [4, 132], [4, 135], [5, 14], [5, 18], [5, 20], [5, 26], [5, 30], [5, 31], [5, 35], [5, 44], [5, 48], [5, 52], [5, 62], [5, 64], [5, 69], [5, 70], [5, 72], [5, 77], [5, 81], [5, 86], [5, 90], [5, 92], [5, 94], [5, 96], [5, 97], [5, 98], [5, 99], [5, 109], [5, 110], [5, 113], [5, 114], [5, 122], [5, 123], [5, 126], [5, 127], [5, 132], [5, 133], [5, 137], [5, 139], [6, 7], [6, 8], [6, 9], [6, 13], [6, 18], [6, 23], [6, 24], [6, 30], [6, 32], [6, 33], [6, 36], [6, 50], [6, 51], [6, 55], [6, 57], [6, 66], [6, 70], [6, 77], [6, 78], [6, 82], [6, 86], [6, 91], [6, 92], [6, 93], [6, 96], [6, 99], [6, 106], [6, 109], [6, 110], [6, 112], [6, 115], [6, 117], [6, 119], [6, 121], [6, 123], [6, 128], [6, 132], [6, 134], [6, 138], [6, 139], [7, 21], [7, 22], [7, 24], [7, 26], [7, 28], [7, 34], [7, 35], [7, 36], [7, 37], [7, 43], [7, 44], [7, 54], [7, 58], [7, 63], [7, 69], [7, 70], [7, 72], [7, 77], [7, 81], [7, 83], [7, 90], [7, 94], [7, 96], [7, 97], [7, 99], [7, 101], [7, 103], [7, 105], [7, 108], [7, 111], [7, 114], [7, 124], [7, 125], [7, 126], [7, 127], [7, 129], [7, 131], [7, 136], [8, 11], [8, 12], [8, 13], [8, 17], [8, 18], [8, 21], [8, 23], [8, 30], [8, 34], [8, 37], [8, 38], [8, 40], [8, 43], [8, 45], [8, 46], [8, 52], [8, 54], [8, 56], [8, 57], [8, 59], [8, 60], [8, 61], [8, 65], [8, 71], [8, 72], [8, 75], [8, 77], [8, 82], [8, 83], [8, 84], [8, 85], [8, 86], [8, 90], [8, 92], [8, 93], [8, 97], [8, 99], [8, 105], [8, 107], [8, 110], [8, 111], [8, 112], [8, 114], [8, 115], [8, 116], [8, 122], [8, 123], [8, 125], [8, 127], [8, 130], [8, 139], [9, 11], [9, 15], [9, 17], [9, 22], [9, 27], [9, 34], [9, 38], [9, 41], [9, 49], [9, 59], [9, 62], [9, 64], [9, 65], [9, 68], [9, 69], [9, 73], [9, 78], [9, 79], [9, 83], [9, 89], [9, 95], [9, 100], [9, 101], [9, 105], [9, 108], [9, 111], [9, 116], [9, 119], [9, 123], [9, 125], [9, 127], [9, 132], [10, 11], [10, 13], [10, 16], [10, 17], [10, 23], [10, 24], [10, 32], [10, 33], [10, 35], [10, 38], [10, 42], [10, 47], [10, 48], [10, 52], [10, 56], [10, 57], [10, 59], [10, 60], [10, 61], [10, 73], [10, 82], [10, 84], [10, 85], [10, 86], [10, 89], [10, 90], [10, 92], [10, 93], [10, 101], [10, 102], [10, 103], [10, 109], [10, 111], [10, 112], [10, 113], [10, 115], [10, 117], [10, 122], [10, 124], [10, 127], [10, 134], [10, 136], [11, 12], [11, 15], [11, 23], [11, 24], [11, 29], [11, 31], [11, 32], [11, 34], [11, 38], [11, 42], [11, 45], [11, 50], [11, 51], [11, 53], [11, 55], [11, 57], [11, 63], [11, 65], [11, 71], [11, 72], [11, 74], [11, 76], [11, 77], [11, 78], [11, 79], [11, 82], [11, 85], [11, 86], [11, 88], [11, 90], [11, 91], [11, 94], [11, 103], [11, 111], [11, 124], [11, 125], [11, 127], [11, 128], [11, 132], [11, 133], [11, 137], [12, 14], [12, 23], [12, 25], [12, 28], [12, 29], [12, 38], [12, 42], [12, 56], [12, 59], [12, 60], [12, 64], [12, 66], [12, 67], [12, 69], [12, 78], [12, 79], [12, 84], [12, 86], [12, 92], [12, 96], [12, 98], [12, 99], [12, 101], [12, 108], [12, 110], [12, 115], [12, 119], [12, 122], [12, 124], [12, 130], [12, 132], [12, 134], [12, 136], [12, 138], [13, 14], [13, 19], [13, 23], [13, 24], [13, 30], [13, 31], [13, 35], [13, 39], [13, 40], [13, 41], [13, 43], [13, 55], [13, 57], [13, 61], [13, 63], [13, 68], [13, 71], [13, 74], [13, 76], [13, 83], [13, 86], [13, 89], [13, 90], [13, 91], [13, 94], [13, 100], [13, 106], [13, 108], [13, 112], [13, 113], [13, 124], [13, 127], [13, 129], [13, 130], [13, 131], [13, 133], [14, 16], [14, 26], [14, 29], [14, 34], [14, 35], [14, 41], [14, 49], [14, 50], [14, 51], [14, 53], [14, 54], [14, 58], [14, 60], [14, 65], [14, 67], [14, 68], [14, 69], [14, 71], [14, 82], [14, 87], [14, 89], [14, 92], [14, 93], [14, 95], [14, 98], [14, 100], [14, 104], [14, 106], [14, 108], [14, 109], [14, 112], [14, 115], [14, 116], [14, 118], [14, 120], [14, 127], [14, 132], [14, 136], [15, 18], [15, 20], [15, 22], [15, 23], [15, 26], [15, 33], [15, 34], [15, 37], [15, 40], [15, 42], [15, 43], [15, 51], [15, 54], [15, 55], [15, 56], [15, 63], [15, 71], [15, 76], [15, 80], [15, 82], [15, 83], [15, 89], [15, 92], [15, 99], [15, 102], [15, 105], [15, 107], [15, 111], [15, 112], [15, 118], [15, 131], [15, 134], [15, 136], [15, 138], [16, 21], [16, 22], [16, 24], [16, 29], [16, 31], [16, 34], [16, 35], [16, 37], [16, 38], [16, 43], [16, 44], [16, 45], [16, 49], [16, 53], [16, 61], [16, 62], [16, 66], [16, 67], [16, 70], [16, 72], [16, 74], [16, 75], [16, 82], [16, 86], [16, 87], [16, 88], [16, 91], [16, 94], [16, 101], [16, 108], [16, 109], [16, 116], [16, 118], [16, 119], [16, 125], [16, 128], [16, 130], [16, 132], [17, 20], [17, 21], [17, 23], [17, 26], [17, 31], [17, 34], [17, 36], [17, 37], [17, 38], [17, 39], [17, 41], [17, 43], [17, 44], [17, 45], [17, 48], [17, 52], [17, 53], [17, 57], [17, 59], [17, 60], [17, 61], [17, 65], [17, 68], [17, 69], [17, 76], [17, 77], [17, 80], [17, 81], [17, 87], [17, 93], [17, 101], [17, 106], [17, 112], [17, 117], [17, 118], [17, 120], [17, 125], [17, 130], [17, 132], [17, 135], [18, 19], [18, 20], [18, 21], [18, 22], [18, 25], [18, 31], [18, 32], [18, 33], [18, 36], [18, 38], [18, 41], [18, 42], [18, 46], [18, 48], [18, 53], [18, 56], [18, 59], [18, 61], [18, 62], [18, 68], [18, 69], [18, 71], [18, 74], [18, 78], [18, 81], [18, 83], [18, 92], [18, 93], [18, 95], [18, 100], [18, 101], [18, 102], [18, 105], [18, 106], [18, 107], [18, 109], [18, 114], [18, 117], [18, 120], [18, 128], [18, 129], [18, 132], [18, 134], [18, 135], [19, 22], [19, 26], [19, 34], [19, 38], [19, 51], [19, 58], [19, 65], [19, 68], [19, 71], [19, 76], [19, 79], [19, 80], [19, 83], [19, 84], [19, 87], [19, 95], [19, 96], [19, 99], [19, 104], [19, 108], [19, 111], [19, 112], [19, 116], [19, 117], [19, 125], [19, 130], [19, 131], [19, 133], [19, 135], [19, 138], [20, 26], [20, 27], [20, 28], [20, 31], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [20, 39], [20, 41], [20, 45], [20, 48], [20, 49], [20, 54], [20, 57], [20, 59], [20, 60], [20, 64], [20, 65], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 74], [20, 80], [20, 85], [20, 88], [20, 89], [20, 90], [20, 95], [20, 96], [20, 100], [20, 101], [20, 107], [20, 110], [20, 114], [20, 115], [20, 116], [20, 128], [20, 134], [20, 137], [21, 25], [21, 28], [21, 33], [21, 38], [21, 42], [21, 43], [21, 48], [21, 51], [21, 52], [21, 56], [21, 62], [21, 64], [21, 67], [21, 68], [21, 76], [21, 78], [21, 86], [21, 87], [21, 88], [21, 89], [21, 90], [21, 98], [21, 100], [21, 105], [21, 106], [21, 110], [21, 113], [21, 116], [21, 118], [21, 124], [21, 125], [21, 126], [22, 31], [22, 32], [22, 33], [22, 35], [22, 36], [22, 41], [22, 42], [22, 45], [22, 46], [22, 47], [22, 49], [22, 50], [22, 55], [22, 56], [22, 59], [22, 60], [22, 66], [22, 67], [22, 73], [22, 77], [22, 78], [22, 79], [22, 80], [22, 85], [22, 86], [22, 89], [22, 90], [22, 92], [22, 94], [22, 106], [22, 109], [22, 113], [22, 115], [22, 116], [22, 117], [22, 126], [22, 129], [22, 133], [22, 134], [22, 137], [22, 139], [23, 27], [23, 29], [23, 31], [23, 33], [23, 37], [23, 40], [23, 46], [23, 55], [23, 56], [23, 60], [23, 62], [23, 69], [23, 74], [23, 76], [23, 77], [23, 79], [23, 80], [23, 82], [23, 85], [23, 87], [23, 91], [23, 93], [23, 98], [23, 99], [23, 100], [23, 103], [23, 105], [23, 106], [23, 107], [23, 112], [23, 113], [23, 114], [23, 119], [23, 120], [23, 121], [23, 122], [23, 126], [23, 132], [23, 133], [23, 135], [23, 136], [23, 139], [24, 28], [24, 29], [24, 36], [24, 37], [24, 39], [24, 41], [24, 45], [24, 49], [24, 52], [24, 59], [24, 66], [24, 72], [24, 78], [24, 84], [24, 89], [24, 92], [24, 93], [24, 95], [24, 103], [24, 104], [24, 105], [24, 110], [24, 112], [24, 116], [24, 121], [24, 127], [24, 128], [25, 26], [25, 27], [25, 28], [25, 30], [25, 35], [25, 42], [25, 47], [25, 49], [25, 52], [25, 53], [25, 58], [25, 62], [25, 69], [25, 70], [25, 75], [25, 77], [25, 91], [25, 92], [25, 93], [25, 97], [25, 98], [25, 100], [25, 104], [25, 111], [25, 112], [25, 118], [25, 124], [25, 132], [25, 135], [26, 27], [26, 34], [26, 36], [26, 37], [26, 41], [26, 45], [26, 46], [26, 47], [26, 52], [26, 58], [26, 61], [26, 62], [26, 67], [26, 68], [26, 71], [26, 78], [26, 79], [26, 81], [26, 85], [26, 87], [26, 90], [26, 93], [26, 94], [26, 95], [26, 96], [26, 97], [26, 100], [26, 101], [26, 102], [26, 105], [26, 108], [26, 111], [26, 113], [26, 114], [26, 116], [26, 118], [26, 119], [26, 123], [26, 130], [26, 131], [26, 133], [26, 137], [27, 30], [27, 38], [27, 39], [27, 41], [27, 42], [27, 51], [27, 56], [27, 57], [27, 60], [27, 61], [27, 62], [27, 64], [27, 66], [27, 68], [27, 75], [27, 79], [27, 83], [27, 85], [27, 86], [27, 88], [27, 89], [27, 91], [27, 97], [27, 104], [27, 107], [27, 110], [27, 117], [27, 119], [27, 124], [27, 126], [27, 131], [27, 133], [27, 136], [27, 138], [28, 31], [28, 36], [28, 39], [28, 42], [28, 47], [28, 49], [28, 52], [28, 57], [28, 59], [28, 61], [28, 64], [28, 65], [28, 66], [28, 68], [28, 69], [28, 74], [28, 80], [28, 84], [28, 91], [28, 92], [28, 93], [28, 94], [28, 96], [28, 98], [28, 100], [28, 102], [28, 103], [28, 112], [28, 129], [28, 134], [28, 137], [29, 35], [29, 36], [29, 40], [29, 43], [29, 44], [29, 47], [29, 48], [29, 49], [29, 53], [29, 60], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 70], [29, 76], [29, 78], [29, 91], [29, 97], [29, 109], [29, 110], [29, 112], [29, 113], [29, 119], [29, 120], [29, 122], [29, 123], [29, 127], [29, 129], [29, 133], [29, 136], [30, 39], [30, 41], [30, 47], [30, 52], [30, 55], [30, 56], [30, 57], [30, 61], [30, 67], [30, 68], [30, 69], [30, 71], [30, 74], [30, 76], [30, 86], [30, 92], [30, 97], [30, 98], [30, 99], [30, 100], [30, 102], [30, 103], [30, 106], [30, 107], [30, 108], [30, 113], [30, 117], [30, 118], [30, 122], [30, 123], [30, 125], [30, 128], [30, 133], [30, 137], [31, 32], [31, 34], [31, 35], [31, 37], [31, 40], [31, 42], [31, 47], [31, 48], [31, 49], [31, 51], [31, 57], [31, 59], [31, 61], [31, 62], [31, 65], [31, 68], [31, 73], [31, 74], [31, 76], [31, 79], [31, 80], [31, 83], [31, 85], [31, 86], [31, 95], [31, 100], [31, 112], [31, 113], [31, 114], [31, 115], [31, 118], [31, 125], [31, 134], [31, 139], [32, 33], [32, 36], [32, 37], [32, 39], [32, 40], [32, 42], [32, 48], [32, 66], [32, 70], [32, 71], [32, 73], [32, 80], [32, 82], [32, 90], [32, 91], [32, 92], [32, 95], [32, 98], [32, 99], [32, 100], [32, 101], [32, 102], [32, 105], [32, 109], [32, 115], [32, 117], [32, 119], [32, 121], [32, 122], [32, 123], [32, 127], [32, 128], [32, 129], [32, 130], [32, 136], [33, 34], [33, 37], [33, 39], [33, 42], [33, 43], [33, 48], [33, 51], [33, 52], [33, 54], [33, 55], [33, 56], [33, 57], [33, 58], [33, 63], [33, 66], [33, 67], [33, 75], [33, 80], [33, 81], [33, 86], [33, 89], [33, 92], [33, 93], [33, 95], [33, 97], [33, 99], [33, 100], [33, 101], [33, 110], [33, 111], [33, 116], [33, 119], [33, 124], [33, 130], [33, 132], [33, 133], [33, 135], [33, 136], [33, 137], [33, 138], [34, 37], [34, 38], [34, 40], [34, 41], [34, 43], [34, 48], [34, 54], [34, 58], [34, 62], [34, 64], [34, 71], [34, 81], [34, 83], [34, 95], [34, 96], [34, 97], [34, 99], [34, 100], [34, 102], [34, 108], [34, 109], [34, 110], [34, 115], [34, 117], [34, 122], [34, 124], [34, 126], [34, 134], [35, 38], [35, 42], [35, 43], [35, 45], [35, 48], [35, 49], [35, 50], [35, 58], [35, 61], [35, 62], [35, 65], [35, 66], [35, 68], [35, 69], [35, 70], [35, 72], [35, 73], [35, 74], [35, 75], [35, 78], [35, 85], [35, 88], [35, 89], [35, 91], [35, 97], [35, 98], [35, 104], [35, 108], [35, 112], [35, 113], [35, 116], [35, 117], [35, 121], [35, 126], [35, 127], [35, 132], [35, 134], [35, 137], [35, 139], [36, 38], [36, 39], [36, 40], [36, 41], [36, 49], [36, 52], [36, 54], [36, 58], [36, 59], [36, 65], [36, 66], [36, 70], [36, 72], [36, 77], [36, 81], [36, 84], [36, 88], [36, 89], [36, 91], [36, 92], [36, 96], [36, 97], [36, 101], [36, 103], [36, 104], [36, 109], [36, 111], [36, 113], [36, 114], [36, 118], [36, 124], [36, 128], [36, 130], [36, 133], [36, 134], [36, 135], [36, 136], [37, 40], [37, 44], [37, 45], [37, 48], [37, 49], [37, 59], [37, 61], [37, 62], [37, 65], [37, 69], [37, 72], [37, 73], [37, 80], [37, 81], [37, 83], [37, 88], [37, 90], [37, 93], [37, 96], [37, 97], [37, 100], [37, 101], [37, 104], [37, 106], [37, 108], [37, 111], [37, 118], [37, 125], [37, 128], [37, 130], [37, 132], [37, 134], [37, 135], [38, 39], [38, 41], [38, 47], [38, 49], [38, 50], [38, 51], [38, 53], [38, 56], [38, 58], [38, 62], [38, 69], [38, 70], [38, 74], [38, 75], [38, 78], [38, 85], [38, 86], [38, 94], [38, 97], [38, 101], [38, 103], [38, 107], [38, 108], [38, 110], [38, 111], [38, 114], [38, 116], [38, 121], [38, 123], [38, 127], [38, 132], [38, 133], [38, 134], [38, 135], [38, 136], [38, 137], [39, 52], [39, 59], [39, 61], [39, 63], [39, 67], [39, 69], [39, 71], [39, 72], [39, 73], [39, 76], [39, 77], [39, 79], [39, 84], [39, 85], [39, 90], [39, 95], [39, 97], [39, 98], [39, 102], [39, 105], [39, 106], [39, 119], [39, 123], [39, 128], [39, 131], [39, 132], [39, 134], [39, 138], [39, 139], [40, 42], [40, 47], [40, 48], [40, 49], [40, 53], [40, 59], [40, 61], [40, 63], [40, 66], [40, 70], [40, 74], [40, 78], [40, 80], [40, 83], [40, 90], [40, 94], [40, 96], [40, 101], [40, 103], [40, 105], [40, 111], [40, 112], [40, 116], [40, 117], [40, 118], [40, 126], [40, 137], [40, 139], [41, 42], [41, 43], [41, 47], [41, 54], [41, 56], [41, 66], [41, 67], [41, 69], [41, 70], [41, 73], [41, 75], [41, 77], [41, 79], [41, 80], [41, 81], [41, 82], [41, 92], [41, 94], [41, 96], [41, 101], [41, 104], [41, 107], [41, 109], [41, 119], [41, 121], [41, 125], [41, 126], [41, 130], [41, 136], [42, 43], [42, 47], [42, 51], [42, 52], [42, 57], [42, 59], [42, 61], [42, 63], [42, 64], [42, 75], [42, 92], [42, 93], [42, 103], [42, 110], [42, 113], [42, 119], [42, 121], [42, 124], [42, 126], [42, 127], [42, 128], [42, 129], [42, 131], [42, 132], [42, 133], [43, 44], [43, 51], [43, 55], [43, 60], [43, 61], [43, 64], [43, 65], [43, 69], [43, 76], [43, 84], [43, 92], [43, 93], [43, 96], [43, 106], [43, 107], [43, 111], [43, 112], [43, 113], [43, 117], [43, 120], [43, 123], [43, 125], [43, 127], [43, 138], [43, 139], [44, 45], [44, 51], [44, 54], [44, 55], [44, 56], [44, 57], [44, 59], [44, 61], [44, 64], [44, 68], [44, 69], [44, 71], [44, 72], [44, 73], [44, 74], [44, 78], [44, 82], [44, 85], [44, 89], [44, 92], [44, 94], [44, 95], [44, 103], [44, 105], [44, 106], [44, 107], [44, 116], [44, 122], [44, 125], [44, 126], [44, 127], [44, 128], [44, 130], [44, 132], [45, 52], [45, 54], [45, 58], [45, 62], [45, 63], [45, 65], [45, 66], [45, 69], [45, 70], [45, 81], [45, 88], [45, 91], [45, 103], [45, 108], [45, 109], [45, 120], [45, 122], [45, 130], [45, 131], [45, 134], [45, 138], [45, 139], [46, 51], [46, 55], [46, 56], [46, 57], [46, 60], [46, 62], [46, 66], [46, 68], [46, 76], [46, 77], [46, 78], [46, 79], [46, 80], [46, 84], [46, 93], [46, 95], [46, 99], [46, 103], [46, 104], [46, 105], [46, 112], [46, 118], [46, 120], [46, 125], [46, 131], [46, 138], [47, 50], [47, 52], [47, 53], [47, 58], [47, 62], [47, 65], [47, 69], [47, 71], [47, 79], [47, 80], [47, 89], [47, 92], [47, 93], [47, 94], [47, 98], [47, 99], [47, 100], [47, 102], [47, 114], [47, 115], [47, 118], [47, 120], [47, 124], [47, 126], [47, 133], [47, 135], [47, 139], [48, 51], [48, 53], [48, 55], [48, 56], [48, 57], [48, 64], [48, 65], [48, 67], [48, 73], [48, 80], [48, 82], [48, 98], [48, 99], [48, 101], [48, 108], [48, 110], [48, 117], [48, 120], [48, 123], [48, 124], [48, 125], [48, 136], [48, 138], [48, 139], [49, 52], [49, 54], [49, 60], [49, 61], [49, 62], [49, 66], [49, 74], [49, 77], [49, 82], [49, 92], [49, 94], [49, 95], [49, 97], [49, 103], [49, 107], [49, 116], [49, 117], [49, 120], [49, 123], [49, 124], [49, 126], [49, 127], [49, 128], [49, 129], [49, 130], [49, 132], [50, 51], [50, 54], [50, 58], [50, 64], [50, 65], [50, 67], [50, 69], [50, 71], [50, 73], [50, 76], [50, 77], [50, 81], [50, 83], [50, 87], [50, 92], [50, 97], [50, 98], [50, 102], [50, 107], [50, 109], [50, 114], [50, 120], [50, 121], [50, 129], [50, 130], [50, 131], [50, 137], [51, 53], [51, 57], [51, 61], [51, 68], [51, 72], [51, 75], [51, 77], [51, 81], [51, 86], [51, 90], [51, 91], [51, 93], [51, 94], [51, 95], [51, 97], [51, 98], [51, 99], [51, 104], [51, 107], [51, 109], [51, 110], [51, 128], [51, 129], [51, 132], [51, 133], [51, 138], [52, 54], [52, 55], [52, 58], [52, 61], [52, 65], [52, 67], [52, 68], [52, 69], [52, 71], [52, 73], [52, 88], [52, 97], [52, 100], [52, 104], [52, 106], [52, 108], [52, 109], [52, 110], [52, 112], [52, 113], [52, 116], [52, 117], [52, 124], [52, 127], [52, 132], [52, 135], [52, 137], [52, 138], [53, 54], [53, 59], [53, 63], [53, 67], [53, 70], [53, 72], [53, 73], [53, 77], [53, 83], [53, 87], [53, 88], [53, 91], [53, 93], [53, 95], [53, 100], [53, 101], [53, 117], [53, 125], [53, 128], [53, 133], [53, 135], [54, 56], [54, 57], [54, 61], [54, 62], [54, 66], [54, 70], [54, 72], [54, 74], [54, 78], [54, 79], [54, 82], [54, 87], [54, 90], [54, 94], [54, 96], [54, 100], [54, 106], [54, 109], [54, 114], [54, 120], [54, 121], [54, 124], [54, 125], [54, 127], [54, 129], [54, 130], [54, 132], [54, 137], [55, 58], [55, 61], [55, 62], [55, 65], [55, 66], [55, 68], [55, 70], [55, 74], [55, 78], [55, 79], [55, 85], [55, 86], [55, 89], [55, 90], [55, 92], [55, 97], [55, 99], [55, 101], [55, 103], [55, 105], [55, 109], [55, 112], [55, 121], [55, 125], [55, 135], [55, 136], [55, 137], [55, 139], [56, 59], [56, 61], [56, 62], [56, 64], [56, 66], [56, 68], [56, 72], [56, 73], [56, 77], [56, 80], [56, 82], [56, 83], [56, 85], [56, 87], [56, 93], [56, 95], [56, 96], [56, 99], [56, 100], [56, 104], [56, 105], [56, 110], [56, 111], [56, 112], [56, 120], [56, 121], [56, 129], [56, 134], [56, 137], [57, 59], [57, 60], [57, 61], [57, 66], [57, 74], [57, 77], [57, 87], [57, 88], [57, 89], [57, 96], [57, 98], [57, 99], [57, 103], [57, 105], [57, 109], [57, 110], [57, 113], [57, 115], [57, 117], [57, 121], [57, 123], [57, 128], [57, 137], [58, 64], [58, 66], [58, 76], [58, 81], [58, 85], [58, 91], [58, 101], [58, 102], [58, 103], [58, 104], [58, 110], [58, 114], [58, 115], [58, 123], [58, 124], [58, 125], [58, 127], [59, 60], [59, 66], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [59, 80], [59, 85], [59, 88], [59, 95], [59, 100], [59, 104], [59, 107], [59, 109], [59, 114], [59, 118], [59, 119], [59, 120], [59, 126], [59, 129], [59, 130], [59, 131], [59, 137], [60, 63], [60, 66], [60, 69], [60, 71], [60, 77], [60, 78], [60, 79], [60, 83], [60, 84], [60, 85], [60, 90], [60, 92], [60, 95], [60, 99], [60, 104], [60, 111], [60, 115], [60, 122], [60, 127], [60, 130], [60, 135], [61, 64], [61, 80], [61, 82], [61, 83], [61, 89], [61, 95], [61, 99], [61, 100], [61, 102], [61, 104], [61, 106], [61, 111], [61, 114], [61, 118], [61, 122], [61, 126], [61, 128], [61, 129], [61, 130], [61, 133], [61, 134], [61, 138], [62, 63], [62, 67], [62, 68], [62, 75], [62, 78], [62, 84], [62, 91], [62, 94], [62, 98], [62, 100], [62, 108], [62, 112], [62, 114], [62, 115], [62, 116], [62, 120], [62, 125], [62, 132], [62, 133], [62, 134], [63, 64], [63, 78], [63, 85], [63, 86], [63, 87], [63, 96], [63, 98], [63, 101], [63, 106], [63, 116], [63, 118], [63, 120], [63, 121], [63, 126], [63, 129], [64, 65], [64, 66], [64, 67], [64, 71], [64, 72], [64, 76], [64, 84], [64, 88], [64, 89], [64, 90], [64, 93], [64, 94], [64, 102], [64, 103], [64, 104], [64, 105], [64, 106], [64, 107], [64, 110], [64, 116], [64, 118], [64, 119], [64, 120], [64, 121], [64, 123], [64, 127], [64, 128], [64, 132], [64, 134], [64, 139], [65, 71], [65, 78], [65, 82], [65, 85], [65, 86], [65, 87], [65, 91], [65, 93], [65, 97], [65, 99], [65, 101], [65, 103], [65, 105], [65, 106], [65, 115], [65, 116], [65, 118], [65, 119], [65, 120], [65, 123], [65, 125], [65, 128], [65, 129], [65, 133], [65, 135], [65, 136], [66, 71], [66, 74], [66, 78], [66, 83], [66, 89], [66, 90], [66, 91], [66, 100], [66, 101], [66, 106], [66, 108], [66, 112], [66, 116], [66, 124], [66, 125], [66, 128], [66, 132], [66, 134], [66, 136], [66, 139], [67, 73], [67, 75], [67, 77], [67, 79], [67, 80], [67, 87], [67, 89], [67, 91], [67, 92], [67, 94], [67, 96], [67, 98], [67, 99], [67, 100], [67, 112], [67, 118], [67, 123], [67, 129], [67, 134], [67, 136], [67, 139], [68, 75], [68, 77], [68, 92], [68, 96], [68, 102], [68, 106], [68, 108], [68, 109], [68, 110], [68, 111], [68, 114], [68, 116], [68, 118], [68, 119], [68, 120], [68, 127], [68, 130], [68, 131], [68, 132], [68, 134], [68, 135], [69, 73], [69, 74], [69, 77], [69, 78], [69, 89], [69, 93], [69, 100], [69, 105], [69, 106], [69, 109], [69, 112], [69, 118], [69, 120], [69, 124], [69, 127], [69, 138], [69, 139], [70, 71], [70, 72], [70, 73], [70, 76], [70, 77], [70, 81], [70, 83], [70, 87], [70, 90], [70, 93], [70, 99], [70, 100], [70, 101], [70, 106], [70, 108], [70, 109], [70, 113], [70, 114], [70, 115], [70, 125], [70, 131], [70, 132], [71, 73], [71, 76], [71, 77], [71, 85], [71, 86], [71, 87], [71, 89], [71, 93], [71, 102], [71, 104], [71, 105], [71, 112], [71, 114], [71, 127], [71, 132], [71, 135], [72, 75], [72, 76], [72, 77], [72, 85], [72, 98], [72, 99], [72, 104], [72, 110], [72, 115], [72, 116], [72, 118], [72, 119], [72, 120], [72, 134], [72, 137], [72, 138], [72, 139], [73, 74], [73, 76], [73, 85], [73, 86], [73, 87], [73, 90], [73, 91], [73, 92], [73, 93], [73, 96], [73, 99], [73, 100], [73, 101], [73, 103], [73, 105], [73, 107], [73, 112], [73, 113], [73, 114], [73, 116], [73, 123], [73, 124], [73, 127], [73, 128], [73, 130], [73, 131], [74, 77], [74, 78], [74, 79], [74, 80], [74, 82], [74, 84], [74, 85], [74, 87], [74, 88], [74, 95], [74, 100], [74, 105], [74, 106], [74, 108], [74, 110], [74, 114], [74, 118], [74, 128], [74, 129], [74, 130], [74, 131], [74, 136], [74, 138], [74, 139], [75, 84], [75, 94], [75, 95], [75, 102], [75, 104], [75, 105], [75, 116], [75, 119], [75, 123], [75, 127], [75, 130], [75, 134], [76, 78], [76, 81], [76, 86], [76, 89], [76, 93], [76, 94], [76, 97], [76, 105], [76, 108], [76, 109], [76, 110], [76, 114], [76, 119], [76, 122], [76, 123], [76, 126], [76, 129], [76, 133], [76, 136], [76, 137], [77, 78], [77, 81], [77, 83], [77, 86], [77, 88], [77, 93], [77, 95], [77, 99], [77, 109], [77, 110], [77, 116], [77, 121], [77, 122], [77, 123], [77, 127], [77, 130], [77, 132], [78, 80], [78, 82], [78, 83], [78, 85], [78, 86], [78, 87], [78, 91], [78, 94], [78, 102], [78, 104], [78, 105], [78, 106], [78, 109], [78, 116], [78, 118], [78, 119], [78, 125], [78, 126], [78, 128], [78, 137], [78, 138], [78, 139], [79, 89], [79, 95], [79, 96], [79, 99], [79, 101], [79, 102], [79, 112], [79, 115], [79, 117], [79, 118], [79, 124], [79, 125], [79, 130], [79, 131], [79, 138], [80, 82], [80, 84], [80, 86], [80, 88], [80, 92], [80, 94], [80, 97], [80, 103], [80, 107], [80, 109], [80, 117], [80, 123], [80, 125], [80, 128], [80, 131], [80, 133], [80, 136], [80, 138], [80, 139], [81, 85], [81, 87], [81, 92], [81, 94], [81, 105], [81, 109], [81, 110], [81, 111], [81, 112], [81, 113], [81, 115], [81, 118], [81, 123], [81, 130], [81, 131], [81, 132], [81, 133], [81, 136], [81, 138], [82, 88], [82, 94], [82, 98], [82, 112], [82, 114], [82, 115], [82, 117], [82, 118], [82, 119], [82, 123], [82, 129], [82, 131], [82, 138], [83, 87], [83, 93], [83, 95], [83, 99], [83, 106], [83, 110], [83, 120], [83, 121], [83, 125], [83, 133], [83, 135], [83, 137], [83, 138], [84, 85], [84, 87], [84, 88], [84, 89], [84, 96], [84, 97], [84, 107], [84, 110], [84, 112], [84, 114], [84, 115], [84, 117], [84, 121], [84, 122], [84, 126], [84, 128], [84, 129], [84, 133], [84, 137], [84, 138], [84, 139], [85, 91], [85, 93], [85, 94], [85, 101], [85, 102], [85, 104], [85, 111], [85, 112], [85, 113], [85, 114], [85, 118], [85, 126], [85, 133], [85, 137], [86, 89], [86, 90], [86, 91], [86, 94], [86, 96], [86, 98], [86, 102], [86, 108], [86, 110], [86, 114], [86, 119], [86, 120], [86, 122], [86, 124], [86, 129], [86, 139], [87, 90], [87, 91], [87, 92], [87, 93], [87, 99], [87, 100], [87, 104], [87, 108], [87, 110], [87, 119], [87, 120], [87, 124], [87, 131], [87, 133], [87, 135], [87, 138], [88, 89], [88, 93], [88, 97], [88, 98], [88, 102], [88, 103], [88, 106], [88, 108], [88, 110], [88, 111], [88, 117], [88, 126], [88, 127], [88, 133], [88, 134], [89, 91], [89, 92], [89, 93], [89, 95], [89, 97], [89, 103], [89, 110], [89, 112], [89, 119], [89, 123], [89, 125], [89, 126], [89, 129], [89, 134], [89, 135], [89, 136], [89, 137], [90, 93], [90, 95], [90, 99], [90, 103], [90, 108], [90, 111], [90, 116], [90, 118], [90, 124], [90, 138], [91, 97], [91, 98], [91, 99], [91, 100], [91, 101], [91, 116], [91, 120], [91, 121], [91, 125], [91, 130], [91, 137], [91, 138], [92, 94], [92, 97], [92, 98], [92, 101], [92, 106], [92, 109], [92, 110], [92, 117], [92, 121], [92, 127], [92, 128], [92, 133], [92, 136], [92, 138], [92, 139], [93, 104], [93, 106], [93, 107], [93, 108], [93, 111], [93, 114], [93, 117], [93, 118], [93, 120], [93, 122], [93, 125], [93, 128], [93, 129], [93, 135], [94, 97], [94, 104], [94, 107], [94, 110], [94, 114], [94, 115], [94, 125], [94, 132], [94, 133], [94, 135], [94, 137], [94, 139], [95, 108], [95, 114], [95, 115], [95, 116], [95, 120], [95, 121], [95, 124], [95, 127], [95, 131], [95, 138], [96, 98], [96, 101], [96, 106], [96, 112], [96, 114], [96, 117], [96, 118], [96, 121], [96, 133], [96, 137], [97, 98], [97, 99], [97, 103], [97, 110], [97, 112], [97, 114], [97, 115], [97, 122], [97, 125], [97, 130], [97, 131], [97, 134], [97, 135], [97, 136], [98, 99], [98, 104], [98, 106], [98, 107], [98, 112], [98, 114], [98, 116], [98, 118], [98, 122], [98, 124], [98, 127], [98, 131], [98, 132], [98, 133], [98, 135], [99, 100], [99, 101], [99, 102], [99, 109], [99, 110], [99, 112], [99, 113], [99, 118], [99, 121], [99, 124], [99, 127], [99, 128], [99, 130], [99, 133], [99, 136], [99, 137], [99, 138], [100, 103], [100, 105], [100, 108], [100, 110], [100, 111], [100, 122], [100, 126], [100, 136], [100, 137], [101, 103], [101, 107], [101, 109], [101, 111], [101, 112], [101, 120], [101, 137], [101, 139], [102, 105], [102, 106], [102, 108], [102, 111], [102, 115], [102, 117], [102, 118], [102, 119], [102, 123], [102, 125], [102, 126], [102, 136], [102, 139], [103, 104], [103, 106], [103, 113], [103, 114], [103, 122], [103, 125], [103, 129], [103, 130], [103, 133], [103, 134], [103, 136], [103, 137], [104, 106], [104, 108], [104, 116], [104, 119], [104, 126], [104, 127], [104, 128], [104, 131], [104, 132], [104, 133], [104, 135], [104, 137], [104, 138], [105, 107], [105, 109], [105, 111], [105, 115], [105, 117], [105, 121], [105, 123], [105, 135], [105, 136], [105, 138], [106, 108], [106, 110], [106, 111], [106, 120], [106, 122], [106, 124], [106, 127], [106, 130], [106, 134], [106, 138], [107, 108], [107, 112], [107, 113], [107, 114], [107, 120], [107, 121], [107, 128], [107, 130], [107, 135], [108, 114], [108, 115], [108, 116], [108, 117], [108, 118], [108, 123], [108, 124], [108, 127], [108, 132], [108, 134], [108, 135], [108, 136], [108, 139], [109, 115], [109, 119], [109, 123], [109, 125], [109, 127], [109, 131], [109, 132], [109, 134], [110, 111], [110, 113], [110, 115], [110, 119], [110, 120], [110, 121], [110, 123], [110, 128], [110, 129], [110, 130], [110, 132], [110, 133], [110, 134], [110, 135], [110, 136], [111, 116], [111, 117], [111, 120], [111, 125], [111, 131], [111, 138], [112, 117], [112, 118], [112, 124], [112, 126], [112, 127], [112, 129], [112, 130], [112, 132], [112, 133], [112, 134], [112, 135], [112, 139], [113, 114], [113, 121], [113, 123], [113, 129], [113, 139], [114, 115], [114, 120], [114, 125], [114, 129], [114, 135], [114, 136], [114, 137], [115, 116], [115, 119], [115, 124], [115, 127], [115, 128], [115, 138], [115, 139], [116, 120], [116, 121], [116, 124], [116, 126], [116, 128], [116, 132], [116, 136], [117, 119], [117, 122], [117, 123], [117, 124], [117, 128], [117, 139], [118, 120], [118, 121], [118, 122], [118, 123], [118, 125], [118, 129], [118, 130], [118, 131], [118, 132], [119, 120], [119, 129], [119, 132], [119, 133], [119, 135], [119, 139], [120, 121], [120, 123], [120, 124], [120, 125], [120, 131], [120, 137], [121, 122], [121, 125], [121, 129], [121, 133], [121, 136], [121, 138], [122, 134], [123, 124], [123, 125], [123, 126], [123, 129], [123, 130], [123, 132], [123, 136], [123, 137], [124, 127], [124, 132], [124, 133], [124, 135], [125, 126], [125, 131], [125, 135], [126, 128], [126, 130], [127, 136], [128, 129], [128, 134], [128, 139], [129, 130], [129, 131], [129, 132], [129, 134], [129, 136], [130, 133], [130, 135], [130, 137], [130, 138], [130, 139], [131, 136], [131, 137], [132, 136], [133, 136], [133, 138]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s9/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s9/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c5f4d49723ebcb7bc44d8550a52a3c950237f72 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "m": 6, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ab6de48cd2fbe82a2ee648582dda8f2d57b0ab7 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dice": [[0, 3, 4, 6, 10, 10], [1, 2, 5, 9, 9, 9], [4, 5, 7, 7, 8, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/tests/check.py b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Cyclically intransitive dice (MathConstraint non_transitive_dice, CC-BY-4.0): n dice with m faces in +0..2m-1; die i beats die (i+1) mod n, i.e. #{(a, b): face_i(a) > face_{i+1}(b)} > floor(m^2 / 2). +Face order is irrelevant (upstream additionally demanded sorted faces as a symmetry break; not required).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, m = inst["n"], inst["m"] + D = ans.get("dice") + if not isinstance(D, list) or len(D) != n: + raise Invalid(f"dice must be a list of {n} dice") + D = [int_list(d, m, 0, 2 * m - 1, "die") for d in D] + for i in range(n): + A, B = D[i], D[(i + 1) % n] + w = sum(1 for a in A for b in B if a > b) + if w <= m * m // 2: + raise Invalid(f"die {i} wins only {w} of {m * m} face pairs against die {(i + 1) % n}") + return None, {} diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c5f4d49723ebcb7bc44d8550a52a3c950237f72 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "m": 6, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/tests/run.py b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-non-transitive-dice-l2-s1/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..759039f64d6c936788983c14c850827b118c1f5a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "m": 9, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c6a28bc3a4d73b075b62bf83997273f56003b11b --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dice": [[0, 2, 4, 6, 7, 12, 12, 14, 15], [0, 4, 5, 9, 9, 10, 11, 11, 11], [0, 3, 3, 6, 8, 9, 10, 13, 16], [1, 1, 2, 6, 7, 11, 11, 12, 14], [0, 1, 4, 7, 9, 10, 10, 11, 12], [2, 4, 4, 4, 6, 8, 9, 9, 12], [0, 2, 3, 3, 3, 14, 15, 15, 15], [0, 2, 9, 9, 10, 12, 13, 14, 14], [2, 5, 6, 8, 8, 9, 13, 15, 16]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/tests/check.py b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Cyclically intransitive dice (MathConstraint non_transitive_dice, CC-BY-4.0): n dice with m faces in +0..2m-1; die i beats die (i+1) mod n, i.e. #{(a, b): face_i(a) > face_{i+1}(b)} > floor(m^2 / 2). +Face order is irrelevant (upstream additionally demanded sorted faces as a symmetry break; not required).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, m = inst["n"], inst["m"] + D = ans.get("dice") + if not isinstance(D, list) or len(D) != n: + raise Invalid(f"dice must be a list of {n} dice") + D = [int_list(d, m, 0, 2 * m - 1, "die") for d in D] + for i in range(n): + A, B = D[i], D[(i + 1) % n] + w = sum(1 for a in A for b in B if a > b) + if w <= m * m // 2: + raise Invalid(f"die {i} wins only {w} of {m * m} face pairs against die {(i + 1) % n}") + return None, {} diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..759039f64d6c936788983c14c850827b118c1f5a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "m": 9, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/tests/run.py b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-non-transitive-dice-l6-s0/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l6-s3/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s3/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l6-s3/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l6-s4/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l6-s4/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be8c74c07936812529df1cc790418e39269630ed --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 118, "k": 7, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s4/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5207d781b41883938369b1b9b31481ac2f95d64f --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [6, 6, 5, 2, 4, 3, 3, 2, 4, 0, 1, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s4/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l6-s4/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be8c74c07936812529df1cc790418e39269630ed --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 118, "k": 7, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s4/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l6-s4/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dbd9b9d8d3239c2341554a47b86ab9414b9c178c --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_chromatic_number": 5, "max_clique": 3, "min_degree": 5, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8de7db2be2126c9381b3178c5ad96c219cccb60 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13]], "coloring": [1, 1, 1, 1, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dbd9b9d8d3239c2341554a47b86ab9414b9c178c --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_chromatic_number": 5, "max_clique": 3, "min_degree": 5, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/environment/Dockerfile b/tasks/construct-mc-pysms-graph-builder-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/environment/instance.json b/tasks/construct-mc-pysms-graph-builder-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..03b899f76e562d88a03192c77fecf72605fee11c --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [[3, 7], [2, 9], [0, 9]], "max_degree": 5, "min_degree": 3, "max_chromatic_number": 4, "min_chromatic_number": 3, "min_edges": 7, "max_edges": 19, "family": "mc_pysms_graph_builder", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/solution/solve.sh b/tasks/construct-mc-pysms-graph-builder-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..32d96ba87243742c28c93334df4b88ca95f95e07 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 8], [0, 9], [0, 10], [1, 8], [1, 9], [1, 10], [2, 7], [2, 8], [2, 9], [2, 10], [3, 6], [3, 7], [3, 10], [4, 5], [4, 6], [4, 10], [5, 6], [5, 9], [6, 7]], "coloring": [1, 1, 1, 1, 1, 2, 0, 2, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/check.py b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/instance.json b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..03b899f76e562d88a03192c77fecf72605fee11c --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [[3, 7], [2, 9], [0, 9]], "max_degree": 5, "min_degree": 3, "max_chromatic_number": 4, "min_chromatic_number": 3, "min_edges": 7, "max_edges": 19, "family": "mc_pysms_graph_builder", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/run.py b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/test.sh b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-graph-builder-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..268571e87da17e777b2a3e31d1b13fa2eb8a6e1d --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "max_independent_set": 3, "min_connectivity": 2, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2dfbd8e10be3814720762c87be2212bdd75316c7 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..268571e87da17e777b2a3e31d1b13fa2eb8a6e1d --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "max_independent_set": 3, "min_connectivity": 2, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/environment/Dockerfile b/tasks/construct-mc-pysms-min-connectivity-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/environment/instance.json b/tasks/construct-mc-pysms-min-connectivity-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..870d9d58386d9f666c41da10a51e333c00d42bd8 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "min_connectivity": 3, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/solution/solve.sh b/tasks/construct-mc-pysms-min-connectivity-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..202381af71f4ba7b8da0d1a923832175f9607239 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [13, 14]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/check.py b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/instance.json b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..870d9d58386d9f666c41da10a51e333c00d42bd8 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "min_connectivity": 3, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/run.py b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/test.sh b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/environment/Dockerfile b/tasks/construct-mc-pysms-min-girth-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/environment/instance.json b/tasks/construct-mc-pysms-min-girth-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..05758b72c413647806e189f1879fe7cf9266f11f --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [[0, 7], [0, 4], [0, 2], [2, 9], [1, 4], [4, 6], [2, 8], [1, 8], [3, 9]], "min_girth": 3, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/solution/solve.sh b/tasks/construct-mc-pysms-min-girth-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2dfbd8e10be3814720762c87be2212bdd75316c7 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/tests/check.py b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/tests/instance.json b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..05758b72c413647806e189f1879fe7cf9266f11f --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [[0, 7], [0, 4], [0, 2], [2, 9], [1, 4], [4, 6], [2, 8], [1, 8], [3, 9]], "min_girth": 3, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/tests/run.py b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-girth-l2-s1/tests/test.sh b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/environment/Dockerfile b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/environment/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa9b7105a2999a07138f9eca3685caed04148954 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_edges": 24, "min_edges": 23, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/solution/solve.sh b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aca068303245f929191d154e6b00b4bc5ba8ab95 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/check.py b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa9b7105a2999a07138f9eca3685caed04148954 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_edges": 24, "min_edges": 23, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/run.py b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/test.sh b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l2-s1/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l2-s1/environment/instance.json b/tasks/construct-mc-ramsey-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..014e2f0acb9f8f5311fe5c07f81b281371487237 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "r": 3, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s1/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1eef64c4d48bcef111dc43e2e94363cef4d3db9b --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l2-s1/tests/check.py b/tasks/construct-mc-ramsey-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l2-s1/tests/instance.json b/tasks/construct-mc-ramsey-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..014e2f0acb9f8f5311fe5c07f81b281371487237 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "r": 3, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s1/tests/run.py b/tasks/construct-mc-ramsey-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l2-s1/tests/test.sh b/tasks/construct-mc-ramsey-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l2-s6/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l2-s6/environment/instance.json b/tasks/construct-mc-ramsey-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b24ec2feda64408e4917034b8c153949a884d1a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "r": 5, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s6/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e15a8e1d891fb0a2b16c9bfb2c416247087c638e --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l2-s6/tests/check.py b/tasks/construct-mc-ramsey-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l2-s6/tests/instance.json b/tasks/construct-mc-ramsey-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b24ec2feda64408e4917034b8c153949a884d1a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "r": 5, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s6/tests/run.py b/tasks/construct-mc-ramsey-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l2-s6/tests/test.sh b/tasks/construct-mc-ramsey-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l6-s0/environment/instance.json b/tasks/construct-mc-ramsey-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cfb585fcca23a477eb88275f436dcc1662f9b590 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 36, "r": 5, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb1b15a0be056f7ca4ec7b0aeb17ccf490895242 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 73, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..82b811925db257400eb272b31758abc1e8366bf2 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 2, 3, 3, 0, 3, 0, 0, 2, 0, 3, 1, 1, 0, 3, 1, 3, 1, 2, 3, 3, 1, 2, 0, 2, 2, 1, 2, 1, 1, 0, 0, 3, 2, 0, 0, 1, 2, 2, 3, 3, 0, 3, 0, 0, 2, 0, 3, 1, 1, 0, 3, 1, 3, 1, 2, 3, 3, 1, 2, 0, 2, 2, 1, 2, 1, 1, 0, 0, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb1b15a0be056f7ca4ec7b0aeb17ccf490895242 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 73, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l6-s2/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0c950ddba1500c51532efaf53b1982fef277ed7c --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 4, "n": 291, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9b48bbc2d8f2a152f1e804ec228f66d7fc2dcdb1 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 1, 2, 1, 2, 1, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 0, 2, 1, 2, 2, 0, 0, 1, 0, 1, 2, 0, 0, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 0, 0, 0, 2, 1, 2, 2, 1, 0, 2, 2, 2, 0, 1, 2, 1, 2, 1, 1, 0, 0, 0, 1, 1, 2, 1, 2, 1, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 0, 2, 1, 2, 2, 0, 0, 1, 0, 1, 2, 0, 0, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 0, 0, 0, 2, 1, 2, 2, 1, 0, 2, 2, 2, 0, 1, 2, 1, 2, 1, 1, 0, 0, 0, 1, 1, 2, 1, 2, 1, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 0, 2, 1, 2, 2, 0, 0, 1, 0, 1, 2, 0, 0, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 0, 0, 0, 2, 1, 2, 2, 1, 0, 2, 2, 2, 0, 1, 2, 1, 2, 1, 1, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0c950ddba1500c51532efaf53b1982fef277ed7c --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 4, "n": 291, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l6-s5/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s3/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s3/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e1d206a27cfb57e9ada3085fc99d6a95b2c3216 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 1], [0, 3], [0, 7], [0, 9], [0, 14], [0, 15], [0, 25], [0, 26], [0, 27], [0, 31], [0, 32], [0, 41], [1, 5], [1, 12], [1, 24], [1, 26], [1, 28], [1, 33], [1, 37], [2, 11], [2, 16], [2, 38], [2, 43], [3, 24], [3, 39], [3, 40], [4, 7], [4, 16], [4, 19], [4, 21], [4, 23], [4, 26], [4, 27], [4, 36], [4, 39], [5, 39], [6, 12], [6, 15], [6, 17], [6, 20], [6, 28], [6, 34], [7, 22], [7, 25], [7, 27], [7, 30], [7, 37], [7, 40], [8, 14], [8, 17], [8, 28], [8, 39], [9, 10], [9, 12], [9, 29], [9, 30], [9, 41], [10, 27], [10, 41], [10, 44], [11, 17], [11, 24], [11, 27], [11, 33], [11, 35], [11, 40], [11, 41], [12, 15], [12, 16], [12, 24], [12, 31], [12, 39], [13, 14], [13, 15], [13, 18], [13, 27], [13, 35], [13, 42], [14, 17], [14, 18], [14, 20], [14, 23], [14, 24], [14, 32], [14, 33], [14, 34], [14, 38], [14, 39], [14, 40], [15, 18], [15, 19], [15, 26], [15, 28], [16, 31], [16, 33], [16, 36], [16, 42], [17, 18], [17, 24], [17, 28], [17, 29], [17, 31], [17, 34], [17, 39], [17, 40], [17, 42], [17, 43], [18, 21], [18, 28], [18, 29], [18, 37], [18, 39], [18, 44], [19, 28], [19, 33], [19, 35], [19, 42], [20, 24], [20, 28], [20, 35], [20, 36], [20, 37], [20, 41], [20, 43], [21, 24], [21, 28], [21, 40], [22, 23], [22, 25], [22, 33], [22, 38], [22, 39], [23, 35], [23, 41], [24, 27], [24, 32], [24, 43], [25, 26], [25, 27], [25, 32], [25, 36], [26, 29], [26, 33], [26, 39], [26, 40], [26, 41], [27, 28], [27, 31], [27, 35], [27, 37], [27, 39], [27, 40], [27, 42], [28, 36], [28, 41], [28, 42], [29, 33], [30, 34], [30, 40], [31, 32], [31, 34], [31, 35], [31, 39], [31, 44], [33, 37], [33, 39], [33, 40], [33, 44], [34, 38], [35, 37], [35, 39], [37, 42], [37, 43], [38, 41]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s3/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..de56f26e879af7b285c98cb884578067d98c14c3 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 1, 2, 4, 6, 9, 10, 12, 14, 15, 17, 18, 20, 22, 24, 25, 27, 28, 29, 30, 31, 33, 35, 36, 37, 38, 39, 40, 41, 42]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s3/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l3-s3/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e1d206a27cfb57e9ada3085fc99d6a95b2c3216 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 1], [0, 3], [0, 7], [0, 9], [0, 14], [0, 15], [0, 25], [0, 26], [0, 27], [0, 31], [0, 32], [0, 41], [1, 5], [1, 12], [1, 24], [1, 26], [1, 28], [1, 33], [1, 37], [2, 11], [2, 16], [2, 38], [2, 43], [3, 24], [3, 39], [3, 40], [4, 7], [4, 16], [4, 19], [4, 21], [4, 23], [4, 26], [4, 27], [4, 36], [4, 39], [5, 39], [6, 12], [6, 15], [6, 17], [6, 20], [6, 28], [6, 34], [7, 22], [7, 25], [7, 27], [7, 30], [7, 37], [7, 40], [8, 14], [8, 17], [8, 28], [8, 39], [9, 10], [9, 12], [9, 29], [9, 30], [9, 41], [10, 27], [10, 41], [10, 44], [11, 17], [11, 24], [11, 27], [11, 33], [11, 35], [11, 40], [11, 41], [12, 15], [12, 16], [12, 24], [12, 31], [12, 39], [13, 14], [13, 15], [13, 18], [13, 27], [13, 35], [13, 42], [14, 17], [14, 18], [14, 20], [14, 23], [14, 24], [14, 32], [14, 33], [14, 34], [14, 38], [14, 39], [14, 40], [15, 18], [15, 19], [15, 26], [15, 28], [16, 31], [16, 33], [16, 36], [16, 42], [17, 18], [17, 24], [17, 28], [17, 29], [17, 31], [17, 34], [17, 39], [17, 40], [17, 42], [17, 43], [18, 21], [18, 28], [18, 29], [18, 37], [18, 39], [18, 44], [19, 28], [19, 33], [19, 35], [19, 42], [20, 24], [20, 28], [20, 35], [20, 36], [20, 37], [20, 41], [20, 43], [21, 24], [21, 28], [21, 40], [22, 23], [22, 25], [22, 33], [22, 38], [22, 39], [23, 35], [23, 41], [24, 27], [24, 32], [24, 43], [25, 26], [25, 27], [25, 32], [25, 36], [26, 29], [26, 33], [26, 39], [26, 40], [26, 41], [27, 28], [27, 31], [27, 35], [27, 37], [27, 39], [27, 40], [27, 42], [28, 36], [28, 41], [28, 42], [29, 33], [30, 34], [30, 40], [31, 32], [31, 34], [31, 35], [31, 39], [31, 44], [33, 37], [33, 39], [33, 40], [33, 44], [34, 38], [35, 37], [35, 39], [37, 42], [37, 43], [38, 41]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s3/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s3/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s4/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s4/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd5490a14a28c63ef0e0ad46422ecc2350fafa34 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 1], [0, 8], [0, 16], [0, 23], [0, 27], [0, 31], [0, 34], [1, 2], [1, 4], [1, 5], [1, 12], [1, 27], [1, 33], [1, 34], [1, 35], [1, 36], [1, 40], [2, 7], [2, 13], [2, 19], [2, 24], [2, 33], [2, 37], [3, 5], [3, 14], [3, 21], [3, 32], [3, 34], [3, 38], [3, 44], [4, 11], [4, 20], [4, 30], [4, 36], [4, 37], [4, 43], [5, 32], [5, 34], [5, 43], [6, 13], [6, 14], [6, 39], [7, 13], [7, 15], [7, 17], [7, 33], [7, 40], [7, 41], [7, 44], [8, 17], [8, 18], [8, 24], [8, 29], [8, 33], [8, 35], [8, 43], [8, 44], [9, 10], [9, 13], [9, 17], [9, 23], [9, 34], [9, 35], [9, 38], [9, 41], [10, 15], [10, 16], [10, 30], [10, 37], [10, 38], [10, 41], [11, 16], [11, 19], [11, 24], [11, 25], [11, 28], [11, 30], [11, 37], [11, 40], [12, 22], [12, 26], [12, 27], [12, 33], [12, 35], [12, 38], [12, 43], [13, 16], [13, 22], [13, 26], [13, 27], [14, 20], [14, 23], [14, 26], [14, 29], [14, 32], [15, 32], [15, 35], [15, 36], [16, 17], [16, 22], [16, 27], [16, 30], [16, 31], [16, 37], [16, 38], [16, 44], [17, 20], [17, 21], [17, 25], [17, 35], [17, 43], [17, 44], [18, 27], [18, 31], [18, 33], [18, 34], [18, 37], [18, 42], [18, 43], [18, 44], [19, 30], [19, 34], [20, 22], [20, 31], [20, 35], [20, 44], [21, 23], [21, 38], [22, 23], [22, 31], [22, 38], [23, 24], [23, 25], [23, 26], [23, 27], [23, 33], [23, 37], [24, 26], [24, 31], [24, 35], [24, 41], [25, 26], [25, 27], [25, 29], [25, 34], [25, 38], [26, 30], [26, 34], [26, 35], [26, 43], [27, 34], [28, 31], [28, 34], [28, 37], [28, 38], [29, 31], [29, 35], [29, 38], [30, 32], [30, 39], [30, 42], [30, 43], [31, 34], [31, 35], [31, 42], [31, 43], [32, 38], [32, 43], [33, 36], [34, 38], [34, 39], [34, 42], [35, 38], [35, 41], [35, 42], [35, 43], [36, 43], [37, 40]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s4/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..12203723d36abdcc8103af84eba32646a1cc3433 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 2, 3, 6, 7, 8, 9, 10, 11, 13, 16, 17, 18, 20, 22, 23, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 41, 43]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s4/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l3-s4/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd5490a14a28c63ef0e0ad46422ecc2350fafa34 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 1], [0, 8], [0, 16], [0, 23], [0, 27], [0, 31], [0, 34], [1, 2], [1, 4], [1, 5], [1, 12], [1, 27], [1, 33], [1, 34], [1, 35], [1, 36], [1, 40], [2, 7], [2, 13], [2, 19], [2, 24], [2, 33], [2, 37], [3, 5], [3, 14], [3, 21], [3, 32], [3, 34], [3, 38], [3, 44], [4, 11], [4, 20], [4, 30], [4, 36], [4, 37], [4, 43], [5, 32], [5, 34], [5, 43], [6, 13], [6, 14], [6, 39], [7, 13], [7, 15], [7, 17], [7, 33], [7, 40], [7, 41], [7, 44], [8, 17], [8, 18], [8, 24], [8, 29], [8, 33], [8, 35], [8, 43], [8, 44], [9, 10], [9, 13], [9, 17], [9, 23], [9, 34], [9, 35], [9, 38], [9, 41], [10, 15], [10, 16], [10, 30], [10, 37], [10, 38], [10, 41], [11, 16], [11, 19], [11, 24], [11, 25], [11, 28], [11, 30], [11, 37], [11, 40], [12, 22], [12, 26], [12, 27], [12, 33], [12, 35], [12, 38], [12, 43], [13, 16], [13, 22], [13, 26], [13, 27], [14, 20], [14, 23], [14, 26], [14, 29], [14, 32], [15, 32], [15, 35], [15, 36], [16, 17], [16, 22], [16, 27], [16, 30], [16, 31], [16, 37], [16, 38], [16, 44], [17, 20], [17, 21], [17, 25], [17, 35], [17, 43], [17, 44], [18, 27], [18, 31], [18, 33], [18, 34], [18, 37], [18, 42], [18, 43], [18, 44], [19, 30], [19, 34], [20, 22], [20, 31], [20, 35], [20, 44], [21, 23], [21, 38], [22, 23], [22, 31], [22, 38], [23, 24], [23, 25], [23, 26], [23, 27], [23, 33], [23, 37], [24, 26], [24, 31], [24, 35], [24, 41], [25, 26], [25, 27], [25, 29], [25, 34], [25, 38], [26, 30], [26, 34], [26, 35], [26, 43], [27, 34], [28, 31], [28, 34], [28, 37], [28, 38], [29, 31], [29, 35], [29, 38], [30, 32], [30, 39], [30, 42], [30, 43], [31, 34], [31, 35], [31, 42], [31, 43], [32, 38], [32, 43], [33, 36], [34, 38], [34, 39], [34, 42], [35, 38], [35, 41], [35, 42], [35, 43], [36, 43], [37, 40]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s4/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s4/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l3-s4/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l3-s4/environment/instance.json b/tasks/construct-nppc-3col-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6f9d47b48fc9da831d1272bd53f8266fc6e8888c --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 2], [0, 4], [0, 20], [0, 25], [1, 3], [1, 8], [1, 13], [1, 17], [2, 6], [2, 10], [2, 16], [2, 24], [2, 28], [3, 18], [3, 26], [4, 16], [4, 19], [4, 22], [5, 12], [5, 24], [5, 27], [5, 28], [5, 29], [6, 19], [6, 20], [6, 29], [7, 9], [7, 11], [7, 14], [7, 25], [7, 28], [7, 29], [8, 15], [8, 16], [9, 10], [9, 18], [10, 18], [10, 25], [11, 13], [11, 16], [12, 18], [12, 21], [12, 24], [13, 19], [13, 27], [13, 29], [14, 15], [14, 18], [15, 26], [17, 19], [17, 25], [17, 27], [17, 28], [18, 20], [21, 25], [23, 24], [23, 27], [23, 29], [24, 25], [25, 27]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s4/solution/solve.sh b/tasks/construct-nppc-3col-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..999a66e860b19d643e96103d94072137d473067d --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 0, 2, 0, 0, 1, 0, 2, 2, 1, 2, 2, 0, 1, 0, 1, 0, 0, 2, 2, 0, 1, 0, 1, 2, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s4/tests/check.py b/tasks/construct-nppc-3col-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l3-s4/tests/instance.json b/tasks/construct-nppc-3col-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6f9d47b48fc9da831d1272bd53f8266fc6e8888c --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 2], [0, 4], [0, 20], [0, 25], [1, 3], [1, 8], [1, 13], [1, 17], [2, 6], [2, 10], [2, 16], [2, 24], [2, 28], [3, 18], [3, 26], [4, 16], [4, 19], [4, 22], [5, 12], [5, 24], [5, 27], [5, 28], [5, 29], [6, 19], [6, 20], [6, 29], [7, 9], [7, 11], [7, 14], [7, 25], [7, 28], [7, 29], [8, 15], [8, 16], [9, 10], [9, 18], [10, 18], [10, 25], [11, 13], [11, 16], [12, 18], [12, 21], [12, 24], [13, 19], [13, 27], [13, 29], [14, 15], [14, 18], [15, 26], [17, 19], [17, 25], [17, 27], [17, 28], [18, 20], [21, 25], [23, 24], [23, 27], [23, 29], [24, 25], [25, 27]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s4/tests/run.py b/tasks/construct-nppc-3col-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l3-s4/tests/test.sh b/tasks/construct-nppc-3col-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l1-s0/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l1-s0/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f745661ddf7ca3c8f0611aafbeb22dcaf578b82 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s0/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..231a126127a68ce3f5f9c3062206c84ecf2b6f07 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [2, 0, 1, 4, 5, 3]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s0/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l1-s0/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f745661ddf7ca3c8f0611aafbeb22dcaf578b82 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s0/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l1-s0/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l1-s7/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l1-s7/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f722eea61045df7a8d90dc79a0878537ef60b37a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 2], [1, 3], [2, 3], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s7/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f40cc684a5587d90e503180e6f1473ca8ae723fd --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [5, 0, 4, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s7/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l1-s7/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f722eea61045df7a8d90dc79a0878537ef60b37a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 2], [1, 3], [2, 3], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s7/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l1-s7/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l5-s6/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l5-s6/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d17932c140d764de7031d89ca0d7c4346bf9f3f6 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 3], [0, 14], [0, 18], [0, 19], [0, 22], [0, 27], [1, 6], [1, 11], [1, 15], [1, 29], [2, 11], [2, 16], [2, 24], [2, 25], [2, 26], [2, 37], [2, 38], [3, 13], [3, 14], [3, 19], [3, 36], [4, 8], [4, 12], [4, 15], [4, 28], [4, 35], [4, 39], [5, 7], [5, 9], [5, 21], [5, 23], [5, 30], [5, 34], [6, 8], [6, 26], [6, 29], [7, 9], [7, 23], [8, 15], [8, 33], [8, 35], [8, 39], [9, 13], [9, 18], [9, 19], [9, 27], [10, 12], [10, 14], [10, 22], [10, 32], [10, 36], [11, 25], [11, 26], [11, 29], [12, 14], [12, 22], [12, 39], [13, 18], [13, 21], [13, 30], [14, 17], [14, 19], [14, 22], [15, 28], [15, 33], [15, 39], [16, 24], [16, 25], [16, 37], [17, 18], [17, 19], [17, 22], [17, 36], [18, 19], [18, 21], [18, 27], [19, 27], [20, 21], [20, 23], [20, 30], [20, 31], [20, 34], [21, 27], [21, 30], [22, 32], [23, 30], [23, 34], [24, 37], [25, 26], [25, 37], [25, 38], [26, 33], [26, 37], [27, 30], [28, 29], [28, 32], [28, 39], [29, 33], [29, 39], [31, 34], [32, 35], [32, 36], [32, 39], [35, 36], [35, 39], [37, 38]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s6/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..87d09b436d4324d944a66c09c1627c386c9f6b9f --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [26, 8, 3, 25, 16, 35, 9, 34, 13, 31, 20, 7, 19, 29, 23, 12, 2, 24, 28, 27, 36, 32, 22, 37, 0, 5, 6, 30, 14, 11, 33, 38, 18, 10, 39, 17, 21, 4, 1, 15]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s6/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l5-s6/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d17932c140d764de7031d89ca0d7c4346bf9f3f6 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 3], [0, 14], [0, 18], [0, 19], [0, 22], [0, 27], [1, 6], [1, 11], [1, 15], [1, 29], [2, 11], [2, 16], [2, 24], [2, 25], [2, 26], [2, 37], [2, 38], [3, 13], [3, 14], [3, 19], [3, 36], [4, 8], [4, 12], [4, 15], [4, 28], [4, 35], [4, 39], [5, 7], [5, 9], [5, 21], [5, 23], [5, 30], [5, 34], [6, 8], [6, 26], [6, 29], [7, 9], [7, 23], [8, 15], [8, 33], [8, 35], [8, 39], [9, 13], [9, 18], [9, 19], [9, 27], [10, 12], [10, 14], [10, 22], [10, 32], [10, 36], [11, 25], [11, 26], [11, 29], [12, 14], [12, 22], [12, 39], [13, 18], [13, 21], [13, 30], [14, 17], [14, 19], [14, 22], [15, 28], [15, 33], [15, 39], [16, 24], [16, 25], [16, 37], [17, 18], [17, 19], [17, 22], [17, 36], [18, 19], [18, 21], [18, 27], [19, 27], [20, 21], [20, 23], [20, 30], [20, 31], [20, 34], [21, 27], [21, 30], [22, 32], [23, 30], [23, 34], [24, 37], [25, 26], [25, 37], [25, 38], [26, 33], [26, 37], [27, 30], [28, 29], [28, 32], [28, 39], [29, 33], [29, 39], [31, 34], [32, 35], [32, 36], [32, 39], [35, 36], [35, 39], [37, 38]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s6/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l5-s6/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l5-s8/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l5-s8/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..826dc61fc29fa3fe81ebd870199487a2ea2f34af --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 1], [0, 6], [0, 13], [0, 34], [1, 6], [1, 10], [2, 5], [2, 7], [2, 8], [2, 9], [2, 18], [2, 23], [2, 34], [3, 11], [3, 27], [3, 30], [3, 38], [4, 10], [4, 14], [4, 24], [4, 25], [4, 29], [4, 37], [5, 8], [5, 12], [5, 33], [6, 9], [6, 13], [6, 25], [6, 34], [6, 39], [7, 8], [8, 12], [8, 19], [9, 18], [9, 39], [10, 13], [10, 24], [10, 25], [11, 20], [11, 27], [11, 30], [11, 38], [12, 15], [12, 19], [12, 23], [12, 33], [12, 35], [13, 24], [13, 36], [13, 39], [14, 16], [14, 21], [14, 29], [14, 32], [14, 37], [15, 19], [15, 22], [15, 28], [15, 31], [15, 33], [15, 35], [16, 17], [16, 32], [17, 21], [17, 29], [17, 32], [17, 37], [18, 23], [19, 23], [19, 26], [20, 22], [20, 26], [20, 30], [20, 38], [21, 32], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 38], [23, 33], [24, 25], [24, 29], [24, 36], [24, 37], [25, 29], [25, 36], [25, 39], [26, 28], [26, 35], [27, 30], [27, 38], [28, 31], [28, 35], [29, 32], [29, 36], [30, 38], [31, 35], [31, 38], [32, 37], [33, 35], [36, 37]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s8/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f258c9d8b730e4772e5dc644acbfad549a3748d --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [23, 24, 19, 0, 32, 15, 25, 20, 17, 22, 28, 1, 14, 27, 35, 10, 39, 37, 18, 13, 5, 38, 6, 16, 30, 29, 9, 3, 8, 33, 2, 7, 36, 12, 21, 11, 31, 34, 4, 26]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s8/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l5-s8/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..826dc61fc29fa3fe81ebd870199487a2ea2f34af --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 1], [0, 6], [0, 13], [0, 34], [1, 6], [1, 10], [2, 5], [2, 7], [2, 8], [2, 9], [2, 18], [2, 23], [2, 34], [3, 11], [3, 27], [3, 30], [3, 38], [4, 10], [4, 14], [4, 24], [4, 25], [4, 29], [4, 37], [5, 8], [5, 12], [5, 33], [6, 9], [6, 13], [6, 25], [6, 34], [6, 39], [7, 8], [8, 12], [8, 19], [9, 18], [9, 39], [10, 13], [10, 24], [10, 25], [11, 20], [11, 27], [11, 30], [11, 38], [12, 15], [12, 19], [12, 23], [12, 33], [12, 35], [13, 24], [13, 36], [13, 39], [14, 16], [14, 21], [14, 29], [14, 32], [14, 37], [15, 19], [15, 22], [15, 28], [15, 31], [15, 33], [15, 35], [16, 17], [16, 32], [17, 21], [17, 29], [17, 32], [17, 37], [18, 23], [19, 23], [19, 26], [20, 22], [20, 26], [20, 30], [20, 38], [21, 32], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 38], [23, 33], [24, 25], [24, 29], [24, 36], [24, 37], [25, 29], [25, 36], [25, 39], [26, 28], [26, 35], [27, 30], [27, 38], [28, 31], [28, 35], [29, 32], [29, 36], [30, 38], [31, 35], [31, 38], [32, 37], [33, 35], [36, 37]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s8/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l5-s8/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l4-s1/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l4-s1/environment/instance.json b/tasks/construct-nppc-clique-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddccf635fc648c8912c858388f286dea43677944 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 14], [0, 15], [0, 17], [0, 18], [0, 19], [0, 20], [0, 23], [0, 24], [0, 26], [0, 28], [1, 2], [1, 6], [1, 9], [1, 10], [1, 11], [1, 14], [1, 27], [1, 28], [1, 29], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 17], [3, 19], [3, 20], [3, 21], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [4, 5], [4, 6], [4, 11], [4, 12], [4, 13], [4, 16], [4, 17], [4, 20], [4, 22], [4, 25], [4, 27], [4, 28], [4, 29], [5, 6], [5, 10], [5, 11], [5, 14], [5, 15], [5, 16], [5, 19], [5, 21], [5, 24], [5, 25], [5, 26], [5, 29], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [6, 16], [6, 19], [6, 25], [6, 28], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 23], [7, 26], [7, 28], [7, 29], [8, 9], [8, 10], [8, 11], [8, 12], [8, 16], [8, 19], [8, 22], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [10, 11], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 22], [10, 23], [10, 26], [10, 27], [10, 28], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [12, 14], [12, 17], [12, 18], [12, 19], [12, 22], [12, 24], [12, 25], [12, 27], [12, 29], [13, 15], [13, 19], [13, 23], [13, 25], [13, 26], [13, 27], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 26], [14, 28], [14, 29], [15, 17], [15, 19], [15, 20], [15, 23], [15, 26], [15, 27], [15, 28], [15, 29], [16, 17], [16, 18], [16, 19], [16, 20], [16, 25], [16, 26], [16, 28], [17, 18], [17, 19], [17, 20], [17, 23], [17, 26], [17, 28], [17, 29], [18, 23], [18, 24], [18, 27], [18, 29], [19, 20], [19, 21], [19, 23], [19, 25], [19, 26], [19, 28], [20, 22], [20, 23], [20, 26], [20, 27], [20, 28], [20, 29], [21, 22], [21, 27], [21, 28], [22, 24], [22, 28], [23, 26], [23, 28], [24, 27], [25, 26], [25, 27], [26, 28]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s1/solution/solve.sh b/tasks/construct-nppc-clique-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e542ef26d4e165bac426b7dd71ccd2c764f0d4c4 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 2, 3, 7, 9, 10, 11, 14, 15, 17, 19, 20, 23, 26, 28]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s1/tests/check.py b/tasks/construct-nppc-clique-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l4-s1/tests/instance.json b/tasks/construct-nppc-clique-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddccf635fc648c8912c858388f286dea43677944 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 14], [0, 15], [0, 17], [0, 18], [0, 19], [0, 20], [0, 23], [0, 24], [0, 26], [0, 28], [1, 2], [1, 6], [1, 9], [1, 10], [1, 11], [1, 14], [1, 27], [1, 28], [1, 29], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 17], [3, 19], [3, 20], [3, 21], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [4, 5], [4, 6], [4, 11], [4, 12], [4, 13], [4, 16], [4, 17], [4, 20], [4, 22], [4, 25], [4, 27], [4, 28], [4, 29], [5, 6], [5, 10], [5, 11], [5, 14], [5, 15], [5, 16], [5, 19], [5, 21], [5, 24], [5, 25], [5, 26], [5, 29], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [6, 16], [6, 19], [6, 25], [6, 28], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 23], [7, 26], [7, 28], [7, 29], [8, 9], [8, 10], [8, 11], [8, 12], [8, 16], [8, 19], [8, 22], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [10, 11], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 22], [10, 23], [10, 26], [10, 27], [10, 28], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [12, 14], [12, 17], [12, 18], [12, 19], [12, 22], [12, 24], [12, 25], [12, 27], [12, 29], [13, 15], [13, 19], [13, 23], [13, 25], [13, 26], [13, 27], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 26], [14, 28], [14, 29], [15, 17], [15, 19], [15, 20], [15, 23], [15, 26], [15, 27], [15, 28], [15, 29], [16, 17], [16, 18], [16, 19], [16, 20], [16, 25], [16, 26], [16, 28], [17, 18], [17, 19], [17, 20], [17, 23], [17, 26], [17, 28], [17, 29], [18, 23], [18, 24], [18, 27], [18, 29], [19, 20], [19, 21], [19, 23], [19, 25], [19, 26], [19, 28], [20, 22], [20, 23], [20, 26], [20, 27], [20, 28], [20, 29], [21, 22], [21, 27], [21, 28], [22, 24], [22, 28], [23, 26], [23, 28], [24, 27], [25, 26], [25, 27], [26, 28]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s1/tests/run.py b/tasks/construct-nppc-clique-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l4-s1/tests/test.sh b/tasks/construct-nppc-clique-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l4-s6/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l4-s6/environment/instance.json b/tasks/construct-nppc-clique-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c8e87de40c014b9c17c889aa51517e7cb16d5bb1 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 17], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [1, 3], [1, 4], [1, 5], [1, 7], [1, 9], [1, 15], [1, 16], [1, 22], [1, 24], [1, 25], [1, 26], [1, 28], [1, 29], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 15], [2, 17], [2, 18], [2, 20], [2, 21], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [4, 6], [4, 7], [4, 8], [4, 11], [4, 14], [4, 15], [4, 17], [4, 20], [4, 23], [4, 27], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [7, 8], [7, 9], [7, 10], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [8, 9], [8, 10], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 19], [8, 20], [8, 21], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 26], [10, 27], [10, 28], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 21], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [12, 13], [12, 15], [12, 16], [12, 17], [12, 19], [12, 20], [12, 24], [12, 27], [12, 28], [13, 14], [13, 17], [13, 20], [13, 21], [13, 23], [13, 24], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 17], [14, 20], [14, 22], [14, 23], [14, 25], [14, 26], [14, 28], [14, 29], [15, 16], [15, 17], [15, 18], [15, 19], [15, 21], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [16, 18], [16, 25], [16, 28], [17, 18], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [18, 19], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 28], [18, 29], [19, 20], [19, 21], [19, 23], [20, 21], [20, 23], [20, 25], [20, 27], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [23, 25], [23, 26], [24, 26], [24, 27], [25, 26], [25, 27], [25, 28], [25, 29], [26, 27], [26, 28], [26, 29], [27, 28]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s6/solution/solve.sh b/tasks/construct-nppc-clique-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..609f127d7c05fe79cd80f57087b6ce5a16ea9241 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 2, 3, 6, 7, 8, 9, 10, 15, 17, 21, 25, 26, 27, 28]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s6/tests/check.py b/tasks/construct-nppc-clique-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l4-s6/tests/instance.json b/tasks/construct-nppc-clique-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c8e87de40c014b9c17c889aa51517e7cb16d5bb1 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 17], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [1, 3], [1, 4], [1, 5], [1, 7], [1, 9], [1, 15], [1, 16], [1, 22], [1, 24], [1, 25], [1, 26], [1, 28], [1, 29], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 15], [2, 17], [2, 18], [2, 20], [2, 21], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [4, 6], [4, 7], [4, 8], [4, 11], [4, 14], [4, 15], [4, 17], [4, 20], [4, 23], [4, 27], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [7, 8], [7, 9], [7, 10], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [8, 9], [8, 10], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 19], [8, 20], [8, 21], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 26], [10, 27], [10, 28], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 21], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [12, 13], [12, 15], [12, 16], [12, 17], [12, 19], [12, 20], [12, 24], [12, 27], [12, 28], [13, 14], [13, 17], [13, 20], [13, 21], [13, 23], [13, 24], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 17], [14, 20], [14, 22], [14, 23], [14, 25], [14, 26], [14, 28], [14, 29], [15, 16], [15, 17], [15, 18], [15, 19], [15, 21], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [16, 18], [16, 25], [16, 28], [17, 18], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [18, 19], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 28], [18, 29], [19, 20], [19, 21], [19, 23], [20, 21], [20, 23], [20, 25], [20, 27], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [23, 25], [23, 26], [24, 26], [24, 27], [25, 26], [25, 27], [25, 28], [25, 29], [26, 27], [26, 28], [26, 29], [27, 28]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s6/tests/run.py b/tasks/construct-nppc-clique-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l4-s6/tests/test.sh b/tasks/construct-nppc-clique-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l4-s8/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l4-s8/environment/instance.json b/tasks/construct-nppc-clique-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8892a949632a308b482174a7fa84456ed4131fd4 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 25], [0, 26], [0, 28], [0, 29], [1, 2], [1, 3], [1, 4], [1, 5], [1, 9], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 25], [1, 26], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 14], [2, 15], [2, 17], [2, 20], [2, 22], [2, 23], [2, 25], [2, 27], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 25], [4, 26], [4, 28], [5, 7], [5, 12], [5, 14], [5, 15], [5, 16], [5, 19], [5, 20], [5, 21], [5, 25], [5, 29], [6, 7], [6, 9], [6, 10], [6, 12], [6, 17], [6, 19], [6, 20], [6, 22], [6, 24], [6, 26], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 19], [7, 20], [7, 24], [7, 25], [7, 26], [7, 29], [8, 10], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 25], [8, 26], [8, 27], [8, 29], [9, 10], [9, 12], [9, 13], [9, 14], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 25], [9, 27], [9, 28], [10, 11], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 25], [10, 28], [10, 29], [11, 12], [11, 14], [11, 15], [11, 18], [11, 20], [11, 21], [11, 24], [12, 13], [12, 14], [12, 16], [12, 17], [12, 19], [12, 21], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [15, 16], [15, 17], [15, 20], [15, 21], [15, 22], [15, 23], [15, 26], [15, 27], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 28], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 25], [17, 26], [17, 27], [17, 28], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 27], [18, 29], [19, 20], [19, 21], [19, 22], [19, 24], [19, 25], [19, 26], [19, 27], [19, 29], [20, 21], [20, 22], [20, 24], [20, 25], [21, 22], [21, 24], [21, 25], [21, 27], [21, 28], [21, 29], [22, 23], [22, 25], [22, 26], [22, 28], [23, 25], [23, 26], [24, 25], [24, 26], [24, 29], [25, 28], [26, 28]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s8/solution/solve.sh b/tasks/construct-nppc-clique-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d7a7e13f2d5b51bc8204fa06a8799846bc9a8f73 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 1, 3, 4, 9, 13, 14, 16, 17, 18, 19, 20, 21, 22, 25]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s8/tests/check.py b/tasks/construct-nppc-clique-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l4-s8/tests/instance.json b/tasks/construct-nppc-clique-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8892a949632a308b482174a7fa84456ed4131fd4 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 25], [0, 26], [0, 28], [0, 29], [1, 2], [1, 3], [1, 4], [1, 5], [1, 9], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 25], [1, 26], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 14], [2, 15], [2, 17], [2, 20], [2, 22], [2, 23], [2, 25], [2, 27], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 25], [4, 26], [4, 28], [5, 7], [5, 12], [5, 14], [5, 15], [5, 16], [5, 19], [5, 20], [5, 21], [5, 25], [5, 29], [6, 7], [6, 9], [6, 10], [6, 12], [6, 17], [6, 19], [6, 20], [6, 22], [6, 24], [6, 26], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 19], [7, 20], [7, 24], [7, 25], [7, 26], [7, 29], [8, 10], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 25], [8, 26], [8, 27], [8, 29], [9, 10], [9, 12], [9, 13], [9, 14], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 25], [9, 27], [9, 28], [10, 11], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 25], [10, 28], [10, 29], [11, 12], [11, 14], [11, 15], [11, 18], [11, 20], [11, 21], [11, 24], [12, 13], [12, 14], [12, 16], [12, 17], [12, 19], [12, 21], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [15, 16], [15, 17], [15, 20], [15, 21], [15, 22], [15, 23], [15, 26], [15, 27], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 28], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 25], [17, 26], [17, 27], [17, 28], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 27], [18, 29], [19, 20], [19, 21], [19, 22], [19, 24], [19, 25], [19, 26], [19, 27], [19, 29], [20, 21], [20, 22], [20, 24], [20, 25], [21, 22], [21, 24], [21, 25], [21, 27], [21, 28], [21, 29], [22, 23], [22, 25], [22, 26], [22, 28], [23, 25], [23, 26], [24, 25], [24, 26], [24, 29], [25, 28], [26, 28]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s8/tests/run.py b/tasks/construct-nppc-clique-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l4-s8/tests/test.sh b/tasks/construct-nppc-clique-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l4-s1/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l4-s1/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a7f7478cad62d22b765cdec88880e9c3c37508ab --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 4], [0, 7], [0, 9], [0, 14], [0, 15], [0, 20], [0, 22], [0, 23], [0, 25], [0, 26], [0, 35], [0, 37], [0, 38], [0, 39], [0, 40], [0, 45], [0, 47], [0, 57], [0, 63], [0, 66], [0, 68], [0, 73], [0, 74], [0, 76], [0, 77], [0, 82], [0, 83], [0, 85], [0, 87], [0, 92], [0, 93], [0, 96], [0, 99], [1, 2], [1, 4], [1, 6], [1, 9], [1, 12], [1, 19], [1, 23], [1, 30], [1, 32], [1, 40], [1, 47], [1, 54], [1, 57], [1, 63], [1, 65], [1, 67], [1, 69], [1, 71], [1, 73], [1, 80], [1, 84], [1, 87], [1, 89], [1, 95], [2, 3], [2, 4], [2, 5], [2, 11], [2, 12], [2, 20], [2, 23], [2, 24], [2, 27], [2, 34], [2, 37], [2, 39], [2, 42], [2, 43], [2, 50], [2, 53], [2, 55], [2, 62], [2, 65], [2, 76], [2, 79], [2, 84], [2, 91], [2, 93], [3, 7], [3, 10], [3, 14], [3, 16], [3, 17], [3, 38], [3, 39], [3, 42], [3, 43], [3, 47], [3, 54], [3, 58], [3, 60], [3, 61], [3, 67], [3, 70], [3, 71], [3, 72], [3, 77], [3, 79], [3, 81], [3, 84], [3, 88], [3, 97], [4, 10], [4, 14], [4, 15], [4, 16], [4, 18], [4, 25], [4, 40], [4, 44], [4, 46], [4, 48], [4, 50], [4, 51], [4, 53], [4, 56], [4, 60], [4, 61], [4, 64], [4, 70], [4, 71], [4, 75], [4, 76], [4, 80], [4, 81], [4, 84], [4, 85], [4, 88], [4, 94], [4, 95], [5, 7], [5, 8], [5, 16], [5, 21], [5, 25], [5, 28], [5, 31], [5, 33], [5, 37], [5, 40], [5, 41], [5, 45], [5, 48], [5, 49], [5, 50], [5, 52], [5, 54], [5, 55], [5, 58], [5, 64], [5, 68], [5, 70], [5, 75], [5, 76], [5, 78], [5, 85], [5, 89], [5, 90], [5, 91], [5, 92], [5, 93], [5, 95], [5, 98], [5, 99], [6, 14], [6, 20], [6, 21], [6, 22], [6, 28], [6, 29], [6, 35], [6, 36], [6, 37], [6, 39], [6, 40], [6, 42], [6, 44], [6, 46], [6, 58], [6, 63], [6, 64], [6, 68], [6, 70], [6, 74], [6, 78], [6, 80], [6, 88], [6, 91], [6, 94], [7, 8], [7, 10], [7, 15], [7, 17], [7, 18], [7, 20], [7, 22], [7, 27], [7, 31], [7, 32], [7, 36], [7, 39], [7, 47], [7, 48], [7, 49], [7, 55], [7, 56], [7, 57], [7, 64], [7, 68], [7, 76], [7, 84], [7, 85], [7, 95], [7, 96], [8, 13], [8, 15], [8, 21], [8, 24], [8, 27], [8, 28], [8, 32], [8, 33], [8, 35], [8, 41], [8, 47], [8, 49], [8, 50], [8, 51], [8, 54], [8, 55], [8, 56], [8, 58], [8, 60], [8, 65], [8, 66], [8, 76], [8, 77], [8, 78], [8, 81], [8, 82], [8, 87], [8, 96], [8, 97], [8, 98], [8, 99], [9, 10], [9, 15], [9, 20], [9, 21], [9, 25], [9, 26], [9, 27], [9, 30], [9, 31], [9, 39], [9, 40], [9, 41], [9, 44], [9, 48], [9, 50], [9, 54], [9, 56], [9, 64], [9, 66], [9, 71], [9, 74], [9, 79], [9, 83], [9, 85], [9, 87], [9, 91], [9, 92], [9, 95], [9, 97], [9, 99], [10, 14], [10, 16], [10, 22], [10, 28], [10, 32], [10, 42], [10, 43], [10, 44], [10, 48], [10, 49], [10, 51], [10, 52], [10, 59], [10, 69], [10, 74], [10, 76], [10, 77], [10, 78], [10, 83], [10, 84], [10, 85], [10, 86], [10, 88], [10, 89], [10, 90], [10, 91], [10, 92], [10, 96], [11, 13], [11, 14], [11, 20], [11, 21], [11, 23], [11, 31], [11, 33], [11, 34], [11, 39], [11, 43], [11, 44], [11, 48], [11, 50], [11, 53], [11, 55], [11, 56], [11, 61], [11, 62], [11, 65], [11, 82], [11, 84], [11, 85], [11, 86], [11, 87], [11, 91], [11, 92], [11, 94], [11, 95], [11, 97], [11, 99], [12, 16], [12, 17], [12, 21], [12, 31], [12, 35], [12, 36], [12, 41], [12, 43], [12, 44], [12, 47], [12, 48], [12, 50], [12, 53], [12, 55], [12, 57], [12, 60], [12, 61], [12, 72], [12, 73], [12, 74], [12, 76], [12, 83], [12, 84], [12, 90], [12, 91], [12, 94], [13, 14], [13, 16], [13, 20], [13, 22], [13, 23], [13, 27], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 43], [13, 45], [13, 50], [13, 55], [13, 56], [13, 61], [13, 62], [13, 64], [13, 65], [13, 67], [13, 78], [13, 80], [13, 81], [13, 87], [13, 88], [13, 93], [13, 95], [14, 15], [14, 16], [14, 18], [14, 20], [14, 22], [14, 29], [14, 31], [14, 33], [14, 38], [14, 39], [14, 40], [14, 43], [14, 48], [14, 52], [14, 53], [14, 61], [14, 62], [14, 70], [14, 71], [14, 73], [14, 74], [14, 76], [14, 85], [14, 86], [14, 89], [14, 92], [14, 95], [14, 99], [15, 16], [15, 18], [15, 20], [15, 24], [15, 29], [15, 30], [15, 33], [15, 36], [15, 37], [15, 44], [15, 46], [15, 48], [15, 50], [15, 57], [15, 58], [15, 66], [15, 68], [15, 69], [15, 76], [15, 77], [15, 78], [15, 79], [15, 83], [15, 86], [15, 88], [15, 89], [15, 92], [15, 93], [15, 99], [16, 19], [16, 20], [16, 21], [16, 23], [16, 25], [16, 26], [16, 29], [16, 30], [16, 31], [16, 33], [16, 34], [16, 38], [16, 41], [16, 47], [16, 50], [16, 53], [16, 57], [16, 63], [16, 67], [16, 68], [16, 77], [16, 81], [16, 82], [16, 87], [16, 90], [16, 91], [16, 98], [16, 99], [17, 21], [17, 23], [17, 24], [17, 25], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 37], [17, 39], [17, 43], [17, 45], [17, 48], [17, 49], [17, 54], [17, 60], [17, 62], [17, 74], [17, 77], [17, 83], [17, 85], [17, 88], [17, 89], [17, 90], [17, 91], [17, 92], [17, 96], [17, 98], [17, 99], [18, 19], [18, 26], [18, 27], [18, 28], [18, 30], [18, 33], [18, 35], [18, 37], [18, 38], [18, 39], [18, 43], [18, 45], [18, 46], [18, 47], [18, 49], [18, 51], [18, 52], [18, 54], [18, 55], [18, 59], [18, 60], [18, 64], [18, 67], [18, 76], [18, 82], [18, 85], [18, 87], [19, 25], [19, 26], [19, 27], [19, 28], [19, 32], [19, 34], [19, 36], [19, 42], [19, 44], [19, 53], [19, 58], [19, 60], [19, 71], [19, 72], [19, 74], [19, 77], [19, 79], [19, 80], [19, 82], [19, 83], [19, 85], [19, 87], [19, 89], [19, 90], [19, 91], [19, 94], [19, 96], [19, 99], [20, 27], [20, 29], [20, 32], [20, 35], [20, 38], [20, 41], [20, 44], [20, 48], [20, 53], [20, 60], [20, 75], [20, 77], [20, 80], [20, 81], [20, 90], [20, 93], [20, 98], [21, 23], [21, 26], [21, 28], [21, 32], [21, 38], [21, 42], [21, 43], [21, 44], [21, 46], [21, 50], [21, 51], [21, 52], [21, 53], [21, 59], [21, 60], [21, 65], [21, 68], [21, 70], [21, 72], [21, 73], [21, 74], [21, 82], [21, 84], [21, 86], [21, 88], [21, 89], [21, 96], [21, 97], [22, 23], [22, 27], [22, 31], [22, 38], [22, 39], [22, 42], [22, 43], [22, 46], [22, 50], [22, 51], [22, 57], [22, 62], [22, 63], [22, 66], [22, 67], [22, 70], [22, 71], [22, 72], [22, 81], [22, 86], [22, 93], [22, 95], [22, 97], [22, 99], [23, 24], [23, 25], [23, 28], [23, 29], [23, 33], [23, 43], [23, 51], [23, 54], [23, 59], [23, 68], [23, 69], [23, 81], [23, 82], [23, 86], [23, 91], [23, 94], [23, 95], [23, 99], [24, 25], [24, 26], [24, 30], [24, 33], [24, 36], [24, 39], [24, 40], [24, 44], [24, 56], [24, 59], [24, 64], [24, 69], [24, 70], [24, 73], [24, 74], [24, 85], [24, 87], [24, 92], [24, 94], [25, 28], [25, 30], [25, 37], [25, 42], [25, 46], [25, 48], [25, 49], [25, 50], [25, 52], [25, 62], [25, 64], [25, 65], [25, 67], [25, 68], [25, 69], [25, 73], [25, 75], [25, 79], [25, 82], [25, 85], [25, 86], [25, 87], [25, 93], [25, 94], [25, 95], [25, 97], [25, 98], [26, 27], [26, 28], [26, 30], [26, 31], [26, 37], [26, 39], [26, 43], [26, 47], [26, 51], [26, 53], [26, 56], [26, 60], [26, 68], [26, 75], [26, 78], [26, 82], [26, 86], [26, 88], [26, 90], [27, 32], [27, 34], [27, 36], [27, 42], [27, 43], [27, 51], [27, 54], [27, 66], [27, 67], [27, 74], [27, 76], [27, 77], [27, 86], [27, 87], [27, 90], [27, 92], [27, 95], [27, 97], [28, 29], [28, 30], [28, 32], [28, 33], [28, 34], [28, 37], [28, 38], [28, 41], [28, 44], [28, 46], [28, 58], [28, 60], [28, 62], [28, 66], [28, 67], [28, 69], [28, 74], [28, 75], [28, 78], [28, 81], [28, 91], [28, 93], [28, 95], [28, 99], [29, 35], [29, 39], [29, 51], [29, 52], [29, 53], [29, 54], [29, 56], [29, 57], [29, 59], [29, 62], [29, 65], [29, 66], [29, 67], [29, 70], [29, 71], [29, 75], [29, 76], [29, 77], [29, 78], [29, 80], [29, 85], [29, 88], [29, 90], [29, 92], [29, 96], [30, 31], [30, 36], [30, 42], [30, 43], [30, 44], [30, 45], [30, 47], [30, 48], [30, 52], [30, 59], [30, 61], [30, 64], [30, 68], [30, 70], [30, 75], [30, 85], [30, 88], [30, 90], [30, 94], [30, 95], [31, 35], [31, 37], [31, 43], [31, 48], [31, 49], [31, 54], [31, 56], [31, 61], [31, 63], [31, 64], [31, 66], [31, 67], [31, 71], [31, 74], [31, 75], [31, 77], [31, 78], [31, 79], [31, 81], [31, 84], [31, 85], [31, 86], [31, 87], [31, 95], [31, 96], [32, 44], [32, 47], [32, 48], [32, 52], [32, 60], [32, 62], [32, 64], [32, 70], [32, 75], [32, 86], [32, 88], [32, 91], [32, 93], [33, 41], [33, 42], [33, 43], [33, 49], [33, 50], [33, 53], [33, 54], [33, 60], [33, 63], [33, 68], [33, 71], [33, 72], [33, 73], [33, 74], [33, 76], [33, 77], [33, 80], [33, 83], [33, 86], [33, 91], [33, 92], [33, 99], [34, 38], [34, 39], [34, 40], [34, 43], [34, 44], [34, 50], [34, 53], [34, 54], [34, 55], [34, 59], [34, 67], [34, 68], [34, 75], [34, 76], [34, 77], [34, 79], [34, 82], [34, 84], [34, 89], [34, 95], [35, 37], [35, 39], [35, 42], [35, 44], [35, 47], [35, 50], [35, 54], [35, 55], [35, 58], [35, 62], [35, 63], [35, 68], [35, 71], [35, 73], [35, 80], [35, 82], [35, 83], [35, 85], [35, 90], [35, 92], [36, 37], [36, 45], [36, 46], [36, 47], [36, 61], [36, 62], [36, 63], [36, 65], [36, 66], [36, 68], [36, 70], [36, 71], [36, 75], [36, 79], [36, 81], [36, 82], [36, 84], [36, 86], [36, 90], [36, 91], [37, 41], [37, 42], [37, 47], [37, 50], [37, 55], [37, 57], [37, 67], [37, 69], [37, 72], [37, 75], [37, 79], [37, 80], [37, 81], [37, 83], [37, 85], [37, 91], [37, 94], [37, 95], [37, 97], [38, 40], [38, 44], [38, 47], [38, 49], [38, 50], [38, 51], [38, 52], [38, 54], [38, 59], [38, 60], [38, 61], [38, 63], [38, 66], [38, 68], [38, 72], [38, 76], [38, 80], [38, 82], [38, 86], [38, 88], [38, 90], [39, 42], [39, 48], [39, 51], [39, 52], [39, 54], [39, 60], [39, 64], [39, 66], [39, 70], [39, 71], [39, 72], [39, 74], [39, 76], [39, 77], [39, 81], [39, 82], [39, 83], [39, 84], [39, 86], [39, 87], [39, 88], [39, 93], [39, 94], [39, 98], [40, 56], [40, 60], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 74], [40, 75], [40, 79], [40, 83], [40, 86], [40, 88], [40, 90], [40, 97], [40, 98], [41, 43], [41, 47], [41, 49], [41, 50], [41, 56], [41, 58], [41, 66], [41, 68], [41, 70], [41, 71], [41, 72], [41, 75], [41, 76], [41, 79], [41, 80], [41, 83], [41, 90], [41, 97], [41, 99], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 50], [42, 53], [42, 54], [42, 56], [42, 57], [42, 58], [42, 61], [42, 62], [42, 64], [42, 70], [42, 73], [42, 75], [42, 81], [42, 87], [42, 88], [42, 90], [42, 92], [42, 94], [43, 45], [43, 47], [43, 50], [43, 54], [43, 55], [43, 60], [43, 64], [43, 68], [43, 69], [43, 70], [43, 72], [43, 77], [43, 78], [43, 79], [43, 80], [43, 82], [43, 84], [43, 85], [43, 88], [43, 90], [43, 95], [43, 97], [43, 99], [44, 49], [44, 51], [44, 55], [44, 57], [44, 60], [44, 63], [44, 66], [44, 69], [44, 70], [44, 73], [44, 78], [44, 84], [44, 85], [44, 88], [44, 91], [44, 99], [45, 46], [45, 47], [45, 48], [45, 55], [45, 59], [45, 62], [45, 65], [45, 68], [45, 73], [45, 76], [45, 77], [45, 78], [45, 82], [45, 83], [45, 84], [45, 90], [45, 91], [45, 95], [46, 47], [46, 50], [46, 54], [46, 55], [46, 59], [46, 63], [46, 64], [46, 69], [46, 74], [46, 75], [46, 76], [46, 77], [46, 78], [46, 80], [46, 82], [46, 83], [46, 86], [46, 87], [46, 89], [46, 92], [46, 93], [46, 96], [47, 52], [47, 58], [47, 63], [47, 69], [47, 73], [47, 74], [47, 78], [47, 80], [47, 88], [47, 91], [47, 92], [47, 98], [47, 99], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 61], [48, 66], [48, 67], [48, 69], [48, 73], [48, 76], [48, 79], [48, 82], [48, 90], [48, 94], [48, 95], [49, 51], [49, 52], [49, 54], [49, 56], [49, 59], [49, 68], [49, 70], [49, 72], [49, 73], [49, 79], [49, 81], [49, 85], [49, 91], [49, 94], [49, 96], [49, 97], [50, 53], [50, 54], [50, 58], [50, 60], [50, 65], [50, 67], [50, 77], [50, 78], [50, 79], [50, 80], [50, 90], [50, 92], [50, 96], [50, 97], [51, 54], [51, 55], [51, 60], [51, 62], [51, 63], [51, 69], [51, 73], [51, 74], [51, 84], [51, 85], [51, 92], [51, 93], [51, 94], [51, 95], [52, 55], [52, 56], [52, 57], [52, 59], [52, 60], [52, 64], [52, 65], [52, 67], [52, 68], [52, 70], [52, 71], [52, 74], [52, 76], [52, 83], [52, 86], [52, 93], [52, 98], [52, 99], [53, 54], [53, 55], [53, 65], [53, 67], [53, 69], [53, 78], [53, 79], [53, 84], [53, 87], [53, 88], [53, 89], [53, 91], [53, 92], [53, 93], [53, 94], [53, 98], [54, 56], [54, 57], [54, 62], [54, 64], [54, 73], [54, 75], [54, 77], [54, 82], [54, 85], [54, 87], [54, 90], [54, 91], [54, 96], [54, 97], [55, 58], [55, 60], [55, 61], [55, 63], [55, 66], [55, 68], [55, 73], [55, 74], [55, 76], [55, 82], [55, 85], [55, 89], [55, 90], [55, 91], [55, 95], [55, 97], [55, 98], [55, 99], [56, 57], [56, 59], [56, 60], [56, 61], [56, 67], [56, 71], [56, 81], [56, 82], [56, 86], [56, 87], [56, 88], [56, 89], [56, 95], [56, 97], [57, 58], [57, 60], [57, 62], [57, 64], [57, 69], [57, 70], [57, 72], [57, 74], [57, 75], [57, 80], [57, 81], [57, 82], [57, 83], [57, 85], [57, 89], [57, 91], [57, 96], [58, 59], [58, 68], [58, 73], [58, 78], [58, 80], [58, 88], [58, 90], [58, 92], [58, 94], [59, 62], [59, 63], [59, 64], [59, 71], [59, 74], [59, 75], [59, 77], [59, 79], [59, 81], [59, 85], [59, 86], [59, 90], [59, 92], [59, 95], [60, 61], [60, 66], [60, 67], [60, 70], [60, 78], [60, 80], [60, 81], [60, 85], [60, 91], [60, 92], [60, 93], [60, 97], [61, 62], [61, 73], [61, 74], [61, 75], [61, 76], [61, 77], [61, 78], [61, 79], [61, 82], [61, 85], [61, 87], [61, 89], [61, 91], [61, 96], [61, 98], [62, 69], [62, 77], [62, 79], [62, 81], [62, 82], [62, 84], [62, 92], [62, 93], [62, 94], [62, 97], [63, 64], [63, 65], [63, 66], [63, 74], [63, 77], [63, 82], [63, 84], [63, 86], [63, 90], [63, 93], [63, 95], [63, 96], [63, 98], [64, 69], [64, 70], [64, 72], [64, 73], [64, 74], [64, 76], [64, 78], [64, 79], [64, 80], [64, 85], [64, 86], [64, 89], [64, 93], [64, 94], [64, 95], [64, 98], [65, 73], [65, 76], [65, 79], [65, 81], [65, 82], [65, 83], [65, 86], [65, 87], [65, 88], [65, 91], [66, 69], [66, 73], [66, 76], [66, 79], [66, 81], [66, 83], [66, 86], [66, 89], [66, 93], [66, 96], [66, 99], [67, 79], [67, 86], [67, 88], [67, 89], [67, 98], [68, 74], [68, 80], [68, 83], [68, 85], [68, 92], [68, 93], [68, 94], [68, 95], [68, 96], [68, 98], [69, 71], [69, 72], [69, 75], [69, 77], [69, 86], [69, 89], [69, 96], [70, 72], [70, 75], [70, 76], [70, 78], [70, 84], [70, 86], [70, 89], [70, 90], [71, 74], [71, 76], [71, 78], [71, 85], [71, 92], [71, 93], [71, 99], [72, 73], [72, 74], [72, 76], [72, 77], [72, 84], [72, 88], [72, 90], [72, 95], [72, 97], [73, 76], [73, 77], [73, 79], [73, 84], [73, 85], [73, 89], [73, 91], [74, 75], [74, 81], [74, 83], [74, 87], [74, 90], [74, 92], [74, 94], [74, 96], [75, 81], [75, 83], [75, 90], [75, 91], [75, 95], [75, 96], [75, 98], [76, 78], [76, 84], [77, 84], [77, 86], [77, 88], [77, 96], [77, 97], [78, 80], [78, 88], [78, 93], [78, 96], [78, 97], [79, 84], [79, 87], [79, 91], [79, 94], [79, 95], [79, 97], [79, 98], [80, 82], [80, 87], [80, 94], [81, 83], [81, 84], [81, 91], [81, 93], [81, 95], [81, 99], [82, 83], [82, 84], [82, 88], [82, 92], [82, 96], [82, 99], [83, 89], [83, 90], [83, 96], [83, 98], [83, 99], [84, 85], [84, 87], [84, 92], [84, 94], [84, 98], [84, 99], [85, 87], [85, 89], [85, 93], [85, 95], [85, 96], [85, 98], [85, 99], [86, 97], [87, 89], [87, 93], [87, 96], [87, 99], [88, 91], [88, 99], [89, 96], [89, 97], [90, 92], [90, 93], [90, 94], [90, 98], [91, 94], [91, 98], [92, 94], [92, 97], [92, 99], [93, 94], [93, 97], [94, 97], [95, 99], [97, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s1/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b7f1d2d5c58b9bc2565c667d645afafd30ffd7a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [0, 2, 5, 8, 10, 14, 19, 31, 38, 41, 42, 53, 55, 56, 62, 64, 68, 71, 83, 84]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s1/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l4-s1/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a7f7478cad62d22b765cdec88880e9c3c37508ab --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 4], [0, 7], [0, 9], [0, 14], [0, 15], [0, 20], [0, 22], [0, 23], [0, 25], [0, 26], [0, 35], [0, 37], [0, 38], [0, 39], [0, 40], [0, 45], [0, 47], [0, 57], [0, 63], [0, 66], [0, 68], [0, 73], [0, 74], [0, 76], [0, 77], [0, 82], [0, 83], [0, 85], [0, 87], [0, 92], [0, 93], [0, 96], [0, 99], [1, 2], [1, 4], [1, 6], [1, 9], [1, 12], [1, 19], [1, 23], [1, 30], [1, 32], [1, 40], [1, 47], [1, 54], [1, 57], [1, 63], [1, 65], [1, 67], [1, 69], [1, 71], [1, 73], [1, 80], [1, 84], [1, 87], [1, 89], [1, 95], [2, 3], [2, 4], [2, 5], [2, 11], [2, 12], [2, 20], [2, 23], [2, 24], [2, 27], [2, 34], [2, 37], [2, 39], [2, 42], [2, 43], [2, 50], [2, 53], [2, 55], [2, 62], [2, 65], [2, 76], [2, 79], [2, 84], [2, 91], [2, 93], [3, 7], [3, 10], [3, 14], [3, 16], [3, 17], [3, 38], [3, 39], [3, 42], [3, 43], [3, 47], [3, 54], [3, 58], [3, 60], [3, 61], [3, 67], [3, 70], [3, 71], [3, 72], [3, 77], [3, 79], [3, 81], [3, 84], [3, 88], [3, 97], [4, 10], [4, 14], [4, 15], [4, 16], [4, 18], [4, 25], [4, 40], [4, 44], [4, 46], [4, 48], [4, 50], [4, 51], [4, 53], [4, 56], [4, 60], [4, 61], [4, 64], [4, 70], [4, 71], [4, 75], [4, 76], [4, 80], [4, 81], [4, 84], [4, 85], [4, 88], [4, 94], [4, 95], [5, 7], [5, 8], [5, 16], [5, 21], [5, 25], [5, 28], [5, 31], [5, 33], [5, 37], [5, 40], [5, 41], [5, 45], [5, 48], [5, 49], [5, 50], [5, 52], [5, 54], [5, 55], [5, 58], [5, 64], [5, 68], [5, 70], [5, 75], [5, 76], [5, 78], [5, 85], [5, 89], [5, 90], [5, 91], [5, 92], [5, 93], [5, 95], [5, 98], [5, 99], [6, 14], [6, 20], [6, 21], [6, 22], [6, 28], [6, 29], [6, 35], [6, 36], [6, 37], [6, 39], [6, 40], [6, 42], [6, 44], [6, 46], [6, 58], [6, 63], [6, 64], [6, 68], [6, 70], [6, 74], [6, 78], [6, 80], [6, 88], [6, 91], [6, 94], [7, 8], [7, 10], [7, 15], [7, 17], [7, 18], [7, 20], [7, 22], [7, 27], [7, 31], [7, 32], [7, 36], [7, 39], [7, 47], [7, 48], [7, 49], [7, 55], [7, 56], [7, 57], [7, 64], [7, 68], [7, 76], [7, 84], [7, 85], [7, 95], [7, 96], [8, 13], [8, 15], [8, 21], [8, 24], [8, 27], [8, 28], [8, 32], [8, 33], [8, 35], [8, 41], [8, 47], [8, 49], [8, 50], [8, 51], [8, 54], [8, 55], [8, 56], [8, 58], [8, 60], [8, 65], [8, 66], [8, 76], [8, 77], [8, 78], [8, 81], [8, 82], [8, 87], [8, 96], [8, 97], [8, 98], [8, 99], [9, 10], [9, 15], [9, 20], [9, 21], [9, 25], [9, 26], [9, 27], [9, 30], [9, 31], [9, 39], [9, 40], [9, 41], [9, 44], [9, 48], [9, 50], [9, 54], [9, 56], [9, 64], [9, 66], [9, 71], [9, 74], [9, 79], [9, 83], [9, 85], [9, 87], [9, 91], [9, 92], [9, 95], [9, 97], [9, 99], [10, 14], [10, 16], [10, 22], [10, 28], [10, 32], [10, 42], [10, 43], [10, 44], [10, 48], [10, 49], [10, 51], [10, 52], [10, 59], [10, 69], [10, 74], [10, 76], [10, 77], [10, 78], [10, 83], [10, 84], [10, 85], [10, 86], [10, 88], [10, 89], [10, 90], [10, 91], [10, 92], [10, 96], [11, 13], [11, 14], [11, 20], [11, 21], [11, 23], [11, 31], [11, 33], [11, 34], [11, 39], [11, 43], [11, 44], [11, 48], [11, 50], [11, 53], [11, 55], [11, 56], [11, 61], [11, 62], [11, 65], [11, 82], [11, 84], [11, 85], [11, 86], [11, 87], [11, 91], [11, 92], [11, 94], [11, 95], [11, 97], [11, 99], [12, 16], [12, 17], [12, 21], [12, 31], [12, 35], [12, 36], [12, 41], [12, 43], [12, 44], [12, 47], [12, 48], [12, 50], [12, 53], [12, 55], [12, 57], [12, 60], [12, 61], [12, 72], [12, 73], [12, 74], [12, 76], [12, 83], [12, 84], [12, 90], [12, 91], [12, 94], [13, 14], [13, 16], [13, 20], [13, 22], [13, 23], [13, 27], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 43], [13, 45], [13, 50], [13, 55], [13, 56], [13, 61], [13, 62], [13, 64], [13, 65], [13, 67], [13, 78], [13, 80], [13, 81], [13, 87], [13, 88], [13, 93], [13, 95], [14, 15], [14, 16], [14, 18], [14, 20], [14, 22], [14, 29], [14, 31], [14, 33], [14, 38], [14, 39], [14, 40], [14, 43], [14, 48], [14, 52], [14, 53], [14, 61], [14, 62], [14, 70], [14, 71], [14, 73], [14, 74], [14, 76], [14, 85], [14, 86], [14, 89], [14, 92], [14, 95], [14, 99], [15, 16], [15, 18], [15, 20], [15, 24], [15, 29], [15, 30], [15, 33], [15, 36], [15, 37], [15, 44], [15, 46], [15, 48], [15, 50], [15, 57], [15, 58], [15, 66], [15, 68], [15, 69], [15, 76], [15, 77], [15, 78], [15, 79], [15, 83], [15, 86], [15, 88], [15, 89], [15, 92], [15, 93], [15, 99], [16, 19], [16, 20], [16, 21], [16, 23], [16, 25], [16, 26], [16, 29], [16, 30], [16, 31], [16, 33], [16, 34], [16, 38], [16, 41], [16, 47], [16, 50], [16, 53], [16, 57], [16, 63], [16, 67], [16, 68], [16, 77], [16, 81], [16, 82], [16, 87], [16, 90], [16, 91], [16, 98], [16, 99], [17, 21], [17, 23], [17, 24], [17, 25], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 37], [17, 39], [17, 43], [17, 45], [17, 48], [17, 49], [17, 54], [17, 60], [17, 62], [17, 74], [17, 77], [17, 83], [17, 85], [17, 88], [17, 89], [17, 90], [17, 91], [17, 92], [17, 96], [17, 98], [17, 99], [18, 19], [18, 26], [18, 27], [18, 28], [18, 30], [18, 33], [18, 35], [18, 37], [18, 38], [18, 39], [18, 43], [18, 45], [18, 46], [18, 47], [18, 49], [18, 51], [18, 52], [18, 54], [18, 55], [18, 59], [18, 60], [18, 64], [18, 67], [18, 76], [18, 82], [18, 85], [18, 87], [19, 25], [19, 26], [19, 27], [19, 28], [19, 32], [19, 34], [19, 36], [19, 42], [19, 44], [19, 53], [19, 58], [19, 60], [19, 71], [19, 72], [19, 74], [19, 77], [19, 79], [19, 80], [19, 82], [19, 83], [19, 85], [19, 87], [19, 89], [19, 90], [19, 91], [19, 94], [19, 96], [19, 99], [20, 27], [20, 29], [20, 32], [20, 35], [20, 38], [20, 41], [20, 44], [20, 48], [20, 53], [20, 60], [20, 75], [20, 77], [20, 80], [20, 81], [20, 90], [20, 93], [20, 98], [21, 23], [21, 26], [21, 28], [21, 32], [21, 38], [21, 42], [21, 43], [21, 44], [21, 46], [21, 50], [21, 51], [21, 52], [21, 53], [21, 59], [21, 60], [21, 65], [21, 68], [21, 70], [21, 72], [21, 73], [21, 74], [21, 82], [21, 84], [21, 86], [21, 88], [21, 89], [21, 96], [21, 97], [22, 23], [22, 27], [22, 31], [22, 38], [22, 39], [22, 42], [22, 43], [22, 46], [22, 50], [22, 51], [22, 57], [22, 62], [22, 63], [22, 66], [22, 67], [22, 70], [22, 71], [22, 72], [22, 81], [22, 86], [22, 93], [22, 95], [22, 97], [22, 99], [23, 24], [23, 25], [23, 28], [23, 29], [23, 33], [23, 43], [23, 51], [23, 54], [23, 59], [23, 68], [23, 69], [23, 81], [23, 82], [23, 86], [23, 91], [23, 94], [23, 95], [23, 99], [24, 25], [24, 26], [24, 30], [24, 33], [24, 36], [24, 39], [24, 40], [24, 44], [24, 56], [24, 59], [24, 64], [24, 69], [24, 70], [24, 73], [24, 74], [24, 85], [24, 87], [24, 92], [24, 94], [25, 28], [25, 30], [25, 37], [25, 42], [25, 46], [25, 48], [25, 49], [25, 50], [25, 52], [25, 62], [25, 64], [25, 65], [25, 67], [25, 68], [25, 69], [25, 73], [25, 75], [25, 79], [25, 82], [25, 85], [25, 86], [25, 87], [25, 93], [25, 94], [25, 95], [25, 97], [25, 98], [26, 27], [26, 28], [26, 30], [26, 31], [26, 37], [26, 39], [26, 43], [26, 47], [26, 51], [26, 53], [26, 56], [26, 60], [26, 68], [26, 75], [26, 78], [26, 82], [26, 86], [26, 88], [26, 90], [27, 32], [27, 34], [27, 36], [27, 42], [27, 43], [27, 51], [27, 54], [27, 66], [27, 67], [27, 74], [27, 76], [27, 77], [27, 86], [27, 87], [27, 90], [27, 92], [27, 95], [27, 97], [28, 29], [28, 30], [28, 32], [28, 33], [28, 34], [28, 37], [28, 38], [28, 41], [28, 44], [28, 46], [28, 58], [28, 60], [28, 62], [28, 66], [28, 67], [28, 69], [28, 74], [28, 75], [28, 78], [28, 81], [28, 91], [28, 93], [28, 95], [28, 99], [29, 35], [29, 39], [29, 51], [29, 52], [29, 53], [29, 54], [29, 56], [29, 57], [29, 59], [29, 62], [29, 65], [29, 66], [29, 67], [29, 70], [29, 71], [29, 75], [29, 76], [29, 77], [29, 78], [29, 80], [29, 85], [29, 88], [29, 90], [29, 92], [29, 96], [30, 31], [30, 36], [30, 42], [30, 43], [30, 44], [30, 45], [30, 47], [30, 48], [30, 52], [30, 59], [30, 61], [30, 64], [30, 68], [30, 70], [30, 75], [30, 85], [30, 88], [30, 90], [30, 94], [30, 95], [31, 35], [31, 37], [31, 43], [31, 48], [31, 49], [31, 54], [31, 56], [31, 61], [31, 63], [31, 64], [31, 66], [31, 67], [31, 71], [31, 74], [31, 75], [31, 77], [31, 78], [31, 79], [31, 81], [31, 84], [31, 85], [31, 86], [31, 87], [31, 95], [31, 96], [32, 44], [32, 47], [32, 48], [32, 52], [32, 60], [32, 62], [32, 64], [32, 70], [32, 75], [32, 86], [32, 88], [32, 91], [32, 93], [33, 41], [33, 42], [33, 43], [33, 49], [33, 50], [33, 53], [33, 54], [33, 60], [33, 63], [33, 68], [33, 71], [33, 72], [33, 73], [33, 74], [33, 76], [33, 77], [33, 80], [33, 83], [33, 86], [33, 91], [33, 92], [33, 99], [34, 38], [34, 39], [34, 40], [34, 43], [34, 44], [34, 50], [34, 53], [34, 54], [34, 55], [34, 59], [34, 67], [34, 68], [34, 75], [34, 76], [34, 77], [34, 79], [34, 82], [34, 84], [34, 89], [34, 95], [35, 37], [35, 39], [35, 42], [35, 44], [35, 47], [35, 50], [35, 54], [35, 55], [35, 58], [35, 62], [35, 63], [35, 68], [35, 71], [35, 73], [35, 80], [35, 82], [35, 83], [35, 85], [35, 90], [35, 92], [36, 37], [36, 45], [36, 46], [36, 47], [36, 61], [36, 62], [36, 63], [36, 65], [36, 66], [36, 68], [36, 70], [36, 71], [36, 75], [36, 79], [36, 81], [36, 82], [36, 84], [36, 86], [36, 90], [36, 91], [37, 41], [37, 42], [37, 47], [37, 50], [37, 55], [37, 57], [37, 67], [37, 69], [37, 72], [37, 75], [37, 79], [37, 80], [37, 81], [37, 83], [37, 85], [37, 91], [37, 94], [37, 95], [37, 97], [38, 40], [38, 44], [38, 47], [38, 49], [38, 50], [38, 51], [38, 52], [38, 54], [38, 59], [38, 60], [38, 61], [38, 63], [38, 66], [38, 68], [38, 72], [38, 76], [38, 80], [38, 82], [38, 86], [38, 88], [38, 90], [39, 42], [39, 48], [39, 51], [39, 52], [39, 54], [39, 60], [39, 64], [39, 66], [39, 70], [39, 71], [39, 72], [39, 74], [39, 76], [39, 77], [39, 81], [39, 82], [39, 83], [39, 84], [39, 86], [39, 87], [39, 88], [39, 93], [39, 94], [39, 98], [40, 56], [40, 60], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 74], [40, 75], [40, 79], [40, 83], [40, 86], [40, 88], [40, 90], [40, 97], [40, 98], [41, 43], [41, 47], [41, 49], [41, 50], [41, 56], [41, 58], [41, 66], [41, 68], [41, 70], [41, 71], [41, 72], [41, 75], [41, 76], [41, 79], [41, 80], [41, 83], [41, 90], [41, 97], [41, 99], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 50], [42, 53], [42, 54], [42, 56], [42, 57], [42, 58], [42, 61], [42, 62], [42, 64], [42, 70], [42, 73], [42, 75], [42, 81], [42, 87], [42, 88], [42, 90], [42, 92], [42, 94], [43, 45], [43, 47], [43, 50], [43, 54], [43, 55], [43, 60], [43, 64], [43, 68], [43, 69], [43, 70], [43, 72], [43, 77], [43, 78], [43, 79], [43, 80], [43, 82], [43, 84], [43, 85], [43, 88], [43, 90], [43, 95], [43, 97], [43, 99], [44, 49], [44, 51], [44, 55], [44, 57], [44, 60], [44, 63], [44, 66], [44, 69], [44, 70], [44, 73], [44, 78], [44, 84], [44, 85], [44, 88], [44, 91], [44, 99], [45, 46], [45, 47], [45, 48], [45, 55], [45, 59], [45, 62], [45, 65], [45, 68], [45, 73], [45, 76], [45, 77], [45, 78], [45, 82], [45, 83], [45, 84], [45, 90], [45, 91], [45, 95], [46, 47], [46, 50], [46, 54], [46, 55], [46, 59], [46, 63], [46, 64], [46, 69], [46, 74], [46, 75], [46, 76], [46, 77], [46, 78], [46, 80], [46, 82], [46, 83], [46, 86], [46, 87], [46, 89], [46, 92], [46, 93], [46, 96], [47, 52], [47, 58], [47, 63], [47, 69], [47, 73], [47, 74], [47, 78], [47, 80], [47, 88], [47, 91], [47, 92], [47, 98], [47, 99], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 61], [48, 66], [48, 67], [48, 69], [48, 73], [48, 76], [48, 79], [48, 82], [48, 90], [48, 94], [48, 95], [49, 51], [49, 52], [49, 54], [49, 56], [49, 59], [49, 68], [49, 70], [49, 72], [49, 73], [49, 79], [49, 81], [49, 85], [49, 91], [49, 94], [49, 96], [49, 97], [50, 53], [50, 54], [50, 58], [50, 60], [50, 65], [50, 67], [50, 77], [50, 78], [50, 79], [50, 80], [50, 90], [50, 92], [50, 96], [50, 97], [51, 54], [51, 55], [51, 60], [51, 62], [51, 63], [51, 69], [51, 73], [51, 74], [51, 84], [51, 85], [51, 92], [51, 93], [51, 94], [51, 95], [52, 55], [52, 56], [52, 57], [52, 59], [52, 60], [52, 64], [52, 65], [52, 67], [52, 68], [52, 70], [52, 71], [52, 74], [52, 76], [52, 83], [52, 86], [52, 93], [52, 98], [52, 99], [53, 54], [53, 55], [53, 65], [53, 67], [53, 69], [53, 78], [53, 79], [53, 84], [53, 87], [53, 88], [53, 89], [53, 91], [53, 92], [53, 93], [53, 94], [53, 98], [54, 56], [54, 57], [54, 62], [54, 64], [54, 73], [54, 75], [54, 77], [54, 82], [54, 85], [54, 87], [54, 90], [54, 91], [54, 96], [54, 97], [55, 58], [55, 60], [55, 61], [55, 63], [55, 66], [55, 68], [55, 73], [55, 74], [55, 76], [55, 82], [55, 85], [55, 89], [55, 90], [55, 91], [55, 95], [55, 97], [55, 98], [55, 99], [56, 57], [56, 59], [56, 60], [56, 61], [56, 67], [56, 71], [56, 81], [56, 82], [56, 86], [56, 87], [56, 88], [56, 89], [56, 95], [56, 97], [57, 58], [57, 60], [57, 62], [57, 64], [57, 69], [57, 70], [57, 72], [57, 74], [57, 75], [57, 80], [57, 81], [57, 82], [57, 83], [57, 85], [57, 89], [57, 91], [57, 96], [58, 59], [58, 68], [58, 73], [58, 78], [58, 80], [58, 88], [58, 90], [58, 92], [58, 94], [59, 62], [59, 63], [59, 64], [59, 71], [59, 74], [59, 75], [59, 77], [59, 79], [59, 81], [59, 85], [59, 86], [59, 90], [59, 92], [59, 95], [60, 61], [60, 66], [60, 67], [60, 70], [60, 78], [60, 80], [60, 81], [60, 85], [60, 91], [60, 92], [60, 93], [60, 97], [61, 62], [61, 73], [61, 74], [61, 75], [61, 76], [61, 77], [61, 78], [61, 79], [61, 82], [61, 85], [61, 87], [61, 89], [61, 91], [61, 96], [61, 98], [62, 69], [62, 77], [62, 79], [62, 81], [62, 82], [62, 84], [62, 92], [62, 93], [62, 94], [62, 97], [63, 64], [63, 65], [63, 66], [63, 74], [63, 77], [63, 82], [63, 84], [63, 86], [63, 90], [63, 93], [63, 95], [63, 96], [63, 98], [64, 69], [64, 70], [64, 72], [64, 73], [64, 74], [64, 76], [64, 78], [64, 79], [64, 80], [64, 85], [64, 86], [64, 89], [64, 93], [64, 94], [64, 95], [64, 98], [65, 73], [65, 76], [65, 79], [65, 81], [65, 82], [65, 83], [65, 86], [65, 87], [65, 88], [65, 91], [66, 69], [66, 73], [66, 76], [66, 79], [66, 81], [66, 83], [66, 86], [66, 89], [66, 93], [66, 96], [66, 99], [67, 79], [67, 86], [67, 88], [67, 89], [67, 98], [68, 74], [68, 80], [68, 83], [68, 85], [68, 92], [68, 93], [68, 94], [68, 95], [68, 96], [68, 98], [69, 71], [69, 72], [69, 75], [69, 77], [69, 86], [69, 89], [69, 96], [70, 72], [70, 75], [70, 76], [70, 78], [70, 84], [70, 86], [70, 89], [70, 90], [71, 74], [71, 76], [71, 78], [71, 85], [71, 92], [71, 93], [71, 99], [72, 73], [72, 74], [72, 76], [72, 77], [72, 84], [72, 88], [72, 90], [72, 95], [72, 97], [73, 76], [73, 77], [73, 79], [73, 84], [73, 85], [73, 89], [73, 91], [74, 75], [74, 81], [74, 83], [74, 87], [74, 90], [74, 92], [74, 94], [74, 96], [75, 81], [75, 83], [75, 90], [75, 91], [75, 95], [75, 96], [75, 98], [76, 78], [76, 84], [77, 84], [77, 86], [77, 88], [77, 96], [77, 97], [78, 80], [78, 88], [78, 93], [78, 96], [78, 97], [79, 84], [79, 87], [79, 91], [79, 94], [79, 95], [79, 97], [79, 98], [80, 82], [80, 87], [80, 94], [81, 83], [81, 84], [81, 91], [81, 93], [81, 95], [81, 99], [82, 83], [82, 84], [82, 88], [82, 92], [82, 96], [82, 99], [83, 89], [83, 90], [83, 96], [83, 98], [83, 99], [84, 85], [84, 87], [84, 92], [84, 94], [84, 98], [84, 99], [85, 87], [85, 89], [85, 93], [85, 95], [85, 96], [85, 98], [85, 99], [86, 97], [87, 89], [87, 93], [87, 96], [87, 99], [88, 91], [88, 99], [89, 96], [89, 97], [90, 92], [90, 93], [90, 94], [90, 98], [91, 94], [91, 98], [92, 94], [92, 97], [92, 99], [93, 94], [93, 97], [94, 97], [95, 99], [97, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s1/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l4-s1/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l4-s6/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l4-s6/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..88e3ad22a3200a5c8c77fed5e5f2b5578e8221e9 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 1], [0, 2], [0, 6], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 18], [0, 19], [0, 22], [0, 26], [0, 27], [0, 31], [0, 39], [0, 41], [0, 43], [0, 49], [0, 51], [0, 56], [0, 63], [0, 64], [0, 67], [0, 68], [0, 70], [0, 72], [0, 78], [0, 80], [0, 87], [0, 89], [0, 94], [1, 5], [1, 14], [1, 17], [1, 22], [1, 25], [1, 28], [1, 32], [1, 33], [1, 34], [1, 36], [1, 37], [1, 41], [1, 50], [1, 53], [1, 54], [1, 58], [1, 61], [1, 64], [1, 67], [1, 71], [1, 78], [1, 79], [1, 81], [1, 82], [1, 83], [1, 87], [1, 88], [1, 89], [1, 91], [1, 94], [1, 98], [2, 4], [2, 5], [2, 8], [2, 11], [2, 17], [2, 20], [2, 22], [2, 24], [2, 28], [2, 34], [2, 37], [2, 38], [2, 41], [2, 45], [2, 49], [2, 53], [2, 56], [2, 58], [2, 60], [2, 63], [2, 66], [2, 68], [2, 69], [2, 71], [2, 77], [2, 80], [2, 81], [2, 83], [2, 85], [2, 86], [2, 90], [2, 91], [2, 99], [3, 4], [3, 6], [3, 10], [3, 11], [3, 12], [3, 17], [3, 19], [3, 27], [3, 28], [3, 31], [3, 32], [3, 33], [3, 37], [3, 40], [3, 42], [3, 46], [3, 47], [3, 49], [3, 50], [3, 55], [3, 57], [3, 60], [3, 65], [3, 72], [3, 76], [3, 77], [3, 84], [3, 93], [3, 94], [4, 5], [4, 7], [4, 8], [4, 10], [4, 15], [4, 16], [4, 19], [4, 24], [4, 27], [4, 33], [4, 36], [4, 42], [4, 47], [4, 56], [4, 57], [4, 58], [4, 60], [4, 63], [4, 64], [4, 70], [4, 72], [4, 73], [4, 74], [4, 75], [4, 76], [4, 78], [4, 79], [4, 82], [4, 83], [4, 85], [4, 87], [4, 88], [4, 94], [4, 98], [4, 99], [5, 6], [5, 7], [5, 13], [5, 14], [5, 15], [5, 22], [5, 24], [5, 26], [5, 27], [5, 28], [5, 32], [5, 35], [5, 36], [5, 37], [5, 39], [5, 53], [5, 54], [5, 57], [5, 58], [5, 60], [5, 62], [5, 67], [5, 68], [5, 72], [5, 79], [5, 80], [5, 83], [5, 84], [5, 87], [5, 97], [6, 9], [6, 12], [6, 14], [6, 15], [6, 17], [6, 20], [6, 25], [6, 27], [6, 28], [6, 37], [6, 38], [6, 39], [6, 41], [6, 46], [6, 49], [6, 50], [6, 53], [6, 54], [6, 57], [6, 58], [6, 61], [6, 65], [6, 66], [6, 69], [6, 73], [6, 77], [6, 78], [6, 79], [6, 81], [6, 82], [6, 83], [6, 85], [6, 88], [6, 91], [6, 92], [6, 97], [6, 98], [7, 14], [7, 19], [7, 24], [7, 25], [7, 28], [7, 29], [7, 34], [7, 35], [7, 44], [7, 45], [7, 54], [7, 55], [7, 64], [7, 68], [7, 69], [7, 70], [7, 75], [7, 77], [7, 82], [7, 83], [7, 84], [7, 87], [7, 89], [7, 90], [8, 12], [8, 21], [8, 22], [8, 26], [8, 27], [8, 28], [8, 29], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 44], [8, 46], [8, 55], [8, 56], [8, 57], [8, 60], [8, 64], [8, 67], [8, 71], [8, 75], [8, 83], [8, 84], [8, 85], [8, 86], [8, 87], [8, 92], [8, 94], [8, 99], [9, 11], [9, 12], [9, 18], [9, 19], [9, 21], [9, 23], [9, 36], [9, 40], [9, 42], [9, 44], [9, 45], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 58], [9, 61], [9, 62], [9, 66], [9, 70], [9, 74], [9, 86], [9, 88], [9, 93], [10, 17], [10, 21], [10, 23], [10, 26], [10, 28], [10, 32], [10, 33], [10, 36], [10, 37], [10, 41], [10, 42], [10, 43], [10, 45], [10, 47], [10, 52], [10, 58], [10, 63], [10, 64], [10, 66], [10, 67], [10, 68], [10, 70], [10, 73], [10, 76], [10, 77], [10, 83], [10, 88], [10, 89], [10, 95], [10, 96], [10, 98], [10, 99], [11, 12], [11, 13], [11, 14], [11, 18], [11, 19], [11, 21], [11, 22], [11, 27], [11, 29], [11, 31], [11, 36], [11, 43], [11, 48], [11, 55], [11, 56], [11, 58], [11, 65], [11, 68], [11, 72], [11, 78], [11, 80], [11, 82], [11, 89], [11, 92], [11, 94], [11, 97], [12, 16], [12, 19], [12, 27], [12, 31], [12, 34], [12, 35], [12, 38], [12, 41], [12, 47], [12, 57], [12, 59], [12, 61], [12, 67], [12, 73], [12, 74], [12, 75], [12, 77], [12, 84], [12, 86], [12, 89], [12, 90], [12, 93], [12, 94], [12, 98], [13, 21], [13, 23], [13, 25], [13, 33], [13, 35], [13, 36], [13, 39], [13, 45], [13, 47], [13, 50], [13, 54], [13, 58], [13, 62], [13, 63], [13, 66], [13, 69], [13, 71], [13, 72], [13, 78], [13, 82], [13, 85], [13, 88], [13, 91], [13, 92], [13, 93], [13, 96], [13, 97], [14, 15], [14, 16], [14, 18], [14, 20], [14, 21], [14, 24], [14, 26], [14, 38], [14, 49], [14, 50], [14, 51], [14, 52], [14, 55], [14, 57], [14, 80], [14, 84], [14, 91], [14, 93], [14, 97], [14, 98], [15, 19], [15, 25], [15, 27], [15, 29], [15, 33], [15, 36], [15, 42], [15, 46], [15, 49], [15, 51], [15, 52], [15, 56], [15, 60], [15, 63], [15, 64], [15, 66], [15, 77], [15, 82], [15, 90], [15, 93], [15, 94], [15, 98], [16, 21], [16, 22], [16, 24], [16, 27], [16, 29], [16, 33], [16, 35], [16, 36], [16, 40], [16, 47], [16, 49], [16, 50], [16, 56], [16, 58], [16, 62], [16, 63], [16, 69], [16, 71], [16, 73], [16, 77], [16, 78], [16, 79], [16, 80], [16, 82], [16, 85], [16, 88], [16, 95], [16, 97], [17, 20], [17, 22], [17, 27], [17, 30], [17, 33], [17, 36], [17, 40], [17, 42], [17, 43], [17, 44], [17, 48], [17, 49], [17, 50], [17, 53], [17, 57], [17, 60], [17, 61], [17, 68], [17, 71], [17, 72], [17, 77], [17, 79], [17, 81], [17, 85], [17, 89], [18, 29], [18, 33], [18, 35], [18, 38], [18, 43], [18, 45], [18, 48], [18, 53], [18, 54], [18, 56], [18, 57], [18, 58], [18, 59], [18, 60], [18, 61], [18, 77], [18, 79], [18, 81], [18, 84], [18, 86], [18, 87], [18, 88], [18, 91], [18, 92], [18, 94], [18, 95], [18, 99], [19, 31], [19, 33], [19, 35], [19, 40], [19, 41], [19, 45], [19, 46], [19, 48], [19, 52], [19, 55], [19, 59], [19, 62], [19, 65], [19, 69], [19, 76], [19, 78], [19, 81], [19, 86], [19, 87], [19, 93], [19, 95], [19, 96], [20, 27], [20, 33], [20, 38], [20, 47], [20, 54], [20, 57], [20, 59], [20, 61], [20, 66], [20, 69], [20, 70], [20, 72], [20, 74], [20, 75], [20, 77], [20, 81], [20, 83], [21, 23], [21, 26], [21, 31], [21, 34], [21, 36], [21, 37], [21, 45], [21, 52], [21, 54], [21, 58], [21, 64], [21, 70], [21, 71], [21, 79], [21, 80], [21, 85], [21, 86], [21, 88], [21, 91], [21, 92], [21, 95], [21, 97], [22, 24], [22, 25], [22, 26], [22, 29], [22, 33], [22, 35], [22, 37], [22, 41], [22, 42], [22, 49], [22, 54], [22, 56], [22, 58], [22, 63], [22, 67], [22, 68], [22, 69], [22, 74], [22, 82], [22, 87], [22, 93], [22, 96], [22, 97], [23, 30], [23, 31], [23, 35], [23, 36], [23, 38], [23, 43], [23, 47], [23, 48], [23, 52], [23, 57], [23, 60], [23, 61], [23, 63], [23, 65], [23, 68], [23, 74], [23, 77], [23, 85], [23, 87], [23, 90], [23, 93], [23, 94], [23, 96], [23, 97], [23, 99], [24, 25], [24, 26], [24, 35], [24, 37], [24, 38], [24, 40], [24, 41], [24, 43], [24, 47], [24, 48], [24, 51], [24, 52], [24, 54], [24, 58], [24, 59], [24, 61], [24, 66], [24, 67], [24, 68], [24, 69], [24, 71], [24, 73], [24, 74], [24, 75], [24, 78], [24, 80], [24, 86], [24, 93], [24, 99], [25, 26], [25, 28], [25, 30], [25, 32], [25, 36], [25, 37], [25, 38], [25, 39], [25, 43], [25, 44], [25, 45], [25, 47], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 61], [25, 62], [25, 69], [25, 74], [25, 79], [25, 82], [25, 86], [25, 87], [25, 90], [25, 91], [25, 92], [25, 95], [25, 98], [25, 99], [26, 27], [26, 29], [26, 30], [26, 33], [26, 34], [26, 35], [26, 37], [26, 39], [26, 41], [26, 43], [26, 45], [26, 48], [26, 49], [26, 54], [26, 55], [26, 67], [26, 68], [26, 70], [26, 72], [26, 74], [26, 75], [26, 80], [26, 82], [26, 83], [26, 90], [26, 93], [26, 95], [26, 96], [27, 36], [27, 37], [27, 43], [27, 44], [27, 47], [27, 48], [27, 50], [27, 53], [27, 55], [27, 58], [27, 59], [27, 60], [27, 64], [27, 70], [27, 74], [27, 81], [27, 82], [27, 84], [27, 85], [27, 86], [27, 87], [27, 91], [27, 96], [27, 97], [27, 99], [28, 31], [28, 32], [28, 42], [28, 54], [28, 60], [28, 68], [28, 69], [28, 72], [28, 87], [28, 88], [28, 91], [28, 92], [28, 95], [28, 97], [29, 30], [29, 35], [29, 36], [29, 40], [29, 41], [29, 42], [29, 43], [29, 45], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 53], [29, 56], [29, 58], [29, 62], [29, 63], [29, 66], [29, 68], [29, 69], [29, 71], [29, 76], [29, 77], [29, 79], [29, 81], [29, 87], [29, 90], [29, 91], [29, 93], [29, 94], [29, 96], [29, 97], [29, 99], [30, 34], [30, 35], [30, 37], [30, 38], [30, 42], [30, 46], [30, 58], [30, 59], [30, 60], [30, 62], [30, 65], [30, 71], [30, 85], [30, 93], [30, 94], [30, 99], [31, 32], [31, 41], [31, 42], [31, 49], [31, 54], [31, 56], [31, 58], [31, 59], [31, 60], [31, 61], [31, 63], [31, 64], [31, 66], [31, 68], [31, 71], [31, 74], [31, 75], [31, 76], [31, 80], [31, 84], [31, 88], [31, 92], [31, 94], [31, 95], [31, 96], [31, 98], [32, 33], [32, 35], [32, 38], [32, 42], [32, 45], [32, 46], [32, 48], [32, 49], [32, 51], [32, 54], [32, 61], [32, 70], [32, 72], [32, 75], [32, 76], [32, 91], [33, 36], [33, 39], [33, 44], [33, 46], [33, 49], [33, 51], [33, 56], [33, 57], [33, 58], [33, 62], [33, 63], [33, 66], [33, 70], [33, 75], [33, 77], [33, 78], [33, 86], [33, 90], [33, 91], [33, 97], [34, 35], [34, 36], [34, 37], [34, 40], [34, 44], [34, 45], [34, 48], [34, 49], [34, 50], [34, 53], [34, 55], [34, 56], [34, 62], [34, 63], [34, 64], [34, 70], [34, 72], [34, 73], [34, 76], [34, 77], [34, 79], [34, 80], [34, 81], [34, 84], [34, 85], [34, 91], [34, 92], [34, 94], [34, 98], [34, 99], [35, 36], [35, 41], [35, 42], [35, 43], [35, 47], [35, 49], [35, 52], [35, 54], [35, 55], [35, 59], [35, 63], [35, 69], [35, 71], [35, 72], [35, 73], [35, 76], [35, 83], [35, 84], [35, 86], [35, 89], [35, 96], [36, 40], [36, 41], [36, 45], [36, 48], [36, 54], [36, 55], [36, 57], [36, 63], [36, 67], [36, 68], [36, 69], [36, 73], [36, 79], [36, 80], [36, 84], [36, 86], [36, 89], [36, 92], [36, 94], [36, 98], [37, 38], [37, 39], [37, 40], [37, 42], [37, 46], [37, 56], [37, 57], [37, 59], [37, 63], [37, 65], [37, 66], [37, 68], [37, 70], [37, 72], [37, 74], [37, 75], [37, 77], [37, 81], [37, 86], [37, 91], [38, 43], [38, 45], [38, 49], [38, 51], [38, 53], [38, 56], [38, 58], [38, 60], [38, 72], [38, 74], [38, 77], [38, 79], [38, 85], [38, 86], [38, 90], [38, 91], [38, 92], [38, 96], [39, 44], [39, 48], [39, 49], [39, 51], [39, 53], [39, 54], [39, 56], [39, 58], [39, 59], [39, 66], [39, 70], [39, 74], [39, 77], [39, 78], [39, 79], [39, 82], [39, 88], [39, 92], [39, 98], [40, 45], [40, 47], [40, 50], [40, 51], [40, 55], [40, 56], [40, 57], [40, 61], [40, 66], [40, 69], [40, 74], [40, 80], [40, 83], [40, 86], [40, 87], [40, 93], [40, 96], [40, 98], [41, 47], [41, 52], [41, 53], [41, 57], [41, 59], [41, 60], [41, 69], [41, 72], [41, 73], [41, 75], [41, 76], [41, 77], [41, 83], [41, 84], [41, 93], [42, 44], [42, 46], [42, 49], [42, 50], [42, 51], [42, 53], [42, 55], [42, 56], [42, 59], [42, 61], [42, 62], [42, 63], [42, 64], [42, 66], [42, 68], [42, 70], [42, 72], [42, 73], [42, 76], [42, 78], [42, 83], [42, 85], [42, 91], [42, 93], [42, 98], [42, 99], [43, 46], [43, 47], [43, 49], [43, 54], [43, 55], [43, 57], [43, 60], [43, 64], [43, 66], [43, 75], [43, 77], [43, 80], [43, 83], [43, 86], [43, 87], [43, 89], [43, 91], [43, 96], [43, 98], [44, 46], [44, 51], [44, 52], [44, 54], [44, 57], [44, 60], [44, 61], [44, 63], [44, 65], [44, 76], [44, 78], [44, 80], [44, 81], [44, 83], [44, 84], [44, 85], [44, 86], [44, 89], [44, 92], [44, 95], [44, 97], [45, 47], [45, 51], [45, 54], [45, 55], [45, 58], [45, 69], [45, 71], [45, 84], [45, 85], [45, 86], [45, 91], [46, 47], [46, 50], [46, 52], [46, 54], [46, 55], [46, 62], [46, 66], [46, 68], [46, 69], [46, 70], [46, 73], [46, 75], [46, 76], [46, 80], [46, 84], [46, 87], [46, 89], [46, 95], [46, 97], [47, 48], [47, 57], [47, 58], [47, 62], [47, 65], [47, 66], [47, 69], [47, 70], [47, 74], [47, 76], [47, 78], [47, 80], [47, 84], [47, 85], [47, 88], [47, 91], [47, 96], [47, 98], [48, 51], [48, 53], [48, 54], [48, 56], [48, 58], [48, 60], [48, 64], [48, 66], [48, 68], [48, 71], [48, 79], [48, 83], [48, 84], [48, 85], [48, 89], [48, 90], [48, 92], [48, 95], [48, 96], [48, 98], [48, 99], [49, 54], [49, 57], [49, 62], [49, 66], [49, 69], [49, 79], [49, 81], [49, 87], [49, 88], [49, 90], [49, 96], [50, 57], [50, 60], [50, 63], [50, 64], [50, 65], [50, 69], [50, 71], [50, 73], [50, 75], [50, 78], [50, 84], [50, 85], [50, 87], [50, 96], [50, 99], [51, 53], [51, 57], [51, 58], [51, 70], [51, 73], [51, 75], [51, 76], [51, 79], [51, 81], [51, 85], [51, 86], [51, 87], [51, 89], [51, 91], [51, 95], [51, 96], [51, 99], [52, 53], [52, 65], [52, 69], [52, 72], [52, 73], [52, 74], [52, 76], [52, 79], [52, 81], [52, 83], [52, 85], [52, 86], [52, 88], [52, 89], [52, 91], [52, 92], [52, 93], [52, 94], [52, 96], [53, 56], [53, 62], [53, 63], [53, 67], [53, 69], [53, 74], [53, 76], [53, 80], [53, 82], [53, 85], [53, 91], [53, 95], [53, 96], [53, 97], [54, 55], [54, 58], [54, 59], [54, 61], [54, 62], [54, 65], [54, 68], [54, 69], [54, 76], [54, 77], [54, 78], [54, 80], [54, 83], [54, 85], [54, 88], [54, 89], [54, 90], [54, 94], [54, 96], [54, 99], [55, 62], [55, 64], [55, 65], [55, 66], [55, 73], [55, 74], [55, 78], [55, 85], [55, 86], [55, 89], [55, 90], [55, 97], [55, 99], [56, 60], [56, 64], [56, 74], [56, 75], [56, 76], [56, 77], [56, 78], [56, 82], [56, 84], [56, 86], [56, 89], [56, 90], [56, 99], [57, 58], [57, 60], [57, 62], [57, 68], [57, 74], [57, 79], [57, 80], [57, 83], [57, 86], [57, 87], [57, 88], [57, 89], [57, 91], [57, 92], [57, 94], [58, 61], [58, 63], [58, 67], [58, 71], [58, 72], [58, 73], [58, 81], [58, 82], [58, 85], [58, 86], [58, 88], [58, 89], [58, 92], [58, 93], [58, 94], [58, 97], [58, 98], [59, 66], [59, 70], [59, 75], [59, 79], [59, 81], [59, 86], [59, 87], [59, 88], [59, 89], [59, 91], [59, 95], [59, 97], [60, 62], [60, 64], [60, 67], [60, 71], [60, 72], [60, 74], [60, 76], [60, 77], [60, 84], [60, 86], [60, 88], [60, 91], [60, 93], [60, 99], [61, 62], [61, 63], [61, 66], [61, 68], [61, 69], [61, 70], [61, 73], [61, 79], [61, 80], [61, 83], [61, 85], [61, 86], [61, 88], [61, 97], [62, 64], [62, 65], [62, 70], [62, 71], [62, 73], [62, 75], [62, 76], [62, 77], [62, 78], [62, 80], [62, 86], [62, 91], [62, 93], [62, 95], [62, 99], [63, 66], [63, 67], [63, 68], [63, 72], [63, 76], [63, 86], [63, 89], [63, 95], [63, 99], [64, 66], [64, 67], [64, 68], [64, 82], [64, 83], [64, 85], [64, 92], [64, 96], [64, 97], [65, 69], [65, 73], [65, 78], [65, 86], [65, 87], [65, 88], [65, 94], [66, 68], [66, 69], [66, 76], [66, 81], [66, 90], [66, 94], [66, 97], [66, 99], [67, 77], [67, 78], [67, 79], [67, 81], [67, 84], [67, 88], [67, 89], [67, 90], [67, 92], [67, 99], [68, 72], [68, 74], [68, 80], [68, 81], [68, 83], [68, 85], [68, 86], [68, 92], [68, 94], [68, 96], [68, 99], [69, 71], [69, 75], [69, 77], [69, 78], [69, 82], [69, 96], [70, 74], [70, 79], [70, 80], [70, 88], [70, 93], [70, 95], [70, 96], [70, 98], [71, 72], [71, 74], [71, 75], [71, 81], [71, 83], [71, 84], [71, 88], [71, 91], [71, 95], [71, 99], [72, 73], [72, 74], [72, 76], [72, 80], [72, 85], [72, 88], [72, 94], [72, 96], [73, 76], [73, 78], [73, 80], [73, 81], [73, 85], [73, 96], [74, 79], [74, 82], [74, 84], [74, 85], [74, 95], [74, 96], [75, 76], [75, 79], [75, 82], [75, 83], [75, 86], [75, 90], [75, 91], [75, 94], [75, 95], [76, 79], [76, 80], [76, 81], [76, 82], [76, 83], [76, 85], [76, 89], [76, 93], [76, 96], [76, 99], [77, 78], [77, 82], [77, 84], [77, 86], [77, 89], [77, 94], [77, 97], [78, 79], [78, 82], [78, 83], [78, 84], [78, 88], [78, 90], [79, 83], [79, 85], [79, 88], [79, 91], [79, 98], [80, 83], [80, 86], [80, 87], [80, 88], [80, 89], [80, 91], [80, 92], [80, 95], [80, 97], [81, 82], [81, 86], [81, 89], [81, 90], [82, 83], [82, 90], [82, 91], [82, 92], [83, 85], [83, 87], [83, 94], [83, 95], [83, 98], [84, 87], [84, 92], [84, 95], [84, 96], [85, 87], [85, 89], [85, 94], [85, 97], [85, 99], [86, 87], [86, 88], [86, 93], [86, 98], [86, 99], [87, 90], [87, 93], [88, 91], [88, 95], [88, 96], [88, 97], [88, 99], [89, 90], [89, 91], [89, 97], [90, 92], [90, 96], [90, 97], [91, 93], [91, 94], [91, 97], [92, 93], [92, 94], [92, 96], [92, 99], [93, 95], [93, 98], [94, 95], [94, 97], [95, 96], [96, 98], [97, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s6/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5bb8696760502f913b74d5e43da8ed061a43c2eb --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [6, 26, 29, 31, 35, 36, 37, 40, 43, 48, 49, 51, 54, 57, 60, 77, 83, 85, 88, 90]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s6/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l4-s6/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..88e3ad22a3200a5c8c77fed5e5f2b5578e8221e9 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 1], [0, 2], [0, 6], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 18], [0, 19], [0, 22], [0, 26], [0, 27], [0, 31], [0, 39], [0, 41], [0, 43], [0, 49], [0, 51], [0, 56], [0, 63], [0, 64], [0, 67], [0, 68], [0, 70], [0, 72], [0, 78], [0, 80], [0, 87], [0, 89], [0, 94], [1, 5], [1, 14], [1, 17], [1, 22], [1, 25], [1, 28], [1, 32], [1, 33], [1, 34], [1, 36], [1, 37], [1, 41], [1, 50], [1, 53], [1, 54], [1, 58], [1, 61], [1, 64], [1, 67], [1, 71], [1, 78], [1, 79], [1, 81], [1, 82], [1, 83], [1, 87], [1, 88], [1, 89], [1, 91], [1, 94], [1, 98], [2, 4], [2, 5], [2, 8], [2, 11], [2, 17], [2, 20], [2, 22], [2, 24], [2, 28], [2, 34], [2, 37], [2, 38], [2, 41], [2, 45], [2, 49], [2, 53], [2, 56], [2, 58], [2, 60], [2, 63], [2, 66], [2, 68], [2, 69], [2, 71], [2, 77], [2, 80], [2, 81], [2, 83], [2, 85], [2, 86], [2, 90], [2, 91], [2, 99], [3, 4], [3, 6], [3, 10], [3, 11], [3, 12], [3, 17], [3, 19], [3, 27], [3, 28], [3, 31], [3, 32], [3, 33], [3, 37], [3, 40], [3, 42], [3, 46], [3, 47], [3, 49], [3, 50], [3, 55], [3, 57], [3, 60], [3, 65], [3, 72], [3, 76], [3, 77], [3, 84], [3, 93], [3, 94], [4, 5], [4, 7], [4, 8], [4, 10], [4, 15], [4, 16], [4, 19], [4, 24], [4, 27], [4, 33], [4, 36], [4, 42], [4, 47], [4, 56], [4, 57], [4, 58], [4, 60], [4, 63], [4, 64], [4, 70], [4, 72], [4, 73], [4, 74], [4, 75], [4, 76], [4, 78], [4, 79], [4, 82], [4, 83], [4, 85], [4, 87], [4, 88], [4, 94], [4, 98], [4, 99], [5, 6], [5, 7], [5, 13], [5, 14], [5, 15], [5, 22], [5, 24], [5, 26], [5, 27], [5, 28], [5, 32], [5, 35], [5, 36], [5, 37], [5, 39], [5, 53], [5, 54], [5, 57], [5, 58], [5, 60], [5, 62], [5, 67], [5, 68], [5, 72], [5, 79], [5, 80], [5, 83], [5, 84], [5, 87], [5, 97], [6, 9], [6, 12], [6, 14], [6, 15], [6, 17], [6, 20], [6, 25], [6, 27], [6, 28], [6, 37], [6, 38], [6, 39], [6, 41], [6, 46], [6, 49], [6, 50], [6, 53], [6, 54], [6, 57], [6, 58], [6, 61], [6, 65], [6, 66], [6, 69], [6, 73], [6, 77], [6, 78], [6, 79], [6, 81], [6, 82], [6, 83], [6, 85], [6, 88], [6, 91], [6, 92], [6, 97], [6, 98], [7, 14], [7, 19], [7, 24], [7, 25], [7, 28], [7, 29], [7, 34], [7, 35], [7, 44], [7, 45], [7, 54], [7, 55], [7, 64], [7, 68], [7, 69], [7, 70], [7, 75], [7, 77], [7, 82], [7, 83], [7, 84], [7, 87], [7, 89], [7, 90], [8, 12], [8, 21], [8, 22], [8, 26], [8, 27], [8, 28], [8, 29], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 44], [8, 46], [8, 55], [8, 56], [8, 57], [8, 60], [8, 64], [8, 67], [8, 71], [8, 75], [8, 83], [8, 84], [8, 85], [8, 86], [8, 87], [8, 92], [8, 94], [8, 99], [9, 11], [9, 12], [9, 18], [9, 19], [9, 21], [9, 23], [9, 36], [9, 40], [9, 42], [9, 44], [9, 45], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 58], [9, 61], [9, 62], [9, 66], [9, 70], [9, 74], [9, 86], [9, 88], [9, 93], [10, 17], [10, 21], [10, 23], [10, 26], [10, 28], [10, 32], [10, 33], [10, 36], [10, 37], [10, 41], [10, 42], [10, 43], [10, 45], [10, 47], [10, 52], [10, 58], [10, 63], [10, 64], [10, 66], [10, 67], [10, 68], [10, 70], [10, 73], [10, 76], [10, 77], [10, 83], [10, 88], [10, 89], [10, 95], [10, 96], [10, 98], [10, 99], [11, 12], [11, 13], [11, 14], [11, 18], [11, 19], [11, 21], [11, 22], [11, 27], [11, 29], [11, 31], [11, 36], [11, 43], [11, 48], [11, 55], [11, 56], [11, 58], [11, 65], [11, 68], [11, 72], [11, 78], [11, 80], [11, 82], [11, 89], [11, 92], [11, 94], [11, 97], [12, 16], [12, 19], [12, 27], [12, 31], [12, 34], [12, 35], [12, 38], [12, 41], [12, 47], [12, 57], [12, 59], [12, 61], [12, 67], [12, 73], [12, 74], [12, 75], [12, 77], [12, 84], [12, 86], [12, 89], [12, 90], [12, 93], [12, 94], [12, 98], [13, 21], [13, 23], [13, 25], [13, 33], [13, 35], [13, 36], [13, 39], [13, 45], [13, 47], [13, 50], [13, 54], [13, 58], [13, 62], [13, 63], [13, 66], [13, 69], [13, 71], [13, 72], [13, 78], [13, 82], [13, 85], [13, 88], [13, 91], [13, 92], [13, 93], [13, 96], [13, 97], [14, 15], [14, 16], [14, 18], [14, 20], [14, 21], [14, 24], [14, 26], [14, 38], [14, 49], [14, 50], [14, 51], [14, 52], [14, 55], [14, 57], [14, 80], [14, 84], [14, 91], [14, 93], [14, 97], [14, 98], [15, 19], [15, 25], [15, 27], [15, 29], [15, 33], [15, 36], [15, 42], [15, 46], [15, 49], [15, 51], [15, 52], [15, 56], [15, 60], [15, 63], [15, 64], [15, 66], [15, 77], [15, 82], [15, 90], [15, 93], [15, 94], [15, 98], [16, 21], [16, 22], [16, 24], [16, 27], [16, 29], [16, 33], [16, 35], [16, 36], [16, 40], [16, 47], [16, 49], [16, 50], [16, 56], [16, 58], [16, 62], [16, 63], [16, 69], [16, 71], [16, 73], [16, 77], [16, 78], [16, 79], [16, 80], [16, 82], [16, 85], [16, 88], [16, 95], [16, 97], [17, 20], [17, 22], [17, 27], [17, 30], [17, 33], [17, 36], [17, 40], [17, 42], [17, 43], [17, 44], [17, 48], [17, 49], [17, 50], [17, 53], [17, 57], [17, 60], [17, 61], [17, 68], [17, 71], [17, 72], [17, 77], [17, 79], [17, 81], [17, 85], [17, 89], [18, 29], [18, 33], [18, 35], [18, 38], [18, 43], [18, 45], [18, 48], [18, 53], [18, 54], [18, 56], [18, 57], [18, 58], [18, 59], [18, 60], [18, 61], [18, 77], [18, 79], [18, 81], [18, 84], [18, 86], [18, 87], [18, 88], [18, 91], [18, 92], [18, 94], [18, 95], [18, 99], [19, 31], [19, 33], [19, 35], [19, 40], [19, 41], [19, 45], [19, 46], [19, 48], [19, 52], [19, 55], [19, 59], [19, 62], [19, 65], [19, 69], [19, 76], [19, 78], [19, 81], [19, 86], [19, 87], [19, 93], [19, 95], [19, 96], [20, 27], [20, 33], [20, 38], [20, 47], [20, 54], [20, 57], [20, 59], [20, 61], [20, 66], [20, 69], [20, 70], [20, 72], [20, 74], [20, 75], [20, 77], [20, 81], [20, 83], [21, 23], [21, 26], [21, 31], [21, 34], [21, 36], [21, 37], [21, 45], [21, 52], [21, 54], [21, 58], [21, 64], [21, 70], [21, 71], [21, 79], [21, 80], [21, 85], [21, 86], [21, 88], [21, 91], [21, 92], [21, 95], [21, 97], [22, 24], [22, 25], [22, 26], [22, 29], [22, 33], [22, 35], [22, 37], [22, 41], [22, 42], [22, 49], [22, 54], [22, 56], [22, 58], [22, 63], [22, 67], [22, 68], [22, 69], [22, 74], [22, 82], [22, 87], [22, 93], [22, 96], [22, 97], [23, 30], [23, 31], [23, 35], [23, 36], [23, 38], [23, 43], [23, 47], [23, 48], [23, 52], [23, 57], [23, 60], [23, 61], [23, 63], [23, 65], [23, 68], [23, 74], [23, 77], [23, 85], [23, 87], [23, 90], [23, 93], [23, 94], [23, 96], [23, 97], [23, 99], [24, 25], [24, 26], [24, 35], [24, 37], [24, 38], [24, 40], [24, 41], [24, 43], [24, 47], [24, 48], [24, 51], [24, 52], [24, 54], [24, 58], [24, 59], [24, 61], [24, 66], [24, 67], [24, 68], [24, 69], [24, 71], [24, 73], [24, 74], [24, 75], [24, 78], [24, 80], [24, 86], [24, 93], [24, 99], [25, 26], [25, 28], [25, 30], [25, 32], [25, 36], [25, 37], [25, 38], [25, 39], [25, 43], [25, 44], [25, 45], [25, 47], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 61], [25, 62], [25, 69], [25, 74], [25, 79], [25, 82], [25, 86], [25, 87], [25, 90], [25, 91], [25, 92], [25, 95], [25, 98], [25, 99], [26, 27], [26, 29], [26, 30], [26, 33], [26, 34], [26, 35], [26, 37], [26, 39], [26, 41], [26, 43], [26, 45], [26, 48], [26, 49], [26, 54], [26, 55], [26, 67], [26, 68], [26, 70], [26, 72], [26, 74], [26, 75], [26, 80], [26, 82], [26, 83], [26, 90], [26, 93], [26, 95], [26, 96], [27, 36], [27, 37], [27, 43], [27, 44], [27, 47], [27, 48], [27, 50], [27, 53], [27, 55], [27, 58], [27, 59], [27, 60], [27, 64], [27, 70], [27, 74], [27, 81], [27, 82], [27, 84], [27, 85], [27, 86], [27, 87], [27, 91], [27, 96], [27, 97], [27, 99], [28, 31], [28, 32], [28, 42], [28, 54], [28, 60], [28, 68], [28, 69], [28, 72], [28, 87], [28, 88], [28, 91], [28, 92], [28, 95], [28, 97], [29, 30], [29, 35], [29, 36], [29, 40], [29, 41], [29, 42], [29, 43], [29, 45], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 53], [29, 56], [29, 58], [29, 62], [29, 63], [29, 66], [29, 68], [29, 69], [29, 71], [29, 76], [29, 77], [29, 79], [29, 81], [29, 87], [29, 90], [29, 91], [29, 93], [29, 94], [29, 96], [29, 97], [29, 99], [30, 34], [30, 35], [30, 37], [30, 38], [30, 42], [30, 46], [30, 58], [30, 59], [30, 60], [30, 62], [30, 65], [30, 71], [30, 85], [30, 93], [30, 94], [30, 99], [31, 32], [31, 41], [31, 42], [31, 49], [31, 54], [31, 56], [31, 58], [31, 59], [31, 60], [31, 61], [31, 63], [31, 64], [31, 66], [31, 68], [31, 71], [31, 74], [31, 75], [31, 76], [31, 80], [31, 84], [31, 88], [31, 92], [31, 94], [31, 95], [31, 96], [31, 98], [32, 33], [32, 35], [32, 38], [32, 42], [32, 45], [32, 46], [32, 48], [32, 49], [32, 51], [32, 54], [32, 61], [32, 70], [32, 72], [32, 75], [32, 76], [32, 91], [33, 36], [33, 39], [33, 44], [33, 46], [33, 49], [33, 51], [33, 56], [33, 57], [33, 58], [33, 62], [33, 63], [33, 66], [33, 70], [33, 75], [33, 77], [33, 78], [33, 86], [33, 90], [33, 91], [33, 97], [34, 35], [34, 36], [34, 37], [34, 40], [34, 44], [34, 45], [34, 48], [34, 49], [34, 50], [34, 53], [34, 55], [34, 56], [34, 62], [34, 63], [34, 64], [34, 70], [34, 72], [34, 73], [34, 76], [34, 77], [34, 79], [34, 80], [34, 81], [34, 84], [34, 85], [34, 91], [34, 92], [34, 94], [34, 98], [34, 99], [35, 36], [35, 41], [35, 42], [35, 43], [35, 47], [35, 49], [35, 52], [35, 54], [35, 55], [35, 59], [35, 63], [35, 69], [35, 71], [35, 72], [35, 73], [35, 76], [35, 83], [35, 84], [35, 86], [35, 89], [35, 96], [36, 40], [36, 41], [36, 45], [36, 48], [36, 54], [36, 55], [36, 57], [36, 63], [36, 67], [36, 68], [36, 69], [36, 73], [36, 79], [36, 80], [36, 84], [36, 86], [36, 89], [36, 92], [36, 94], [36, 98], [37, 38], [37, 39], [37, 40], [37, 42], [37, 46], [37, 56], [37, 57], [37, 59], [37, 63], [37, 65], [37, 66], [37, 68], [37, 70], [37, 72], [37, 74], [37, 75], [37, 77], [37, 81], [37, 86], [37, 91], [38, 43], [38, 45], [38, 49], [38, 51], [38, 53], [38, 56], [38, 58], [38, 60], [38, 72], [38, 74], [38, 77], [38, 79], [38, 85], [38, 86], [38, 90], [38, 91], [38, 92], [38, 96], [39, 44], [39, 48], [39, 49], [39, 51], [39, 53], [39, 54], [39, 56], [39, 58], [39, 59], [39, 66], [39, 70], [39, 74], [39, 77], [39, 78], [39, 79], [39, 82], [39, 88], [39, 92], [39, 98], [40, 45], [40, 47], [40, 50], [40, 51], [40, 55], [40, 56], [40, 57], [40, 61], [40, 66], [40, 69], [40, 74], [40, 80], [40, 83], [40, 86], [40, 87], [40, 93], [40, 96], [40, 98], [41, 47], [41, 52], [41, 53], [41, 57], [41, 59], [41, 60], [41, 69], [41, 72], [41, 73], [41, 75], [41, 76], [41, 77], [41, 83], [41, 84], [41, 93], [42, 44], [42, 46], [42, 49], [42, 50], [42, 51], [42, 53], [42, 55], [42, 56], [42, 59], [42, 61], [42, 62], [42, 63], [42, 64], [42, 66], [42, 68], [42, 70], [42, 72], [42, 73], [42, 76], [42, 78], [42, 83], [42, 85], [42, 91], [42, 93], [42, 98], [42, 99], [43, 46], [43, 47], [43, 49], [43, 54], [43, 55], [43, 57], [43, 60], [43, 64], [43, 66], [43, 75], [43, 77], [43, 80], [43, 83], [43, 86], [43, 87], [43, 89], [43, 91], [43, 96], [43, 98], [44, 46], [44, 51], [44, 52], [44, 54], [44, 57], [44, 60], [44, 61], [44, 63], [44, 65], [44, 76], [44, 78], [44, 80], [44, 81], [44, 83], [44, 84], [44, 85], [44, 86], [44, 89], [44, 92], [44, 95], [44, 97], [45, 47], [45, 51], [45, 54], [45, 55], [45, 58], [45, 69], [45, 71], [45, 84], [45, 85], [45, 86], [45, 91], [46, 47], [46, 50], [46, 52], [46, 54], [46, 55], [46, 62], [46, 66], [46, 68], [46, 69], [46, 70], [46, 73], [46, 75], [46, 76], [46, 80], [46, 84], [46, 87], [46, 89], [46, 95], [46, 97], [47, 48], [47, 57], [47, 58], [47, 62], [47, 65], [47, 66], [47, 69], [47, 70], [47, 74], [47, 76], [47, 78], [47, 80], [47, 84], [47, 85], [47, 88], [47, 91], [47, 96], [47, 98], [48, 51], [48, 53], [48, 54], [48, 56], [48, 58], [48, 60], [48, 64], [48, 66], [48, 68], [48, 71], [48, 79], [48, 83], [48, 84], [48, 85], [48, 89], [48, 90], [48, 92], [48, 95], [48, 96], [48, 98], [48, 99], [49, 54], [49, 57], [49, 62], [49, 66], [49, 69], [49, 79], [49, 81], [49, 87], [49, 88], [49, 90], [49, 96], [50, 57], [50, 60], [50, 63], [50, 64], [50, 65], [50, 69], [50, 71], [50, 73], [50, 75], [50, 78], [50, 84], [50, 85], [50, 87], [50, 96], [50, 99], [51, 53], [51, 57], [51, 58], [51, 70], [51, 73], [51, 75], [51, 76], [51, 79], [51, 81], [51, 85], [51, 86], [51, 87], [51, 89], [51, 91], [51, 95], [51, 96], [51, 99], [52, 53], [52, 65], [52, 69], [52, 72], [52, 73], [52, 74], [52, 76], [52, 79], [52, 81], [52, 83], [52, 85], [52, 86], [52, 88], [52, 89], [52, 91], [52, 92], [52, 93], [52, 94], [52, 96], [53, 56], [53, 62], [53, 63], [53, 67], [53, 69], [53, 74], [53, 76], [53, 80], [53, 82], [53, 85], [53, 91], [53, 95], [53, 96], [53, 97], [54, 55], [54, 58], [54, 59], [54, 61], [54, 62], [54, 65], [54, 68], [54, 69], [54, 76], [54, 77], [54, 78], [54, 80], [54, 83], [54, 85], [54, 88], [54, 89], [54, 90], [54, 94], [54, 96], [54, 99], [55, 62], [55, 64], [55, 65], [55, 66], [55, 73], [55, 74], [55, 78], [55, 85], [55, 86], [55, 89], [55, 90], [55, 97], [55, 99], [56, 60], [56, 64], [56, 74], [56, 75], [56, 76], [56, 77], [56, 78], [56, 82], [56, 84], [56, 86], [56, 89], [56, 90], [56, 99], [57, 58], [57, 60], [57, 62], [57, 68], [57, 74], [57, 79], [57, 80], [57, 83], [57, 86], [57, 87], [57, 88], [57, 89], [57, 91], [57, 92], [57, 94], [58, 61], [58, 63], [58, 67], [58, 71], [58, 72], [58, 73], [58, 81], [58, 82], [58, 85], [58, 86], [58, 88], [58, 89], [58, 92], [58, 93], [58, 94], [58, 97], [58, 98], [59, 66], [59, 70], [59, 75], [59, 79], [59, 81], [59, 86], [59, 87], [59, 88], [59, 89], [59, 91], [59, 95], [59, 97], [60, 62], [60, 64], [60, 67], [60, 71], [60, 72], [60, 74], [60, 76], [60, 77], [60, 84], [60, 86], [60, 88], [60, 91], [60, 93], [60, 99], [61, 62], [61, 63], [61, 66], [61, 68], [61, 69], [61, 70], [61, 73], [61, 79], [61, 80], [61, 83], [61, 85], [61, 86], [61, 88], [61, 97], [62, 64], [62, 65], [62, 70], [62, 71], [62, 73], [62, 75], [62, 76], [62, 77], [62, 78], [62, 80], [62, 86], [62, 91], [62, 93], [62, 95], [62, 99], [63, 66], [63, 67], [63, 68], [63, 72], [63, 76], [63, 86], [63, 89], [63, 95], [63, 99], [64, 66], [64, 67], [64, 68], [64, 82], [64, 83], [64, 85], [64, 92], [64, 96], [64, 97], [65, 69], [65, 73], [65, 78], [65, 86], [65, 87], [65, 88], [65, 94], [66, 68], [66, 69], [66, 76], [66, 81], [66, 90], [66, 94], [66, 97], [66, 99], [67, 77], [67, 78], [67, 79], [67, 81], [67, 84], [67, 88], [67, 89], [67, 90], [67, 92], [67, 99], [68, 72], [68, 74], [68, 80], [68, 81], [68, 83], [68, 85], [68, 86], [68, 92], [68, 94], [68, 96], [68, 99], [69, 71], [69, 75], [69, 77], [69, 78], [69, 82], [69, 96], [70, 74], [70, 79], [70, 80], [70, 88], [70, 93], [70, 95], [70, 96], [70, 98], [71, 72], [71, 74], [71, 75], [71, 81], [71, 83], [71, 84], [71, 88], [71, 91], [71, 95], [71, 99], [72, 73], [72, 74], [72, 76], [72, 80], [72, 85], [72, 88], [72, 94], [72, 96], [73, 76], [73, 78], [73, 80], [73, 81], [73, 85], [73, 96], [74, 79], [74, 82], [74, 84], [74, 85], [74, 95], [74, 96], [75, 76], [75, 79], [75, 82], [75, 83], [75, 86], [75, 90], [75, 91], [75, 94], [75, 95], [76, 79], [76, 80], [76, 81], [76, 82], [76, 83], [76, 85], [76, 89], [76, 93], [76, 96], [76, 99], [77, 78], [77, 82], [77, 84], [77, 86], [77, 89], [77, 94], [77, 97], [78, 79], [78, 82], [78, 83], [78, 84], [78, 88], [78, 90], [79, 83], [79, 85], [79, 88], [79, 91], [79, 98], [80, 83], [80, 86], [80, 87], [80, 88], [80, 89], [80, 91], [80, 92], [80, 95], [80, 97], [81, 82], [81, 86], [81, 89], [81, 90], [82, 83], [82, 90], [82, 91], [82, 92], [83, 85], [83, 87], [83, 94], [83, 95], [83, 98], [84, 87], [84, 92], [84, 95], [84, 96], [85, 87], [85, 89], [85, 94], [85, 97], [85, 99], [86, 87], [86, 88], [86, 93], [86, 98], [86, 99], [87, 90], [87, 93], [88, 91], [88, 95], [88, 96], [88, 97], [88, 99], [89, 90], [89, 91], [89, 97], [90, 92], [90, 96], [90, 97], [91, 93], [91, 94], [91, 97], [92, 93], [92, 94], [92, 96], [92, 99], [93, 95], [93, 98], [94, 95], [94, 97], [95, 96], [96, 98], [97, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s6/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l4-s6/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l1-s0/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l1-s0/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd56aeab87df61e6297606bfa4a72a2cc8f49865 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 6], [0, 7], [1, 2], [1, 5], [1, 7], [2, 3], [2, 4], [2, 5], [3, 7], [4, 5], [4, 7], [6, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s0/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..774c4266d9e66fb43e141e439a7438929e6883a8 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 3, 4, 6]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s0/tests/check.py b/tasks/construct-nppc-independent-set-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l1-s0/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd56aeab87df61e6297606bfa4a72a2cc8f49865 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 6], [0, 7], [1, 2], [1, 5], [1, 7], [2, 3], [2, 4], [2, 5], [3, 7], [4, 5], [4, 7], [6, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s0/tests/run.py b/tasks/construct-nppc-independent-set-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l1-s0/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l1-s7/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l1-s7/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..77af1c9b2e999a6c374ea416a76ada47e488e692 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 3], [0, 4], [0, 6], [1, 3], [1, 5], [1, 6], [2, 4], [2, 6], [3, 5], [4, 7], [5, 6]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s7/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb34c71067826b778d3191abcf614fa7d7ef062d --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 1, 2, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s7/tests/check.py b/tasks/construct-nppc-independent-set-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l1-s7/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..77af1c9b2e999a6c374ea416a76ada47e488e692 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 3], [0, 4], [0, 6], [1, 3], [1, 5], [1, 6], [2, 4], [2, 6], [3, 5], [4, 7], [5, 6]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s7/tests/run.py b/tasks/construct-nppc-independent-set-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l1-s7/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l1-s9/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l1-s9/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d84c230b24cfdedc623128bc6ad93daa2844612b --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 7], [1, 3], [1, 5], [1, 7], [2, 4], [2, 7], [4, 5], [4, 7], [5, 6]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s9/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa05ad24cfc3df260fe4a3e069e8098ac4104708 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 1, 4, 6]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s9/tests/check.py b/tasks/construct-nppc-independent-set-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l1-s9/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d84c230b24cfdedc623128bc6ad93daa2844612b --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 7], [1, 3], [1, 5], [1, 7], [2, 4], [2, 7], [4, 5], [4, 7], [5, 6]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s9/tests/run.py b/tasks/construct-nppc-independent-set-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l1-s9/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l5-s1/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s1/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9cfe903627da01f8b2dc7ea710ae9c0b11519e81 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 4], [0, 5], [0, 7], [0, 8], [0, 9], [0, 14], [0, 16], [0, 17], [0, 18], [0, 22], [0, 24], [0, 26], [0, 28], [0, 30], [0, 34], [0, 36], [0, 39], [0, 46], [1, 2], [1, 3], [1, 5], [1, 6], [1, 9], [1, 11], [1, 13], [1, 15], [1, 17], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 34], [1, 37], [1, 39], [1, 43], [1, 45], [2, 5], [2, 11], [2, 13], [2, 20], [2, 25], [2, 26], [2, 29], [2, 34], [2, 41], [2, 44], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 17], [3, 20], [3, 21], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 35], [3, 36], [3, 38], [3, 39], [3, 41], [3, 46], [3, 47], [4, 26], [4, 33], [4, 34], [4, 38], [4, 41], [4, 46], [5, 7], [5, 10], [5, 11], [5, 12], [5, 13], [5, 15], [5, 20], [5, 23], [5, 24], [5, 26], [5, 32], [5, 33], [5, 34], [5, 37], [5, 38], [5, 39], [5, 46], [5, 47], [6, 13], [6, 21], [6, 25], [6, 26], [6, 33], [6, 38], [6, 40], [6, 43], [6, 44], [6, 46], [7, 10], [7, 13], [7, 20], [7, 21], [7, 25], [7, 31], [7, 33], [7, 34], [7, 38], [7, 40], [7, 41], [7, 43], [8, 11], [8, 13], [8, 14], [8, 17], [8, 19], [8, 22], [8, 24], [8, 28], [8, 29], [8, 31], [8, 33], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 41], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [9, 10], [9, 11], [9, 13], [9, 26], [9, 29], [9, 31], [9, 38], [9, 41], [10, 11], [10, 14], [10, 15], [10, 17], [10, 19], [10, 22], [10, 26], [10, 28], [10, 29], [10, 30], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 40], [10, 41], [10, 44], [10, 45], [10, 46], [11, 12], [11, 13], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 34], [11, 37], [11, 45], [11, 46], [11, 47], [12, 19], [12, 20], [12, 27], [12, 29], [12, 38], [12, 43], [12, 46], [13, 16], [13, 17], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 31], [13, 33], [13, 34], [13, 38], [13, 39], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [14, 19], [14, 20], [14, 29], [14, 31], [14, 34], [14, 38], [14, 40], [14, 43], [14, 44], [14, 46], [15, 20], [15, 21], [15, 25], [15, 26], [15, 29], [15, 38], [15, 40], [15, 44], [16, 19], [16, 20], [16, 21], [16, 25], [16, 26], [16, 29], [16, 31], [16, 33], [16, 38], [16, 41], [16, 43], [16, 46], [17, 25], [17, 26], [17, 27], [17, 29], [17, 31], [17, 33], [17, 34], [17, 38], [17, 46], [18, 19], [18, 25], [18, 27], [18, 29], [18, 31], [18, 38], [18, 40], [18, 43], [19, 28], [19, 30], [19, 32], [19, 35], [19, 37], [19, 38], [19, 40], [19, 43], [19, 44], [19, 45], [19, 47], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 32], [20, 33], [20, 38], [20, 42], [20, 43], [20, 44], [20, 47], [21, 22], [21, 28], [21, 31], [21, 33], [21, 36], [21, 37], [21, 39], [21, 41], [21, 42], [21, 46], [22, 26], [22, 31], [22, 33], [22, 34], [22, 40], [22, 41], [22, 43], [22, 44], [22, 46], [23, 25], [23, 27], [23, 29], [23, 31], [23, 34], [23, 38], [23, 43], [23, 44], [24, 26], [24, 31], [24, 38], [24, 40], [24, 41], [24, 43], [24, 46], [25, 28], [25, 36], [25, 39], [25, 40], [25, 42], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 34], [26, 35], [26, 36], [26, 37], [26, 41], [26, 42], [26, 43], [27, 29], [27, 30], [27, 35], [27, 38], [27, 43], [27, 45], [28, 31], [28, 33], [28, 34], [28, 40], [28, 41], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [29, 37], [29, 38], [29, 40], [29, 44], [29, 45], [30, 31], [30, 33], [30, 38], [30, 40], [30, 43], [30, 44], [30, 46], [31, 33], [31, 34], [31, 39], [31, 41], [31, 42], [32, 40], [32, 43], [32, 44], [33, 35], [33, 36], [33, 38], [33, 42], [33, 43], [33, 44], [33, 47], [34, 38], [34, 39], [34, 41], [34, 44], [34, 47], [35, 41], [35, 46], [36, 38], [36, 40], [36, 41], [36, 43], [37, 40], [37, 43], [37, 44], [38, 40], [38, 42], [38, 44], [38, 45], [39, 41], [39, 43], [39, 44], [40, 41], [40, 42], [40, 44], [40, 45], [40, 47], [41, 43], [41, 44], [41, 47], [43, 45], [43, 47], [44, 45], [44, 46], [45, 46], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s1/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..95115dcdf383ae9af925deed3a9c84b12033db64 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [2, 4, 6, 7, 9, 12, 14, 15, 16, 17, 18, 22, 23, 24, 28, 30, 32, 35, 36, 37, 39, 42, 45, 47]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s1/tests/check.py b/tasks/construct-nppc-independent-set-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l5-s1/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9cfe903627da01f8b2dc7ea710ae9c0b11519e81 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 4], [0, 5], [0, 7], [0, 8], [0, 9], [0, 14], [0, 16], [0, 17], [0, 18], [0, 22], [0, 24], [0, 26], [0, 28], [0, 30], [0, 34], [0, 36], [0, 39], [0, 46], [1, 2], [1, 3], [1, 5], [1, 6], [1, 9], [1, 11], [1, 13], [1, 15], [1, 17], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 34], [1, 37], [1, 39], [1, 43], [1, 45], [2, 5], [2, 11], [2, 13], [2, 20], [2, 25], [2, 26], [2, 29], [2, 34], [2, 41], [2, 44], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 17], [3, 20], [3, 21], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 35], [3, 36], [3, 38], [3, 39], [3, 41], [3, 46], [3, 47], [4, 26], [4, 33], [4, 34], [4, 38], [4, 41], [4, 46], [5, 7], [5, 10], [5, 11], [5, 12], [5, 13], [5, 15], [5, 20], [5, 23], [5, 24], [5, 26], [5, 32], [5, 33], [5, 34], [5, 37], [5, 38], [5, 39], [5, 46], [5, 47], [6, 13], [6, 21], [6, 25], [6, 26], [6, 33], [6, 38], [6, 40], [6, 43], [6, 44], [6, 46], [7, 10], [7, 13], [7, 20], [7, 21], [7, 25], [7, 31], [7, 33], [7, 34], [7, 38], [7, 40], [7, 41], [7, 43], [8, 11], [8, 13], [8, 14], [8, 17], [8, 19], [8, 22], [8, 24], [8, 28], [8, 29], [8, 31], [8, 33], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 41], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [9, 10], [9, 11], [9, 13], [9, 26], [9, 29], [9, 31], [9, 38], [9, 41], [10, 11], [10, 14], [10, 15], [10, 17], [10, 19], [10, 22], [10, 26], [10, 28], [10, 29], [10, 30], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 40], [10, 41], [10, 44], [10, 45], [10, 46], [11, 12], [11, 13], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 34], [11, 37], [11, 45], [11, 46], [11, 47], [12, 19], [12, 20], [12, 27], [12, 29], [12, 38], [12, 43], [12, 46], [13, 16], [13, 17], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 31], [13, 33], [13, 34], [13, 38], [13, 39], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [14, 19], [14, 20], [14, 29], [14, 31], [14, 34], [14, 38], [14, 40], [14, 43], [14, 44], [14, 46], [15, 20], [15, 21], [15, 25], [15, 26], [15, 29], [15, 38], [15, 40], [15, 44], [16, 19], [16, 20], [16, 21], [16, 25], [16, 26], [16, 29], [16, 31], [16, 33], [16, 38], [16, 41], [16, 43], [16, 46], [17, 25], [17, 26], [17, 27], [17, 29], [17, 31], [17, 33], [17, 34], [17, 38], [17, 46], [18, 19], [18, 25], [18, 27], [18, 29], [18, 31], [18, 38], [18, 40], [18, 43], [19, 28], [19, 30], [19, 32], [19, 35], [19, 37], [19, 38], [19, 40], [19, 43], [19, 44], [19, 45], [19, 47], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 32], [20, 33], [20, 38], [20, 42], [20, 43], [20, 44], [20, 47], [21, 22], [21, 28], [21, 31], [21, 33], [21, 36], [21, 37], [21, 39], [21, 41], [21, 42], [21, 46], [22, 26], [22, 31], [22, 33], [22, 34], [22, 40], [22, 41], [22, 43], [22, 44], [22, 46], [23, 25], [23, 27], [23, 29], [23, 31], [23, 34], [23, 38], [23, 43], [23, 44], [24, 26], [24, 31], [24, 38], [24, 40], [24, 41], [24, 43], [24, 46], [25, 28], [25, 36], [25, 39], [25, 40], [25, 42], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 34], [26, 35], [26, 36], [26, 37], [26, 41], [26, 42], [26, 43], [27, 29], [27, 30], [27, 35], [27, 38], [27, 43], [27, 45], [28, 31], [28, 33], [28, 34], [28, 40], [28, 41], [29, 31], [29, 32], [29, 33], [29, 34], [29, 36], [29, 37], [29, 38], [29, 40], [29, 44], [29, 45], [30, 31], [30, 33], [30, 38], [30, 40], [30, 43], [30, 44], [30, 46], [31, 33], [31, 34], [31, 39], [31, 41], [31, 42], [32, 40], [32, 43], [32, 44], [33, 35], [33, 36], [33, 38], [33, 42], [33, 43], [33, 44], [33, 47], [34, 38], [34, 39], [34, 41], [34, 44], [34, 47], [35, 41], [35, 46], [36, 38], [36, 40], [36, 41], [36, 43], [37, 40], [37, 43], [37, 44], [38, 40], [38, 42], [38, 44], [38, 45], [39, 41], [39, 43], [39, 44], [40, 41], [40, 42], [40, 44], [40, 45], [40, 47], [41, 43], [41, 44], [41, 47], [43, 45], [43, 47], [44, 45], [44, 46], [45, 46], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s1/tests/run.py b/tasks/construct-nppc-independent-set-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s1/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l5-s6/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s6/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab913255cc6aa04d03e6795fe0f8f9724873e222 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 4], [0, 10], [0, 17], [0, 19], [0, 20], [0, 21], [0, 22], [0, 25], [0, 34], [0, 41], [0, 43], [0, 47], [1, 4], [1, 6], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 19], [1, 20], [1, 23], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 37], [1, 39], [1, 42], [1, 45], [1, 47], [2, 4], [2, 9], [2, 10], [2, 19], [2, 21], [2, 22], [2, 25], [2, 28], [2, 41], [2, 42], [2, 46], [2, 47], [3, 4], [3, 7], [3, 9], [3, 17], [3, 20], [3, 21], [3, 24], [3, 28], [3, 29], [3, 33], [3, 42], [3, 43], [4, 5], [4, 8], [4, 10], [4, 11], [4, 14], [4, 16], [4, 17], [4, 19], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 31], [4, 39], [4, 41], [4, 42], [4, 46], [4, 47], [5, 9], [5, 25], [5, 34], [5, 36], [5, 45], [5, 46], [5, 47], [6, 7], [6, 10], [6, 20], [6, 21], [6, 22], [6, 24], [6, 29], [6, 33], [6, 39], [6, 43], [6, 45], [6, 46], [6, 47], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 20], [7, 21], [7, 25], [7, 26], [7, 27], [7, 30], [7, 32], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 46], [8, 10], [8, 21], [8, 25], [8, 34], [8, 36], [8, 39], [8, 42], [8, 43], [9, 12], [9, 13], [9, 14], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 27], [9, 28], [9, 30], [9, 31], [9, 34], [9, 36], [9, 38], [9, 42], [9, 44], [9, 46], [9, 47], [10, 11], [10, 12], [10, 16], [10, 17], [10, 21], [10, 23], [10, 24], [10, 25], [10, 26], [10, 29], [10, 30], [10, 34], [10, 35], [10, 36], [10, 37], [10, 41], [10, 42], [10, 43], [10, 45], [10, 46], [11, 19], [11, 20], [11, 28], [11, 29], [11, 34], [11, 36], [11, 39], [11, 41], [11, 42], [11, 43], [11, 45], [12, 19], [12, 20], [12, 25], [12, 29], [12, 33], [12, 34], [12, 36], [12, 39], [12, 41], [12, 43], [12, 45], [12, 47], [13, 19], [13, 21], [13, 25], [13, 28], [13, 29], [13, 34], [13, 36], [13, 42], [13, 43], [13, 45], [13, 46], [14, 17], [14, 20], [14, 21], [14, 25], [14, 28], [14, 29], [14, 45], [15, 17], [15, 19], [15, 20], [15, 25], [15, 28], [15, 29], [15, 36], [15, 41], [15, 42], [15, 45], [15, 46], [15, 47], [16, 17], [16, 21], [16, 24], [16, 36], [16, 42], [17, 18], [17, 19], [17, 22], [17, 25], [17, 29], [17, 34], [17, 35], [17, 36], [17, 37], [17, 41], [18, 20], [18, 25], [18, 33], [18, 34], [18, 36], [18, 41], [18, 46], [18, 47], [19, 26], [19, 27], [19, 28], [19, 29], [19, 32], [19, 33], [19, 38], [19, 40], [19, 45], [19, 46], [19, 47], [20, 21], [20, 23], [20, 27], [20, 30], [20, 33], [20, 38], [20, 39], [20, 40], [20, 43], [20, 47], [21, 23], [21, 26], [21, 28], [21, 30], [21, 32], [21, 35], [21, 40], [21, 41], [21, 46], [22, 23], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 36], [22, 41], [22, 42], [22, 45], [22, 46], [22, 47], [23, 24], [23, 25], [23, 28], [23, 29], [23, 33], [23, 36], [23, 41], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [24, 30], [24, 34], [24, 35], [24, 38], [24, 39], [24, 42], [24, 44], [24, 45], [24, 46], [24, 47], [25, 26], [25, 27], [25, 30], [25, 32], [25, 34], [25, 36], [25, 37], [25, 39], [25, 46], [25, 47], [26, 33], [26, 36], [26, 39], [26, 42], [26, 43], [27, 39], [27, 45], [28, 30], [28, 31], [28, 33], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 42], [28, 43], [28, 44], [28, 47], [29, 32], [29, 33], [29, 34], [29, 35], [29, 38], [29, 39], [29, 41], [29, 43], [29, 44], [30, 36], [30, 39], [30, 41], [30, 42], [31, 33], [31, 34], [31, 41], [31, 47], [32, 33], [32, 34], [32, 39], [32, 41], [32, 42], [32, 43], [32, 45], [32, 47], [33, 35], [33, 38], [33, 40], [33, 43], [33, 46], [33, 47], [34, 36], [34, 41], [34, 43], [35, 36], [35, 39], [35, 41], [35, 42], [35, 43], [35, 46], [36, 41], [36, 42], [36, 46], [37, 41], [37, 43], [37, 45], [37, 46], [38, 41], [38, 42], [38, 46], [38, 47], [39, 40], [39, 41], [39, 44], [39, 46], [39, 47], [40, 41], [40, 42], [40, 43], [40, 45], [40, 47], [41, 42], [41, 44], [41, 45], [41, 46], [41, 47], [42, 43], [42, 44], [42, 45], [43, 46], [43, 47], [44, 46], [45, 47], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s6/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c7e6c06baeef16d60be10ccc8721376e607ff281 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 2, 3, 5, 6, 8, 11, 12, 13, 14, 15, 16, 18, 23, 26, 27, 30, 31, 32, 35, 37, 38, 40, 44]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s6/tests/check.py b/tasks/construct-nppc-independent-set-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l5-s6/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab913255cc6aa04d03e6795fe0f8f9724873e222 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 4], [0, 10], [0, 17], [0, 19], [0, 20], [0, 21], [0, 22], [0, 25], [0, 34], [0, 41], [0, 43], [0, 47], [1, 4], [1, 6], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 19], [1, 20], [1, 23], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 37], [1, 39], [1, 42], [1, 45], [1, 47], [2, 4], [2, 9], [2, 10], [2, 19], [2, 21], [2, 22], [2, 25], [2, 28], [2, 41], [2, 42], [2, 46], [2, 47], [3, 4], [3, 7], [3, 9], [3, 17], [3, 20], [3, 21], [3, 24], [3, 28], [3, 29], [3, 33], [3, 42], [3, 43], [4, 5], [4, 8], [4, 10], [4, 11], [4, 14], [4, 16], [4, 17], [4, 19], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 31], [4, 39], [4, 41], [4, 42], [4, 46], [4, 47], [5, 9], [5, 25], [5, 34], [5, 36], [5, 45], [5, 46], [5, 47], [6, 7], [6, 10], [6, 20], [6, 21], [6, 22], [6, 24], [6, 29], [6, 33], [6, 39], [6, 43], [6, 45], [6, 46], [6, 47], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 20], [7, 21], [7, 25], [7, 26], [7, 27], [7, 30], [7, 32], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 46], [8, 10], [8, 21], [8, 25], [8, 34], [8, 36], [8, 39], [8, 42], [8, 43], [9, 12], [9, 13], [9, 14], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 27], [9, 28], [9, 30], [9, 31], [9, 34], [9, 36], [9, 38], [9, 42], [9, 44], [9, 46], [9, 47], [10, 11], [10, 12], [10, 16], [10, 17], [10, 21], [10, 23], [10, 24], [10, 25], [10, 26], [10, 29], [10, 30], [10, 34], [10, 35], [10, 36], [10, 37], [10, 41], [10, 42], [10, 43], [10, 45], [10, 46], [11, 19], [11, 20], [11, 28], [11, 29], [11, 34], [11, 36], [11, 39], [11, 41], [11, 42], [11, 43], [11, 45], [12, 19], [12, 20], [12, 25], [12, 29], [12, 33], [12, 34], [12, 36], [12, 39], [12, 41], [12, 43], [12, 45], [12, 47], [13, 19], [13, 21], [13, 25], [13, 28], [13, 29], [13, 34], [13, 36], [13, 42], [13, 43], [13, 45], [13, 46], [14, 17], [14, 20], [14, 21], [14, 25], [14, 28], [14, 29], [14, 45], [15, 17], [15, 19], [15, 20], [15, 25], [15, 28], [15, 29], [15, 36], [15, 41], [15, 42], [15, 45], [15, 46], [15, 47], [16, 17], [16, 21], [16, 24], [16, 36], [16, 42], [17, 18], [17, 19], [17, 22], [17, 25], [17, 29], [17, 34], [17, 35], [17, 36], [17, 37], [17, 41], [18, 20], [18, 25], [18, 33], [18, 34], [18, 36], [18, 41], [18, 46], [18, 47], [19, 26], [19, 27], [19, 28], [19, 29], [19, 32], [19, 33], [19, 38], [19, 40], [19, 45], [19, 46], [19, 47], [20, 21], [20, 23], [20, 27], [20, 30], [20, 33], [20, 38], [20, 39], [20, 40], [20, 43], [20, 47], [21, 23], [21, 26], [21, 28], [21, 30], [21, 32], [21, 35], [21, 40], [21, 41], [21, 46], [22, 23], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 36], [22, 41], [22, 42], [22, 45], [22, 46], [22, 47], [23, 24], [23, 25], [23, 28], [23, 29], [23, 33], [23, 36], [23, 41], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [24, 30], [24, 34], [24, 35], [24, 38], [24, 39], [24, 42], [24, 44], [24, 45], [24, 46], [24, 47], [25, 26], [25, 27], [25, 30], [25, 32], [25, 34], [25, 36], [25, 37], [25, 39], [25, 46], [25, 47], [26, 33], [26, 36], [26, 39], [26, 42], [26, 43], [27, 39], [27, 45], [28, 30], [28, 31], [28, 33], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 42], [28, 43], [28, 44], [28, 47], [29, 32], [29, 33], [29, 34], [29, 35], [29, 38], [29, 39], [29, 41], [29, 43], [29, 44], [30, 36], [30, 39], [30, 41], [30, 42], [31, 33], [31, 34], [31, 41], [31, 47], [32, 33], [32, 34], [32, 39], [32, 41], [32, 42], [32, 43], [32, 45], [32, 47], [33, 35], [33, 38], [33, 40], [33, 43], [33, 46], [33, 47], [34, 36], [34, 41], [34, 43], [35, 36], [35, 39], [35, 41], [35, 42], [35, 43], [35, 46], [36, 41], [36, 42], [36, 46], [37, 41], [37, 43], [37, 45], [37, 46], [38, 41], [38, 42], [38, 46], [38, 47], [39, 40], [39, 41], [39, 44], [39, 46], [39, 47], [40, 41], [40, 42], [40, 43], [40, 45], [40, 47], [41, 42], [41, 44], [41, 45], [41, 46], [41, 47], [42, 43], [42, 44], [42, 45], [43, 46], [43, 47], [44, 46], [45, 47], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s6/tests/run.py b/tasks/construct-nppc-independent-set-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s6/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l5-s8/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s8/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c829fd0741e5393116fd102452901ce5eec73e4 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 4], [0, 5], [0, 7], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 25], [0, 30], [0, 33], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 43], [0, 45], [1, 2], [1, 8], [1, 20], [1, 21], [1, 22], [1, 23], [1, 32], [1, 33], [1, 34], [1, 37], [1, 40], [1, 43], [1, 45], [1, 47], [2, 7], [2, 9], [2, 10], [2, 11], [2, 19], [2, 22], [2, 24], [2, 26], [2, 27], [2, 28], [2, 30], [2, 32], [2, 34], [2, 35], [2, 38], [2, 40], [2, 42], [3, 4], [3, 6], [3, 7], [3, 12], [3, 14], [3, 15], [3, 16], [3, 20], [3, 21], [3, 26], [3, 32], [3, 33], [3, 40], [3, 42], [3, 43], [3, 44], [4, 7], [4, 16], [4, 21], [4, 22], [4, 32], [4, 33], [4, 40], [4, 44], [4, 47], [5, 7], [5, 8], [5, 11], [5, 16], [5, 23], [5, 29], [5, 32], [5, 34], [5, 37], [5, 43], [5, 44], [5, 45], [5, 47], [6, 7], [6, 11], [6, 15], [6, 21], [6, 23], [6, 29], [6, 33], [6, 36], [6, 40], [6, 43], [6, 44], [7, 10], [7, 11], [7, 13], [7, 16], [7, 17], [7, 20], [7, 22], [7, 23], [7, 25], [7, 28], [7, 29], [7, 30], [7, 31], [7, 33], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 46], [7, 47], [8, 10], [8, 12], [8, 13], [8, 14], [8, 16], [8, 20], [8, 21], [8, 25], [8, 28], [8, 30], [8, 33], [8, 34], [8, 40], [8, 41], [8, 47], [9, 12], [9, 15], [9, 16], [9, 20], [9, 21], [9, 23], [9, 34], [9, 45], [10, 12], [10, 16], [10, 23], [10, 33], [10, 37], [10, 44], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 24], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 35], [11, 36], [11, 37], [11, 39], [11, 40], [11, 41], [11, 42], [11, 44], [11, 45], [11, 47], [12, 13], [12, 14], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 32], [12, 34], [12, 35], [12, 36], [12, 37], [12, 43], [13, 15], [13, 16], [13, 20], [13, 21], [13, 23], [13, 29], [13, 34], [13, 40], [13, 43], [13, 45], [14, 16], [14, 22], [14, 34], [14, 36], [14, 37], [14, 40], [14, 44], [14, 45], [15, 18], [15, 20], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 37], [15, 38], [15, 39], [15, 41], [15, 45], [16, 17], [16, 21], [16, 22], [16, 26], [16, 27], [16, 30], [16, 31], [16, 32], [16, 34], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [17, 20], [17, 22], [17, 23], [17, 29], [17, 32], [17, 33], [17, 34], [17, 40], [17, 43], [18, 20], [18, 21], [18, 23], [18, 29], [18, 33], [18, 36], [18, 37], [18, 43], [18, 44], [18, 45], [18, 47], [19, 20], [19, 21], [19, 34], [19, 40], [19, 43], [19, 47], [20, 22], [20, 23], [20, 24], [20, 27], [20, 28], [20, 30], [20, 33], [20, 34], [20, 37], [20, 41], [20, 43], [20, 45], [21, 22], [21, 23], [21, 25], [21, 27], [21, 29], [21, 30], [21, 32], [21, 33], [21, 35], [21, 37], [21, 42], [21, 43], [21, 44], [21, 47], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 37], [22, 38], [22, 40], [22, 41], [22, 43], [22, 44], [23, 26], [23, 29], [23, 32], [23, 33], [23, 34], [23, 36], [23, 38], [23, 43], [23, 44], [23, 45], [23, 46], [24, 32], [24, 34], [24, 37], [24, 40], [25, 29], [25, 34], [25, 36], [25, 43], [26, 36], [26, 37], [26, 43], [26, 45], [26, 47], [27, 29], [27, 33], [27, 36], [27, 45], [27, 47], [28, 29], [28, 32], [28, 33], [28, 36], [28, 37], [28, 43], [29, 30], [29, 32], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 46], [29, 47], [30, 33], [30, 34], [30, 47], [31, 33], [31, 47], [32, 34], [32, 35], [32, 37], [32, 40], [32, 41], [32, 44], [32, 45], [32, 47], [33, 35], [33, 36], [33, 38], [33, 45], [33, 47], [34, 37], [34, 39], [34, 43], [34, 44], [34, 45], [35, 36], [35, 37], [35, 40], [35, 45], [35, 47], [36, 38], [36, 39], [36, 41], [36, 42], [36, 45], [37, 38], [37, 41], [37, 42], [37, 43], [37, 46], [38, 43], [38, 45], [38, 47], [39, 40], [39, 43], [39, 44], [39, 45], [39, 47], [40, 42], [40, 43], [40, 44], [40, 46], [41, 44], [41, 47], [42, 47], [43, 44], [43, 45], [45, 46], [45, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s8/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..21003d8d3cbf61bef591173b1b960576fa91cbce --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 4, 5, 6, 9, 10, 13, 14, 17, 18, 19, 24, 25, 26, 27, 28, 30, 31, 35, 38, 39, 41, 42, 46]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s8/tests/check.py b/tasks/construct-nppc-independent-set-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l5-s8/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c829fd0741e5393116fd102452901ce5eec73e4 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 4], [0, 5], [0, 7], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 25], [0, 30], [0, 33], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 43], [0, 45], [1, 2], [1, 8], [1, 20], [1, 21], [1, 22], [1, 23], [1, 32], [1, 33], [1, 34], [1, 37], [1, 40], [1, 43], [1, 45], [1, 47], [2, 7], [2, 9], [2, 10], [2, 11], [2, 19], [2, 22], [2, 24], [2, 26], [2, 27], [2, 28], [2, 30], [2, 32], [2, 34], [2, 35], [2, 38], [2, 40], [2, 42], [3, 4], [3, 6], [3, 7], [3, 12], [3, 14], [3, 15], [3, 16], [3, 20], [3, 21], [3, 26], [3, 32], [3, 33], [3, 40], [3, 42], [3, 43], [3, 44], [4, 7], [4, 16], [4, 21], [4, 22], [4, 32], [4, 33], [4, 40], [4, 44], [4, 47], [5, 7], [5, 8], [5, 11], [5, 16], [5, 23], [5, 29], [5, 32], [5, 34], [5, 37], [5, 43], [5, 44], [5, 45], [5, 47], [6, 7], [6, 11], [6, 15], [6, 21], [6, 23], [6, 29], [6, 33], [6, 36], [6, 40], [6, 43], [6, 44], [7, 10], [7, 11], [7, 13], [7, 16], [7, 17], [7, 20], [7, 22], [7, 23], [7, 25], [7, 28], [7, 29], [7, 30], [7, 31], [7, 33], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 46], [7, 47], [8, 10], [8, 12], [8, 13], [8, 14], [8, 16], [8, 20], [8, 21], [8, 25], [8, 28], [8, 30], [8, 33], [8, 34], [8, 40], [8, 41], [8, 47], [9, 12], [9, 15], [9, 16], [9, 20], [9, 21], [9, 23], [9, 34], [9, 45], [10, 12], [10, 16], [10, 23], [10, 33], [10, 37], [10, 44], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 24], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 35], [11, 36], [11, 37], [11, 39], [11, 40], [11, 41], [11, 42], [11, 44], [11, 45], [11, 47], [12, 13], [12, 14], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 32], [12, 34], [12, 35], [12, 36], [12, 37], [12, 43], [13, 15], [13, 16], [13, 20], [13, 21], [13, 23], [13, 29], [13, 34], [13, 40], [13, 43], [13, 45], [14, 16], [14, 22], [14, 34], [14, 36], [14, 37], [14, 40], [14, 44], [14, 45], [15, 18], [15, 20], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 37], [15, 38], [15, 39], [15, 41], [15, 45], [16, 17], [16, 21], [16, 22], [16, 26], [16, 27], [16, 30], [16, 31], [16, 32], [16, 34], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [17, 20], [17, 22], [17, 23], [17, 29], [17, 32], [17, 33], [17, 34], [17, 40], [17, 43], [18, 20], [18, 21], [18, 23], [18, 29], [18, 33], [18, 36], [18, 37], [18, 43], [18, 44], [18, 45], [18, 47], [19, 20], [19, 21], [19, 34], [19, 40], [19, 43], [19, 47], [20, 22], [20, 23], [20, 24], [20, 27], [20, 28], [20, 30], [20, 33], [20, 34], [20, 37], [20, 41], [20, 43], [20, 45], [21, 22], [21, 23], [21, 25], [21, 27], [21, 29], [21, 30], [21, 32], [21, 33], [21, 35], [21, 37], [21, 42], [21, 43], [21, 44], [21, 47], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 37], [22, 38], [22, 40], [22, 41], [22, 43], [22, 44], [23, 26], [23, 29], [23, 32], [23, 33], [23, 34], [23, 36], [23, 38], [23, 43], [23, 44], [23, 45], [23, 46], [24, 32], [24, 34], [24, 37], [24, 40], [25, 29], [25, 34], [25, 36], [25, 43], [26, 36], [26, 37], [26, 43], [26, 45], [26, 47], [27, 29], [27, 33], [27, 36], [27, 45], [27, 47], [28, 29], [28, 32], [28, 33], [28, 36], [28, 37], [28, 43], [29, 30], [29, 32], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 46], [29, 47], [30, 33], [30, 34], [30, 47], [31, 33], [31, 47], [32, 34], [32, 35], [32, 37], [32, 40], [32, 41], [32, 44], [32, 45], [32, 47], [33, 35], [33, 36], [33, 38], [33, 45], [33, 47], [34, 37], [34, 39], [34, 43], [34, 44], [34, 45], [35, 36], [35, 37], [35, 40], [35, 45], [35, 47], [36, 38], [36, 39], [36, 41], [36, 42], [36, 45], [37, 38], [37, 41], [37, 42], [37, 43], [37, 46], [38, 43], [38, 45], [38, 47], [39, 40], [39, 43], [39, 44], [39, 45], [39, 47], [40, 42], [40, 43], [40, 44], [40, 46], [41, 44], [41, 47], [42, 47], [43, 44], [43, 45], [45, 46], [45, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s8/tests/run.py b/tasks/construct-nppc-independent-set-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s8/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6434d216482e27e2bea1229d56565d4ae34473f6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"a": 103907, "b": 82853, "c": 214886170432637, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e0dd3fb219b052bf035bad0c756af5e6a715f7a1 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 45475, "y": 108954} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6434d216482e27e2bea1229d56565d4ae34473f6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"a": 103907, "b": 82853, "c": 214886170432637, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l4-s0/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..492a5498229b52954b146da275178711b6ebb68f --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"a": 72738, "b": 157036, "c": 1490949905830426, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2b7e56590a281e3db74110365677f7ed11310c7c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 143169, "y": 81178} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..492a5498229b52954b146da275178711b6ebb68f --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"a": 72738, "b": 157036, "c": 1490949905830426, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l4-s7/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d97c5ab03f34141a0b7e13cebc2582b7cdbeac06 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"a": 911497, "b": 1519936, "c": 4023914, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..43fac4b3dc0cd860375ef77b10db8718ee2b1e17 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 2087197} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d97c5ab03f34141a0b7e13cebc2582b7cdbeac06 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"a": 911497, "b": 1519936, "c": 4023914, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2187fd512d8405dbff3b06cb2b45f20a66c93783 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"a": 479049, "b": 1936095, "c": 3427846, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..10e61c180920f6b3f8cb52b8c200c7ee3010387f --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 1125882} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2187fd512d8405dbff3b06cb2b45f20a66c93783 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"a": 479049, "b": 1936095, "c": 3427846, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5815926b2aefd76398413fb2fe63afc18d4d50cc --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 5], [0, 7], [0, 8], [0, 12], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 12], [1, 13], [1, 15], [2, 7], [2, 8], [3, 7], [3, 8], [3, 12], [4, 7], [4, 8], [4, 12], [5, 9], [5, 10], [5, 11], [5, 12], [5, 14], [5, 15], [6, 7], [7, 8], [7, 9], [7, 10], [7, 12], [7, 14], [7, 15], [8, 9], [8, 11], [8, 13], [8, 14], [9, 12], [12, 13], [12, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f7be78de7664537b6d565eabe8f22d80888c571 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 5, 7, 8, 12]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5815926b2aefd76398413fb2fe63afc18d4d50cc --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 5], [0, 7], [0, 8], [0, 12], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 12], [1, 13], [1, 15], [2, 7], [2, 8], [3, 7], [3, 8], [3, 12], [4, 7], [4, 8], [4, 12], [5, 9], [5, 10], [5, 11], [5, 12], [5, 14], [5, 15], [6, 7], [7, 8], [7, 9], [7, 10], [7, 12], [7, 14], [7, 15], [8, 9], [8, 11], [8, 13], [8, 14], [9, 12], [12, 13], [12, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s3/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a6eac3eff054fb9c15df24d7715e52a75321fafd --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 11], [0, 12], [0, 13], [0, 14], [1, 6], [1, 13], [2, 3], [2, 6], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 15], [4, 11], [4, 12], [4, 13], [4, 14], [5, 13], [6, 8], [6, 9], [6, 11], [6, 13], [6, 14], [7, 13], [8, 13], [9, 13], [13, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..04a1c7777b462c3b63e9e92c8fe0e2ad08bdab41 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 3, 4, 6, 13]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a6eac3eff054fb9c15df24d7715e52a75321fafd --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 11], [0, 12], [0, 13], [0, 14], [1, 6], [1, 13], [2, 3], [2, 6], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 15], [4, 11], [4, 12], [4, 13], [4, 14], [5, 13], [6, 8], [6, 9], [6, 11], [6, 13], [6, 14], [7, 13], [8, 13], [9, 13], [13, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s4/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f0287d3b6b46cfc96baab2dd65fee1ead650c41 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 4], [0, 5], [0, 18], [0, 19], [0, 23], [0, 28], [0, 33], [0, 35], [0, 36], [0, 41], [0, 44], [0, 47], [0, 50], [0, 62], [0, 63], [0, 72], [0, 74], [0, 80], [0, 81], [0, 86], [0, 90], [0, 106], [0, 107], [0, 115], [0, 116], [0, 119], [0, 126], [0, 128], [0, 132], [0, 135], [0, 140], [0, 141], [0, 144], [0, 145], [0, 150], [0, 152], [0, 155], [1, 3], [1, 26], [1, 49], [1, 58], [1, 67], [1, 77], [1, 83], [1, 84], [1, 97], [1, 100], [1, 128], [1, 136], [1, 138], [1, 139], [1, 143], [1, 156], [2, 26], [2, 35], [2, 77], [2, 97], [2, 115], [2, 121], [2, 127], [2, 132], [2, 133], [2, 139], [2, 141], [3, 12], [3, 17], [3, 20], [3, 23], [3, 26], [3, 34], [3, 52], [3, 61], [3, 62], [3, 69], [3, 73], [3, 80], [3, 97], [3, 102], [3, 103], [3, 104], [3, 106], [3, 111], [3, 113], [3, 114], [3, 126], [3, 131], [3, 132], [3, 137], [3, 146], [3, 152], [3, 154], [3, 158], [3, 159], [4, 5], [4, 69], [4, 103], [4, 104], [4, 119], [4, 121], [4, 139], [5, 15], [5, 17], [5, 24], [5, 30], [5, 35], [5, 44], [5, 52], [5, 53], [5, 62], [5, 64], [5, 74], [5, 78], [5, 88], [5, 92], [5, 102], [5, 103], [5, 105], [5, 107], [5, 112], [5, 115], [5, 129], [5, 130], [5, 131], [5, 132], [5, 134], [5, 146], [5, 147], [5, 149], [5, 152], [5, 157], [6, 17], [6, 52], [6, 65], [6, 72], [6, 73], [6, 96], [6, 100], [6, 115], [6, 119], [6, 129], [6, 132], [6, 137], [6, 138], [7, 16], [7, 26], [7, 61], [7, 67], [7, 72], [7, 74], [7, 96], [7, 102], [7, 114], [7, 118], [7, 121], [7, 138], [7, 143], [7, 149], [7, 152], [8, 23], [8, 25], [8, 30], [8, 49], [8, 52], [8, 88], [8, 92], [8, 129], [8, 133], [8, 152], [9, 16], [9, 88], [9, 97], [9, 102], [9, 103], [9, 119], [9, 130], [9, 132], [9, 138], [9, 149], [10, 15], [10, 72], [10, 84], [10, 112], [10, 115], [10, 132], [10, 136], [10, 143], [11, 13], [11, 16], [11, 35], [11, 63], [11, 77], [11, 100], [11, 112], [11, 133], [11, 154], [11, 156], [12, 13], [12, 25], [12, 49], [12, 52], [12, 67], [12, 80], [12, 92], [12, 154], [13, 26], [13, 31], [13, 41], [13, 58], [13, 62], [13, 67], [13, 69], [13, 70], [13, 82], [13, 84], [13, 88], [13, 93], [13, 94], [13, 102], [13, 106], [13, 111], [13, 118], [13, 119], [13, 122], [13, 128], [13, 131], [13, 132], [13, 136], [13, 137], [13, 144], [13, 145], [13, 154], [14, 25], [14, 26], [14, 27], [14, 39], [14, 49], [14, 52], [14, 63], [14, 65], [14, 114], [14, 121], [14, 128], [14, 130], [14, 149], [14, 154], [15, 21], [15, 23], [15, 28], [15, 31], [15, 38], [15, 39], [15, 42], [15, 43], [15, 46], [15, 47], [15, 54], [15, 61], [15, 62], [15, 74], [15, 76], [15, 85], [15, 86], [15, 88], [15, 90], [15, 94], [15, 96], [15, 98], [15, 102], [15, 105], [15, 109], [15, 112], [15, 125], [15, 127], [15, 132], [15, 138], [15, 146], [15, 152], [15, 155], [16, 19], [16, 27], [16, 30], [16, 44], [16, 49], [16, 60], [16, 63], [16, 67], [16, 72], [16, 74], [16, 77], [16, 81], [16, 82], [16, 85], [16, 88], [16, 92], [16, 98], [16, 101], [16, 103], [16, 108], [16, 114], [16, 124], [16, 133], [16, 137], [16, 139], [16, 145], [16, 149], [16, 154], [17, 18], [17, 19], [17, 21], [17, 22], [17, 27], [17, 30], [17, 39], [17, 40], [17, 44], [17, 52], [17, 58], [17, 65], [17, 72], [17, 73], [17, 77], [17, 80], [17, 83], [17, 88], [17, 91], [17, 94], [17, 100], [17, 104], [17, 110], [17, 118], [17, 121], [17, 133], [17, 134], [17, 136], [17, 138], [17, 143], [17, 146], [17, 153], [17, 154], [17, 156], [17, 157], [18, 39], [18, 61], [18, 69], [18, 72], [18, 91], [18, 105], [18, 112], [18, 114], [18, 138], [18, 139], [19, 27], [19, 30], [19, 39], [19, 73], [19, 114], [19, 115], [19, 138], [20, 26], [20, 44], [20, 49], [20, 65], [20, 102], [20, 114], [20, 118], [20, 119], [20, 121], [20, 130], [20, 143], [21, 52], [21, 84], [21, 88], [21, 100], [21, 103], [21, 119], [21, 129], [21, 130], [22, 25], [22, 35], [22, 49], [22, 58], [22, 67], [22, 72], [22, 100], [22, 112], [22, 136], [22, 141], [22, 153], [23, 24], [23, 27], [23, 30], [23, 33], [23, 43], [23, 49], [23, 55], [23, 58], [23, 61], [23, 63], [23, 64], [23, 65], [23, 71], [23, 74], [23, 77], [23, 78], [23, 79], [23, 81], [23, 95], [23, 96], [23, 98], [23, 102], [23, 111], [23, 121], [23, 124], [23, 127], [23, 129], [23, 130], [23, 136], [23, 138], [23, 139], [23, 140], [23, 141], [23, 144], [23, 147], [23, 149], [23, 156], [23, 157], [24, 39], [24, 61], [24, 67], [24, 88], [24, 96], [24, 102], [24, 112], [24, 128], [24, 143], [24, 156], [25, 27], [25, 30], [25, 31], [25, 54], [25, 61], [25, 69], [25, 73], [25, 74], [25, 83], [25, 84], [25, 90], [25, 97], [25, 110], [25, 112], [25, 116], [25, 127], [25, 130], [25, 132], [25, 141], [25, 142], [25, 150], [25, 153], [25, 154], [25, 156], [26, 27], [26, 35], [26, 41], [26, 44], [26, 45], [26, 51], [26, 61], [26, 73], [26, 75], [26, 87], [26, 100], [26, 101], [26, 102], [26, 107], [26, 112], [26, 113], [26, 115], [26, 119], [26, 121], [26, 123], [26, 128], [26, 132], [26, 137], [26, 139], [26, 141], [26, 145], [26, 152], [26, 153], [26, 156], [27, 32], [27, 34], [27, 40], [27, 43], [27, 44], [27, 48], [27, 52], [27, 55], [27, 59], [27, 64], [27, 68], [27, 72], [27, 73], [27, 75], [27, 79], [27, 80], [27, 84], [27, 88], [27, 91], [27, 98], [27, 107], [27, 112], [27, 113], [27, 115], [27, 118], [27, 124], [27, 128], [27, 129], [27, 130], [27, 133], [27, 145], [27, 159], [28, 39], [28, 49], [28, 58], [28, 69], [28, 88], [28, 96], [29, 52], [29, 67], [29, 92], [29, 100], [29, 112], [29, 118], [29, 121], [29, 129], [29, 143], [29, 156], [30, 36], [30, 38], [30, 43], [30, 49], [30, 50], [30, 64], [30, 67], [30, 70], [30, 74], [30, 80], [30, 81], [30, 83], [30, 89], [30, 90], [30, 91], [30, 92], [30, 96], [30, 97], [30, 103], [30, 106], [30, 114], [30, 123], [30, 138], [30, 140], [30, 148], [30, 149], [30, 152], [30, 153], [30, 156], [31, 35], [31, 77], [31, 83], [31, 88], [31, 105], [31, 114], [31, 118], [31, 130], [32, 35], [32, 52], [32, 69], [32, 97], [32, 102], [32, 118], [33, 39], [33, 44], [33, 49], [33, 61], [33, 72], [33, 88], [33, 100], [33, 114], [33, 129], [34, 52], [34, 67], [34, 74], [34, 100], [34, 102], [34, 112], [34, 128], [34, 132], [34, 137], [34, 138], [34, 139], [35, 38], [35, 45], [35, 46], [35, 48], [35, 52], [35, 58], [35, 67], [35, 73], [35, 80], [35, 83], [35, 88], [35, 90], [35, 92], [35, 96], [35, 103], [35, 104], [35, 114], [35, 115], [35, 139], [35, 141], [35, 145], [35, 154], [36, 97], [36, 103], [36, 104], [36, 112], [36, 121], [36, 133], [36, 136], [36, 149], [36, 154], [37, 44], [37, 52], [37, 63], [37, 67], [37, 69], [37, 72], [37, 83], [37, 84], [37, 88], [37, 115], [37, 133], [37, 149], [37, 153], [38, 44], [38, 65], [38, 72], [38, 73], [38, 96], [38, 102], [38, 103], [39, 44], [39, 49], [39, 54], [39, 57], [39, 58], [39, 59], [39, 61], [39, 64], [39, 65], [39, 74], [39, 75], [39, 77], [39, 82], [39, 83], [39, 84], [39, 85], [39, 91], [39, 92], [39, 97], [39, 98], [39, 101], [39, 103], [39, 107], [39, 110], [39, 113], [39, 116], [39, 121], [39, 125], [39, 128], [39, 135], [39, 136], [39, 138], [39, 142], [39, 154], [40, 58], [40, 88], [40, 91], [40, 97], [40, 112], [40, 128], [40, 138], [40, 141], [40, 152], [41, 69], [41, 77], [41, 102], [41, 112], [41, 129], [41, 133], [41, 154], [42, 61], [42, 69], [42, 73], [42, 80], [42, 88], [42, 96], [42, 97], [42, 100], [42, 103], [42, 118], [42, 132], [43, 72], [43, 77], [43, 112], [43, 114], [43, 119], [43, 129], [43, 136], [44, 46], [44, 48], [44, 61], [44, 63], [44, 68], [44, 69], [44, 78], [44, 88], [44, 89], [44, 102], [44, 115], [44, 120], [44, 123], [44, 135], [44, 136], [44, 147], [44, 150], [44, 156], [44, 157], [44, 159], [45, 49], [45, 58], [45, 84], [45, 88], [45, 102], [45, 103], [45, 115], [45, 128], [46, 52], [46, 97], [46, 102], [46, 115], [46, 121], [46, 139], [46, 149], [46, 152], [46, 154], [47, 97], [47, 118], [47, 121], [47, 129], [47, 139], [47, 149], [47, 152], [48, 52], [48, 61], [48, 65], [48, 72], [48, 74], [48, 114], [48, 127], [48, 149], [48, 152], [49, 53], [49, 57], [49, 61], [49, 63], [49, 64], [49, 68], [49, 69], [49, 70], [49, 73], [49, 77], [49, 84], [49, 102], [49, 105], [49, 108], [49, 118], [49, 119], [49, 127], [49, 129], [49, 130], [49, 133], [49, 136], [49, 139], [49, 140], [49, 149], [49, 152], [49, 156], [49, 157], [49, 159], [50, 77], [50, 80], [50, 97], [50, 100], [50, 118], [50, 137], [50, 139], [51, 65], [51, 67], [51, 77], [51, 112], [51, 127], [51, 128], [51, 133], [51, 137], [51, 141], [51, 149], [52, 54], [52, 62], [52, 63], [52, 65], [52, 79], [52, 86], [52, 91], [52, 94], [52, 104], [52, 106], [52, 108], [52, 112], [52, 113], [52, 119], [52, 121], [52, 129], [52, 130], [52, 132], [52, 135], [52, 137], [52, 142], [52, 143], [52, 146], [52, 148], [53, 58], [53, 88], [53, 97], [53, 119], [53, 133], [53, 137], [53, 139], [53, 149], [54, 67], [54, 69], [54, 84], [54, 105], [54, 115], [54, 129], [55, 61], [55, 69], [55, 127], [55, 141], [55, 156], [56, 63], [56, 65], [56, 69], [56, 77], [56, 80], [56, 92], [56, 119], [56, 128], [56, 138], [56, 152], [57, 88], [57, 104], [57, 105], [57, 127], [57, 128], [57, 129], [57, 149], [58, 63], [58, 69], [58, 70], [58, 77], [58, 94], [58, 109], [58, 111], [58, 127], [58, 130], [58, 152], [58, 156], [59, 65], [59, 67], [59, 102], [59, 103], [59, 128], [59, 130], [59, 136], [59, 143], [60, 67], [60, 69], [60, 83], [60, 91], [60, 100], [60, 103], [60, 112], [60, 114], [60, 143], [60, 152], [61, 62], [61, 66], [61, 70], [61, 73], [61, 76], [61, 80], [61, 92], [61, 98], [61, 103], [61, 105], [61, 109], [61, 118], [61, 125], [61, 128], [61, 130], [61, 132], [61, 136], [61, 143], [61, 149], [62, 83], [62, 92], [62, 105], [62, 118], [62, 127], [62, 130], [62, 137], [63, 69], [63, 73], [63, 76], [63, 77], [63, 84], [63, 92], [63, 97], [63, 98], [63, 99], [63, 105], [63, 115], [63, 118], [63, 131], [63, 143], [63, 151], [63, 156], [63, 157], [64, 69], [64, 74], [64, 121], [64, 129], [64, 154], [65, 68], [65, 72], [65, 78], [65, 94], [65, 100], [65, 114], [65, 124], [65, 125], [65, 130], [65, 133], [65, 135], [65, 137], [65, 138], [65, 152], [65, 153], [65, 154], [66, 72], [66, 83], [66, 103], [66, 133], [66, 136], [66, 137], [66, 149], [66, 152], [67, 69], [67, 82], [67, 83], [67, 84], [67, 88], [67, 89], [67, 100], [67, 102], [67, 106], [67, 107], [67, 111], [67, 114], [67, 115], [67, 118], [67, 119], [67, 121], [67, 123], [67, 130], [67, 132], [67, 134], [67, 135], [67, 137], [67, 138], [67, 144], [67, 146], [67, 147], [67, 148], [67, 153], [67, 154], [67, 159], [68, 69], [68, 80], [68, 129], [68, 148], [68, 149], [69, 70], [69, 72], [69, 73], [69, 74], [69, 75], [69, 76], [69, 88], [69, 91], [69, 92], [69, 93], [69, 96], [69, 101], [69, 111], [69, 112], [69, 120], [69, 124], [69, 125], [69, 129], [69, 130], [69, 133], [69, 138], [69, 142], [69, 143], [69, 144], [69, 148], [69, 149], [69, 156], [70, 100], [70, 102], [70, 115], [70, 119], [70, 130], [70, 136], [70, 138], [70, 152], [71, 102], [71, 112], [71, 152], [72, 73], [72, 75], [72, 84], [72, 86], [72, 97], [72, 100], [72, 105], [72, 108], [72, 112], [72, 117], [72, 122], [72, 123], [72, 124], [72, 127], [72, 133], [72, 135], [72, 144], [72, 145], [72, 147], [72, 148], [72, 152], [72, 153], [73, 85], [73, 93], [73, 96], [73, 97], [73, 102], [73, 103], [73, 108], [73, 115], [73, 119], [73, 125], [73, 132], [73, 139], [73, 146], [73, 151], [73, 152], [74, 88], [74, 91], [74, 95], [74, 100], [74, 105], [74, 115], [74, 116], [74, 119], [74, 124], [74, 137], [74, 142], [74, 143], [74, 146], [74, 152], [74, 153], [74, 157], [75, 83], [75, 103], [75, 119], [75, 127], [75, 128], [76, 84], [76, 96], [76, 105], [76, 119], [76, 129], [76, 136], [76, 139], [76, 141], [76, 152], [77, 87], [77, 88], [77, 93], [77, 94], [77, 103], [77, 104], [77, 108], [77, 114], [77, 117], [77, 127], [77, 129], [77, 138], [77, 140], [77, 142], [77, 147], [77, 154], [78, 80], [78, 91], [78, 105], [78, 112], [78, 115], [78, 118], [78, 136], [79, 96], [79, 103], [79, 104], [79, 114], [79, 115], [79, 119], [79, 127], [79, 133], [80, 88], [80, 92], [80, 102], [80, 104], [80, 110], [80, 115], [80, 117], [80, 122], [80, 128], [80, 132], [80, 138], [80, 145], [80, 147], [80, 150], [80, 155], [81, 84], [81, 91], [81, 118], [81, 119], [81, 137], [81, 153], [81, 156], [82, 91], [82, 96], [82, 100], [82, 119], [82, 129], [82, 132], [82, 137], [82, 138], [82, 139], [82, 148], [82, 153], [82, 154], [83, 96], [83, 98], [83, 103], [83, 105], [83, 108], [83, 116], [83, 118], [83, 123], [83, 125], [83, 128], [83, 132], [83, 141], [83, 148], [83, 149], [83, 153], [83, 154], [84, 87], [84, 110], [84, 115], [84, 140], [84, 141], [84, 142], [84, 156], [84, 158], [85, 129], [85, 133], [85, 139], [85, 141], [85, 152], [86, 105], [86, 118], [86, 137], [86, 149], [87, 91], [87, 100], [87, 103], [87, 112], [87, 127], [87, 128], [87, 132], [87, 138], [88, 92], [88, 97], [88, 105], [88, 109], [88, 115], [88, 120], [88, 128], [88, 129], [88, 149], [88, 153], [88, 155], [88, 156], [89, 92], [89, 102], [89, 114], [89, 121], [89, 128], [89, 130], [89, 133], [89, 149], [90, 112], [90, 127], [90, 129], [90, 130], [90, 137], [91, 94], [91, 100], [91, 101], [91, 105], [91, 109], [91, 110], [91, 115], [91, 120], [91, 121], [91, 123], [91, 126], [91, 130], [91, 132], [91, 133], [91, 139], [91, 143], [91, 146], [91, 159], [92, 98], [92, 104], [92, 109], [92, 113], [92, 116], [92, 125], [92, 126], [92, 128], [92, 131], [92, 138], [92, 141], [92, 142], [92, 146], [92, 154], [92, 156], [92, 158], [93, 96], [93, 105], [93, 119], [93, 154], [94, 103], [94, 115], [94, 118], [94, 129], [94, 137], [94, 153], [94, 156], [95, 102], [95, 118], [95, 138], [95, 139], [95, 141], [95, 148], [95, 149], [96, 97], [96, 100], [96, 105], [96, 110], [96, 112], [96, 118], [96, 122], [96, 132], [96, 138], [96, 147], [96, 155], [96, 159], [97, 102], [97, 104], [97, 114], [97, 119], [97, 126], [97, 129], [97, 136], [97, 138], [97, 140], [97, 141], [97, 146], [97, 150], [97, 155], [97, 156], [98, 112], [99, 102], [99, 104], [99, 115], [99, 129], [99, 141], [99, 143], [99, 148], [99, 156], [100, 109], [100, 117], [100, 125], [100, 126], [100, 128], [100, 132], [100, 134], [100, 137], [100, 138], [100, 140], [100, 143], [100, 146], [100, 147], [100, 150], [100, 155], [101, 104], [101, 105], [101, 128], [101, 130], [101, 143], [102, 105], [102, 109], [102, 121], [102, 126], [102, 127], [102, 131], [102, 137], [102, 139], [102, 143], [102, 159], [103, 104], [103, 106], [103, 127], [103, 135], [103, 136], [103, 139], [103, 148], [103, 151], [103, 152], [103, 153], [103, 158], [104, 108], [104, 111], [104, 112], [104, 114], [104, 115], [104, 126], [104, 139], [104, 148], [105, 115], [105, 121], [105, 126], [105, 129], [105, 133], [105, 135], [105, 136], [105, 139], [105, 145], [105, 146], [105, 148], [105, 153], [105, 156], [105, 157], [105, 159], [106, 112], [106, 139], [106, 153], [107, 115], [107, 132], [107, 149], [107, 152], [107, 156], [108, 115], [108, 118], [108, 143], [108, 156], [109, 128], [109, 132], [109, 156], [110, 112], [110, 118], [110, 129], [110, 132], [110, 136], [110, 153], [111, 118], [111, 128], [111, 130], [111, 143], [112, 113], [112, 119], [112, 130], [112, 132], [112, 133], [112, 134], [112, 141], [112, 151], [112, 156], [113, 115], [113, 137], [113, 138], [114, 121], [114, 123], [114, 129], [114, 130], [114, 132], [114, 145], [114, 149], [114, 151], [114, 158], [115, 118], [115, 120], [115, 124], [115, 125], [115, 126], [115, 127], [115, 133], [115, 135], [115, 137], [115, 146], [115, 147], [115, 150], [116, 118], [116, 153], [116, 156], [117, 128], [117, 138], [117, 139], [117, 141], [118, 119], [118, 120], [118, 123], [118, 131], [118, 136], [118, 144], [118, 149], [119, 130], [119, 133], [119, 134], [119, 139], [119, 140], [120, 121], [120, 127], [120, 136], [120, 139], [120, 154], [121, 129], [121, 130], [121, 135], [121, 137], [121, 138], [121, 141], [121, 145], [121, 147], [121, 148], [121, 149], [121, 154], [122, 130], [122, 132], [122, 143], [122, 149], [122, 152], [123, 127], [123, 130], [123, 137], [124, 141], [124, 149], [124, 154], [125, 127], [125, 130], [125, 143], [125, 152], [126, 127], [126, 138], [127, 130], [127, 133], [127, 143], [127, 145], [127, 150], [127, 151], [127, 155], [127, 159], [128, 130], [128, 132], [128, 140], [128, 141], [128, 147], [128, 153], [128, 155], [129, 130], [129, 131], [129, 135], [129, 137], [129, 146], [129, 149], [130, 131], [130, 135], [130, 141], [130, 147], [130, 148], [130, 149], [130, 158], [131, 133], [131, 136], [131, 138], [131, 153], [132, 139], [132, 140], [132, 155], [132, 157], [133, 136], [133, 137], [133, 143], [133, 154], [133, 157], [134, 136], [135, 139], [135, 141], [135, 143], [135, 153], [136, 150], [136, 151], [136, 154], [137, 139], [137, 145], [137, 149], [137, 152], [137, 154], [138, 141], [138, 149], [138, 153], [139, 148], [139, 152], [139, 153], [139, 159], [140, 143], [141, 143], [141, 148], [141, 149], [141, 152], [141, 153], [141, 156], [142, 149], [143, 151], [143, 156], [145, 154], [148, 153], [148, 159], [149, 150], [149, 152], [149, 154], [149, 155], [152, 155], [153, 156], [154, 158]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..27d2c0ed5980f71cbb18f757b79a73a68fe79c87 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 3, 5, 13, 15, 16, 17, 23, 25, 26, 27, 30, 35, 39, 44, 49, 52, 58, 61, 63, 65, 67, 69, 72, 73, 74, 77, 80, 83, 84, 88, 91, 92, 96, 97, 100, 102, 103, 104, 105, 112, 114, 115, 118, 119, 121, 127, 128, 129, 130, 132, 133, 136, 137, 138, 139, 141, 143, 148, 149, 152, 153, 154, 156]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f0287d3b6b46cfc96baab2dd65fee1ead650c41 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 4], [0, 5], [0, 18], [0, 19], [0, 23], [0, 28], [0, 33], [0, 35], [0, 36], [0, 41], [0, 44], [0, 47], [0, 50], [0, 62], [0, 63], [0, 72], [0, 74], [0, 80], [0, 81], [0, 86], [0, 90], [0, 106], [0, 107], [0, 115], [0, 116], [0, 119], [0, 126], [0, 128], [0, 132], [0, 135], [0, 140], [0, 141], [0, 144], [0, 145], [0, 150], [0, 152], [0, 155], [1, 3], [1, 26], [1, 49], [1, 58], [1, 67], [1, 77], [1, 83], [1, 84], [1, 97], [1, 100], [1, 128], [1, 136], [1, 138], [1, 139], [1, 143], [1, 156], [2, 26], [2, 35], [2, 77], [2, 97], [2, 115], [2, 121], [2, 127], [2, 132], [2, 133], [2, 139], [2, 141], [3, 12], [3, 17], [3, 20], [3, 23], [3, 26], [3, 34], [3, 52], [3, 61], [3, 62], [3, 69], [3, 73], [3, 80], [3, 97], [3, 102], [3, 103], [3, 104], [3, 106], [3, 111], [3, 113], [3, 114], [3, 126], [3, 131], [3, 132], [3, 137], [3, 146], [3, 152], [3, 154], [3, 158], [3, 159], [4, 5], [4, 69], [4, 103], [4, 104], [4, 119], [4, 121], [4, 139], [5, 15], [5, 17], [5, 24], [5, 30], [5, 35], [5, 44], [5, 52], [5, 53], [5, 62], [5, 64], [5, 74], [5, 78], [5, 88], [5, 92], [5, 102], [5, 103], [5, 105], [5, 107], [5, 112], [5, 115], [5, 129], [5, 130], [5, 131], [5, 132], [5, 134], [5, 146], [5, 147], [5, 149], [5, 152], [5, 157], [6, 17], [6, 52], [6, 65], [6, 72], [6, 73], [6, 96], [6, 100], [6, 115], [6, 119], [6, 129], [6, 132], [6, 137], [6, 138], [7, 16], [7, 26], [7, 61], [7, 67], [7, 72], [7, 74], [7, 96], [7, 102], [7, 114], [7, 118], [7, 121], [7, 138], [7, 143], [7, 149], [7, 152], [8, 23], [8, 25], [8, 30], [8, 49], [8, 52], [8, 88], [8, 92], [8, 129], [8, 133], [8, 152], [9, 16], [9, 88], [9, 97], [9, 102], [9, 103], [9, 119], [9, 130], [9, 132], [9, 138], [9, 149], [10, 15], [10, 72], [10, 84], [10, 112], [10, 115], [10, 132], [10, 136], [10, 143], [11, 13], [11, 16], [11, 35], [11, 63], [11, 77], [11, 100], [11, 112], [11, 133], [11, 154], [11, 156], [12, 13], [12, 25], [12, 49], [12, 52], [12, 67], [12, 80], [12, 92], [12, 154], [13, 26], [13, 31], [13, 41], [13, 58], [13, 62], [13, 67], [13, 69], [13, 70], [13, 82], [13, 84], [13, 88], [13, 93], [13, 94], [13, 102], [13, 106], [13, 111], [13, 118], [13, 119], [13, 122], [13, 128], [13, 131], [13, 132], [13, 136], [13, 137], [13, 144], [13, 145], [13, 154], [14, 25], [14, 26], [14, 27], [14, 39], [14, 49], [14, 52], [14, 63], [14, 65], [14, 114], [14, 121], [14, 128], [14, 130], [14, 149], [14, 154], [15, 21], [15, 23], [15, 28], [15, 31], [15, 38], [15, 39], [15, 42], [15, 43], [15, 46], [15, 47], [15, 54], [15, 61], [15, 62], [15, 74], [15, 76], [15, 85], [15, 86], [15, 88], [15, 90], [15, 94], [15, 96], [15, 98], [15, 102], [15, 105], [15, 109], [15, 112], [15, 125], [15, 127], [15, 132], [15, 138], [15, 146], [15, 152], [15, 155], [16, 19], [16, 27], [16, 30], [16, 44], [16, 49], [16, 60], [16, 63], [16, 67], [16, 72], [16, 74], [16, 77], [16, 81], [16, 82], [16, 85], [16, 88], [16, 92], [16, 98], [16, 101], [16, 103], [16, 108], [16, 114], [16, 124], [16, 133], [16, 137], [16, 139], [16, 145], [16, 149], [16, 154], [17, 18], [17, 19], [17, 21], [17, 22], [17, 27], [17, 30], [17, 39], [17, 40], [17, 44], [17, 52], [17, 58], [17, 65], [17, 72], [17, 73], [17, 77], [17, 80], [17, 83], [17, 88], [17, 91], [17, 94], [17, 100], [17, 104], [17, 110], [17, 118], [17, 121], [17, 133], [17, 134], [17, 136], [17, 138], [17, 143], [17, 146], [17, 153], [17, 154], [17, 156], [17, 157], [18, 39], [18, 61], [18, 69], [18, 72], [18, 91], [18, 105], [18, 112], [18, 114], [18, 138], [18, 139], [19, 27], [19, 30], [19, 39], [19, 73], [19, 114], [19, 115], [19, 138], [20, 26], [20, 44], [20, 49], [20, 65], [20, 102], [20, 114], [20, 118], [20, 119], [20, 121], [20, 130], [20, 143], [21, 52], [21, 84], [21, 88], [21, 100], [21, 103], [21, 119], [21, 129], [21, 130], [22, 25], [22, 35], [22, 49], [22, 58], [22, 67], [22, 72], [22, 100], [22, 112], [22, 136], [22, 141], [22, 153], [23, 24], [23, 27], [23, 30], [23, 33], [23, 43], [23, 49], [23, 55], [23, 58], [23, 61], [23, 63], [23, 64], [23, 65], [23, 71], [23, 74], [23, 77], [23, 78], [23, 79], [23, 81], [23, 95], [23, 96], [23, 98], [23, 102], [23, 111], [23, 121], [23, 124], [23, 127], [23, 129], [23, 130], [23, 136], [23, 138], [23, 139], [23, 140], [23, 141], [23, 144], [23, 147], [23, 149], [23, 156], [23, 157], [24, 39], [24, 61], [24, 67], [24, 88], [24, 96], [24, 102], [24, 112], [24, 128], [24, 143], [24, 156], [25, 27], [25, 30], [25, 31], [25, 54], [25, 61], [25, 69], [25, 73], [25, 74], [25, 83], [25, 84], [25, 90], [25, 97], [25, 110], [25, 112], [25, 116], [25, 127], [25, 130], [25, 132], [25, 141], [25, 142], [25, 150], [25, 153], [25, 154], [25, 156], [26, 27], [26, 35], [26, 41], [26, 44], [26, 45], [26, 51], [26, 61], [26, 73], [26, 75], [26, 87], [26, 100], [26, 101], [26, 102], [26, 107], [26, 112], [26, 113], [26, 115], [26, 119], [26, 121], [26, 123], [26, 128], [26, 132], [26, 137], [26, 139], [26, 141], [26, 145], [26, 152], [26, 153], [26, 156], [27, 32], [27, 34], [27, 40], [27, 43], [27, 44], [27, 48], [27, 52], [27, 55], [27, 59], [27, 64], [27, 68], [27, 72], [27, 73], [27, 75], [27, 79], [27, 80], [27, 84], [27, 88], [27, 91], [27, 98], [27, 107], [27, 112], [27, 113], [27, 115], [27, 118], [27, 124], [27, 128], [27, 129], [27, 130], [27, 133], [27, 145], [27, 159], [28, 39], [28, 49], [28, 58], [28, 69], [28, 88], [28, 96], [29, 52], [29, 67], [29, 92], [29, 100], [29, 112], [29, 118], [29, 121], [29, 129], [29, 143], [29, 156], [30, 36], [30, 38], [30, 43], [30, 49], [30, 50], [30, 64], [30, 67], [30, 70], [30, 74], [30, 80], [30, 81], [30, 83], [30, 89], [30, 90], [30, 91], [30, 92], [30, 96], [30, 97], [30, 103], [30, 106], [30, 114], [30, 123], [30, 138], [30, 140], [30, 148], [30, 149], [30, 152], [30, 153], [30, 156], [31, 35], [31, 77], [31, 83], [31, 88], [31, 105], [31, 114], [31, 118], [31, 130], [32, 35], [32, 52], [32, 69], [32, 97], [32, 102], [32, 118], [33, 39], [33, 44], [33, 49], [33, 61], [33, 72], [33, 88], [33, 100], [33, 114], [33, 129], [34, 52], [34, 67], [34, 74], [34, 100], [34, 102], [34, 112], [34, 128], [34, 132], [34, 137], [34, 138], [34, 139], [35, 38], [35, 45], [35, 46], [35, 48], [35, 52], [35, 58], [35, 67], [35, 73], [35, 80], [35, 83], [35, 88], [35, 90], [35, 92], [35, 96], [35, 103], [35, 104], [35, 114], [35, 115], [35, 139], [35, 141], [35, 145], [35, 154], [36, 97], [36, 103], [36, 104], [36, 112], [36, 121], [36, 133], [36, 136], [36, 149], [36, 154], [37, 44], [37, 52], [37, 63], [37, 67], [37, 69], [37, 72], [37, 83], [37, 84], [37, 88], [37, 115], [37, 133], [37, 149], [37, 153], [38, 44], [38, 65], [38, 72], [38, 73], [38, 96], [38, 102], [38, 103], [39, 44], [39, 49], [39, 54], [39, 57], [39, 58], [39, 59], [39, 61], [39, 64], [39, 65], [39, 74], [39, 75], [39, 77], [39, 82], [39, 83], [39, 84], [39, 85], [39, 91], [39, 92], [39, 97], [39, 98], [39, 101], [39, 103], [39, 107], [39, 110], [39, 113], [39, 116], [39, 121], [39, 125], [39, 128], [39, 135], [39, 136], [39, 138], [39, 142], [39, 154], [40, 58], [40, 88], [40, 91], [40, 97], [40, 112], [40, 128], [40, 138], [40, 141], [40, 152], [41, 69], [41, 77], [41, 102], [41, 112], [41, 129], [41, 133], [41, 154], [42, 61], [42, 69], [42, 73], [42, 80], [42, 88], [42, 96], [42, 97], [42, 100], [42, 103], [42, 118], [42, 132], [43, 72], [43, 77], [43, 112], [43, 114], [43, 119], [43, 129], [43, 136], [44, 46], [44, 48], [44, 61], [44, 63], [44, 68], [44, 69], [44, 78], [44, 88], [44, 89], [44, 102], [44, 115], [44, 120], [44, 123], [44, 135], [44, 136], [44, 147], [44, 150], [44, 156], [44, 157], [44, 159], [45, 49], [45, 58], [45, 84], [45, 88], [45, 102], [45, 103], [45, 115], [45, 128], [46, 52], [46, 97], [46, 102], [46, 115], [46, 121], [46, 139], [46, 149], [46, 152], [46, 154], [47, 97], [47, 118], [47, 121], [47, 129], [47, 139], [47, 149], [47, 152], [48, 52], [48, 61], [48, 65], [48, 72], [48, 74], [48, 114], [48, 127], [48, 149], [48, 152], [49, 53], [49, 57], [49, 61], [49, 63], [49, 64], [49, 68], [49, 69], [49, 70], [49, 73], [49, 77], [49, 84], [49, 102], [49, 105], [49, 108], [49, 118], [49, 119], [49, 127], [49, 129], [49, 130], [49, 133], [49, 136], [49, 139], [49, 140], [49, 149], [49, 152], [49, 156], [49, 157], [49, 159], [50, 77], [50, 80], [50, 97], [50, 100], [50, 118], [50, 137], [50, 139], [51, 65], [51, 67], [51, 77], [51, 112], [51, 127], [51, 128], [51, 133], [51, 137], [51, 141], [51, 149], [52, 54], [52, 62], [52, 63], [52, 65], [52, 79], [52, 86], [52, 91], [52, 94], [52, 104], [52, 106], [52, 108], [52, 112], [52, 113], [52, 119], [52, 121], [52, 129], [52, 130], [52, 132], [52, 135], [52, 137], [52, 142], [52, 143], [52, 146], [52, 148], [53, 58], [53, 88], [53, 97], [53, 119], [53, 133], [53, 137], [53, 139], [53, 149], [54, 67], [54, 69], [54, 84], [54, 105], [54, 115], [54, 129], [55, 61], [55, 69], [55, 127], [55, 141], [55, 156], [56, 63], [56, 65], [56, 69], [56, 77], [56, 80], [56, 92], [56, 119], [56, 128], [56, 138], [56, 152], [57, 88], [57, 104], [57, 105], [57, 127], [57, 128], [57, 129], [57, 149], [58, 63], [58, 69], [58, 70], [58, 77], [58, 94], [58, 109], [58, 111], [58, 127], [58, 130], [58, 152], [58, 156], [59, 65], [59, 67], [59, 102], [59, 103], [59, 128], [59, 130], [59, 136], [59, 143], [60, 67], [60, 69], [60, 83], [60, 91], [60, 100], [60, 103], [60, 112], [60, 114], [60, 143], [60, 152], [61, 62], [61, 66], [61, 70], [61, 73], [61, 76], [61, 80], [61, 92], [61, 98], [61, 103], [61, 105], [61, 109], [61, 118], [61, 125], [61, 128], [61, 130], [61, 132], [61, 136], [61, 143], [61, 149], [62, 83], [62, 92], [62, 105], [62, 118], [62, 127], [62, 130], [62, 137], [63, 69], [63, 73], [63, 76], [63, 77], [63, 84], [63, 92], [63, 97], [63, 98], [63, 99], [63, 105], [63, 115], [63, 118], [63, 131], [63, 143], [63, 151], [63, 156], [63, 157], [64, 69], [64, 74], [64, 121], [64, 129], [64, 154], [65, 68], [65, 72], [65, 78], [65, 94], [65, 100], [65, 114], [65, 124], [65, 125], [65, 130], [65, 133], [65, 135], [65, 137], [65, 138], [65, 152], [65, 153], [65, 154], [66, 72], [66, 83], [66, 103], [66, 133], [66, 136], [66, 137], [66, 149], [66, 152], [67, 69], [67, 82], [67, 83], [67, 84], [67, 88], [67, 89], [67, 100], [67, 102], [67, 106], [67, 107], [67, 111], [67, 114], [67, 115], [67, 118], [67, 119], [67, 121], [67, 123], [67, 130], [67, 132], [67, 134], [67, 135], [67, 137], [67, 138], [67, 144], [67, 146], [67, 147], [67, 148], [67, 153], [67, 154], [67, 159], [68, 69], [68, 80], [68, 129], [68, 148], [68, 149], [69, 70], [69, 72], [69, 73], [69, 74], [69, 75], [69, 76], [69, 88], [69, 91], [69, 92], [69, 93], [69, 96], [69, 101], [69, 111], [69, 112], [69, 120], [69, 124], [69, 125], [69, 129], [69, 130], [69, 133], [69, 138], [69, 142], [69, 143], [69, 144], [69, 148], [69, 149], [69, 156], [70, 100], [70, 102], [70, 115], [70, 119], [70, 130], [70, 136], [70, 138], [70, 152], [71, 102], [71, 112], [71, 152], [72, 73], [72, 75], [72, 84], [72, 86], [72, 97], [72, 100], [72, 105], [72, 108], [72, 112], [72, 117], [72, 122], [72, 123], [72, 124], [72, 127], [72, 133], [72, 135], [72, 144], [72, 145], [72, 147], [72, 148], [72, 152], [72, 153], [73, 85], [73, 93], [73, 96], [73, 97], [73, 102], [73, 103], [73, 108], [73, 115], [73, 119], [73, 125], [73, 132], [73, 139], [73, 146], [73, 151], [73, 152], [74, 88], [74, 91], [74, 95], [74, 100], [74, 105], [74, 115], [74, 116], [74, 119], [74, 124], [74, 137], [74, 142], [74, 143], [74, 146], [74, 152], [74, 153], [74, 157], [75, 83], [75, 103], [75, 119], [75, 127], [75, 128], [76, 84], [76, 96], [76, 105], [76, 119], [76, 129], [76, 136], [76, 139], [76, 141], [76, 152], [77, 87], [77, 88], [77, 93], [77, 94], [77, 103], [77, 104], [77, 108], [77, 114], [77, 117], [77, 127], [77, 129], [77, 138], [77, 140], [77, 142], [77, 147], [77, 154], [78, 80], [78, 91], [78, 105], [78, 112], [78, 115], [78, 118], [78, 136], [79, 96], [79, 103], [79, 104], [79, 114], [79, 115], [79, 119], [79, 127], [79, 133], [80, 88], [80, 92], [80, 102], [80, 104], [80, 110], [80, 115], [80, 117], [80, 122], [80, 128], [80, 132], [80, 138], [80, 145], [80, 147], [80, 150], [80, 155], [81, 84], [81, 91], [81, 118], [81, 119], [81, 137], [81, 153], [81, 156], [82, 91], [82, 96], [82, 100], [82, 119], [82, 129], [82, 132], [82, 137], [82, 138], [82, 139], [82, 148], [82, 153], [82, 154], [83, 96], [83, 98], [83, 103], [83, 105], [83, 108], [83, 116], [83, 118], [83, 123], [83, 125], [83, 128], [83, 132], [83, 141], [83, 148], [83, 149], [83, 153], [83, 154], [84, 87], [84, 110], [84, 115], [84, 140], [84, 141], [84, 142], [84, 156], [84, 158], [85, 129], [85, 133], [85, 139], [85, 141], [85, 152], [86, 105], [86, 118], [86, 137], [86, 149], [87, 91], [87, 100], [87, 103], [87, 112], [87, 127], [87, 128], [87, 132], [87, 138], [88, 92], [88, 97], [88, 105], [88, 109], [88, 115], [88, 120], [88, 128], [88, 129], [88, 149], [88, 153], [88, 155], [88, 156], [89, 92], [89, 102], [89, 114], [89, 121], [89, 128], [89, 130], [89, 133], [89, 149], [90, 112], [90, 127], [90, 129], [90, 130], [90, 137], [91, 94], [91, 100], [91, 101], [91, 105], [91, 109], [91, 110], [91, 115], [91, 120], [91, 121], [91, 123], [91, 126], [91, 130], [91, 132], [91, 133], [91, 139], [91, 143], [91, 146], [91, 159], [92, 98], [92, 104], [92, 109], [92, 113], [92, 116], [92, 125], [92, 126], [92, 128], [92, 131], [92, 138], [92, 141], [92, 142], [92, 146], [92, 154], [92, 156], [92, 158], [93, 96], [93, 105], [93, 119], [93, 154], [94, 103], [94, 115], [94, 118], [94, 129], [94, 137], [94, 153], [94, 156], [95, 102], [95, 118], [95, 138], [95, 139], [95, 141], [95, 148], [95, 149], [96, 97], [96, 100], [96, 105], [96, 110], [96, 112], [96, 118], [96, 122], [96, 132], [96, 138], [96, 147], [96, 155], [96, 159], [97, 102], [97, 104], [97, 114], [97, 119], [97, 126], [97, 129], [97, 136], [97, 138], [97, 140], [97, 141], [97, 146], [97, 150], [97, 155], [97, 156], [98, 112], [99, 102], [99, 104], [99, 115], [99, 129], [99, 141], [99, 143], [99, 148], [99, 156], [100, 109], [100, 117], [100, 125], [100, 126], [100, 128], [100, 132], [100, 134], [100, 137], [100, 138], [100, 140], [100, 143], [100, 146], [100, 147], [100, 150], [100, 155], [101, 104], [101, 105], [101, 128], [101, 130], [101, 143], [102, 105], [102, 109], [102, 121], [102, 126], [102, 127], [102, 131], [102, 137], [102, 139], [102, 143], [102, 159], [103, 104], [103, 106], [103, 127], [103, 135], [103, 136], [103, 139], [103, 148], [103, 151], [103, 152], [103, 153], [103, 158], [104, 108], [104, 111], [104, 112], [104, 114], [104, 115], [104, 126], [104, 139], [104, 148], [105, 115], [105, 121], [105, 126], [105, 129], [105, 133], [105, 135], [105, 136], [105, 139], [105, 145], [105, 146], [105, 148], [105, 153], [105, 156], [105, 157], [105, 159], [106, 112], [106, 139], [106, 153], [107, 115], [107, 132], [107, 149], [107, 152], [107, 156], [108, 115], [108, 118], [108, 143], [108, 156], [109, 128], [109, 132], [109, 156], [110, 112], [110, 118], [110, 129], [110, 132], [110, 136], [110, 153], [111, 118], [111, 128], [111, 130], [111, 143], [112, 113], [112, 119], [112, 130], [112, 132], [112, 133], [112, 134], [112, 141], [112, 151], [112, 156], [113, 115], [113, 137], [113, 138], [114, 121], [114, 123], [114, 129], [114, 130], [114, 132], [114, 145], [114, 149], [114, 151], [114, 158], [115, 118], [115, 120], [115, 124], [115, 125], [115, 126], [115, 127], [115, 133], [115, 135], [115, 137], [115, 146], [115, 147], [115, 150], [116, 118], [116, 153], [116, 156], [117, 128], [117, 138], [117, 139], [117, 141], [118, 119], [118, 120], [118, 123], [118, 131], [118, 136], [118, 144], [118, 149], [119, 130], [119, 133], [119, 134], [119, 139], [119, 140], [120, 121], [120, 127], [120, 136], [120, 139], [120, 154], [121, 129], [121, 130], [121, 135], [121, 137], [121, 138], [121, 141], [121, 145], [121, 147], [121, 148], [121, 149], [121, 154], [122, 130], [122, 132], [122, 143], [122, 149], [122, 152], [123, 127], [123, 130], [123, 137], [124, 141], [124, 149], [124, 154], [125, 127], [125, 130], [125, 143], [125, 152], [126, 127], [126, 138], [127, 130], [127, 133], [127, 143], [127, 145], [127, 150], [127, 151], [127, 155], [127, 159], [128, 130], [128, 132], [128, 140], [128, 141], [128, 147], [128, 153], [128, 155], [129, 130], [129, 131], [129, 135], [129, 137], [129, 146], [129, 149], [130, 131], [130, 135], [130, 141], [130, 147], [130, 148], [130, 149], [130, 158], [131, 133], [131, 136], [131, 138], [131, 153], [132, 139], [132, 140], [132, 155], [132, 157], [133, 136], [133, 137], [133, 143], [133, 154], [133, 157], [134, 136], [135, 139], [135, 141], [135, 143], [135, 153], [136, 150], [136, 151], [136, 154], [137, 139], [137, 145], [137, 149], [137, 152], [137, 154], [138, 141], [138, 149], [138, 153], [139, 148], [139, 152], [139, 153], [139, 159], [140, 143], [141, 143], [141, 148], [141, 149], [141, 152], [141, 153], [141, 156], [142, 149], [143, 151], [143, 156], [145, 154], [148, 153], [148, 159], [149, 150], [149, 152], [149, 154], [149, 155], [152, 155], [153, 156], [154, 158]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s5/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l1-s6/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l1-s6/environment/instance.json b/tasks/construct-rg-graph-color-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8e62f4c9285da31e0b4e270ecb4c990c21ca0ff --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 1], [1, 4], [2, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s6/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..294f2b7e8de07056bdc407484d4857e2e7a98026 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 1, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s6/tests/check.py b/tasks/construct-rg-graph-color-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l1-s6/tests/instance.json b/tasks/construct-rg-graph-color-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8e62f4c9285da31e0b4e270ecb4c990c21ca0ff --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 1], [1, 4], [2, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s6/tests/run.py b/tasks/construct-rg-graph-color-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l1-s6/tests/test.sh b/tasks/construct-rg-graph-color-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l1-s8/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l1-s8/environment/instance.json b/tasks/construct-rg-graph-color-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..207c92908aceef35b854c0032ae6f6ce68935918 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 2], [0, 4], [1, 2], [1, 5], [2, 3], [3, 4]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s8/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb2dac66b799653557cdebf68849d53f1013e407 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 2, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s8/tests/check.py b/tasks/construct-rg-graph-color-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l1-s8/tests/instance.json b/tasks/construct-rg-graph-color-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..207c92908aceef35b854c0032ae6f6ce68935918 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 2], [0, 4], [1, 2], [1, 5], [2, 3], [3, 4]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s8/tests/run.py b/tasks/construct-rg-graph-color-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l1-s8/tests/test.sh b/tasks/construct-rg-graph-color-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l5-s7/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l5-s7/environment/instance.json b/tasks/construct-rg-graph-color-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e2593a7f766af4e46b4d7469a5f24fda8d34d2c --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 13], [0, 21], [1, 9], [1, 12], [1, 20], [1, 21], [1, 23], [2, 7], [2, 19], [3, 13], [3, 18], [4, 6], [4, 17], [4, 21], [5, 20], [5, 21], [5, 23], [6, 14], [6, 21], [6, 24], [7, 10], [7, 11], [7, 13], [7, 17], [8, 10], [8, 21], [8, 23], [10, 11], [10, 15], [10, 20], [11, 21], [11, 23], [12, 16], [12, 18], [12, 22], [13, 24], [14, 15], [14, 16], [15, 17], [15, 24], [16, 24], [17, 20], [18, 19], [21, 22]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s7/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..66abf548975687e08713b67ba423dbd37d61eae0 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 1, 1, 2, 2, 1, 2, 3, 1, 2, 3, 1, 2, 3, 3, 3, 2, 2, 3, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s7/tests/check.py b/tasks/construct-rg-graph-color-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l5-s7/tests/instance.json b/tasks/construct-rg-graph-color-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e2593a7f766af4e46b4d7469a5f24fda8d34d2c --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 13], [0, 21], [1, 9], [1, 12], [1, 20], [1, 21], [1, 23], [2, 7], [2, 19], [3, 13], [3, 18], [4, 6], [4, 17], [4, 21], [5, 20], [5, 21], [5, 23], [6, 14], [6, 21], [6, 24], [7, 10], [7, 11], [7, 13], [7, 17], [8, 10], [8, 21], [8, 23], [10, 11], [10, 15], [10, 20], [11, 21], [11, 23], [12, 16], [12, 18], [12, 22], [13, 24], [14, 15], [14, 16], [15, 17], [15, 24], [16, 24], [17, 20], [18, 19], [21, 22]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s7/tests/run.py b/tasks/construct-rg-graph-color-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l5-s7/tests/test.sh b/tasks/construct-rg-graph-color-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l5-s9/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l5-s9/environment/instance.json b/tasks/construct-rg-graph-color-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddd92c54b56bee89231a30abf6be3a39b14d9428 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 8], [0, 11], [0, 18], [0, 20], [1, 7], [1, 23], [2, 5], [2, 12], [2, 18], [3, 5], [4, 21], [5, 6], [5, 10], [5, 21], [5, 24], [6, 14], [6, 19], [6, 21], [7, 9], [7, 10], [7, 16], [8, 10], [8, 23], [9, 18], [9, 21], [10, 11], [10, 14], [10, 17], [10, 20], [11, 23], [11, 24], [12, 14], [12, 16], [12, 19], [12, 21], [12, 23], [13, 14], [13, 17], [13, 21], [14, 15], [15, 23], [16, 17], [16, 18], [18, 23], [19, 20], [19, 22], [20, 21]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s9/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b844c8ab287a4fc9ee830dd7c7d56619017cf268 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 3, 1, 1, 2, 2, 3, 2, 3, 1, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s9/tests/check.py b/tasks/construct-rg-graph-color-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l5-s9/tests/instance.json b/tasks/construct-rg-graph-color-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddd92c54b56bee89231a30abf6be3a39b14d9428 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 8], [0, 11], [0, 18], [0, 20], [1, 7], [1, 23], [2, 5], [2, 12], [2, 18], [3, 5], [4, 21], [5, 6], [5, 10], [5, 21], [5, 24], [6, 14], [6, 19], [6, 21], [7, 9], [7, 10], [7, 16], [8, 10], [8, 23], [9, 18], [9, 21], [10, 11], [10, 14], [10, 17], [10, 20], [11, 23], [11, 24], [12, 14], [12, 16], [12, 19], [12, 21], [12, 23], [13, 14], [13, 17], [13, 21], [14, 15], [15, 23], [16, 17], [16, 18], [18, 23], [19, 20], [19, 22], [20, 21]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s9/tests/run.py b/tasks/construct-rg-graph-color-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l5-s9/tests/test.sh b/tasks/construct-rg-graph-color-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e1410f15758e8b3c867fa46e58f6c850828fcdb --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "3*sin(x - 3)*cos(x - 3)**2", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eee4fab269f0993f1e6baaf45408bf33e2591889 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-cos(x - 3)**3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e1410f15758e8b3c867fa46e58f6c850828fcdb --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "3*sin(x - 3)*cos(x - 3)**2", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s3/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65a989569584707dbc443ebb983d7ce1f4adb5cb --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-7*sin(7*x + 8)**3*cos(7*x + 8)", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8d9d19c4ae3300648f9da0bc1eb7eaf8eb4abc17 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-sin(7*x + 8)**4/4 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65a989569584707dbc443ebb983d7ce1f4adb5cb --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-7*sin(7*x + 8)**3*cos(7*x + 8)", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s4/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l1-s0/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-simple-integration-l1-s0/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e91e6755794473257ad67d886ca8f91e9d97b73f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "9*x/4 + 7/9", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s0/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..35e0a5a42a25be29a827559c3f0561f268603885 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "9*x**2/8 + 7*x/9 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s0/tests/check.py b/tasks/construct-rg-simple-integration-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l1-s0/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e91e6755794473257ad67d886ca8f91e9d97b73f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "9*x/4 + 7/9", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s0/tests/run.py b/tasks/construct-rg-simple-integration-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-simple-integration-l1-s0/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l5-s1/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-simple-integration-l5-s1/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3287d472acc26766c5acfd6042b3c8fe545c4a7a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "15*X**9 + 15*X**6 + 57*X**2/2 + 4/X**5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s1/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..31c2ffaf3b1ccb42ce23e4510d5144eb0b8ac7c3 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "3*X**10/2 + 15*X**7/7 + 19*X**3/2 - 1/X**4 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s1/tests/check.py b/tasks/construct-rg-simple-integration-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l5-s1/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3287d472acc26766c5acfd6042b3c8fe545c4a7a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "15*X**9 + 15*X**6 + 57*X**2/2 + 4/X**5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s1/tests/run.py b/tasks/construct-rg-simple-integration-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-simple-integration-l5-s1/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l5-s6/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-simple-integration-l5-s6/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9f601b2612e0ca9e61d0d87cc06a7a56f81ea0b0 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-8*X + 3/(2*X**2) + 2/X**4 - 50/X**6", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s6/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..335500d0811280f5c62ff7ab65f759babd196fe4 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-4*X**2 + 5 - 3/(2*X) - 2/(3*X**3) + 10/X**5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s6/tests/check.py b/tasks/construct-rg-simple-integration-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l5-s6/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9f601b2612e0ca9e61d0d87cc06a7a56f81ea0b0 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-8*X + 3/(2*X**2) + 2/X**4 - 50/X**6", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s6/tests/run.py b/tasks/construct-rg-simple-integration-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-simple-integration-l5-s6/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l4-s6/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l4-s6/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..235f42050584dd5c3a248e0bc2aaa9e4c31b9d89 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "2*cos(x - sin(4))", "max_ops": 36, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s6/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..835cc2affc8513dd6ce4324a4eaba0f70ea68e3f --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"F": "2*sin(x - sin(4))"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s6/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l4-s6/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..235f42050584dd5c3a248e0bc2aaa9e4c31b9d89 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "2*cos(x - sin(4))", "max_ops": 36, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s6/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l4-s6/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l4-s8/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l4-s8/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..562cdda52ab75a1fef6d4b3d91772a560d5acc8b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-2*x*exp(x)*sin(2*x) + x*exp(x)*cos(2*x) + exp(x)*cos(2*x)", "max_ops": 40, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s8/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..176e9d2cc014c2e7a1c10362ce45de96bdf4818b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"F": "x*exp(x)*cos(2*x)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s8/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l4-s8/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..562cdda52ab75a1fef6d4b3d91772a560d5acc8b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-2*x*exp(x)*sin(2*x) + x*exp(x)*cos(2*x) + exp(x)*cos(2*x)", "max_ops": 40, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s8/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l4-s8/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..462022d24e5019516177d44ac08e697ab91a5e0f --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [6246, -5421, 5973, -1911, -1944, 6735, 7326, -1305, 408, -444], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4686ea4c0c3b6ca98c8f1f17d2c0777e84e41576 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [46, 53, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..462022d24e5019516177d44ac08e697ab91a5e0f --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [6246, -5421, 5973, -1911, -1944, 6735, 7326, -1305, 408, -444], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l5-s2/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..45b60a66c6550c086427f97c9b68871edaac971a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"mod": 722404, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f4ae6d4085e8487c0fa589dd4c0d29895739180b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"L": 19, "R": 37726} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..45b60a66c6550c086427f97c9b68871edaac971a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"mod": 722404, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6f83bebe3d9573f928b3ef1547a20b830564e607 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"mod": 757272, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7f144ab2c6ce700d7e4626826004f64b4fdddd54 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"L": 22, "R": 39140} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6f83bebe3d9573f928b3ef1547a20b830564e607 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"mod": 757272, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l2-s6/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l2-s6/environment/instance.json b/tasks/construct-rlve-crt-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..853e86dafa1f12ce13d4d4eaa6ac03dc6e56a178 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [58, 87, 130], "residues": [37, 66, 23], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s6/solution/solve.sh b/tasks/construct-rlve-crt-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..119d6c9e9719399890e50fca932dc3a6b0f386e5 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 153} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s6/tests/check.py b/tasks/construct-rlve-crt-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l2-s6/tests/instance.json b/tasks/construct-rlve-crt-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..853e86dafa1f12ce13d4d4eaa6ac03dc6e56a178 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [58, 87, 130], "residues": [37, 66, 23], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s6/tests/run.py b/tasks/construct-rlve-crt-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l2-s6/tests/test.sh b/tasks/construct-rlve-crt-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l2-s8/environment/instance.json b/tasks/construct-rlve-crt-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1fa6a0aeabf4d6883711d91daf58e3e7d5a6e4d2 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [28, 19, 23], "residues": [26, 6, 13], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s7/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l6-s7/environment/instance.json b/tasks/construct-rlve-crt-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6a756a2e78486ae2e6a48c38d0db50373c63b43 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [568789213172665, 513192589417695, 601101896245989, 82933842106292, 66436829116139, 517199215462209, 400071579241132, 44681588137481], "residues": [110614837867648, 166211461622618, 78302154794324, 15933314189977, 15035759878923, 162204835578104, 279332471799181, 9180228978098], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s7/solution/solve.sh b/tasks/construct-rlve-crt-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..96c14d1058a63029714a2d187d6267918881534f --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 679404051040313} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s7/tests/check.py b/tasks/construct-rlve-crt-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l6-s7/tests/instance.json b/tasks/construct-rlve-crt-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6a756a2e78486ae2e6a48c38d0db50373c63b43 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [568789213172665, 513192589417695, 601101896245989, 82933842106292, 66436829116139, 517199215462209, 400071579241132, 44681588137481], "residues": [110614837867648, 166211461622618, 78302154794324, 15933314189977, 15035759878923, 162204835578104, 279332471799181, 9180228978098], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s7/tests/run.py b/tasks/construct-rlve-crt-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l6-s7/tests/test.sh b/tasks/construct-rlve-crt-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l6-s9/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l6-s9/environment/instance.json b/tasks/construct-rlve-crt-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6ff1421f483743fd69fe4bd1eeb1e5f7464c76c --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [54294713611346, 468591800308393, 675262069458179, 585821668766769, 101111323131242, 103491426206435, 832932486471626, 41041700362452], "residues": [50825584869996, 36652115646092, 298573646804699, 388014047496109, 63833808081700, 42412880404963, 140903229791252, 29876607926482], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s9/solution/solve.sh b/tasks/construct-rlve-crt-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..78d47a8bd66bb537cc5d1593c8ab77748dbd802c --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 973835716262878} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s9/tests/check.py b/tasks/construct-rlve-crt-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l6-s9/tests/instance.json b/tasks/construct-rlve-crt-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6ff1421f483743fd69fe4bd1eeb1e5f7464c76c --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [54294713611346, 468591800308393, 675262069458179, 585821668766769, 101111323131242, 103491426206435, 832932486471626, 41041700362452], "residues": [50825584869996, 36652115646092, 298573646804699, 388014047496109, 63833808081700, 42412880404963, 140903229791252, 29876607926482], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s9/tests/run.py b/tasks/construct-rlve-crt-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l6-s9/tests/test.sh b/tasks/construct-rlve-crt-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..791fa78f328cb3a834d414ff96d0062f9d975c74 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": [15, 5, 17, 18, 19, 12, 4, 7, 8, 6], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b3406bfa5ae2b53fe3f0c9c40d9519d11cc05267 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [17, 6, 18, 19, 4, 15, 5, 8, 12, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..791fa78f328cb3a834d414ff96d0062f9d975c74 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": [15, 5, 17, 18, 19, 12, 4, 7, 8, 6], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e2afd4fc099535a390f8ccd1fd546b4a2c2d485 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [8, 7, 15, 16, 10, 6, 14, 13, 2, 1], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d0b9225ef48c08cf35b20079ce660f8e4a35c689 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [10, 8, 16, 1, 13, 7, 15, 14, 6, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e2afd4fc099535a390f8ccd1fd546b4a2c2d485 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [8, 7, 15, 16, 10, 6, 14, 13, 2, 1], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..822eff89c042f805f84834cfcb63af34d0080bd0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 3], [2, 4], [2, 6], [2, 7], [3, 6], [3, 7], [4, 5], [4, 7], [5, 6], [6, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ae92d823f998ca7c08bd821c14367a18385d93ee --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [1, 1, 1, 1, 2, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..822eff89c042f805f84834cfcb63af34d0080bd0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 3], [2, 4], [2, 6], [2, 7], [3, 6], [3, 7], [4, 5], [4, 7], [5, 6], [6, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l2-s1/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..181871ce00338d98a26de87a25babc38d31a894d --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 2], [0, 4], [0, 5], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 15], [0, 17], [0, 18], [0, 20], [0, 22], [0, 23], [0, 26], [0, 28], [0, 29], [0, 31], [0, 34], [0, 36], [0, 37], [0, 38], [1, 3], [1, 5], [1, 6], [1, 8], [1, 9], [1, 12], [1, 14], [1, 16], [1, 19], [1, 21], [1, 22], [1, 29], [1, 32], [1, 34], [1, 36], [2, 4], [2, 5], [2, 6], [2, 16], [2, 20], [2, 25], [2, 28], [2, 31], [2, 32], [2, 35], [2, 37], [2, 38], [2, 39], [3, 6], [3, 7], [3, 10], [3, 12], [3, 14], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 23], [3, 25], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 35], [3, 36], [3, 38], [4, 7], [4, 8], [4, 9], [4, 13], [4, 17], [4, 19], [4, 20], [4, 24], [4, 27], [4, 28], [4, 31], [4, 32], [4, 33], [4, 35], [4, 36], [5, 9], [5, 18], [5, 22], [5, 26], [5, 27], [5, 29], [5, 30], [5, 33], [5, 34], [5, 36], [5, 38], [5, 39], [6, 7], [6, 13], [6, 15], [6, 22], [6, 27], [6, 28], [6, 33], [6, 37], [6, 39], [7, 8], [7, 9], [7, 12], [7, 13], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 27], [7, 29], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 36], [8, 10], [8, 12], [8, 13], [8, 14], [8, 16], [8, 19], [8, 20], [8, 21], [8, 23], [8, 25], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 36], [9, 11], [9, 15], [9, 17], [9, 19], [9, 20], [9, 23], [9, 25], [9, 27], [9, 31], [9, 33], [9, 34], [9, 35], [9, 38], [10, 12], [10, 13], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 23], [10, 26], [10, 28], [10, 29], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [11, 17], [11, 18], [11, 19], [11, 21], [11, 26], [11, 29], [11, 30], [11, 32], [11, 34], [11, 36], [11, 38], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 24], [12, 25], [12, 26], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 35], [12, 37], [13, 15], [13, 16], [13, 17], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 29], [13, 38], [14, 21], [14, 22], [14, 26], [14, 31], [14, 32], [14, 34], [14, 35], [14, 36], [14, 37], [14, 39], [15, 17], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 31], [15, 33], [15, 34], [15, 36], [15, 37], [15, 38], [16, 17], [16, 18], [16, 19], [16, 21], [16, 22], [16, 24], [16, 25], [16, 29], [16, 30], [16, 31], [16, 32], [16, 34], [16, 36], [16, 37], [16, 38], [17, 20], [17, 21], [17, 23], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 34], [17, 36], [17, 38], [18, 20], [18, 22], [18, 28], [18, 29], [18, 31], [18, 32], [18, 36], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 28], [19, 29], [19, 32], [19, 36], [20, 22], [20, 24], [20, 27], [20, 30], [20, 32], [20, 34], [20, 35], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 34], [21, 35], [21, 36], [22, 24], [22, 27], [22, 29], [22, 30], [22, 32], [22, 33], [22, 36], [22, 37], [23, 25], [23, 26], [23, 27], [23, 29], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [24, 26], [24, 30], [24, 32], [24, 34], [24, 35], [24, 38], [25, 28], [25, 29], [25, 31], [25, 33], [25, 34], [25, 35], [25, 38], [25, 39], [26, 30], [27, 28], [27, 31], [27, 34], [27, 36], [27, 38], [27, 39], [28, 32], [28, 33], [28, 34], [28, 35], [28, 37], [28, 39], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 37], [30, 36], [31, 33], [31, 36], [31, 37], [31, 39], [32, 34], [32, 36], [33, 34], [33, 38], [34, 35], [34, 38], [35, 36], [35, 37], [35, 38], [36, 37], [36, 38], [37, 38]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..01361c286367e6bbf7d9253eb1fc8c9de6e17b2a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [1, 2, 1, 2, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 2, 1, 2, 1, 1, 2, 1, 2, 2, 1, 2, 1, 2, 1, 1, 2, 2, 1, 2, 1, 1, 2, 2, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..181871ce00338d98a26de87a25babc38d31a894d --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 2], [0, 4], [0, 5], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 15], [0, 17], [0, 18], [0, 20], [0, 22], [0, 23], [0, 26], [0, 28], [0, 29], [0, 31], [0, 34], [0, 36], [0, 37], [0, 38], [1, 3], [1, 5], [1, 6], [1, 8], [1, 9], [1, 12], [1, 14], [1, 16], [1, 19], [1, 21], [1, 22], [1, 29], [1, 32], [1, 34], [1, 36], [2, 4], [2, 5], [2, 6], [2, 16], [2, 20], [2, 25], [2, 28], [2, 31], [2, 32], [2, 35], [2, 37], [2, 38], [2, 39], [3, 6], [3, 7], [3, 10], [3, 12], [3, 14], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 23], [3, 25], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 35], [3, 36], [3, 38], [4, 7], [4, 8], [4, 9], [4, 13], [4, 17], [4, 19], [4, 20], [4, 24], [4, 27], [4, 28], [4, 31], [4, 32], [4, 33], [4, 35], [4, 36], [5, 9], [5, 18], [5, 22], [5, 26], [5, 27], [5, 29], [5, 30], [5, 33], [5, 34], [5, 36], [5, 38], [5, 39], [6, 7], [6, 13], [6, 15], [6, 22], [6, 27], [6, 28], [6, 33], [6, 37], [6, 39], [7, 8], [7, 9], [7, 12], [7, 13], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 27], [7, 29], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 36], [8, 10], [8, 12], [8, 13], [8, 14], [8, 16], [8, 19], [8, 20], [8, 21], [8, 23], [8, 25], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 36], [9, 11], [9, 15], [9, 17], [9, 19], [9, 20], [9, 23], [9, 25], [9, 27], [9, 31], [9, 33], [9, 34], [9, 35], [9, 38], [10, 12], [10, 13], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 23], [10, 26], [10, 28], [10, 29], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [11, 17], [11, 18], [11, 19], [11, 21], [11, 26], [11, 29], [11, 30], [11, 32], [11, 34], [11, 36], [11, 38], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 24], [12, 25], [12, 26], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 35], [12, 37], [13, 15], [13, 16], [13, 17], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 29], [13, 38], [14, 21], [14, 22], [14, 26], [14, 31], [14, 32], [14, 34], [14, 35], [14, 36], [14, 37], [14, 39], [15, 17], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 31], [15, 33], [15, 34], [15, 36], [15, 37], [15, 38], [16, 17], [16, 18], [16, 19], [16, 21], [16, 22], [16, 24], [16, 25], [16, 29], [16, 30], [16, 31], [16, 32], [16, 34], [16, 36], [16, 37], [16, 38], [17, 20], [17, 21], [17, 23], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 34], [17, 36], [17, 38], [18, 20], [18, 22], [18, 28], [18, 29], [18, 31], [18, 32], [18, 36], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 28], [19, 29], [19, 32], [19, 36], [20, 22], [20, 24], [20, 27], [20, 30], [20, 32], [20, 34], [20, 35], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 34], [21, 35], [21, 36], [22, 24], [22, 27], [22, 29], [22, 30], [22, 32], [22, 33], [22, 36], [22, 37], [23, 25], [23, 26], [23, 27], [23, 29], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [24, 26], [24, 30], [24, 32], [24, 34], [24, 35], [24, 38], [25, 28], [25, 29], [25, 31], [25, 33], [25, 34], [25, 35], [25, 38], [25, 39], [26, 30], [27, 28], [27, 31], [27, 34], [27, 36], [27, 38], [27, 39], [28, 32], [28, 33], [28, 34], [28, 35], [28, 37], [28, 39], [29, 30], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 37], [30, 36], [31, 33], [31, 36], [31, 37], [31, 39], [32, 34], [32, 36], [33, 34], [33, 38], [34, 35], [34, 38], [35, 36], [35, 37], [35, 38], [36, 37], [36, 38], [37, 38]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l6-s0/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d695731f1f94e8c83b4e3446dc8d04669e1520b0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 4], [0, 6], [0, 7], [0, 9], [0, 10], [0, 11], [0, 13], [0, 14], [0, 15], [0, 17], [0, 18], [0, 19], [0, 21], [0, 25], [0, 26], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 35], [0, 36], [1, 9], [1, 12], [1, 17], [1, 21], [1, 23], [1, 25], [1, 31], [1, 34], [2, 6], [2, 7], [2, 8], [2, 16], [2, 17], [2, 18], [2, 19], [2, 24], [2, 25], [2, 27], [2, 28], [2, 31], [2, 32], [2, 33], [2, 39], [3, 6], [3, 7], [3, 9], [3, 10], [3, 17], [3, 19], [3, 21], [3, 22], [3, 32], [3, 38], [4, 9], [4, 11], [4, 15], [4, 17], [4, 19], [4, 21], [4, 34], [4, 36], [4, 37], [5, 10], [5, 12], [5, 16], [5, 22], [5, 24], [5, 28], [5, 33], [5, 35], [5, 38], [5, 39], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 21], [6, 22], [6, 23], [6, 25], [6, 26], [6, 27], [6, 29], [6, 30], [6, 33], [6, 34], [6, 35], [6, 38], [6, 39], [7, 8], [7, 12], [7, 19], [7, 20], [7, 24], [7, 28], [7, 31], [7, 32], [7, 36], [7, 37], [8, 12], [8, 16], [8, 22], [8, 24], [8, 28], [8, 29], [8, 31], [8, 32], [8, 34], [9, 10], [9, 11], [9, 13], [9, 15], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 29], [9, 30], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [10, 11], [10, 12], [10, 13], [10, 14], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 25], [10, 26], [10, 29], [10, 30], [10, 32], [10, 34], [10, 35], [10, 36], [10, 38], [11, 12], [11, 13], [11, 15], [11, 17], [11, 19], [11, 20], [11, 21], [11, 23], [11, 25], [11, 26], [11, 30], [11, 33], [11, 34], [11, 36], [12, 15], [12, 16], [12, 24], [12, 29], [12, 31], [12, 32], [12, 35], [12, 38], [12, 39], [13, 15], [13, 17], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 28], [13, 30], [13, 32], [13, 34], [13, 35], [13, 36], [13, 38], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 30], [14, 31], [14, 33], [14, 36], [15, 18], [15, 23], [15, 29], [15, 30], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [16, 17], [16, 22], [16, 23], [16, 26], [16, 27], [16, 32], [17, 18], [17, 19], [17, 21], [17, 22], [17, 24], [17, 25], [17, 28], [17, 29], [17, 30], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [18, 21], [18, 23], [18, 25], [18, 28], [18, 30], [18, 31], [18, 34], [18, 36], [18, 39], [19, 20], [19, 21], [19, 22], [19, 25], [19, 26], [19, 31], [19, 34], [19, 35], [19, 38], [20, 21], [20, 30], [20, 38], [20, 39], [21, 22], [21, 25], [21, 26], [21, 29], [21, 30], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [22, 23], [22, 25], [22, 26], [22, 30], [22, 32], [22, 34], [22, 36], [22, 38], [23, 28], [23, 34], [23, 36], [23, 38], [23, 39], [24, 25], [24, 28], [24, 29], [24, 32], [24, 33], [24, 38], [25, 28], [25, 30], [25, 34], [25, 35], [25, 38], [25, 39], [26, 29], [26, 30], [26, 34], [26, 36], [26, 37], [26, 38], [27, 28], [27, 31], [27, 32], [27, 34], [27, 36], [27, 39], [28, 30], [28, 31], [28, 32], [28, 38], [29, 32], [29, 39], [30, 34], [30, 36], [31, 32], [31, 35], [31, 39], [32, 33], [32, 35], [32, 37], [33, 35], [34, 35], [35, 36], [36, 37], [36, 38]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..81b9a700f3c04acb062933d4d67d9754f17f8994 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [2, 2, 1, 2, 2, 1, 2, 1, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d695731f1f94e8c83b4e3446dc8d04669e1520b0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 4], [0, 6], [0, 7], [0, 9], [0, 10], [0, 11], [0, 13], [0, 14], [0, 15], [0, 17], [0, 18], [0, 19], [0, 21], [0, 25], [0, 26], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 35], [0, 36], [1, 9], [1, 12], [1, 17], [1, 21], [1, 23], [1, 25], [1, 31], [1, 34], [2, 6], [2, 7], [2, 8], [2, 16], [2, 17], [2, 18], [2, 19], [2, 24], [2, 25], [2, 27], [2, 28], [2, 31], [2, 32], [2, 33], [2, 39], [3, 6], [3, 7], [3, 9], [3, 10], [3, 17], [3, 19], [3, 21], [3, 22], [3, 32], [3, 38], [4, 9], [4, 11], [4, 15], [4, 17], [4, 19], [4, 21], [4, 34], [4, 36], [4, 37], [5, 10], [5, 12], [5, 16], [5, 22], [5, 24], [5, 28], [5, 33], [5, 35], [5, 38], [5, 39], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 21], [6, 22], [6, 23], [6, 25], [6, 26], [6, 27], [6, 29], [6, 30], [6, 33], [6, 34], [6, 35], [6, 38], [6, 39], [7, 8], [7, 12], [7, 19], [7, 20], [7, 24], [7, 28], [7, 31], [7, 32], [7, 36], [7, 37], [8, 12], [8, 16], [8, 22], [8, 24], [8, 28], [8, 29], [8, 31], [8, 32], [8, 34], [9, 10], [9, 11], [9, 13], [9, 15], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 29], [9, 30], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [10, 11], [10, 12], [10, 13], [10, 14], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 25], [10, 26], [10, 29], [10, 30], [10, 32], [10, 34], [10, 35], [10, 36], [10, 38], [11, 12], [11, 13], [11, 15], [11, 17], [11, 19], [11, 20], [11, 21], [11, 23], [11, 25], [11, 26], [11, 30], [11, 33], [11, 34], [11, 36], [12, 15], [12, 16], [12, 24], [12, 29], [12, 31], [12, 32], [12, 35], [12, 38], [12, 39], [13, 15], [13, 17], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 28], [13, 30], [13, 32], [13, 34], [13, 35], [13, 36], [13, 38], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 30], [14, 31], [14, 33], [14, 36], [15, 18], [15, 23], [15, 29], [15, 30], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [16, 17], [16, 22], [16, 23], [16, 26], [16, 27], [16, 32], [17, 18], [17, 19], [17, 21], [17, 22], [17, 24], [17, 25], [17, 28], [17, 29], [17, 30], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [18, 21], [18, 23], [18, 25], [18, 28], [18, 30], [18, 31], [18, 34], [18, 36], [18, 39], [19, 20], [19, 21], [19, 22], [19, 25], [19, 26], [19, 31], [19, 34], [19, 35], [19, 38], [20, 21], [20, 30], [20, 38], [20, 39], [21, 22], [21, 25], [21, 26], [21, 29], [21, 30], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [22, 23], [22, 25], [22, 26], [22, 30], [22, 32], [22, 34], [22, 36], [22, 38], [23, 28], [23, 34], [23, 36], [23, 38], [23, 39], [24, 25], [24, 28], [24, 29], [24, 32], [24, 33], [24, 38], [25, 28], [25, 30], [25, 34], [25, 35], [25, 38], [25, 39], [26, 29], [26, 30], [26, 34], [26, 36], [26, 37], [26, 38], [27, 28], [27, 31], [27, 32], [27, 34], [27, 36], [27, 39], [28, 30], [28, 31], [28, 32], [28, 38], [29, 32], [29, 39], [30, 34], [30, 36], [31, 32], [31, 35], [31, 39], [32, 33], [32, 35], [32, 37], [33, 35], [34, 35], [35, 36], [36, 37], [36, 38]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l6-s7/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8fb04babcd5d0c600d43ddb39ac763ae1c4b776 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[11, 15], [0, 1], [0, 8], [4, 15], [0, 10], [13, 17], [1, 13], [5, 9], [9, 14], [11, 16], [5, 14], [15, 16], [1, 15], [1, 5], [3, 15], [9, 10], [12, 17], [0, 16], [11, 13], [5, 16], [2, 15], [12, 16], [0, 12], [10, 16], [4, 11], [0, 5], [8, 12], [5, 11], [5, 6], [3, 17], [1, 14], [1, 12], [7, 15], [9, 17], [10, 11], [3, 4], [1, 17], [6, 15], [0, 6], [6, 11], [4, 6], [10, 17], [14, 16], [4, 16], [3, 10], [6, 10], [4, 5], [12, 14], [1, 10], [13, 15], [0, 3], [8, 16], [10, 14], [1, 6], [2, 14], [1, 11], [1, 4], [0, 11], [3, 5], [1, 7], [7, 11], [3, 13], [0, 9], [0, 15], [4, 8], [1, 8], [11, 14], [2, 5], [3, 14], [2, 16], [2, 12], [11, 17], [12, 13], [4, 10], [2, 9], [3, 16], [6, 13], [4, 7], [10, 12], [5, 10], [6, 8], [6, 17], [3, 7], [8, 11], [1, 2], [7, 17], [16, 17], [2, 11], [8, 14], [13, 14], [2, 17], [4, 12], [8, 9], [14, 15], [10, 13], [2, 6], [7, 12], [8, 17], [3, 8], [13, 16], [3, 9], [8, 10], [11, 12], [7, 14], [5, 17], [9, 11], [3, 11], [6, 12], [9, 13], [4, 13], [2, 8], [2, 10], [0, 14], [7, 10]], "edges2": [[6, 11], [15, 17], [4, 5], [3, 8], [12, 13], [8, 9], [0, 9], [11, 15], [5, 15], [4, 8], [5, 13], [12, 14], [5, 14], [14, 17], [3, 6], [7, 9], [2, 12], [7, 14], [5, 17], [8, 17], [6, 9], [4, 10], [9, 10], [7, 8], [3, 5], [1, 12], [14, 15], [1, 9], [1, 15], [9, 16], [2, 16], [3, 14], [9, 12], [2, 5], [1, 11], [0, 10], [0, 8], [0, 15], [6, 16], [2, 8], [7, 16], [1, 10], [5, 8], [13, 14], [1, 2], [13, 17], [9, 11], [9, 17], [4, 17], [8, 15], [3, 4], [9, 14], [0, 5], [1, 6], [13, 16], [4, 16], [4, 15], [5, 9], [12, 15], [0, 2], [4, 7], [1, 4], [3, 9], [7, 15], [0, 14], [2, 10], [11, 16], [1, 7], [4, 12], [7, 11], [7, 12], [3, 16], [3, 7], [6, 14], [2, 3], [12, 17], [0, 7], [10, 17], [3, 10], [4, 14], [5, 16], [12, 16], [1, 17], [5, 6], [0, 13], [5, 10], [7, 10], [0, 4], [5, 7], [11, 14], [1, 8], [10, 16], [3, 13], [8, 13], [11, 17], [2, 15], [2, 7], [6, 12], [10, 13], [1, 3], [3, 15], [1, 5], [0, 16], [6, 10], [5, 12], [4, 6], [6, 13], [0, 1], [7, 13], [6, 8], [6, 7], [5, 11], [9, 13], [15, 16]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56d08358ecacfbfa001fa881c75158b75a11a4ad --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [8, 9, 10, 15, 14, 0, 13, 11, 3, 2, 7, 5, 6, 12, 1, 17, 4, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8fb04babcd5d0c600d43ddb39ac763ae1c4b776 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[11, 15], [0, 1], [0, 8], [4, 15], [0, 10], [13, 17], [1, 13], [5, 9], [9, 14], [11, 16], [5, 14], [15, 16], [1, 15], [1, 5], [3, 15], [9, 10], [12, 17], [0, 16], [11, 13], [5, 16], [2, 15], [12, 16], [0, 12], [10, 16], [4, 11], [0, 5], [8, 12], [5, 11], [5, 6], [3, 17], [1, 14], [1, 12], [7, 15], [9, 17], [10, 11], [3, 4], [1, 17], [6, 15], [0, 6], [6, 11], [4, 6], [10, 17], [14, 16], [4, 16], [3, 10], [6, 10], [4, 5], [12, 14], [1, 10], [13, 15], [0, 3], [8, 16], [10, 14], [1, 6], [2, 14], [1, 11], [1, 4], [0, 11], [3, 5], [1, 7], [7, 11], [3, 13], [0, 9], [0, 15], [4, 8], [1, 8], [11, 14], [2, 5], [3, 14], [2, 16], [2, 12], [11, 17], [12, 13], [4, 10], [2, 9], [3, 16], [6, 13], [4, 7], [10, 12], [5, 10], [6, 8], [6, 17], [3, 7], [8, 11], [1, 2], [7, 17], [16, 17], [2, 11], [8, 14], [13, 14], [2, 17], [4, 12], [8, 9], [14, 15], [10, 13], [2, 6], [7, 12], [8, 17], [3, 8], [13, 16], [3, 9], [8, 10], [11, 12], [7, 14], [5, 17], [9, 11], [3, 11], [6, 12], [9, 13], [4, 13], [2, 8], [2, 10], [0, 14], [7, 10]], "edges2": [[6, 11], [15, 17], [4, 5], [3, 8], [12, 13], [8, 9], [0, 9], [11, 15], [5, 15], [4, 8], [5, 13], [12, 14], [5, 14], [14, 17], [3, 6], [7, 9], [2, 12], [7, 14], [5, 17], [8, 17], [6, 9], [4, 10], [9, 10], [7, 8], [3, 5], [1, 12], [14, 15], [1, 9], [1, 15], [9, 16], [2, 16], [3, 14], [9, 12], [2, 5], [1, 11], [0, 10], [0, 8], [0, 15], [6, 16], [2, 8], [7, 16], [1, 10], [5, 8], [13, 14], [1, 2], [13, 17], [9, 11], [9, 17], [4, 17], [8, 15], [3, 4], [9, 14], [0, 5], [1, 6], [13, 16], [4, 16], [4, 15], [5, 9], [12, 15], [0, 2], [4, 7], [1, 4], [3, 9], [7, 15], [0, 14], [2, 10], [11, 16], [1, 7], [4, 12], [7, 11], [7, 12], [3, 16], [3, 7], [6, 14], [2, 3], [12, 17], [0, 7], [10, 17], [3, 10], [4, 14], [5, 16], [12, 16], [1, 17], [5, 6], [0, 13], [5, 10], [7, 10], [0, 4], [5, 7], [11, 14], [1, 8], [10, 16], [3, 13], [8, 13], [11, 17], [2, 15], [2, 7], [6, 12], [10, 13], [1, 3], [3, 15], [1, 5], [0, 16], [6, 10], [5, 12], [4, 6], [6, 13], [0, 1], [7, 13], [6, 8], [6, 7], [5, 11], [9, 13], [15, 16]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6dce6cf182d13cbb0331dca611cf22a1feda1dd8 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["11101101000", "01011100001", "01010100110", "10100101000", "10000011001", "11000110100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c318ca9dc6f639e64438c18ade3475541818d722 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"grid": ["10111010110", "01111111001", "01011000000", "11101111111", "10111010110", "11111110111"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6dce6cf182d13cbb0331dca611cf22a1feda1dd8 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["11101101000", "01011100001", "01010100110", "10100101000", "10000011001", "11000110100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l2-s5/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l2-s5/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd742d799a934dd8df14155dde67f5127d5e36dc --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 9], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 14], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [6, 7], [6, 8], [6, 9], [6, 11], [6, 12], [7, 8], [7, 9], [7, 11], [7, 12], [7, 14], [8, 9], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [11, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s5/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..538e6ac8735f2fe22321e6a8a16c98e46e3ee80b --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [2, 4, 5, 7, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s5/tests/check.py b/tasks/construct-rlve-imp-party-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l2-s5/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd742d799a934dd8df14155dde67f5127d5e36dc --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 9], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 14], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [6, 7], [6, 8], [6, 9], [6, 11], [6, 12], [7, 8], [7, 9], [7, 11], [7, 12], [7, 14], [8, 9], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [11, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s5/tests/run.py b/tasks/construct-rlve-imp-party-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l2-s5/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s3/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l6-s3/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c08f0f9efba1c69cac41f02bcb5ebe8c2e6f523e --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 3], [0, 12], [0, 19], [0, 29], [0, 35], [0, 39], [0, 48], [0, 66], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 10], [1, 12], [1, 13], [1, 14], [1, 16], [1, 19], [1, 20], [1, 21], [1, 23], [1, 24], [1, 25], [1, 27], [1, 29], [1, 30], [1, 32], [1, 33], [1, 35], [1, 37], [1, 38], [1, 39], [1, 41], [1, 42], [1, 43], [1, 44], [1, 46], [1, 47], [1, 48], [1, 49], [1, 51], [1, 52], [1, 53], [1, 55], [1, 56], [1, 57], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 70], [1, 72], [1, 73], [1, 74], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 19], [2, 20], [2, 21], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 32], [2, 33], [2, 35], [2, 37], [2, 38], [2, 39], [2, 40], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 51], [2, 53], [2, 55], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 68], [2, 69], [2, 70], [2, 72], [2, 73], [2, 74], [3, 4], [3, 5], [3, 7], [3, 9], [3, 10], [3, 12], [3, 13], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 27], [3, 29], [3, 30], [3, 32], [3, 33], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 53], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 70], [3, 72], [3, 73], [3, 74], [4, 5], [4, 6], [4, 7], [4, 8], [4, 10], [4, 12], [4, 13], [4, 16], [4, 19], [4, 20], [4, 21], [4, 23], [4, 24], [4, 25], [4, 27], [4, 28], [4, 29], [4, 30], [4, 32], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 51], [4, 53], [4, 54], [4, 55], [4, 57], [4, 58], [4, 59], [4, 60], [4, 61], [4, 62], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 68], [4, 69], [4, 70], [4, 71], [4, 72], [4, 73], [4, 74], [5, 7], [5, 9], [5, 10], [5, 12], [5, 13], [5, 16], [5, 17], [5, 19], [5, 21], [5, 23], [5, 24], [5, 25], [5, 27], [5, 29], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 41], [5, 42], [5, 43], [5, 44], [5, 46], [5, 47], [5, 48], [5, 49], [5, 50], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 61], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 68], [5, 70], [5, 71], [5, 72], [5, 73], [5, 74], [6, 7], [6, 12], [6, 13], [6, 21], [6, 25], [6, 27], [6, 29], [6, 30], [6, 37], [6, 38], [6, 42], [6, 46], [6, 58], [6, 61], [6, 70], [7, 10], [7, 11], [7, 12], [7, 13], [7, 16], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 35], [7, 37], [7, 38], [7, 39], [7, 41], [7, 42], [7, 43], [7, 44], [7, 46], [7, 47], [7, 48], [7, 49], [7, 51], [7, 53], [7, 55], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 63], [7, 64], [7, 65], [7, 66], [7, 67], [7, 68], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [8, 12], [8, 21], [8, 24], [8, 27], [8, 29], [8, 32], [8, 37], [8, 39], [8, 47], [8, 48], [8, 51], [8, 59], [8, 64], [8, 65], [8, 66], [8, 67], [8, 73], [9, 21], [9, 23], [9, 25], [9, 27], [9, 33], [9, 35], [9, 38], [9, 39], [9, 49], [9, 51], [9, 55], [9, 58], [9, 60], [9, 73], [10, 12], [10, 13], [10, 16], [10, 17], [10, 19], [10, 21], [10, 23], [10, 24], [10, 25], [10, 27], [10, 29], [10, 30], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 42], [10, 43], [10, 44], [10, 46], [10, 47], [10, 48], [10, 49], [10, 51], [10, 52], [10, 53], [10, 54], [10, 55], [10, 57], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 70], [10, 72], [10, 73], [10, 74], [11, 12], [11, 19], [11, 23], [11, 27], [11, 33], [11, 44], [11, 46], [11, 51], [11, 53], [11, 59], [11, 64], [11, 70], [11, 72], [12, 13], [12, 16], [12, 18], [12, 19], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [12, 30], [12, 32], [12, 33], [12, 34], [12, 35], [12, 37], [12, 38], [12, 39], [12, 40], [12, 42], [12, 43], [12, 44], [12, 46], [12, 47], [12, 48], [12, 49], [12, 51], [12, 53], [12, 55], [12, 56], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 67], [12, 68], [12, 70], [12, 71], [12, 72], [12, 73], [12, 74], [13, 15], [13, 16], [13, 19], [13, 21], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 37], [13, 38], [13, 39], [13, 42], [13, 43], [13, 44], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 70], [13, 72], [13, 73], [13, 74], [14, 21], [14, 30], [14, 33], [14, 49], [14, 51], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 70], [14, 72], [14, 74], [15, 19], [15, 23], [15, 24], [15, 32], [15, 42], [15, 43], [15, 47], [15, 49], [15, 53], [15, 57], [15, 59], [15, 67], [15, 70], [16, 19], [16, 21], [16, 23], [16, 24], [16, 25], [16, 27], [16, 29], [16, 30], [16, 32], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 51], [16, 53], [16, 55], [16, 57], [16, 58], [16, 59], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 70], [16, 72], [16, 73], [16, 74], [17, 19], [17, 23], [17, 27], [17, 32], [17, 33], [17, 38], [17, 43], [17, 47], [17, 49], [17, 57], [17, 65], [17, 73], [18, 19], [18, 29], [18, 39], [18, 44], [18, 63], [18, 65], [18, 67], [18, 72], [18, 73], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 30], [19, 32], [19, 33], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 51], [19, 53], [19, 55], [19, 57], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 70], [19, 72], [19, 73], [19, 74], [20, 21], [20, 24], [20, 25], [20, 33], [20, 37], [20, 39], [20, 43], [20, 44], [20, 47], [20, 58], [20, 62], [20, 64], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 32], [21, 33], [21, 35], [21, 37], [21, 38], [21, 39], [21, 42], [21, 43], [21, 44], [21, 46], [21, 47], [21, 48], [21, 49], [21, 51], [21, 53], [21, 55], [21, 57], [21, 58], [21, 59], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 68], [21, 70], [21, 72], [21, 73], [21, 74], [22, 24], [22, 25], [22, 30], [22, 32], [22, 33], [22, 42], [22, 44], [22, 48], [22, 51], [22, 53], [22, 57], [22, 59], [22, 73], [22, 74], [23, 24], [23, 25], [23, 27], [23, 29], [23, 30], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [23, 55], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 27], [24, 29], [24, 30], [24, 32], [24, 33], [24, 35], [24, 37], [24, 38], [24, 39], [24, 42], [24, 43], [24, 44], [24, 46], [24, 47], [24, 48], [24, 49], [24, 50], [24, 51], [24, 52], [24, 53], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 70], [24, 71], [24, 72], [24, 73], [24, 74], [25, 27], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 37], [25, 38], [25, 39], [25, 42], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 53], [25, 55], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [26, 33], [26, 44], [26, 51], [26, 55], [26, 57], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 73], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 42], [27, 43], [27, 44], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 53], [27, 55], [27, 57], [27, 58], [27, 59], [27, 60], [27, 61], [27, 62], [27, 63], [27, 64], [27, 65], [27, 66], [27, 67], [27, 68], [27, 70], [27, 72], [27, 73], [27, 74], [28, 33], [28, 37], [28, 47], [28, 49], [28, 63], [28, 68], [29, 30], [29, 31], [29, 32], [29, 33], [29, 35], [29, 37], [29, 38], [29, 39], [29, 42], [29, 43], [29, 44], [29, 46], [29, 47], [29, 48], [29, 49], [29, 51], [29, 52], [29, 53], [29, 55], [29, 57], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 67], [29, 68], [29, 70], [29, 72], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 46], [30, 47], [30, 48], [30, 49], [30, 51], [30, 53], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 35], [31, 37], [31, 39], [31, 42], [31, 44], [31, 46], [31, 47], [31, 55], [31, 59], [31, 62], [31, 63], [31, 66], [31, 68], [32, 33], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 42], [32, 43], [32, 44], [32, 46], [32, 47], [32, 48], [32, 49], [32, 51], [32, 53], [32, 55], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 67], [32, 68], [32, 70], [32, 72], [32, 73], [32, 74], [33, 35], [33, 37], [33, 38], [33, 39], [33, 42], [33, 43], [33, 44], [33, 46], [33, 47], [33, 48], [33, 49], [33, 50], [33, 51], [33, 53], [33, 55], [33, 57], [33, 58], [33, 59], [33, 60], [33, 61], [33, 62], [33, 63], [33, 64], [33, 65], [33, 66], [33, 67], [33, 68], [33, 70], [33, 71], [33, 72], [33, 73], [33, 74], [34, 35], [34, 37], [34, 46], [34, 53], [34, 59], [34, 66], [35, 36], [35, 37], [35, 38], [35, 39], [35, 42], [35, 43], [35, 44], [35, 46], [35, 47], [35, 48], [35, 49], [35, 51], [35, 53], [35, 55], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 70], [35, 72], [35, 73], [35, 74], [36, 37], [36, 39], [36, 46], [36, 49], [36, 51], [36, 53], [36, 55], [36, 58], [36, 63], [36, 65], [36, 67], [36, 68], [37, 38], [37, 39], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 47], [37, 48], [37, 49], [37, 50], [37, 51], [37, 52], [37, 53], [37, 54], [37, 55], [37, 57], [37, 58], [37, 59], [37, 60], [37, 61], [37, 62], [37, 63], [37, 64], [37, 65], [37, 66], [37, 67], [37, 68], [37, 69], [37, 70], [37, 72], [37, 73], [37, 74], [38, 39], [38, 42], [38, 43], [38, 44], [38, 46], [38, 47], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [38, 54], [38, 55], [38, 57], [38, 58], [38, 59], [38, 60], [38, 61], [38, 62], [38, 63], [38, 64], [38, 65], [38, 66], [38, 67], [38, 68], [38, 70], [38, 72], [38, 73], [38, 74], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 49], [39, 50], [39, 51], [39, 53], [39, 55], [39, 57], [39, 58], [39, 59], [39, 60], [39, 61], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 67], [39, 68], [39, 70], [39, 71], [39, 72], [39, 73], [39, 74], [40, 46], [40, 49], [40, 53], [40, 60], [40, 61], [40, 62], [40, 64], [40, 66], [40, 72], [41, 44], [41, 48], [41, 57], [41, 58], [41, 59], [41, 64], [41, 66], [41, 68], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 53], [42, 55], [42, 57], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 67], [42, 68], [42, 70], [42, 72], [42, 73], [42, 74], [43, 44], [43, 46], [43, 47], [43, 48], [43, 49], [43, 51], [43, 53], [43, 55], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 70], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 51], [44, 52], [44, 53], [44, 54], [44, 55], [44, 57], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 69], [44, 70], [44, 72], [44, 73], [44, 74], [45, 47], [45, 62], [45, 66], [45, 67], [45, 68], [45, 70], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 55], [46, 57], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 65], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [47, 48], [47, 49], [47, 51], [47, 52], [47, 53], [47, 55], [47, 57], [47, 58], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 70], [47, 72], [47, 73], [47, 74], [48, 49], [48, 51], [48, 53], [48, 55], [48, 57], [48, 58], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 72], [48, 73], [48, 74], [49, 51], [49, 53], [49, 55], [49, 57], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 67], [49, 68], [49, 70], [49, 71], [49, 72], [49, 73], [49, 74], [50, 70], [51, 53], [51, 54], [51, 55], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 70], [51, 72], [51, 73], [51, 74], [52, 58], [52, 61], [52, 64], [52, 66], [52, 70], [53, 55], [53, 57], [53, 58], [53, 59], [53, 60], [53, 61], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [54, 55], [54, 57], [54, 58], [54, 61], [54, 64], [54, 65], [54, 68], [54, 72], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 70], [55, 72], [55, 73], [55, 74], [56, 58], [56, 62], [56, 63], [56, 64], [56, 68], [57, 58], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 68], [57, 70], [57, 72], [57, 73], [57, 74], [58, 59], [58, 60], [58, 61], [58, 62], [58, 63], [58, 64], [58, 65], [58, 66], [58, 67], [58, 68], [58, 70], [58, 71], [58, 72], [58, 73], [58, 74], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 67], [59, 68], [59, 70], [59, 72], [59, 73], [59, 74], [60, 61], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 70], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 72], [61, 73], [61, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 70], [62, 71], [62, 72], [62, 73], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 70], [64, 72], [64, 73], [64, 74], [65, 66], [65, 67], [65, 68], [65, 70], [65, 72], [65, 73], [65, 74], [66, 67], [66, 68], [66, 70], [66, 72], [66, 73], [66, 74], [67, 68], [67, 70], [67, 72], [67, 73], [67, 74], [68, 70], [68, 72], [68, 73], [68, 74], [69, 70], [69, 72], [69, 73], [70, 72], [70, 73], [70, 74], [72, 73], [72, 74], [73, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s3/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..61d4efc2edc58991041df1d9bb5245775aa53618 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 3, 4, 5, 10, 13, 23, 24, 25, 29, 30, 32, 33, 35, 38, 39, 42, 48, 55, 60, 61, 63, 64, 65, 70]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s3/tests/check.py b/tasks/construct-rlve-imp-party-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l6-s3/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c08f0f9efba1c69cac41f02bcb5ebe8c2e6f523e --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 3], [0, 12], [0, 19], [0, 29], [0, 35], [0, 39], [0, 48], [0, 66], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 10], [1, 12], [1, 13], [1, 14], [1, 16], [1, 19], [1, 20], [1, 21], [1, 23], [1, 24], [1, 25], [1, 27], [1, 29], [1, 30], [1, 32], [1, 33], [1, 35], [1, 37], [1, 38], [1, 39], [1, 41], [1, 42], [1, 43], [1, 44], [1, 46], [1, 47], [1, 48], [1, 49], [1, 51], [1, 52], [1, 53], [1, 55], [1, 56], [1, 57], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 70], [1, 72], [1, 73], [1, 74], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 19], [2, 20], [2, 21], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 32], [2, 33], [2, 35], [2, 37], [2, 38], [2, 39], [2, 40], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 51], [2, 53], [2, 55], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 68], [2, 69], [2, 70], [2, 72], [2, 73], [2, 74], [3, 4], [3, 5], [3, 7], [3, 9], [3, 10], [3, 12], [3, 13], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 27], [3, 29], [3, 30], [3, 32], [3, 33], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 53], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 70], [3, 72], [3, 73], [3, 74], [4, 5], [4, 6], [4, 7], [4, 8], [4, 10], [4, 12], [4, 13], [4, 16], [4, 19], [4, 20], [4, 21], [4, 23], [4, 24], [4, 25], [4, 27], [4, 28], [4, 29], [4, 30], [4, 32], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 51], [4, 53], [4, 54], [4, 55], [4, 57], [4, 58], [4, 59], [4, 60], [4, 61], [4, 62], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 68], [4, 69], [4, 70], [4, 71], [4, 72], [4, 73], [4, 74], [5, 7], [5, 9], [5, 10], [5, 12], [5, 13], [5, 16], [5, 17], [5, 19], [5, 21], [5, 23], [5, 24], [5, 25], [5, 27], [5, 29], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 41], [5, 42], [5, 43], [5, 44], [5, 46], [5, 47], [5, 48], [5, 49], [5, 50], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 61], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 68], [5, 70], [5, 71], [5, 72], [5, 73], [5, 74], [6, 7], [6, 12], [6, 13], [6, 21], [6, 25], [6, 27], [6, 29], [6, 30], [6, 37], [6, 38], [6, 42], [6, 46], [6, 58], [6, 61], [6, 70], [7, 10], [7, 11], [7, 12], [7, 13], [7, 16], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 35], [7, 37], [7, 38], [7, 39], [7, 41], [7, 42], [7, 43], [7, 44], [7, 46], [7, 47], [7, 48], [7, 49], [7, 51], [7, 53], [7, 55], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 63], [7, 64], [7, 65], [7, 66], [7, 67], [7, 68], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [8, 12], [8, 21], [8, 24], [8, 27], [8, 29], [8, 32], [8, 37], [8, 39], [8, 47], [8, 48], [8, 51], [8, 59], [8, 64], [8, 65], [8, 66], [8, 67], [8, 73], [9, 21], [9, 23], [9, 25], [9, 27], [9, 33], [9, 35], [9, 38], [9, 39], [9, 49], [9, 51], [9, 55], [9, 58], [9, 60], [9, 73], [10, 12], [10, 13], [10, 16], [10, 17], [10, 19], [10, 21], [10, 23], [10, 24], [10, 25], [10, 27], [10, 29], [10, 30], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 42], [10, 43], [10, 44], [10, 46], [10, 47], [10, 48], [10, 49], [10, 51], [10, 52], [10, 53], [10, 54], [10, 55], [10, 57], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 70], [10, 72], [10, 73], [10, 74], [11, 12], [11, 19], [11, 23], [11, 27], [11, 33], [11, 44], [11, 46], [11, 51], [11, 53], [11, 59], [11, 64], [11, 70], [11, 72], [12, 13], [12, 16], [12, 18], [12, 19], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [12, 30], [12, 32], [12, 33], [12, 34], [12, 35], [12, 37], [12, 38], [12, 39], [12, 40], [12, 42], [12, 43], [12, 44], [12, 46], [12, 47], [12, 48], [12, 49], [12, 51], [12, 53], [12, 55], [12, 56], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 67], [12, 68], [12, 70], [12, 71], [12, 72], [12, 73], [12, 74], [13, 15], [13, 16], [13, 19], [13, 21], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 37], [13, 38], [13, 39], [13, 42], [13, 43], [13, 44], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 70], [13, 72], [13, 73], [13, 74], [14, 21], [14, 30], [14, 33], [14, 49], [14, 51], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 70], [14, 72], [14, 74], [15, 19], [15, 23], [15, 24], [15, 32], [15, 42], [15, 43], [15, 47], [15, 49], [15, 53], [15, 57], [15, 59], [15, 67], [15, 70], [16, 19], [16, 21], [16, 23], [16, 24], [16, 25], [16, 27], [16, 29], [16, 30], [16, 32], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 51], [16, 53], [16, 55], [16, 57], [16, 58], [16, 59], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 70], [16, 72], [16, 73], [16, 74], [17, 19], [17, 23], [17, 27], [17, 32], [17, 33], [17, 38], [17, 43], [17, 47], [17, 49], [17, 57], [17, 65], [17, 73], [18, 19], [18, 29], [18, 39], [18, 44], [18, 63], [18, 65], [18, 67], [18, 72], [18, 73], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 30], [19, 32], [19, 33], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 51], [19, 53], [19, 55], [19, 57], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 70], [19, 72], [19, 73], [19, 74], [20, 21], [20, 24], [20, 25], [20, 33], [20, 37], [20, 39], [20, 43], [20, 44], [20, 47], [20, 58], [20, 62], [20, 64], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 32], [21, 33], [21, 35], [21, 37], [21, 38], [21, 39], [21, 42], [21, 43], [21, 44], [21, 46], [21, 47], [21, 48], [21, 49], [21, 51], [21, 53], [21, 55], [21, 57], [21, 58], [21, 59], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 68], [21, 70], [21, 72], [21, 73], [21, 74], [22, 24], [22, 25], [22, 30], [22, 32], [22, 33], [22, 42], [22, 44], [22, 48], [22, 51], [22, 53], [22, 57], [22, 59], [22, 73], [22, 74], [23, 24], [23, 25], [23, 27], [23, 29], [23, 30], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [23, 55], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 27], [24, 29], [24, 30], [24, 32], [24, 33], [24, 35], [24, 37], [24, 38], [24, 39], [24, 42], [24, 43], [24, 44], [24, 46], [24, 47], [24, 48], [24, 49], [24, 50], [24, 51], [24, 52], [24, 53], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 70], [24, 71], [24, 72], [24, 73], [24, 74], [25, 27], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 37], [25, 38], [25, 39], [25, 42], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 53], [25, 55], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [26, 33], [26, 44], [26, 51], [26, 55], [26, 57], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 73], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 42], [27, 43], [27, 44], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 53], [27, 55], [27, 57], [27, 58], [27, 59], [27, 60], [27, 61], [27, 62], [27, 63], [27, 64], [27, 65], [27, 66], [27, 67], [27, 68], [27, 70], [27, 72], [27, 73], [27, 74], [28, 33], [28, 37], [28, 47], [28, 49], [28, 63], [28, 68], [29, 30], [29, 31], [29, 32], [29, 33], [29, 35], [29, 37], [29, 38], [29, 39], [29, 42], [29, 43], [29, 44], [29, 46], [29, 47], [29, 48], [29, 49], [29, 51], [29, 52], [29, 53], [29, 55], [29, 57], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 67], [29, 68], [29, 70], [29, 72], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 46], [30, 47], [30, 48], [30, 49], [30, 51], [30, 53], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 35], [31, 37], [31, 39], [31, 42], [31, 44], [31, 46], [31, 47], [31, 55], [31, 59], [31, 62], [31, 63], [31, 66], [31, 68], [32, 33], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 42], [32, 43], [32, 44], [32, 46], [32, 47], [32, 48], [32, 49], [32, 51], [32, 53], [32, 55], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 67], [32, 68], [32, 70], [32, 72], [32, 73], [32, 74], [33, 35], [33, 37], [33, 38], [33, 39], [33, 42], [33, 43], [33, 44], [33, 46], [33, 47], [33, 48], [33, 49], [33, 50], [33, 51], [33, 53], [33, 55], [33, 57], [33, 58], [33, 59], [33, 60], [33, 61], [33, 62], [33, 63], [33, 64], [33, 65], [33, 66], [33, 67], [33, 68], [33, 70], [33, 71], [33, 72], [33, 73], [33, 74], [34, 35], [34, 37], [34, 46], [34, 53], [34, 59], [34, 66], [35, 36], [35, 37], [35, 38], [35, 39], [35, 42], [35, 43], [35, 44], [35, 46], [35, 47], [35, 48], [35, 49], [35, 51], [35, 53], [35, 55], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 70], [35, 72], [35, 73], [35, 74], [36, 37], [36, 39], [36, 46], [36, 49], [36, 51], [36, 53], [36, 55], [36, 58], [36, 63], [36, 65], [36, 67], [36, 68], [37, 38], [37, 39], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 47], [37, 48], [37, 49], [37, 50], [37, 51], [37, 52], [37, 53], [37, 54], [37, 55], [37, 57], [37, 58], [37, 59], [37, 60], [37, 61], [37, 62], [37, 63], [37, 64], [37, 65], [37, 66], [37, 67], [37, 68], [37, 69], [37, 70], [37, 72], [37, 73], [37, 74], [38, 39], [38, 42], [38, 43], [38, 44], [38, 46], [38, 47], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [38, 54], [38, 55], [38, 57], [38, 58], [38, 59], [38, 60], [38, 61], [38, 62], [38, 63], [38, 64], [38, 65], [38, 66], [38, 67], [38, 68], [38, 70], [38, 72], [38, 73], [38, 74], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 49], [39, 50], [39, 51], [39, 53], [39, 55], [39, 57], [39, 58], [39, 59], [39, 60], [39, 61], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 67], [39, 68], [39, 70], [39, 71], [39, 72], [39, 73], [39, 74], [40, 46], [40, 49], [40, 53], [40, 60], [40, 61], [40, 62], [40, 64], [40, 66], [40, 72], [41, 44], [41, 48], [41, 57], [41, 58], [41, 59], [41, 64], [41, 66], [41, 68], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 53], [42, 55], [42, 57], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 67], [42, 68], [42, 70], [42, 72], [42, 73], [42, 74], [43, 44], [43, 46], [43, 47], [43, 48], [43, 49], [43, 51], [43, 53], [43, 55], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 70], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 51], [44, 52], [44, 53], [44, 54], [44, 55], [44, 57], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 69], [44, 70], [44, 72], [44, 73], [44, 74], [45, 47], [45, 62], [45, 66], [45, 67], [45, 68], [45, 70], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 55], [46, 57], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 65], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [47, 48], [47, 49], [47, 51], [47, 52], [47, 53], [47, 55], [47, 57], [47, 58], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 70], [47, 72], [47, 73], [47, 74], [48, 49], [48, 51], [48, 53], [48, 55], [48, 57], [48, 58], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 72], [48, 73], [48, 74], [49, 51], [49, 53], [49, 55], [49, 57], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 67], [49, 68], [49, 70], [49, 71], [49, 72], [49, 73], [49, 74], [50, 70], [51, 53], [51, 54], [51, 55], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 70], [51, 72], [51, 73], [51, 74], [52, 58], [52, 61], [52, 64], [52, 66], [52, 70], [53, 55], [53, 57], [53, 58], [53, 59], [53, 60], [53, 61], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [54, 55], [54, 57], [54, 58], [54, 61], [54, 64], [54, 65], [54, 68], [54, 72], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 70], [55, 72], [55, 73], [55, 74], [56, 58], [56, 62], [56, 63], [56, 64], [56, 68], [57, 58], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 68], [57, 70], [57, 72], [57, 73], [57, 74], [58, 59], [58, 60], [58, 61], [58, 62], [58, 63], [58, 64], [58, 65], [58, 66], [58, 67], [58, 68], [58, 70], [58, 71], [58, 72], [58, 73], [58, 74], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 67], [59, 68], [59, 70], [59, 72], [59, 73], [59, 74], [60, 61], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 70], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 72], [61, 73], [61, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 70], [62, 71], [62, 72], [62, 73], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 70], [64, 72], [64, 73], [64, 74], [65, 66], [65, 67], [65, 68], [65, 70], [65, 72], [65, 73], [65, 74], [66, 67], [66, 68], [66, 70], [66, 72], [66, 73], [66, 74], [67, 68], [67, 70], [67, 72], [67, 73], [67, 74], [68, 70], [68, 72], [68, 73], [68, 74], [69, 70], [69, 72], [69, 73], [70, 72], [70, 73], [70, 74], [72, 73], [72, 74], [73, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s3/tests/run.py b/tasks/construct-rlve-imp-party-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l6-s3/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s4/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l6-s4/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da6e7a4f1a4e30954073885b7384481161476021 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 11], [0, 12], [0, 17], [0, 18], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 29], [0, 31], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 40], [0, 41], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 10], [1, 12], [1, 17], [1, 18], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 27], [1, 29], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 40], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 50], [1, 51], [1, 53], [1, 54], [1, 55], [1, 56], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 72], [1, 73], [2, 5], [2, 8], [2, 18], [2, 22], [2, 23], [2, 36], [2, 42], [2, 43], [2, 44], [2, 47], [2, 53], [2, 54], [2, 56], [2, 69], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 12], [3, 13], [3, 17], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 27], [3, 29], [3, 31], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 39], [3, 40], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 51], [3, 53], [3, 54], [3, 55], [3, 56], [3, 58], [3, 59], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 17], [4, 18], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 27], [4, 28], [4, 29], [4, 31], [4, 33], [4, 34], [4, 35], [4, 36], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 51], [4, 53], [4, 54], [4, 55], [4, 56], [4, 58], [4, 59], [4, 60], [4, 61], [4, 62], [4, 63], [4, 66], [4, 67], [4, 68], [4, 69], [4, 70], [4, 72], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 17], [5, 18], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 29], [5, 31], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [5, 38], [5, 40], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 47], [5, 48], [5, 49], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 61], [5, 62], [5, 63], [5, 66], [5, 67], [5, 68], [5, 69], [5, 70], [5, 72], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 27], [6, 29], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 53], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 63], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 29], [7, 31], [7, 33], [7, 34], [7, 35], [7, 36], [7, 39], [7, 40], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 53], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 63], [7, 66], [7, 67], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [8, 9], [8, 10], [8, 12], [8, 17], [8, 18], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 27], [8, 29], [8, 30], [8, 31], [8, 33], [8, 34], [8, 35], [8, 36], [8, 40], [8, 42], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 49], [8, 51], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 72], [9, 18], [9, 29], [9, 33], [9, 42], [9, 46], [9, 53], [9, 54], [9, 56], [9, 58], [10, 12], [10, 14], [10, 17], [10, 18], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 27], [10, 29], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 39], [10, 40], [10, 42], [10, 43], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 49], [10, 51], [10, 53], [10, 54], [10, 55], [10, 56], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 72], [11, 12], [11, 25], [11, 29], [11, 44], [11, 47], [11, 54], [11, 60], [11, 66], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 40], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 47], [12, 48], [12, 49], [12, 50], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 56], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 65], [12, 66], [12, 67], [12, 68], [12, 69], [12, 70], [12, 72], [12, 73], [13, 23], [13, 31], [13, 33], [13, 42], [13, 44], [13, 49], [13, 51], [13, 56], [13, 59], [13, 61], [13, 66], [13, 69], [13, 70], [13, 72], [14, 17], [14, 27], [14, 31], [14, 40], [14, 45], [14, 48], [14, 51], [14, 53], [14, 54], [14, 66], [14, 72], [15, 17], [15, 21], [15, 31], [15, 35], [15, 45], [15, 53], [15, 58], [15, 66], [15, 68], [16, 18], [16, 29], [16, 31], [16, 36], [16, 46], [16, 49], [16, 51], [16, 55], [16, 58], [16, 59], [16, 60], [16, 69], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 27], [17, 29], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 40], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 51], [17, 53], [17, 54], [17, 55], [17, 56], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 64], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 31], [18, 33], [18, 34], [18, 35], [18, 36], [18, 40], [18, 42], [18, 43], [18, 44], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 51], [18, 53], [18, 54], [18, 55], [18, 56], [18, 58], [18, 59], [18, 60], [18, 61], [18, 62], [18, 63], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 72], [18, 73], [19, 22], [19, 36], [19, 42], [19, 43], [19, 47], [19, 53], [19, 54], [19, 58], [19, 66], [19, 69], [20, 22], [20, 29], [20, 44], [20, 51], [20, 53], [20, 56], [20, 58], [20, 60], [20, 62], [20, 63], [20, 66], [20, 69], [20, 70], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 47], [21, 48], [21, 49], [21, 51], [21, 53], [21, 54], [21, 55], [21, 56], [21, 58], [21, 59], [21, 60], [21, 61], [21, 62], [21, 63], [21, 65], [21, 66], [21, 67], [21, 68], [21, 69], [21, 70], [21, 71], [21, 72], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 29], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 38], [22, 40], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 51], [22, 53], [22, 54], [22, 55], [22, 56], [22, 58], [22, 59], [22, 60], [22, 61], [22, 62], [22, 63], [22, 66], [22, 67], [22, 68], [22, 69], [22, 70], [22, 71], [22, 72], [22, 74], [23, 24], [23, 25], [23, 27], [23, 28], [23, 29], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [23, 40], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 51], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 72], [23, 73], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 40], [24, 42], [24, 43], [24, 44], [24, 45], [24, 46], [24, 47], [24, 48], [24, 49], [24, 51], [24, 53], [24, 54], [24, 55], [24, 56], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 66], [24, 67], [24, 68], [24, 69], [24, 70], [24, 72], [24, 73], [25, 26], [25, 27], [25, 29], [25, 31], [25, 33], [25, 34], [25, 35], [25, 36], [25, 38], [25, 40], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 72], [26, 31], [26, 44], [26, 48], [26, 60], [26, 61], [26, 66], [27, 29], [27, 31], [27, 33], [27, 34], [27, 35], [27, 36], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 49], [27, 51], [27, 53], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [27, 61], [27, 62], [27, 63], [27, 65], [27, 66], [27, 67], [27, 68], [27, 69], [27, 70], [27, 72], [28, 29], [28, 33], [28, 36], [28, 40], [28, 47], [28, 48], [28, 59], [28, 60], [28, 63], [28, 68], [28, 69], [28, 70], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 37], [29, 40], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 47], [29, 48], [29, 49], [29, 50], [29, 51], [29, 53], [29, 54], [29, 55], [29, 56], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 64], [29, 66], [29, 67], [29, 68], [29, 69], [29, 70], [29, 72], [30, 40], [30, 54], [30, 55], [30, 60], [30, 62], [30, 69], [30, 70], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 47], [31, 48], [31, 49], [31, 50], [31, 51], [31, 53], [31, 54], [31, 55], [31, 56], [31, 58], [31, 59], [31, 60], [31, 61], [31, 62], [31, 63], [31, 64], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 71], [31, 72], [32, 33], [32, 36], [32, 43], [32, 49], [32, 66], [32, 68], [33, 34], [33, 35], [33, 36], [33, 37], [33, 38], [33, 40], [33, 42], [33, 43], [33, 44], [33, 45], [33, 46], [33, 47], [33, 48], [33, 49], [33, 51], [33, 53], [33, 54], [33, 55], [33, 56], [33, 58], [33, 59], [33, 60], [33, 61], [33, 62], [33, 63], [33, 66], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [34, 35], [34, 36], [34, 37], [34, 39], [34, 40], [34, 42], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 48], [34, 49], [34, 51], [34, 53], [34, 54], [34, 55], [34, 56], [34, 57], [34, 58], [34, 59], [34, 60], [34, 61], [34, 62], [34, 63], [34, 65], [34, 66], [34, 67], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 74], [35, 36], [35, 37], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 49], [35, 51], [35, 52], [35, 53], [35, 54], [35, 55], [35, 56], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 51], [36, 53], [36, 54], [36, 55], [36, 56], [36, 58], [36, 59], [36, 60], [36, 61], [36, 62], [36, 63], [36, 64], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 72], [36, 73], [37, 40], [37, 42], [37, 43], [37, 51], [37, 54], [37, 55], [37, 58], [37, 59], [37, 60], [37, 62], [37, 66], [37, 69], [37, 72], [38, 46], [38, 47], [38, 48], [38, 49], [38, 53], [38, 54], [38, 60], [38, 61], [38, 63], [38, 69], [39, 40], [39, 44], [39, 51], [39, 54], [39, 67], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 72], [41, 43], [41, 47], [41, 48], [41, 53], [41, 59], [41, 66], [41, 68], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 65], [42, 66], [42, 67], [42, 68], [42, 69], [42, 70], [42, 72], [43, 44], [43, 45], [43, 46], [43, 47], [43, 48], [43, 49], [43, 51], [43, 53], [43, 54], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 72], [43, 73], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 51], [44, 53], [44, 54], [44, 55], [44, 56], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 66], [44, 67], [44, 68], [44, 69], [44, 70], [44, 72], [45, 46], [45, 47], [45, 48], [45, 49], [45, 51], [45, 52], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 66], [45, 67], [45, 68], [45, 69], [45, 70], [45, 72], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [46, 56], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 72], [47, 48], [47, 49], [47, 51], [47, 53], [47, 54], [47, 55], [47, 56], [47, 58], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 66], [47, 67], [47, 68], [47, 69], [47, 70], [47, 72], [47, 73], [47, 74], [48, 49], [48, 51], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 72], [49, 50], [49, 51], [49, 53], [49, 54], [49, 55], [49, 56], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 63], [49, 65], [49, 66], [49, 67], [49, 68], [49, 69], [49, 70], [49, 72], [50, 51], [50, 55], [50, 67], [51, 52], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 70], [51, 72], [52, 55], [52, 58], [52, 61], [52, 72], [53, 54], [53, 55], [53, 56], [53, 58], [53, 59], [53, 60], [53, 61], [53, 62], [53, 63], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 72], [53, 73], [53, 74], [54, 55], [54, 56], [54, 58], [54, 59], [54, 60], [54, 61], [54, 62], [54, 63], [54, 66], [54, 67], [54, 68], [54, 69], [54, 70], [54, 72], [55, 56], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [56, 57], [56, 58], [56, 59], [56, 60], [56, 61], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 72], [57, 59], [57, 67], [58, 59], [58, 60], [58, 61], [58, 62], [58, 63], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 72], [59, 60], [59, 61], [59, 62], [59, 63], [59, 65], [59, 66], [59, 67], [59, 68], [59, 69], [59, 70], [59, 72], [60, 61], [60, 62], [60, 63], [60, 66], [60, 67], [60, 68], [60, 69], [60, 70], [60, 71], [60, 72], [60, 73], [61, 62], [61, 63], [61, 64], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 72], [61, 73], [62, 63], [62, 66], [62, 67], [62, 68], [62, 69], [62, 70], [62, 72], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [64, 68], [65, 69], [65, 70], [66, 67], [66, 68], [66, 69], [66, 70], [66, 72], [66, 74], [67, 68], [67, 69], [67, 70], [67, 72], [68, 69], [68, 70], [68, 72], [69, 70], [69, 72], [69, 74], [70, 72], [70, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s4/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a95a150483fddf1d6bccb64895d75461af8735ea --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [5, 8, 17, 18, 21, 23, 25, 27, 29, 31, 33, 34, 35, 40, 44, 46, 48, 49, 51, 53, 56, 61, 66, 67, 69]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s4/tests/check.py b/tasks/construct-rlve-imp-party-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l6-s4/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da6e7a4f1a4e30954073885b7384481161476021 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 11], [0, 12], [0, 17], [0, 18], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 29], [0, 31], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 40], [0, 41], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 10], [1, 12], [1, 17], [1, 18], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 27], [1, 29], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 40], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 50], [1, 51], [1, 53], [1, 54], [1, 55], [1, 56], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 72], [1, 73], [2, 5], [2, 8], [2, 18], [2, 22], [2, 23], [2, 36], [2, 42], [2, 43], [2, 44], [2, 47], [2, 53], [2, 54], [2, 56], [2, 69], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 12], [3, 13], [3, 17], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 27], [3, 29], [3, 31], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 39], [3, 40], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 51], [3, 53], [3, 54], [3, 55], [3, 56], [3, 58], [3, 59], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 17], [4, 18], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 27], [4, 28], [4, 29], [4, 31], [4, 33], [4, 34], [4, 35], [4, 36], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 51], [4, 53], [4, 54], [4, 55], [4, 56], [4, 58], [4, 59], [4, 60], [4, 61], [4, 62], [4, 63], [4, 66], [4, 67], [4, 68], [4, 69], [4, 70], [4, 72], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 17], [5, 18], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 29], [5, 31], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [5, 38], [5, 40], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 47], [5, 48], [5, 49], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 61], [5, 62], [5, 63], [5, 66], [5, 67], [5, 68], [5, 69], [5, 70], [5, 72], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 27], [6, 29], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 53], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 63], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 29], [7, 31], [7, 33], [7, 34], [7, 35], [7, 36], [7, 39], [7, 40], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 53], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 63], [7, 66], [7, 67], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [8, 9], [8, 10], [8, 12], [8, 17], [8, 18], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 27], [8, 29], [8, 30], [8, 31], [8, 33], [8, 34], [8, 35], [8, 36], [8, 40], [8, 42], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 49], [8, 51], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 72], [9, 18], [9, 29], [9, 33], [9, 42], [9, 46], [9, 53], [9, 54], [9, 56], [9, 58], [10, 12], [10, 14], [10, 17], [10, 18], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 27], [10, 29], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 39], [10, 40], [10, 42], [10, 43], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 49], [10, 51], [10, 53], [10, 54], [10, 55], [10, 56], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 72], [11, 12], [11, 25], [11, 29], [11, 44], [11, 47], [11, 54], [11, 60], [11, 66], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 40], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 47], [12, 48], [12, 49], [12, 50], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 56], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 65], [12, 66], [12, 67], [12, 68], [12, 69], [12, 70], [12, 72], [12, 73], [13, 23], [13, 31], [13, 33], [13, 42], [13, 44], [13, 49], [13, 51], [13, 56], [13, 59], [13, 61], [13, 66], [13, 69], [13, 70], [13, 72], [14, 17], [14, 27], [14, 31], [14, 40], [14, 45], [14, 48], [14, 51], [14, 53], [14, 54], [14, 66], [14, 72], [15, 17], [15, 21], [15, 31], [15, 35], [15, 45], [15, 53], [15, 58], [15, 66], [15, 68], [16, 18], [16, 29], [16, 31], [16, 36], [16, 46], [16, 49], [16, 51], [16, 55], [16, 58], [16, 59], [16, 60], [16, 69], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 27], [17, 29], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 40], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 51], [17, 53], [17, 54], [17, 55], [17, 56], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 64], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 31], [18, 33], [18, 34], [18, 35], [18, 36], [18, 40], [18, 42], [18, 43], [18, 44], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 51], [18, 53], [18, 54], [18, 55], [18, 56], [18, 58], [18, 59], [18, 60], [18, 61], [18, 62], [18, 63], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 72], [18, 73], [19, 22], [19, 36], [19, 42], [19, 43], [19, 47], [19, 53], [19, 54], [19, 58], [19, 66], [19, 69], [20, 22], [20, 29], [20, 44], [20, 51], [20, 53], [20, 56], [20, 58], [20, 60], [20, 62], [20, 63], [20, 66], [20, 69], [20, 70], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 47], [21, 48], [21, 49], [21, 51], [21, 53], [21, 54], [21, 55], [21, 56], [21, 58], [21, 59], [21, 60], [21, 61], [21, 62], [21, 63], [21, 65], [21, 66], [21, 67], [21, 68], [21, 69], [21, 70], [21, 71], [21, 72], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 29], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 38], [22, 40], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 51], [22, 53], [22, 54], [22, 55], [22, 56], [22, 58], [22, 59], [22, 60], [22, 61], [22, 62], [22, 63], [22, 66], [22, 67], [22, 68], [22, 69], [22, 70], [22, 71], [22, 72], [22, 74], [23, 24], [23, 25], [23, 27], [23, 28], [23, 29], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [23, 40], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 51], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 72], [23, 73], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 40], [24, 42], [24, 43], [24, 44], [24, 45], [24, 46], [24, 47], [24, 48], [24, 49], [24, 51], [24, 53], [24, 54], [24, 55], [24, 56], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 66], [24, 67], [24, 68], [24, 69], [24, 70], [24, 72], [24, 73], [25, 26], [25, 27], [25, 29], [25, 31], [25, 33], [25, 34], [25, 35], [25, 36], [25, 38], [25, 40], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 72], [26, 31], [26, 44], [26, 48], [26, 60], [26, 61], [26, 66], [27, 29], [27, 31], [27, 33], [27, 34], [27, 35], [27, 36], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 49], [27, 51], [27, 53], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [27, 61], [27, 62], [27, 63], [27, 65], [27, 66], [27, 67], [27, 68], [27, 69], [27, 70], [27, 72], [28, 29], [28, 33], [28, 36], [28, 40], [28, 47], [28, 48], [28, 59], [28, 60], [28, 63], [28, 68], [28, 69], [28, 70], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 37], [29, 40], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 47], [29, 48], [29, 49], [29, 50], [29, 51], [29, 53], [29, 54], [29, 55], [29, 56], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 64], [29, 66], [29, 67], [29, 68], [29, 69], [29, 70], [29, 72], [30, 40], [30, 54], [30, 55], [30, 60], [30, 62], [30, 69], [30, 70], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 47], [31, 48], [31, 49], [31, 50], [31, 51], [31, 53], [31, 54], [31, 55], [31, 56], [31, 58], [31, 59], [31, 60], [31, 61], [31, 62], [31, 63], [31, 64], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 71], [31, 72], [32, 33], [32, 36], [32, 43], [32, 49], [32, 66], [32, 68], [33, 34], [33, 35], [33, 36], [33, 37], [33, 38], [33, 40], [33, 42], [33, 43], [33, 44], [33, 45], [33, 46], [33, 47], [33, 48], [33, 49], [33, 51], [33, 53], [33, 54], [33, 55], [33, 56], [33, 58], [33, 59], [33, 60], [33, 61], [33, 62], [33, 63], [33, 66], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [34, 35], [34, 36], [34, 37], [34, 39], [34, 40], [34, 42], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 48], [34, 49], [34, 51], [34, 53], [34, 54], [34, 55], [34, 56], [34, 57], [34, 58], [34, 59], [34, 60], [34, 61], [34, 62], [34, 63], [34, 65], [34, 66], [34, 67], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 74], [35, 36], [35, 37], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 49], [35, 51], [35, 52], [35, 53], [35, 54], [35, 55], [35, 56], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 51], [36, 53], [36, 54], [36, 55], [36, 56], [36, 58], [36, 59], [36, 60], [36, 61], [36, 62], [36, 63], [36, 64], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 72], [36, 73], [37, 40], [37, 42], [37, 43], [37, 51], [37, 54], [37, 55], [37, 58], [37, 59], [37, 60], [37, 62], [37, 66], [37, 69], [37, 72], [38, 46], [38, 47], [38, 48], [38, 49], [38, 53], [38, 54], [38, 60], [38, 61], [38, 63], [38, 69], [39, 40], [39, 44], [39, 51], [39, 54], [39, 67], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 72], [41, 43], [41, 47], [41, 48], [41, 53], [41, 59], [41, 66], [41, 68], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 65], [42, 66], [42, 67], [42, 68], [42, 69], [42, 70], [42, 72], [43, 44], [43, 45], [43, 46], [43, 47], [43, 48], [43, 49], [43, 51], [43, 53], [43, 54], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 72], [43, 73], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 51], [44, 53], [44, 54], [44, 55], [44, 56], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 66], [44, 67], [44, 68], [44, 69], [44, 70], [44, 72], [45, 46], [45, 47], [45, 48], [45, 49], [45, 51], [45, 52], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 66], [45, 67], [45, 68], [45, 69], [45, 70], [45, 72], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [46, 56], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 72], [47, 48], [47, 49], [47, 51], [47, 53], [47, 54], [47, 55], [47, 56], [47, 58], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 66], [47, 67], [47, 68], [47, 69], [47, 70], [47, 72], [47, 73], [47, 74], [48, 49], [48, 51], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 72], [49, 50], [49, 51], [49, 53], [49, 54], [49, 55], [49, 56], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 63], [49, 65], [49, 66], [49, 67], [49, 68], [49, 69], [49, 70], [49, 72], [50, 51], [50, 55], [50, 67], [51, 52], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 70], [51, 72], [52, 55], [52, 58], [52, 61], [52, 72], [53, 54], [53, 55], [53, 56], [53, 58], [53, 59], [53, 60], [53, 61], [53, 62], [53, 63], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 72], [53, 73], [53, 74], [54, 55], [54, 56], [54, 58], [54, 59], [54, 60], [54, 61], [54, 62], [54, 63], [54, 66], [54, 67], [54, 68], [54, 69], [54, 70], [54, 72], [55, 56], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [56, 57], [56, 58], [56, 59], [56, 60], [56, 61], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 72], [57, 59], [57, 67], [58, 59], [58, 60], [58, 61], [58, 62], [58, 63], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 72], [59, 60], [59, 61], [59, 62], [59, 63], [59, 65], [59, 66], [59, 67], [59, 68], [59, 69], [59, 70], [59, 72], [60, 61], [60, 62], [60, 63], [60, 66], [60, 67], [60, 68], [60, 69], [60, 70], [60, 71], [60, 72], [60, 73], [61, 62], [61, 63], [61, 64], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 72], [61, 73], [62, 63], [62, 66], [62, 67], [62, 68], [62, 69], [62, 70], [62, 72], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [64, 68], [65, 69], [65, 70], [66, 67], [66, 68], [66, 69], [66, 70], [66, 72], [66, 74], [67, 68], [67, 69], [67, 70], [67, 72], [68, 69], [68, 70], [68, 72], [69, 70], [69, 72], [69, 74], [70, 72], [70, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s4/tests/run.py b/tasks/construct-rlve-imp-party-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l6-s4/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6deccba54f2b857ef026f8131fcf3741ba1bd0d1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1], [0, 0, 1], [1, 1, 1], [0, 1, 0], [1, 1, 1], [1, 0, 0], [1, 1, 0]], "rhs": [5, 1, 5, 2, 5, 2, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a94cbb1d4449f2cde581ed0819d23548238d3378 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6deccba54f2b857ef026f8131fcf3741ba1bd0d1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1], [0, 0, 1], [1, 1, 1], [0, 1, 0], [1, 1, 1], [1, 0, 0], [1, 1, 0]], "rhs": [5, 1, 5, 2, 5, 2, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s3/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ab2c7284625bd0147059983145ee3e11615ca07 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1], [1, 0, 0], [1, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 0, 1], [1, 0, 0], [1, 0, 1]], "rhs": [7, 2, 5, 2, 3, 2, 4, 2, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ec52359737558e3deebb4b871910b01d4bb7e02c --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ab2c7284625bd0147059983145ee3e11615ca07 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1], [1, 0, 0], [1, 1, 0], [0, 0, 1], [0, 1, 0], [1, 0, 0], [1, 0, 1], [1, 0, 0], [1, 0, 1]], "rhs": [7, 2, 5, 2, 3, 2, 4, 2, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s4/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a323f83ac946b5e3716b74f6d0431e8112a394e5 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 2, 2, 2, 3, 1, 0, 0, 3, 0, 1, 0, 0, 2, 0, 0, 3, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1], [0, 3, 3, 0, 2, 3, 0, 1, 1, 3, 0, 1, 0, 0, 1, 0, 2, 0], [0, 0, 2, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 1, 1], [0, 3, 3, 0, 0, 3, 0, 1, 2, 0, 2, 0, 2, 1, 2, 0, 0, 0], [2, 0, 1, 1, 0, 0, 1, 0, 1, 0, 2, 0, 2, 0, 3, 0, 3, 0], [3, 1, 0, 1, 1, 0, 2, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 3], [0, 0, 3, 0, 0, 2, 0, 0, 3, 2, 0, 3, 0, 0, 0, 0, 1, 1], [0, 3, 3, 1, 2, 0, 3, 0, 0, 1, 3, 2, 0, 0, 0, 1, 0, 2], [1, 0, 3, 3, 0, 2, 0, 0, 2, 0, 2, 0, 2, 2, 0, 1, 0, 0], [3, 3, 2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 1, 0, 3, 2, 2], [3, 3, 3, 2, 0, 2, 2, 1, 2, 3, 3, 0, 3, 1, 0, 3, 2, 1], [3, 0, 0, 0, 3, 2, 3, 0, 2, 2, 3, 0, 0, 0, 0, 0, 0, 3], [0, 0, 1, 1, 0, 0, 3, 1, 3, 3, 0, 0, 3, 2, 2, 0, 1, 0], [0, 0, 0, 1, 3, 2, 2, 1, 0, 0, 1, 1, 1, 1, 0, 2, 3, 0], [0, 2, 0, 0, 0, 0, 1, 3, 1, 3, 0, 0, 0, 0, 0, 3, 0, 1], [2, 1, 0, 1, 0, 3, 3, 0, 0, 0, 0, 3, 3, 3, 0, 3, 1, 3], [1, 1, 2, 1, 1, 1, 2, 0, 1, 2, 2, 0, 0, 3, 3, 0, 3, 0], [0, 1, 0, 2, 2, 0, 2, 1, 1, 0, 0, 0, 0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 3, 0, 3, 0, 0, 1, 2, 2, 0, 0, 0], [1, 0, 0, 1, 0, 0, 0, 0, 0, 2, 1, 0, 2, 3, 1, 0, 0, 1], [1, 0, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 3, 3, 2, 2, 1], [0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 1], [0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 2, 3, 2, 1, 2], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 2, 1], [0, 2, 1, 2, 3, 0, 2, 1, 1, 2, 2, 1, 0, 1, 0, 2, 0, 1], [0, 2, 1, 1, 0, 3, 0, 0, 2, 3, 3, 0, 3, 3, 0, 3, 0, 2], [0, 2, 0, 1, 2, 0, 1, 0, 3, 2, 2, 1, 3, 0, 3, 2, 0, 2], [2, 0, 0, 0, 0, 3, 1, 3, 2, 0, 0, 2, 0, 1, 0, 0, 0, 0], [3, 0, 0, 0, 2, 0, 0, 1, 3, 1, 1, 1, 2, 0, 3, 3, 0, 0], [0, 0, 0, 2, 2, 0, 2, 0, 1, 0, 2, 2, 0, 1, 0, 0, 2, 3], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3], [1, 3, 0, 0, 1, 3, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 3], [2, 2, 3, 0, 0, 1, 3, 0, 2, 2, 1, 3, 0, 0, 1, 0, 0, 0], [0, 0, 0, 3, 2, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 3, 0], [0, 2, 1, 0, 2, 1, 2, 0, 2, 1, 3, 0, 0, 3, 3, 0, 0, 0], [2, 0, 0, 3, 0, 0, 1, 1, 0, 3, 0, 3, 2, 2, 1, 0, 0, 2]], "rhs": [152, 79, 177, 74, 140, 143, 145, 127, 167, 139, 166, 321, 187, 149, 143, 147, 201, 205, 60, 123, 120, 155, 70, 57, 28, 86, 91, 174, 237, 172, 135, 147, 151, 54, 117, 163, 106, 147, 199], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ca2e9082c2a594f8e44a128447cd28d7c2ce232a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [14, 10, 3, 9, 1, 7, 2, 15, 5, 17, 17, 10, 4, 9, 2, 5, 16, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a323f83ac946b5e3716b74f6d0431e8112a394e5 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 2, 2, 2, 3, 1, 0, 0, 3, 0, 1, 0, 0, 2, 0, 0, 3, 0], [0, 1, 0, 0, 0, 1, 0, 1, 0, 2, 0, 0, 1, 0, 0, 0, 0, 1], [0, 3, 3, 0, 2, 3, 0, 1, 1, 3, 0, 1, 0, 0, 1, 0, 2, 0], [0, 0, 2, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 1, 1], [0, 3, 3, 0, 0, 3, 0, 1, 2, 0, 2, 0, 2, 1, 2, 0, 0, 0], [2, 0, 1, 1, 0, 0, 1, 0, 1, 0, 2, 0, 2, 0, 3, 0, 3, 0], [3, 1, 0, 1, 1, 0, 2, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 3], [0, 0, 3, 0, 0, 2, 0, 0, 3, 2, 0, 3, 0, 0, 0, 0, 1, 1], [0, 3, 3, 1, 2, 0, 3, 0, 0, 1, 3, 2, 0, 0, 0, 1, 0, 2], [1, 0, 3, 3, 0, 2, 0, 0, 2, 0, 2, 0, 2, 2, 0, 1, 0, 0], [3, 3, 2, 0, 1, 0, 0, 0, 1, 0, 0, 0, 2, 1, 0, 3, 2, 2], [3, 3, 3, 2, 0, 2, 2, 1, 2, 3, 3, 0, 3, 1, 0, 3, 2, 1], [3, 0, 0, 0, 3, 2, 3, 0, 2, 2, 3, 0, 0, 0, 0, 0, 0, 3], [0, 0, 1, 1, 0, 0, 3, 1, 3, 3, 0, 0, 3, 2, 2, 0, 1, 0], [0, 0, 0, 1, 3, 2, 2, 1, 0, 0, 1, 1, 1, 1, 0, 2, 3, 0], [0, 2, 0, 0, 0, 0, 1, 3, 1, 3, 0, 0, 0, 0, 0, 3, 0, 1], [2, 1, 0, 1, 0, 3, 3, 0, 0, 0, 0, 3, 3, 3, 0, 3, 1, 3], [1, 1, 2, 1, 1, 1, 2, 0, 1, 2, 2, 0, 0, 3, 3, 0, 3, 0], [0, 1, 0, 2, 2, 0, 2, 1, 1, 0, 0, 0, 0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 3, 0, 3, 0, 0, 1, 2, 2, 0, 0, 0], [1, 0, 0, 1, 0, 0, 0, 0, 0, 2, 1, 0, 2, 3, 1, 0, 0, 1], [1, 0, 2, 0, 0, 0, 0, 0, 0, 2, 1, 0, 0, 3, 3, 2, 2, 1], [0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 2, 0, 1], [0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, 2], [0, 0, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 2, 3, 2, 1, 2], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 2, 2, 1], [0, 2, 1, 2, 3, 0, 2, 1, 1, 2, 2, 1, 0, 1, 0, 2, 0, 1], [0, 2, 1, 1, 0, 3, 0, 0, 2, 3, 3, 0, 3, 3, 0, 3, 0, 2], [0, 2, 0, 1, 2, 0, 1, 0, 3, 2, 2, 1, 3, 0, 3, 2, 0, 2], [2, 0, 0, 0, 0, 3, 1, 3, 2, 0, 0, 2, 0, 1, 0, 0, 0, 0], [3, 0, 0, 0, 2, 0, 0, 1, 3, 1, 1, 1, 2, 0, 3, 3, 0, 0], [0, 0, 0, 2, 2, 0, 2, 0, 1, 0, 2, 2, 0, 1, 0, 0, 2, 3], [0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3], [1, 3, 0, 0, 1, 3, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 3], [2, 2, 3, 0, 0, 1, 3, 0, 2, 2, 1, 3, 0, 0, 1, 0, 0, 0], [0, 0, 0, 3, 2, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 3, 0], [0, 2, 1, 0, 2, 1, 2, 0, 2, 1, 3, 0, 0, 3, 3, 0, 0, 0], [2, 0, 0, 3, 0, 0, 1, 1, 0, 3, 0, 3, 2, 2, 1, 0, 0, 2]], "rhs": [152, 79, 177, 74, 140, 143, 145, 127, 167, 139, 166, 321, 187, 149, 143, 147, 201, 205, 60, 123, 120, 155, 70, 57, 28, 86, 91, 174, 237, 172, 135, 147, 151, 54, 117, 163, 106, 147, 199], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s2/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e555f11618f99d129d45119e03415b1ea78ccb93 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[35, 30], [2, 27], [1, 31], [31, 20], [20, 17], [9, 2], [6, 33], [22, 35], [16, 1], [10, 30], [0, 32], [16, 22], [21, 12], [5, 0], [3, 12], [25, 0], [22, 31], [27, 15], [33, 7], [30, 23], [35, 13], [8, 20], [30, 29], [8, 35], [7, 6], [7, 24], [12, 17], [23, 23], [33, 9], [15, 6], [4, 34], [18, 2], [17, 34], [6, 9], [2, 24]], "k": 15, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..692edf8752008e5da0d33c603469680fd7dc871b --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 30, 23, 32, 16, 19, 3, 28, 18, 15, 8, 5, 24, 33, 34]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e555f11618f99d129d45119e03415b1ea78ccb93 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[35, 30], [2, 27], [1, 31], [31, 20], [20, 17], [9, 2], [6, 33], [22, 35], [16, 1], [10, 30], [0, 32], [16, 22], [21, 12], [5, 0], [3, 12], [25, 0], [22, 31], [27, 15], [33, 7], [30, 23], [35, 13], [8, 20], [30, 29], [8, 35], [7, 6], [7, 24], [12, 17], [23, 23], [33, 9], [15, 6], [4, 34], [18, 2], [17, 34], [6, 9], [2, 24]], "k": 15, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..baf269b967a009a9440e87232a36109f806b6194 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-8, -12], [0, 24], [-6, -1], [-4, 6], [1, -4], [5, 6], [21, -11], [9, 23], [9, 0], [24, 25], [-2, 16], [7, 4], [-12, 22], [18, 19], [3, 4], [7, -13], [13, 14], [-25, -25], [-12, -12], [5, -22], [-15, 11], [5, 2], [-5, -20], [-8, 18], [-1, -8]], "area": 8, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5845c3f1ff0a1907c46ec49a0c67285fa073cd86 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [5, 11, 21, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..baf269b967a009a9440e87232a36109f806b6194 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-8, -12], [0, 24], [-6, -1], [-4, 6], [1, -4], [5, 6], [21, -11], [9, 23], [9, 0], [24, 25], [-2, 16], [7, 4], [-12, 22], [18, 19], [3, 4], [7, -13], [13, 14], [-25, -25], [-12, -12], [5, -22], [-15, 11], [5, 2], [-5, -20], [-8, 18], [-1, -8]], "area": 8, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l4-s5/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc286f169b1e1537f5b7540daf6ed6b8442d35d6 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": ["10", "10", "10", "10", "00", "11", "10"], "B": ["10", "10", "11", "00", "10", "10", "10"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79a0b770f7897237dc37ddd51c1ce88751358e9a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"a": [0, 3, 5, 4, 1, 2, 6], "b": [0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc286f169b1e1537f5b7540daf6ed6b8442d35d6 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": ["10", "10", "10", "10", "00", "11", "10"], "B": ["10", "10", "11", "00", "10", "10", "10"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbeb839240496d92dc36aa893575908d71a7a6b6 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": ["01111", "11101", "11111", "11011", "00011"], "B": ["01111", "10111", "00101", "11111", "11110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9db0f40936f8af85d4cbcc38b7d034afc2da86db --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"a": [3, 0, 4, 2, 1], "b": [2, 0, 4, 1, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbeb839240496d92dc36aa893575908d71a7a6b6 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": ["01111", "11101", "11111", "11011", "00011"], "B": ["01111", "10111", "00101", "11111", "11110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35f6569011f9f3d0af036416f70985108d05b87d --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [1, 2], [1, 5], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 7], [5, 6], [5, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3b278618267ab934a2c282c3724b1047bfd5b369 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 2, 3, 4, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35f6569011f9f3d0af036416f70985108d05b87d --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [1, 2], [1, 5], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [3, 4], [3, 5], [3, 6], [3, 7], [4, 5], [4, 7], [5, 6], [5, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..267c50a5b9c1ce28536234e394c0f089a1bf26ff --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 3], [0, 9], [0, 12], [0, 13], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 13], [2, 5], [2, 6], [2, 7], [2, 9], [2, 11], [3, 4], [3, 6], [3, 8], [4, 6], [4, 8], [4, 9], [4, 11], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [6, 11], [6, 12], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [10, 12], [10, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c79a41243872c89e36f1052e616de8309f654a9 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 2, 3, 2, 4, 3, 5, 4, 6, 7, 7, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..267c50a5b9c1ce28536234e394c0f089a1bf26ff --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 3], [0, 9], [0, 12], [0, 13], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 13], [2, 5], [2, 6], [2, 7], [2, 9], [2, 11], [3, 4], [3, 6], [3, 8], [4, 6], [4, 8], [4, 9], [4, 11], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [6, 11], [6, 12], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [10, 12], [10, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ab79ccebfa7063efbe0abf222eaeee12ad44ca3 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 4], [0, 5], [0, 8], [0, 10], [0, 11], [1, 2], [1, 6], [1, 9], [1, 10], [1, 11], [1, 12], [2, 5], [2, 9], [2, 10], [2, 12], [3, 5], [3, 6], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11], [4, 13], [5, 6], [5, 9], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 8], [7, 10], [7, 11], [7, 12], [8, 10], [9, 10], [9, 11], [9, 12], [9, 13], [11, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d220f70aeeef4093d9dc0d70272bb04c1f1e906f --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 0, 2, 3, 4, 3, 5, 6, 7, 1, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ab79ccebfa7063efbe0abf222eaeee12ad44ca3 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 4], [0, 5], [0, 8], [0, 10], [0, 11], [1, 2], [1, 6], [1, 9], [1, 10], [1, 11], [1, 12], [2, 5], [2, 9], [2, 10], [2, 12], [3, 5], [3, 6], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11], [4, 13], [5, 6], [5, 9], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 8], [7, 10], [7, 11], [7, 12], [8, 10], [9, 10], [9, 11], [9, 12], [9, 13], [11, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cc02e514dfff26290b9922735e726c5cd7f7f5f --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 29], [0, 30], [1, 2], [1, 4], [1, 6], [1, 7], [1, 10], [1, 12], [1, 13], [1, 14], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 29], [1, 30], [1, 31], [2, 4], [2, 5], [2, 6], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 19], [2, 21], [2, 22], [2, 23], [2, 24], [2, 27], [2, 29], [2, 30], [2, 31], [3, 4], [3, 5], [3, 8], [3, 9], [3, 10], [3, 17], [3, 18], [3, 19], [3, 20], [3, 23], [3, 24], [3, 27], [3, 28], [3, 30], [3, 31], [4, 5], [4, 6], [4, 8], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 18], [4, 19], [4, 21], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [5, 6], [5, 7], [5, 10], [5, 11], [5, 13], [5, 14], [5, 16], [5, 17], [5, 19], [5, 20], [5, 21], [5, 23], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [6, 7], [6, 10], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 24], [6, 25], [6, 26], [6, 31], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [8, 9], [8, 12], [8, 15], [8, 16], [8, 17], [8, 19], [8, 21], [8, 25], [8, 26], [8, 27], [8, 28], [8, 30], [8, 31], [9, 10], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 23], [9, 24], [9, 25], [9, 27], [9, 31], [10, 15], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 23], [10, 24], [10, 25], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 31], [12, 14], [12, 15], [12, 17], [12, 18], [12, 23], [12, 28], [12, 31], [13, 14], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 27], [13, 30], [13, 31], [14, 16], [14, 17], [14, 20], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [15, 16], [15, 17], [15, 18], [15, 19], [15, 21], [15, 22], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 31], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 28], [16, 29], [16, 31], [17, 18], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 31], [18, 19], [18, 21], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [19, 20], [19, 22], [19, 25], [19, 26], [19, 29], [20, 21], [20, 22], [20, 23], [20, 24], [20, 26], [20, 29], [20, 30], [21, 22], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 24], [22, 27], [22, 28], [22, 29], [22, 31], [23, 24], [23, 25], [23, 26], [23, 28], [23, 30], [23, 31], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [25, 26], [25, 27], [25, 28], [25, 31], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [27, 29], [27, 30], [27, 31], [28, 30], [28, 31], [29, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..94781cfbc552f6301100fad61fd61f8c2cc8e9af --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 1, 6, 13, 14, 20, 22, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cc02e514dfff26290b9922735e726c5cd7f7f5f --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 29], [0, 30], [1, 2], [1, 4], [1, 6], [1, 7], [1, 10], [1, 12], [1, 13], [1, 14], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 29], [1, 30], [1, 31], [2, 4], [2, 5], [2, 6], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 16], [2, 17], [2, 18], [2, 19], [2, 21], [2, 22], [2, 23], [2, 24], [2, 27], [2, 29], [2, 30], [2, 31], [3, 4], [3, 5], [3, 8], [3, 9], [3, 10], [3, 17], [3, 18], [3, 19], [3, 20], [3, 23], [3, 24], [3, 27], [3, 28], [3, 30], [3, 31], [4, 5], [4, 6], [4, 8], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 18], [4, 19], [4, 21], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [5, 6], [5, 7], [5, 10], [5, 11], [5, 13], [5, 14], [5, 16], [5, 17], [5, 19], [5, 20], [5, 21], [5, 23], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [6, 7], [6, 10], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 24], [6, 25], [6, 26], [6, 31], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [8, 9], [8, 12], [8, 15], [8, 16], [8, 17], [8, 19], [8, 21], [8, 25], [8, 26], [8, 27], [8, 28], [8, 30], [8, 31], [9, 10], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 23], [9, 24], [9, 25], [9, 27], [9, 31], [10, 15], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 23], [10, 24], [10, 25], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 31], [12, 14], [12, 15], [12, 17], [12, 18], [12, 23], [12, 28], [12, 31], [13, 14], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 27], [13, 30], [13, 31], [14, 16], [14, 17], [14, 20], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [15, 16], [15, 17], [15, 18], [15, 19], [15, 21], [15, 22], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 31], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 28], [16, 29], [16, 31], [17, 18], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 31], [18, 19], [18, 21], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [19, 20], [19, 22], [19, 25], [19, 26], [19, 29], [20, 21], [20, 22], [20, 23], [20, 24], [20, 26], [20, 29], [20, 30], [21, 22], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 24], [22, 27], [22, 28], [22, 29], [22, 31], [23, 24], [23, 25], [23, 26], [23, 28], [23, 30], [23, 31], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [25, 26], [25, 27], [25, 28], [25, 31], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [27, 29], [27, 30], [27, 31], [28, 30], [28, 31], [29, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l4-s0/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..005c24a7810df25072ef22bc5ad6eb3fb1b61ecd --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 30], [0, 31], [1, 4], [1, 5], [1, 8], [1, 11], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 30], [1, 31], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 15], [2, 16], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [2, 30], [2, 31], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [5, 6], [5, 8], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 28], [5, 29], [5, 31], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [7, 9], [7, 10], [7, 11], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 21], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 28], [9, 31], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 21], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [10, 30], [10, 31], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 30], [12, 13], [12, 14], [12, 15], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 27], [12, 28], [12, 30], [12, 31], [13, 15], [13, 16], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [14, 16], [14, 18], [14, 20], [14, 21], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [15, 16], [15, 17], [15, 18], [15, 19], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [19, 20], [19, 24], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [20, 21], [20, 22], [20, 23], [20, 24], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 31], [23, 24], [23, 25], [23, 26], [23, 28], [23, 29], [23, 30], [23, 31], [24, 26], [24, 27], [24, 28], [24, 29], [24, 30], [25, 26], [25, 27], [25, 30], [25, 31], [26, 27], [26, 28], [26, 29], [26, 30], [27, 28], [27, 29], [27, 30], [27, 31], [28, 29], [28, 30], [29, 31], [30, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4125cab42b014289a86fb833763776e896ca644f --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 4, 5, 6, 8, 9, 12, 13, 18, 22, 23, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..005c24a7810df25072ef22bc5ad6eb3fb1b61ecd --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 30], [0, 31], [1, 4], [1, 5], [1, 8], [1, 11], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 30], [1, 31], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 15], [2, 16], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [2, 30], [2, 31], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [5, 6], [5, 8], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 28], [5, 29], [5, 31], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [7, 9], [7, 10], [7, 11], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 21], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 28], [9, 31], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 21], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [10, 30], [10, 31], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 30], [12, 13], [12, 14], [12, 15], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 27], [12, 28], [12, 30], [12, 31], [13, 15], [13, 16], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [14, 16], [14, 18], [14, 20], [14, 21], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [15, 16], [15, 17], [15, 18], [15, 19], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [19, 20], [19, 24], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [20, 21], [20, 22], [20, 23], [20, 24], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 31], [23, 24], [23, 25], [23, 26], [23, 28], [23, 29], [23, 30], [23, 31], [24, 26], [24, 27], [24, 28], [24, 29], [24, 30], [25, 26], [25, 27], [25, 30], [25, 31], [26, 27], [26, 28], [26, 29], [26, 30], [27, 28], [27, 29], [27, 30], [27, 31], [28, 29], [28, 30], [29, 31], [30, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l4-s7/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31e492112fb2e013e664e194522f91d91704254e --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 6, "edges": [[0, 3], [0, 4], [0, 5], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 20], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 30], [0, 31], [1, 2], [1, 3], [1, 4], [1, 7], [1, 10], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 22], [1, 27], [1, 28], [1, 30], [1, 31], [2, 3], [2, 6], [2, 8], [2, 9], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 21], [2, 24], [2, 27], [2, 31], [3, 4], [3, 5], [3, 7], [3, 9], [3, 10], [3, 11], [3, 13], [3, 17], [3, 18], [3, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [4, 6], [4, 7], [4, 11], [4, 13], [4, 15], [4, 17], [4, 20], [4, 21], [4, 24], [4, 25], [4, 28], [4, 29], [5, 7], [5, 11], [5, 12], [5, 13], [5, 15], [5, 16], [5, 20], [5, 22], [5, 23], [5, 26], [5, 27], [6, 7], [6, 10], [6, 13], [6, 14], [6, 15], [6, 16], [6, 19], [6, 22], [6, 27], [6, 29], [6, 31], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 31], [8, 11], [8, 12], [8, 15], [8, 19], [8, 20], [8, 23], [8, 24], [8, 29], [9, 10], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 21], [9, 23], [9, 25], [9, 26], [9, 29], [9, 30], [10, 11], [10, 13], [10, 15], [10, 17], [10, 19], [10, 23], [10, 24], [10, 27], [10, 28], [10, 29], [11, 12], [11, 13], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 30], [12, 15], [12, 16], [12, 19], [12, 23], [12, 24], [12, 25], [12, 29], [12, 30], [13, 14], [13, 16], [13, 19], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [14, 16], [14, 18], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [15, 16], [15, 19], [15, 20], [15, 23], [15, 24], [15, 25], [15, 26], [15, 28], [15, 30], [16, 18], [16, 20], [16, 27], [16, 28], [16, 29], [16, 31], [17, 19], [17, 20], [17, 22], [17, 23], [17, 24], [17, 25], [18, 19], [18, 20], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [19, 21], [19, 23], [19, 24], [19, 25], [19, 26], [19, 28], [19, 29], [19, 31], [20, 21], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [21, 25], [21, 28], [21, 31], [22, 28], [22, 29], [22, 31], [23, 25], [23, 27], [23, 29], [24, 28], [24, 30], [24, 31], [25, 26], [25, 30], [25, 31], [26, 28], [26, 29], [26, 30], [27, 28], [27, 29], [27, 30], [28, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..204e338ca056e04afb8ebe4853b7e27468d52546 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 3, 4, 11, 17, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31e492112fb2e013e664e194522f91d91704254e --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 6, "edges": [[0, 3], [0, 4], [0, 5], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 20], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 30], [0, 31], [1, 2], [1, 3], [1, 4], [1, 7], [1, 10], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 22], [1, 27], [1, 28], [1, 30], [1, 31], [2, 3], [2, 6], [2, 8], [2, 9], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 21], [2, 24], [2, 27], [2, 31], [3, 4], [3, 5], [3, 7], [3, 9], [3, 10], [3, 11], [3, 13], [3, 17], [3, 18], [3, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [4, 6], [4, 7], [4, 11], [4, 13], [4, 15], [4, 17], [4, 20], [4, 21], [4, 24], [4, 25], [4, 28], [4, 29], [5, 7], [5, 11], [5, 12], [5, 13], [5, 15], [5, 16], [5, 20], [5, 22], [5, 23], [5, 26], [5, 27], [6, 7], [6, 10], [6, 13], [6, 14], [6, 15], [6, 16], [6, 19], [6, 22], [6, 27], [6, 29], [6, 31], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 31], [8, 11], [8, 12], [8, 15], [8, 19], [8, 20], [8, 23], [8, 24], [8, 29], [9, 10], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 21], [9, 23], [9, 25], [9, 26], [9, 29], [9, 30], [10, 11], [10, 13], [10, 15], [10, 17], [10, 19], [10, 23], [10, 24], [10, 27], [10, 28], [10, 29], [11, 12], [11, 13], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 30], [12, 15], [12, 16], [12, 19], [12, 23], [12, 24], [12, 25], [12, 29], [12, 30], [13, 14], [13, 16], [13, 19], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [14, 16], [14, 18], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [15, 16], [15, 19], [15, 20], [15, 23], [15, 24], [15, 25], [15, 26], [15, 28], [15, 30], [16, 18], [16, 20], [16, 27], [16, 28], [16, 29], [16, 31], [17, 19], [17, 20], [17, 22], [17, 23], [17, 24], [17, 25], [18, 19], [18, 20], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [19, 21], [19, 23], [19, 24], [19, 25], [19, 26], [19, 28], [19, 29], [19, 31], [20, 21], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [21, 25], [21, 28], [21, 31], [22, 28], [22, 29], [22, 31], [23, 25], [23, 27], [23, 29], [24, 28], [24, 30], [24, 31], [25, 26], [25, 30], [25, 31], [26, 28], [26, 29], [26, 30], [27, 28], [27, 29], [27, 30], [28, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l4-s9/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..954eeff51332c1d117ed93e53864da2eb26adbe4 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 3, "edges": [[0, 6], [1, 2], [1, 5], [1, 11], [1, 12], [2, 8], [3, 4], [3, 5], [3, 7], [3, 8], [3, 10], [3, 12], [4, 6], [4, 7], [5, 11], [6, 7], [6, 9], [7, 11], [7, 13], [8, 10], [9, 13], [10, 12]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..93b0b849d7a4624467177cdcba9435e4841db9d9 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 1, 0, 2, 1, 2, 2, 0, 0, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..954eeff51332c1d117ed93e53864da2eb26adbe4 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 3, "edges": [[0, 6], [1, 2], [1, 5], [1, 11], [1, 12], [2, 8], [3, 4], [3, 5], [3, 7], [3, 8], [3, 10], [3, 12], [4, 6], [4, 7], [5, 11], [6, 7], [6, 9], [7, 11], [7, 13], [8, 10], [9, 13], [10, 12]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..868e3f4516d335debf5c411c5e26edf971b3420b --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 6, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 11], [0, 12], [0, 13], [1, 4], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 11], [3, 12], [4, 5], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 7], [6, 9], [6, 12], [6, 13], [7, 8], [7, 9], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..89f611ba487e57fe320ef739eefb4880588c2c6a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 1, 2, 3, 1, 4, 5, 0, 2, 4, 4, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..868e3f4516d335debf5c411c5e26edf971b3420b --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 6, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 11], [0, 12], [0, 13], [1, 4], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 11], [3, 12], [4, 5], [4, 6], [4, 7], [4, 8], [4, 10], [4, 11], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 7], [6, 9], [6, 12], [6, 13], [7, 8], [7, 9], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d39d330e4026c7fc0765e8bd7c9c3fb7f9415af5 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "edges": [[1, 6], [2, 6], [2, 9], [3, 4], [3, 6], [3, 7], [5, 9], [6, 9], [7, 8]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fea96ce0912628e8c1a214589088db7aa2ac28f7 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 2, 0, 0, 3, 1, 0, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d39d330e4026c7fc0765e8bd7c9c3fb7f9415af5 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "edges": [[1, 6], [2, 6], [2, 9], [3, 4], [3, 6], [3, 7], [5, 9], [6, 9], [7, 8]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..577fc700db6ac412d00703d84936707ba3854c4e --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [1, 3], [2, 4], [5, 6], [6, 9], [8, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f30618885bac8adc82eba7af1a8ecc065437322 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 2, 3, 0, 1, 0, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..577fc700db6ac412d00703d84936707ba3854c4e --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [1, 3], [2, 4], [5, 6], [6, 9], [8, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32dbd37375318a6967077d6881aa9db81e5e64e3 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [28, 56, 52, 40, 59, 53, 26, 35, 60, 58, 45, 57, 39, 30, 12, 30, 31, 50, 47, 27, 20, 33, 35, 37, 54, 62, 42, 53, 38, 26, 32, 38, 19, 31, 14, 16, 41, 52, 45, 46, 48, 4, 51, 18, 46, 21, 59, 53, 39, 44, 46, 66, 49, 50, 50, 64, 46, 59, 58, 34, 42, 23, 52, 43, 22, 67, 11, 35, 28, 21, 45, 49, 40, 43, 48, 34, 39, 35, 44, 42, 47, 60, 49, 41, 63, 50, 49, 34, 43, 45, 31, 25, 51, 54, 29, 29, 44, 38, 23, 42, 38, 56, 52, 51, 32, 37, 10, 42, 24, 25, 31, 54, 45, 38, 41, 27, 43, 56, 55, 54, 33, 35, 47, 19, 38, 39, 37, 48, 55, 57, 63, 65, 57, 23, 41, 52, 33, 53, 30, 62, 61, 47, 22, 69, 64, 30, 33, 37, 31, 13, 55, 36, 27], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ab84bb2d7437c1e703960ca90c046c95f0b7831b --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [1, 3, 9, 10, 13, 17, 18, 20, 21, 22, 24, 25, 28, 29, 30, 32, 34, 35]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32dbd37375318a6967077d6881aa9db81e5e64e3 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [28, 56, 52, 40, 59, 53, 26, 35, 60, 58, 45, 57, 39, 30, 12, 30, 31, 50, 47, 27, 20, 33, 35, 37, 54, 62, 42, 53, 38, 26, 32, 38, 19, 31, 14, 16, 41, 52, 45, 46, 48, 4, 51, 18, 46, 21, 59, 53, 39, 44, 46, 66, 49, 50, 50, 64, 46, 59, 58, 34, 42, 23, 52, 43, 22, 67, 11, 35, 28, 21, 45, 49, 40, 43, 48, 34, 39, 35, 44, 42, 47, 60, 49, 41, 63, 50, 49, 34, 43, 45, 31, 25, 51, 54, 29, 29, 44, 38, 23, 42, 38, 56, 52, 51, 32, 37, 10, 42, 24, 25, 31, 54, 45, 38, 41, 27, 43, 56, 55, 54, 33, 35, 47, 19, 38, 39, 37, 48, 55, 57, 63, 65, 57, 23, 41, 52, 33, 53, 30, 62, 61, 47, 22, 69, 64, 30, 33, 37, 31, 13, 55, 36, 27], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..240c7dcbdf752efae733c5a902ff03e0fc943704 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": 7992730, "B": 8010563, "C": 9083026, "D": 9990374, "target": 1602112, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2521911e0ba65b87a400eea060207ccd633efe18 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 8010560, "Y": 9612672} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..240c7dcbdf752efae733c5a902ff03e0fc943704 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": 7992730, "B": 8010563, "C": 9083026, "D": 9990374, "target": 1602112, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a6bb0e712f3aef1507033aef49281a72e8b09d9 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": 3046746, "B": 3994125, "C": 4282691, "D": 4738460, "target": 1579486, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d5fd93e06228e0ccecc9c36cee994335a91891cf --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 3158972, "Y": 4738458} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a6bb0e712f3aef1507033aef49281a72e8b09d9 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": 3046746, "B": 3994125, "C": 4282691, "D": 4738460, "target": 1579486, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd7a5d5cc5a16318fd78f59f9eb945011578370d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [2, -4, 2], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..329870fd5b1e946da000c53d6f9779a52476e3df --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x0": 1.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd7a5d5cc5a16318fd78f59f9eb945011578370d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [2, -4, 2], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..18179af7ea0c2ba279128db1f1a5e2b95cbe8143 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [2056, -10220, 23105, -30620, 26981, -16060, 6750, -1912, 361, -40, 2], "fmin": "142.429407109776784749641321076634589399466232", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fd29d85b521f9d1bd8a5c0aa89da01bbb92554f7 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x0": 0.6149685846840874} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..18179af7ea0c2ba279128db1f1a5e2b95cbe8143 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [2056, -10220, 23105, -30620, 26981, -16060, 6750, -1912, 361, -40, 2], "fmin": "142.429407109776784749641321076634589399466232", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b382d9d9c62cf5df91b76fa3ecaca71adc7074 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [67, 186, 287, 40, 272, -240, 211, -120, 47, -10, 1], "fmin": "38.7470475930799924039816348559858550567925699", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2f1ba907eb583b298b9b9523551a64b400b28cb --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x0": -0.2808606259243819} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b382d9d9c62cf5df91b76fa3ecaca71adc7074 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [67, 186, 287, 40, 272, -240, 211, -120, 47, -10, 1], "fmin": "38.7470475930799924039816348559858550567925699", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4590cf757cffdabe66e32bfd6da516afbb7501e4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 0, 0, 1100346962130763776, 253322713481084928, -822212505988927488, 195176757108722688, 99242600563789056, -59181806638425024, 11452229991963648, -613774875685968, -107600209349232, 17581190495516, -327217647784, -104487980847, 6726899672, 190873508, -28235544, 221926, 49528, -1128, -32, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9973882c572c439ef6eabf169558833dd354f271 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-22, -19, -18, -18, -13, -2, -1, 0, 0, 0, 3, 4, 6, 8, 8, 9, 9, 12, 12, 17, 18, 19]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4590cf757cffdabe66e32bfd6da516afbb7501e4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 0, 0, 1100346962130763776, 253322713481084928, -822212505988927488, 195176757108722688, 99242600563789056, -59181806638425024, 11452229991963648, -613774875685968, -107600209349232, 17581190495516, -327217647784, -104487980847, 6726899672, 190873508, -28235544, 221926, 49528, -1128, -32, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5130c92056a2cc2cbd086b50cf702e12230f62 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -555412321345609728000, 297272139313379328000, 272637298505517603840, 7216570079314500096, -20358885382098700608, -2064343441920168384, 629219182940651376, 91501934888253168, -9353944716872076, -1902624360093684, 55966954518377, 21723194550455, 176225682731, -139694144179, -4516865542, 476650502, 25563898, -667754, -62051, -221, 55, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9da6a07cad8331a9865a5153bd52ca79c2c1b845 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-20, -18, -18, -17, -17, -14, -13, -9, -7, -6, -6, -4, 0, 1, 6, 8, 8, 9, 11, 15, 15, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5130c92056a2cc2cbd086b50cf702e12230f62 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -555412321345609728000, 297272139313379328000, 272637298505517603840, 7216570079314500096, -20358885382098700608, -2064343441920168384, 629219182940651376, 91501934888253168, -9353944716872076, -1902624360093684, 55966954518377, 21723194550455, 176225682731, -139694144179, -4516865542, 476650502, 25563898, -667754, -62051, -221, 55, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fccb95dbd0f3efc1a738ed198bc5050614fad04a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"X": [-2, 1, -1], "Y": [19, 1, 3], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f1480a11dec12a717da7778b571060ee4979d890 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [-3, -1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fccb95dbd0f3efc1a738ed198bc5050614fad04a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"X": [-2, 1, -1], "Y": [19, 1, 3], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a3329559f03a80a5568738dad29dd9460381222 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"X": [8, -6, -2, -4, 1, -5, 12, 9, 6, -1, -12, 10, 3, 4], "Y": [2866286024281, -60452914661, -35209, -298075067, 8, -5556311614, 551145370132981, 13202341861744, 68783522383, -26, -515855930418899, 51773597373131, 8554186, 358342109], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5814f0ec9026a7d3803184262efc8f6d6b3a4d01 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [1, 3, 1, 3, -3, 4, -3, 0, -4, 4, -3, -2, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a3329559f03a80a5568738dad29dd9460381222 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"X": [8, -6, -2, -4, 1, -5, 12, 9, 6, -1, -12, 10, 3, 4], "Y": [2866286024281, -60452914661, -35209, -298075067, 8, -5556311614, 551145370132981, 13202341861744, 68783522383, -26, -515855930418899, 51773597373131, 8554186, 358342109], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cac86f40d49f1659d60a70fe2eab2a1124932c98 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ef023c73a2885637b360afced512a3fd4c6a3d9a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 4, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cac86f40d49f1659d60a70fe2eab2a1124932c98 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..538a527c9917f49545828bd6d4237db40289419e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 6469, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a47fd110c3157b1da30b0a8ef09716be18db12e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 3236, 4314, 4853, 1295, 5392, 5546, 2427, 3595, 648, 5882, 5931, 3982, 6008, 4745, 1214, 5709, 1798, 682, 3559, 6162, 6176, 5345, 2966, 5435, 5226, 1199, 6239, 3124, 2373, 5844, 3842, 6274, 2855, 1110, 4134, 5421, 3576, 1328, 1780, 5050, 6316, 1355, 6323, 5895, 2673, 4956, 4718, 6338, 2718, 4060, 5848, 4273, 600, 2471, 3120, 228, 4797, 4935, 1187, 2122, 6157, 4211, 5156, 2091, 6372, 3670, 1428, 6095, 3790, 5650, 5302, 5318, 2711, 6125, 5023, 6386, 3899, 3604, 4125, 4713, 5760, 3898, 6393, 5024, 678, 1042, 3162, 2545, 2948, 2418, 1337, 4105, 5713, 1431, 5594, 3669, 6404, 2092, 4594, 1282, 5265, 4209, 6159, 2527, 2137, 1452, 3535, 2553, 1236, 3964, 4795, 230, 3349, 6245, 2399, 4756, 2468, 4513, 594, 2888, 4296, 1684, 3079, 6263, 2106, 816, 5813, 4765, 1046, 2717, 6421, 4719, 5070, 4122, 3949, 4959, 3048, 2933, 5130, 3809, 6060, 951, 5886, 4507, 5894, 6426, 1356, 522, 3063, 4585, 2512, 1354, 6428, 5051, 1950, 4245, 5037, 1425, 2063, 4461, 2357, 636, 6115, 5137, 5184, 737, 3197, 5781, 5747, 2233, 3574, 5423, 3756, 5398, 4816, 3802, 1273, 4916, 4709, 3718, 4444, 708, 669, 1085, 2053, 1108, 2857, 5717, 716, 3625, 6032, 3688, 1835, 2854, 6437, 3843, 4281, 4292, 5532, 1224, 3876, 5992, 2633, 6186, 2105, 6345, 3080, 651, 1264, 2607, 1069, 1884, 3961, 5447, 1768, 2684, 1277, 6086, 3853, 4421, 5217, 3221, 2398, 6355, 3350, 58, 1675, 114, 3123, 6442, 1200, 4471, 5613, 992, 4469, 1202, 2257, 6064, 3532, 5960, 4679, 3728, 5383, 3856, 4077, 551, 1540, 1300, 3132, 5903, 4288, 1663, 3643, 5988, 2907, 3676, 2383, 5396, 3758, 348, 1359, 1649, 3211, 3443, 2360, 849, 5770, 1492, 5296, 741, 1975, 2963, 2480, 495, 4759, 1519, 1467, 1369, 5800, 5388, 1905, 2104, 6265, 2634, 476, 5343, 6178, 3381, 2254, 3380, 6182, 5344, 6448, 6163, 3913, 698, 3496, 4393, 1532, 3891, 2293, 428, 4491, 1719, 3912, 6175, 6449, 3560, 2526, 6366, 4210, 6408, 2123, 843, 2519, 1756, 713, 873, 1032, 2641, 2231, 5749, 1179, 419, 3553, 3008, 3058, 1633, 2569, 1115, 5827, 1322, 369, 5910, 1599, 1863, 2891, 4390, 2874, 5825, 1117, 5527, 5022, 6395, 2712, 262, 5113, 5951, 5934, 1586, 5643, 4051, 5136, 6306, 637, 1505, 5693, 3695, 2355, 4463, 5094, 5276, 5457, 3652, 3589, 5148, 335, 562, 543, 5232, 1027, 4701, 3789, 6401, 1429, 5715, 2859, 1742, 3593, 2429, 1813, 3852, 6251, 1278, 5079, 1589, 918, 3011, 4662, 2218, 3219, 5219, 1922, 4603, 2141, 1549, 5381, 3730, 6001, 2808, 3847, 4929, 5173, 3531, 6231, 2258, 1317, 950, 6328, 3810, 1053, 1630, 3173, 3368, 4775, 5291, 326, 2919, 3867, 631, 1304, 5583, 535, 4887, 4177, 304, 1981, 2474, 2724, 4849, 4119, 748, 4577, 1503, 639, 3687, 6278, 3626, 1927, 4299, 2211, 1067, 2609, 5685, 1611, 2331, 4434, 3041, 3178, 460, 4910, 1529, 3264, 3072, 838, 5012, 3292, 452, 1562, 4744, 6456, 3983, 3835, 5997, 2236, 1220, 2807, 6070, 3731, 3572, 2235, 6005, 3836, 287, 1129, 2632, 6267, 3877, 5001, 2906, 6215, 3644, 2340, 4616, 5099, 5673, 2692, 2369, 5163, 4138, 2039, 3990, 276, 1713, 4005, 808, 3885, 3955, 4801, 4559, 2952, 3975, 5379, 1551, 832, 4084, 1822, 4678, 6229, 3533, 1454, 745, 5073, 4724, 1192, 3980, 5933, 6121, 5114, 150, 3409, 1040, 680, 1800, 825, 4150, 1606, 4171, 1722, 1268, 4415, 887, 425, 1585, 6120, 5952, 3981, 6458, 5883, 5908, 371, 1240, 988, 3099, 1482, 4223, 4475, 2393, 248, 4932, 2380, 2364, 760, 4675, 734, 663, 685, 1598, 6135, 370, 5929, 5884, 953, 5222, 4287, 6219, 3133, 5515, 4552, 930, 3473, 1209, 2672, 6425, 6324, 4508, 1691, 1230, 4362, 2406, 4925, 4506, 6326, 952, 5907, 5930, 6459, 649, 3082, 3438, 1957, 121, 3584, 3491, 4983, 5744, 2197, 55, 4001, 1960, 1946, 2565, 1147, 3166, 3449, 1525, 2246, 1998, 860, 1875, 5191, 1394, 3088, 4219, 3225, 1364, 5015, 5728, 4498, 4272, 6418, 4061, 5340, 3841, 6439, 2374, 1062, 2603, 422, 5168, 1260, 3026, 4113, 164, 357, 4967, 437, 2785, 3751, 2413, 1321, 6138, 1116, 6129, 2875, 11, 590, 3390, 210, 5208, 1777, 1804, 4739, 1838, 4764, 6342, 817, 2995, 1285, 5736, 558, 5787, 2914, 4826, 3896, 5762, 185, 5387, 6190, 1370, 800, 3471, 932, 2119, 1446, 87, 5430, 525, 4672, 20, 2913, 5807, 559, 4874, 2764, 2195, 5746, 6301, 3198, 4167, 4591, 2148, 3366, 3175, 2557, 298, 2976, 1491, 6202, 850, 4028, 3691, 2822, 4644, 2026, 184, 5803, 3897, 6388, 4714, 319, 5599, 753, 191, 2847, 2022, 1848, 3240, 1178, 6147, 2232, 6300, 5782, 2196, 5873, 4984, 2729, 5556, 5061, 4647, 1795, 557, 5809, 1286, 168, 3275, 3516, 1174, 272, 4497, 5851, 5016, 514, 1399, 2351, 434, 1895, 4829, 3201, 871, 715, 6281, 2858, 6093, 1430, 6376, 4106, 555, 1797, 6453, 1215, 3138, 907, 4153, 5161, 2371, 3126, 5368, 3874, 1226, 2540, 4813, 795, 1011, 3694, 6112, 1506, 3331, 5566, 3455, 4344, 2273, 1610, 6025, 2610, 1908, 4196, 4863, 2302, 1882, 1071, 1657, 775, 5461, 2691, 5983, 5100, 673, 3001, 2440, 4639, 4601, 1924, 893, 2465, 498, 2587, 2160, 1766, 5449, 3116, 2404, 4364, 128, 659, 3477, 3710, 5301, 6399, 3791, 5140, 4670, 527, 2322, 4050, 6118, 1587, 5081, 4919, 507, 2388, 3418, 2646, 1442, 3398, 457, 1460, 3941, 1934, 4347, 316, 3953, 3887, 1157, 2792, 4110, 268, 702, 2444, 2768, 2089, 5158, 3387, 3035, 991, 6236, 4472, 611, 4597, 3938, 2425, 5548, 2060, 3673, 3609, 3284, 2289, 3269, 752, 5757, 320, 5440, 1844, 3668, 6374, 1432, 5048, 1782, 964, 3364, 2150, 2045, 1106, 2055, 534, 6047, 1305, 3814, 2843, 4546, 806, 4007, 1166, 984, 5452, 1465, 1521, 5110, 4824, 2916, 3465, 3454, 5690, 3332, 765, 2319, 4867, 4456, 4771, 3587, 3654, 5060, 5741, 2730, 4881, 389, 3461, 3415, 4016, 2059, 5607, 2426, 6463, 5393, 1992, 5500, 1918, 572, 2999, 675, 4353, 4279, 3845, 2810, 1404, 1223, 6270, 4293, 1866, 4332, 5021, 6127, 1118, 2438, 3003, 1497, 5153, 410, 144, 586, 565, 1250, 4551, 5901, 3134, 2448, 1939, 5330, 2501, 3737, 4688, 881, 3108, 3326, 5057, 4249, 4405, 1917, 5543, 1993, 2550, 1344, 2837, 4453, 4581, 3795, 1185, 4937, 2582, 5316, 5304, 896, 1020, 3357, 5230, 545, 3373, 3435, 857, 236, 2003, 4685, 3639, 2153, 1943, 4783, 1978, 4754, 2401, 1985, 2280, 3716, 4711, 4127, 1988, 4652, 2690, 5675, 776, 2778, 3651, 6106, 5277, 2493, 4146, 1464, 5574, 985, 3115, 5659, 1767, 6255, 3962, 1238, 373, 1771, 2537, 1843, 5597, 321, 3831, 2030, 5225, 6445, 2967, 3170, 3061, 524, 5792, 88, 3310, 3772, 1705, 131, 3755, 6297, 3575, 6433, 4135, 2660, 413, 4842, 5310, 1816, 4038, 1580, 2086, 1351, 4096, 629, 3869, 4906, 2208, 4259, 444, 3863, 213, 4588, 793, 4815, 6295, 3757, 6211, 2384, 1991, 5545, 6464, 1296, 2942, 1904, 6189, 5801, 186, 4419, 3855, 6226, 3729, 6072, 1550, 5966, 3976, 2327, 2112, 1218, 2238, 1375, 1197, 5228, 3359, 3873, 5701, 3127, 4425, 885, 4417, 188, 3615, 36, 2338, 3646, 3602, 3901, 332, 645, 343, 945, 4034, 3724, 3068, 2644, 3420, 2478, 2965, 6447, 6177, 6183, 477, 3840, 5846, 4062, 2144, 3324, 3110, 2600, 1567, 4894, 2758, 2500, 5511, 1940, 3700, 5123, 1737, 3905, 605, 3306, 4571, 3441, 3213, 2710, 6397, 5303, 5489, 2583, 846, 3680, 3850, 1815, 5416, 4843, 4438, 2187, 2463, 895, 5488, 5317, 6398, 5651, 3711, 3973, 2954, 740, 6200, 1493, 3230, 721, 325, 6053, 4776, 1710, 4954, 2675, 979, 1535, 61, 4350, 5027, 3075, 1746, 517, 2492, 5456, 6107, 5095, 1099, 1244, 28, 233, 2001, 238, 4215, 3093, 4208, 6368, 1283, 2997, 574, 3800, 4818, 3548, 1725, 17, 763, 3334, 4358, 1096, 4234, 468, 3665, 5066, 938, 202, 2596, 772, 3932, 4630, 4779, 580, 2110, 2329, 1613, 3427, 3917, 111, 2508, 1026, 6099, 544, 5484, 3358, 5371, 1198, 6444, 5436, 2031, 4286, 5905, 954, 1921, 6077, 3220, 6248, 4422, 3769, 3766, 3130, 1302, 633, 3446, 1776, 5819, 211, 3865, 2921, 4748, 532, 2057, 4018, 3317, 2668, 179, 1556, 2484, 3786, 219, 386, 1393, 5858, 1876, 102, 1207, 3475, 661, 736, 6304, 5138, 3793, 4583, 3065, 2311, 1438, 1617, 6, 1080, 3530, 6066, 4930, 250, 3340, 1259, 5839, 423, 889, 2658, 4137, 5980, 2370, 5704, 4154, 3386, 5617, 2090, 6406, 4212, 409, 5522, 1498, 4057, 643, 334, 6103, 3590, 3514, 3277, 2894, 40, 4692, 4669, 5648, 3792, 5183, 6305, 6116, 4052, 93, 2367, 2694, 3808, 6330, 2934, 3920, 974, 3635, 1593, 1736, 5327, 3701, 4384, 1060, 2376, 3958, 154, 44, 149, 5950, 6122, 263, 4823, 5571, 1522, 3245, 618, 1457, 3181, 2904, 5003, 280, 672, 5672, 5984, 4617, 4232, 1098, 5275, 6108, 4464, 3151, 1474, 4834, 3191, 2084, 1582, 2296, 4186, 4309, 4707, 4918, 5641, 1588, 6084, 1279, 614, 3384, 4156, 4723, 5956, 746, 4121, 6336, 4720, 3660, 937, 5249, 3666, 1846, 2024, 4646, 5740, 5557, 3655, 4248, 5504, 3327, 4303, 2902, 3183, 1949, 6315, 6429, 1781, 5592, 1433, 160, 4409, 2800, 69, 377, 757, 96, 878, 1424, 6312, 4246, 3657, 4159, 1293, 4855, 3485, 3824, 836, 3074, 5282, 4351, 677, 6385, 6394, 6126, 5528, 4333, 108, 2937, 513, 5727, 5852, 1365, 3291, 6013, 839, 2531, 4048, 2324, 1018, 898, 4951, 279, 5103, 2905, 5990, 3878, 2666, 3319, 1380, 1638, 3821, 4993, 4994, 3822, 3487, 3371, 547, 2249, 2073, 2926, 2728, 5743, 5874, 3492, 3494, 700, 270, 1176, 3242, 3452, 3467, 948, 1319, 2415, 1861, 1601, 1893, 436, 5833, 358, 779, 3141, 2216, 4664, 3482, 3047, 6333, 3950, 4717, 6423, 2674, 5288, 1711, 278, 5005, 899, 1362, 3227, 3021, 608, 4226, 4804, 1560, 454, 3208, 2077, 301, 2581, 5491, 1186, 6411, 4798, 2379, 5919, 249, 5172, 6067, 3848, 3682, 4505, 5888, 2407, 4329, 398, 1091, 506, 5640, 5082, 4708, 6291, 1274, 3988, 2041, 1666, 1528, 6018, 461, 1728, 2207, 5407, 3870, 1137, 1578, 4040, 4660, 3013, 2134, 4540, 4204, 4189, 2757, 5333, 1568, 2432, 1058, 4386, 1384, 4176, 6045, 536, 352, 829, 1391, 388, 5554, 2731, 2835, 1346, 4736, 2992, 2763, 5785, 560, 337, 4609, 1501, 4579, 4455, 5562, 2320, 529, 2301, 5681, 4197, 785, 447, 4141, 1233, 3045, 3484, 5032, 1294, 6466, 4315, 2774, 4118, 6039, 2725, 1970, 4793, 3966, 4437, 5309, 5417, 414, 3299, 3412, 330, 3903, 1739, 3190, 5090, 1475, 2651, 4165, 3200, 5721, 1896, 3895, 5805, 2915, 5570, 5111, 264, 3261, 4396, 3547, 5260, 3801, 6294, 5399, 794, 5697, 2541, 2945, 2460, 2182, 254, 2829, 4429, 1559, 4944, 4227, 4558, 5970, 3956, 2378, 4934, 6412, 229, 6358, 3965, 4846, 1971, 2201, 4202, 4542, 2174, 124, 3393, 2961, 1977, 5473, 1944, 1962, 579, 5242, 4631, 1709, 5290, 6054, 3369, 3489, 3586, 5560, 4457, 4230, 4619, 2698, 1045, 6341, 5814, 1839, 1694, 1182, 1518, 6194, 496, 2467, 6353, 2400, 5471, 1979, 306, 2560, 2299, 531, 5204, 2922, 1213, 6455, 6009, 1563, 4265, 2852, 1837, 5816, 1805, 2991, 4877, 1347, 1145, 2567, 1635, 3282, 3611, 380, 2879, 2959, 3395, 1191, 5955, 5074, 4157, 3659, 5069, 6337, 6422, 4957, 3951, 318, 5759, 6389, 4126, 5466, 3717, 6290, 4917, 5083, 4310, 811, 1023, 217, 3788, 6097, 1028, 3935, 3502, 3303, 3024, 1262, 653, 4668, 5142, 41, 1422, 880, 5508, 3738, 3638, 5477, 2004, 2097, 3818, 2308, 3727, 6228, 5961, 1823, 733, 5915, 761, 19, 5790, 526, 5647, 5141, 4693, 654, 1733, 3481, 4962, 2217, 6080, 3012, 4901, 4041, 383, 2620, 1160, 1056, 2434, 2689, 5463, 1989, 2386, 509, 1794, 5739, 5062, 2025, 5765, 2823, 2871, 3499, 4600, 5668, 2441, 2782, 195, 3618, 1731, 656, 1708, 4778, 5243, 3933, 1030, 875, 2804, 1407, 4448, 719, 3232, 2590, 2697, 4768, 4231, 5098, 5985, 2341, 4194, 1910, 3521, 4055, 1500, 4871, 338, 3581, 2177, 941, 2140, 6075, 1923, 5667, 4640, 3500, 3937, 5610, 612, 1281, 6370, 2093, 2147, 5778, 4168, 792, 5401, 214, 2511, 6319, 3064, 5181, 3794, 5494, 4454, 4869, 1502, 6036, 749, 1643, 2577, 1955, 3440, 5322, 3307, 3928, 3528, 1082, 283, 4368, 3860, 788, 2276, 1858, 2951, 5969, 4802, 4228, 4459, 2065, 970, 929, 5900, 5516, 1251, 395, 1869, 805, 5579, 2844, 441, 2173, 4789, 4203, 4898, 2135, 2529, 841, 2125, 4200, 2203, 4022, 959, 1142, 2772, 4317, 997, 1689, 4510, 603, 3907, 3287, 1419, 157, 2227, 3267, 2291, 3893, 1898, 3032, 593, 6351, 2469, 602, 4526, 1690, 5893, 6325, 5887, 4926, 3683, 3543, 3745, 1624, 1679, 4271, 5850, 5729, 273, 3509, 1687, 999, 1718, 6166, 429, 3998, 3353, 4069, 1002, 4192, 2343, 1007, 1820, 4086, 1077, 927, 972, 3922, 2392, 5922, 4224, 610, 5612, 6237, 1201, 6234, 993, 1787, 4375, 3150, 5093, 6109, 2356, 6309, 2064, 4556, 4229, 4770, 5561, 4868, 4580, 5495, 2838, 3314, 3623, 718, 4624, 1408, 1826, 707, 6288, 3719, 2639, 1034, 1247, 2186, 5308, 4844, 3967, 3040, 6022, 2332, 493, 2482, 1558, 4806, 2830, 4320, 884, 5366, 3128, 3768, 5216, 6249, 3854, 5385, 187, 5364, 886, 5938, 1269, 2454, 922, 865, 2799, 5045, 161, 2011, 1916, 5502, 4250, 2101, 2613, 2396, 3223, 4221, 1484, 3546, 4820, 3262, 1531, 6171, 3497, 2873, 6131, 2892, 3279, 1383, 4890, 1059, 5121, 3702, 853, 1314, 66, 100, 1878, 4325, 3149, 4466, 1788, 2654, 3217, 2220, 2068, 3859, 4565, 284, 207, 127, 5656, 2405, 5890, 1231, 4143, 1095, 5254, 3335, 4025, 3705, 4278, 5538, 676, 5026, 5283, 62, 315, 5629, 1935, 2272, 5688, 3456, 4339, 2131, 2130, 4342, 3457, 1572, 1932, 3943, 107, 5020, 5529, 1867, 397, 4923, 2408, 1133, 3148, 4377, 1879, 694, 3106, 883, 4427, 2831, 996, 4529, 2773, 4852, 6467, 3237, 3883, 810, 4706, 5084, 4187, 4206, 3095, 2738, 2901, 5055, 3328, 4257, 2210, 6029, 1928, 1683, 6348, 2889, 1865, 5531, 6271, 4282, 4010, 1662, 6218, 5904, 5223, 2032, 1164, 4009, 4291, 6272, 3844, 5537, 4354, 3706, 688, 726, 599, 6417, 5849, 4499, 1680, 2270, 1937, 2450, 2851, 4742, 1564, 1065, 2213, 2171, 443, 5405, 2209, 4301, 3329, 1508, 1808, 392, 3253, 2100, 4404, 5503, 5058, 3656, 5036, 6313, 1951, 3205, 3401, 3829, 323, 723, 172, 2898, 473, 467, 5252, 1097, 5097, 4618, 4769, 4458, 4557, 4803, 4945, 609, 4474, 5923, 1483, 4399, 3224, 5855, 3089, 291, 3092, 5268, 239, 408, 5155, 6407, 6158, 6367, 5266, 3094, 4307, 4188, 4897, 4541, 4790, 2202, 4535, 2126, 784, 4862, 5682, 1909, 4614, 2342, 4485, 1003, 2756, 4896, 4205, 4308, 5085, 2297, 2562, 3186, 869, 3203, 1953, 2579, 303, 6044, 4888, 1385, 2286, 3910, 1721, 5941, 1607, 791, 4590, 5779, 3199, 4831, 2652, 1790, 2745, 3405, 1292, 5034, 3658, 4722, 5075, 3385, 5160, 5705, 908, 1605, 5943, 826, 2422, 1463, 5454, 2494, 1094, 4360, 1232, 4859, 448, 2038, 5979, 5164, 2659, 5420, 6434, 1111, 2826, 485, 1856, 2278, 1987, 5465, 4712, 6390, 3605, 3948, 6335, 5071, 747, 6038, 4850, 2775, 361, 2009, 163, 5836, 3027, 267, 5623, 2793, 4090, 554, 5712, 6377, 1338, 3778, 490, 1309, 768, 3346, 31, 628, 5410, 1352, 2514, 1672, 1538, 553, 4108, 2794, 259, 1076, 4481, 1821, 5963, 833, 3054, 2457, 2548, 1995, 550, 6224, 3857, 2070, 3249, 225, 117, 1716, 1001, 4487, 3354, 814, 2108, 582, 1547, 2143, 5339, 5847, 6419, 2719, 642, 5151, 1499, 4611, 3522, 92, 5135, 6117, 5644, 2323, 5009, 2532, 863, 924, 9, 2877, 382, 4659, 4902, 1579, 5414, 1817, 3783, 3723, 5352, 946, 3469, 802, 1833, 3690, 5768, 851, 3704, 4356, 3336, 958, 4533, 2204, 3621, 3316, 5201, 2058, 5550, 3416, 2390, 3924, 3525, 1661, 4290, 4283, 1165, 5577, 807, 5974, 1714, 119, 1959, 5870, 56, 3352, 4489, 430, 3748, 2931, 3050, 1124, 3507, 275, 5977, 2040, 4914, 1275, 2686, 2750, 3834, 6007, 6457, 5932, 5953, 1193, 1016, 2326, 5378, 5967, 2953, 5299, 3712, 1140, 961, 2735, 3039, 4436, 4845, 4794, 6359, 1237, 5446, 6256, 1885, 153, 5118, 2377, 4800, 5971, 3886, 5627, 317, 4716, 4958, 6334, 4123, 3606, 2910, 311, 106, 4335, 1933, 5631, 1461, 2424, 5609, 4598, 3501, 4699, 1029, 4629, 5244, 773, 1659, 3527, 4569, 3308, 90, 3524, 4013, 2391, 4477, 973, 5128, 2935, 110, 5236, 3428, 3295, 697, 6174, 6164, 1720, 4173, 2287, 3286, 4524, 604, 5325, 1738, 4837, 331, 5357, 3603, 6392, 6387, 5761, 5804, 4827, 1897, 4517, 2292, 6169, 1533, 981, 1156, 5626, 3954, 5972, 809, 4312, 3238, 1850, 3775, 2665, 5000, 5991, 6268, 1225, 5700, 5369, 3360, 1136, 4905, 5408, 630, 6050, 2920, 5206, 212, 5403, 445, 787, 4564, 4369, 2069, 4076, 6225, 5384, 4420, 6250, 6087, 1814, 5312, 3681, 4928, 6068, 2809, 5536, 4280, 6273, 6438, 5845, 5341, 478, 205, 286, 5996, 6006, 3984, 2751, 2029, 5438, 322, 4241, 3402, 1122, 3052, 835, 5030, 3486, 4992, 4995, 1639, 2307, 4682, 2098, 3255, 2842, 5581, 1306, 2335, 1052, 6059, 6329, 5131, 2695, 2592, 1472, 3153, 1272, 6293, 4817, 5261, 575, 47, 1516, 1184, 5493, 4582, 5182, 5139, 5649, 6400, 6096, 4702, 218, 5195, 2485, 3722, 4036, 1818, 1009, 797, 489, 4103, 1339, 2664, 3880, 1851, 1704, 5427, 3311, 3765, 5215, 4423, 3129, 5214, 3770, 3312, 2840, 3257, 1152, 75, 347, 6210, 5397, 6296, 5424, 132, 51, 2412, 5830, 2786, 2930, 3996, 431, 1623, 4502, 3544, 1486, 729, 916, 1591, 3637, 4687, 5509, 2502, 3433, 3375, 2166, 3571, 6000, 6071, 5382, 6227, 4680, 2309, 3067, 5351, 4035, 3784, 2486, 2638, 4443, 6289, 4710, 5467, 2281, 1576, 1139, 3972, 5300, 5652, 3478, 1596, 687, 4277, 4355, 4026, 852, 4383, 5122, 5328, 1941, 2155, 1620, 2354, 6111, 5694, 1012, 2821, 5767, 4029, 1834, 6277, 6033, 640, 2721, 3542, 4504, 4927, 3849, 5313, 847, 2362, 2382, 6213, 2908, 3608, 5605, 2061, 1427, 6403, 6373, 5595, 1845, 5065, 5250, 469, 402, 2625, 936, 5068, 4721, 4158, 5035, 4247, 5059, 5558, 3588, 6105, 5458, 2779, 705, 1828, 3601, 5359, 2339, 5987, 6216, 1664, 2043, 2152, 5476, 4686, 3739, 1592, 5126, 975, 2019, 3158, 2708, 3215, 2656, 891, 1926, 6031, 6279, 717, 4450, 3315, 4020, 2205, 1730, 4635, 196, 35, 5362, 189, 755, 379, 4730, 3283, 5604, 3674, 2909, 3947, 4124, 6391, 3900, 5358, 3647, 1829, 2973, 2080, 341, 647, 6461, 2428, 6090, 1743, 3513, 5147, 6104, 3653, 5559, 4772, 3490, 5876, 122, 2176, 4607, 339, 2082, 3193, 1327, 6432, 5422, 6298, 2234, 5999, 3732, 2167, 1417, 3289, 1367, 1469, 482, 257, 2796, 2864, 2525, 6161, 6450, 683, 665, 1646, 902, 3007, 6144, 420, 2605, 1266, 1724, 5259, 4819, 4397, 1485, 3744, 4503, 3684, 2722, 2476, 3422, 140, 1342, 2552, 6362, 1453, 5959, 6230, 6065, 5174, 1081, 4568, 3929, 1660, 4012, 3925, 91, 4054, 4612, 1911, 503, 2497, 1173, 5732, 3276, 5146, 3591, 1744, 3077, 1686, 4495, 274, 3992, 1125, 25, 1037, 3302, 4698, 3936, 4599, 4641, 2872, 4392, 6172, 699, 4981, 3493, 4982, 5875, 3585, 4773, 3370, 4991, 3823, 5031, 4856, 3046, 4961, 4665, 1734, 1595, 3709, 5653, 660, 5187, 1208, 5898, 931, 5797, 801, 4032, 947, 4975, 3453, 5568, 2917, 328, 3414, 5552, 390, 1810, 1571, 4338, 4343, 5689, 5567, 3466, 4976, 3243, 1524, 5864, 3167, 1775, 5210, 634, 2359, 6205, 3212, 5321, 4572, 1956, 5879, 3083, 856, 5481, 3374, 3735, 2503, 2036, 450, 3294, 3916, 5237, 1614, 2988, 1511, 139, 3539, 2477, 5348, 2645, 5637, 2389, 4015, 5551, 3462, 329, 4839, 3300, 1039, 5948, 151, 1887, 1291, 4161, 2746, 1121, 3828, 4242, 3206, 456, 5634, 1443, 1190, 4726, 2960, 4786, 125, 209, 5821, 591, 3034, 5616, 5159, 4155, 5076, 615, 2253, 6181, 6179, 2255, 1204, 2264, 2165, 3734, 3434, 5482, 546, 4990, 3488, 4774, 6055, 3174, 5776, 2149, 5589, 965, 3146, 1135, 3872, 5370, 5229, 5485, 1021, 813, 4068, 4488, 3999, 57, 6244, 6356, 231, 30, 4099, 769, 1104, 2047, 2704, 1258, 5170, 251, 569, 957, 4024, 4357, 5255, 764, 5565, 5691, 1507, 4256, 4302, 5056, 5505, 3109, 5337, 2145, 2095, 2006, 1379, 4998, 2667, 5200, 4019, 3622, 4451, 2839, 3764, 3771, 5428, 89, 3927, 4570, 5323, 606, 3023, 4697, 3503, 1038, 3411, 4840, 415, 3104, 696, 3915, 3429, 451, 6012, 5013, 1366, 3568, 1418, 4523, 3908, 2288, 5603, 3610, 4731, 1636, 1382, 4388, 2893, 5145, 3515, 5733, 169, 691, 2305, 1641, 751, 5601, 2290, 4519, 2228, 3071, 6016, 1530, 4395, 4821, 265, 3029, 1151, 3762, 2841, 3816, 2099, 4252, 393, 1253, 224, 4074, 2071, 2251, 617, 5108, 1523, 3451, 4977, 1177, 5751, 1849, 3882, 4313, 6468, 3, 2158, 2589, 4622, 720, 5294, 1494, 3020, 4948, 1363, 5854, 4220, 4400, 2397, 6247, 5218, 6078, 2219, 4372, 2655, 3630, 2709, 5320, 3442, 6206, 1650, 2076, 4941, 455, 3400, 4243, 1952, 4181, 870, 5720, 4830, 4166, 5780, 6302, 738, 2956, 1326, 3578, 2083, 5089, 4835, 1740, 2861, 868, 4183, 2563, 1948, 5053, 2903, 5105, 1458, 459, 6020, 3042, 2556, 5775, 3367, 6056, 1631, 3060, 5433, 2968, 1774, 3448, 5865, 1148, 1901, 2544, 6382, 1043, 2700, 2707, 3632, 2020, 2849, 2452, 1271, 3804, 1473, 5092, 4465, 4376, 4326, 1134, 3362, 966, 1415, 2169, 2215, 4964, 780, 906, 5707, 1216, 2114, 2447, 5514, 5902, 6220, 1301, 5213, 3767, 4424, 5367, 5702, 2372, 6441, 6240, 115, 227, 6414, 2472, 1983, 2403, 5658, 5450, 986, 1242, 1101, 2599, 5336, 3325, 5506, 882, 4322, 695, 3297, 416, 1697, 2983, 1481, 5925, 989, 3037, 2737, 4306, 4207, 5267, 4216, 292, 290, 4218, 5856, 1395, 2316, 1312, 855, 3437, 5880, 650, 6262, 6346, 1685, 3511, 1745, 5281, 5028, 837, 6015, 3265, 2229, 2643, 5350, 3725, 2310, 5180, 4584, 6320, 523, 5432, 3171, 1632, 6142, 3009, 920, 2456, 4082, 834, 3826, 1123, 3994, 2932, 6332, 4960, 3483, 4857, 1234, 2555, 3177, 6021, 4435, 3968, 2736, 3097, 990, 5615, 3388, 592, 4515, 1899, 1150, 3259, 266, 4112, 5837, 1261, 4696, 3304, 607, 4947, 3228, 1495, 3005, 904, 782, 2128, 2133, 4900, 4661, 6081, 919, 3057, 6143, 3554, 903, 3018, 1496, 5524, 2439, 5670, 674, 5540, 573, 5263, 1284, 5811, 818, 2762, 4876, 4737, 1806, 1510, 3425, 1615, 1440, 2648, 1480, 3101, 1698, 2886, 596, 1489, 2978, 1490, 5772, 299, 2079, 3599, 1830, 1872, 2535, 1773, 3169, 5434, 6446, 5346, 2479, 6197, 1976, 4785, 3394, 4727, 2880, 1325, 3195, 739, 5298, 3974, 5968, 4560, 1859, 2417, 6380, 2546, 2459, 4811, 2542, 1903, 5390, 1297, 406, 241, 512, 5018, 109, 3919, 5129, 6331, 3049, 3995, 3749, 2787, 1968, 2727, 4986, 2074, 1652, 1212, 4747, 5205, 3866, 6051, 327, 3464, 5569, 4825, 5806, 5788, 21, 310, 3946, 3607, 3675, 6214, 5989, 5002, 5104, 3182, 5054, 4304, 2739, 472, 4237, 173, 1049, 39, 5144, 3278, 4389, 6132, 1864, 4295, 6349, 595, 2981, 1699, 912, 2818, 367, 1324, 2958, 4728, 381, 4043, 10, 5824, 6130, 4391, 3498, 4642, 2824, 1113, 2571, 80, 2347, 2524, 3562, 2797, 867, 3188, 1741, 6092, 5716, 6282, 1109, 6436, 6275, 1836, 4741, 4266, 2451, 3156, 2021, 5754, 192, 440, 4545, 5580, 3815, 3256, 3763, 3313, 4452, 5496, 1345, 4879, 2732, 1785, 995, 4319, 4428, 4807, 255, 484, 4132, 1112, 2870, 4643, 5766, 3692, 1013, 366, 2883, 913, 1412, 2224, 1436, 2313, 1750, 1403, 5535, 3846, 6069, 6002, 1221, 1406, 4626, 876, 98, 68, 5044, 4410, 866, 2863, 3563, 258, 4089, 4109, 5624, 1158, 2622, 1544, 1967, 2929, 3750, 5831, 438, 194, 4637, 2442, 704, 3650, 5459, 777, 360, 4117, 4851, 4316, 4530, 1143, 1349, 2088, 5619, 2445, 2116, 2194, 5784, 4875, 2993, 819, 1171, 2499, 5332, 4895, 4190, 1004, 1761, 182, 2028, 3833, 3985, 2687, 2436, 1120, 3404, 4162, 1791, 244, 1089, 400, 471, 2900, 4305, 3096, 3038, 3969, 962, 1784, 2834, 4880, 5555, 5742, 4985, 2927, 1969, 4848, 6040, 2475, 3541, 3685, 641, 4059, 6420, 6339, 1047, 175, 1074, 261, 6124, 6396, 5319, 3214, 3631, 3159, 2701, 1257, 3342, 2048, 1256, 2706, 3160, 1044, 4767, 4620, 2591, 3807, 5132, 2368, 5982, 5674, 5462, 4653, 2435, 2749, 3986, 1276, 6253, 1769, 375, 71, 822, 1332, 1289, 1889, 978, 5287, 4955, 6424, 5896, 1210, 1654, 178, 5199, 3318, 4999, 3879, 3776, 1340, 142, 412, 5419, 4136, 5165, 890, 3629, 3216, 4373, 1789, 4164, 4832, 1476, 1479, 2985, 1441, 5636, 3419, 5349, 3069, 2230, 6149, 1033, 4442, 3720, 2487, 465, 475, 6185, 6266, 5993, 1130, 626, 33, 198, 2191, 935, 3662, 403, 1543, 2790, 1159, 4657, 384, 221, 2051, 1087, 246, 2395, 4402, 2102, 1907, 5684, 6026, 1068, 6259, 1265, 3551, 421, 5841, 1063, 1566, 5335, 3111, 1102, 771, 5246, 203, 480, 1471, 3806, 2696, 4621, 3233, 2159, 5662, 499, 2517, 845, 5315, 5490, 4938, 302, 4179, 1954, 4574, 1644, 667, 710, 84, 79, 2868, 1114, 6140, 1634, 4733, 1146, 5867, 1947, 3185, 4184, 2298, 4751, 307, 297, 5774, 3176, 3043, 1235, 6361, 3536, 1343, 5498, 1994, 4080, 2458, 2947, 6381, 3163, 1902, 2944, 4812, 5698, 1227, 1842, 5442, 1772, 2970, 1873, 862, 4047, 5010, 840, 4538, 2136, 6365, 6160, 3561, 2865, 2348, 137, 1513, 1755, 6154, 844, 2585, 500, 1671, 4094, 1353, 6318, 4586, 215, 1025, 5234, 112, 1677, 1626, 2035, 3432, 3736, 5510, 5331, 2759, 1172, 3518, 504, 1093, 4145, 5455, 5278, 518, 539, 14, 464, 2637, 3721, 3785, 5196, 1557, 4431, 494, 6196, 2964, 5347, 3421, 3540, 2723, 6041, 1982, 3119, 6415, 601, 4512, 6352, 4757, 497, 5664, 894, 5306, 2188, 2181, 4810, 2946, 2547, 4081, 3055, 921, 4413, 1270, 3155, 2850, 4267, 1938, 5513, 3135, 2115, 2767, 5620, 703, 2781, 4638, 5669, 3002, 5525, 1119, 2748, 2688, 4654, 1057, 4892, 1569, 1812, 6089, 3594, 6462, 5547, 5608, 3939, 1462, 4148, 827, 354, 1336, 6379, 2949, 1860, 4972, 1320, 5829, 3752, 52, 624, 1132, 4328, 4924, 5889, 4363, 5657, 3117, 1984, 5470, 4755, 6354, 6246, 3222, 4401, 2614, 247, 5921, 4476, 3923, 4014, 3417, 5638, 508, 4650, 1990, 5395, 6212, 3677, 2363, 5918, 4933, 4799, 3957, 5119, 1061, 5843, 6440, 3125, 5703, 5162, 5981, 2693, 5133, 94, 759, 5917, 2381, 3678, 848, 6204, 3444, 635, 6308, 4462, 6110, 3696, 1621, 433, 5724, 1400, 136, 2523, 2866, 81, 1759, 1006, 4484, 4193, 4615, 5986, 3645, 5360, 37, 1051, 3812, 1307, 492, 4433, 6023, 1612, 5239, 2111, 5377, 3977, 1017, 5008, 4049, 5645, 528, 4866, 5563, 766, 1311, 3086, 1396, 1749, 2813, 1437, 5179, 3066, 3726, 4681, 3819, 1640, 3272, 692, 1881, 5680, 4864, 530, 4750, 2561, 4185, 5086, 1583, 427, 6168, 3892, 4518, 3268, 5602, 3285, 3909, 4174, 1386, 2163, 2266, 1575, 3715, 5468, 1986, 4129, 1857, 4562, 789, 1609, 5687, 4345, 1936, 4269, 1681, 1930, 1574, 2283, 2164, 3377, 1205, 104, 313, 64, 1316, 6063, 6232, 1203, 3379, 6180, 3382, 616, 3247, 2072, 4988, 548, 1997, 5862, 1526, 1668, 1914, 2013, 1702, 1853, 1374, 5374, 1219, 6004, 5998, 3573, 6299, 5748, 6148, 2642, 3070, 3266, 4520, 158, 1435, 2815, 1413, 968, 2067, 4371, 3218, 6079, 4663, 4963, 3142, 2170, 4262, 1066, 6028, 4300, 4258, 5406, 4907, 1729, 3620, 4021, 4534, 4201, 4791, 1972, 622, 54, 5872, 5745, 5783, 2765, 2117, 934, 2627, 199, 2180, 2462, 5307, 4439, 1248, 567, 253, 4809, 2461, 2189, 200, 940, 4606, 3582, 123, 4788, 4543, 442, 4261, 2214, 3143, 1416, 3570, 3733, 3376, 2265, 2284, 1387, 1765, 5661, 2588, 3234, 4, 1619, 3698, 1942, 5475, 3640, 2044, 5588, 3365, 5777, 4592, 2094, 3323, 5338, 4063, 1548, 6074, 4604, 942, 1451, 6364, 2528, 4539, 4899, 3014, 2129, 4341, 4340, 2132, 3015, 783, 4199, 4536, 842, 6156, 6409, 1188, 1445, 5795, 933, 2193, 2766, 2446, 3136, 1217, 5376, 2328, 5240, 581, 4066, 815, 6344, 6264, 6187, 1906, 2612, 4403, 4251, 3254, 3817, 4683, 2005, 3322, 2146, 4593, 6371, 6405, 5157, 5618, 2769, 1350, 5412, 1581, 5088, 3192, 3579, 340, 3598, 2974, 300, 4940, 3209, 1651, 2925, 4987, 2250, 3248, 4075, 3858, 4370, 2221, 969, 4555, 4460, 6310, 1426, 3672, 5606, 5549, 4017, 5202, 533, 5585, 1107, 6284, 1086, 2617, 222, 1255, 2703, 3343, 1105, 5587, 2151, 3641, 1665, 4913, 3989, 5978, 4139, 449, 3431, 2504, 1627, 1163, 4285, 5224, 5437, 3832, 2752, 183, 5764, 4645, 5063, 1847, 5753, 2848, 3157, 3633, 976, 1891, 1603, 910, 1701, 2242, 1915, 4407, 162, 4115, 362, 1378, 3321, 2096, 4684, 5478, 237, 5270, 234, 859, 5861, 2247, 549, 4079, 2549, 5499, 5544, 5394, 2385, 4651, 5464, 4128, 2279, 5469, 2402, 3118, 2473, 6042, 305, 4753, 5472, 4784, 2962, 6198, 742, 621, 2200, 4792, 4847, 2726, 2928, 2788, 1545, 584, 146, 578, 4781, 1945, 5869, 4002, 120, 5878, 3439, 4573, 2578, 4180, 3204, 4244, 6314, 5052, 3184, 2564, 5868, 1961, 4782, 5474, 2154, 3699, 5329, 5512, 2449, 4268, 2271, 4346, 5630, 3942, 4336, 1573, 2268, 1682, 4298, 6030, 3627, 892, 5666, 4602, 6076, 5220, 955, 571, 5542, 5501, 4406, 2012, 2243, 1669, 502, 3520, 4613, 4195, 5683, 2611, 2103, 6188, 5389, 2943, 2543, 3164, 1149, 3031, 4516, 3894, 4828, 5722, 435, 4969, 1602, 2017, 977, 2677, 1290, 3407, 152, 3960, 6257, 1070, 5679, 2303, 693, 4324, 4378, 101, 5190, 5859, 861, 2534, 2971, 1831, 804, 4548, 396, 4331, 5530, 4294, 2890, 6133, 1600, 4971, 2416, 2950, 4561, 2277, 4130, 486, 1373, 2240, 1703, 3774, 3881, 3239, 5752, 2023, 5064, 3667, 5596, 5441, 2538, 1228, 1693, 4763, 5815, 4740, 2853, 6276, 3689, 4030, 803, 1871, 2972, 3600, 3648, 706, 4446, 1409, 732, 4677, 5962, 4085, 4482, 1008, 3782, 4037, 5415, 5311, 3851, 6088, 2430, 1570, 3459, 391, 4254, 1509, 2990, 4738, 5817, 1778, 1330, 824, 5945, 681, 6452, 5710, 556, 5738, 4648, 510, 243, 2744, 4163, 2653, 4374, 4467, 994, 2833, 2733, 963, 5591, 5049, 6430, 1329, 1803, 5818, 5209, 3447, 3168, 2969, 2536, 5443, 374, 2683, 6254, 5448, 5660, 2161, 1388, 1554, 181, 2754, 1005, 2345, 82, 712, 6153, 2520, 1514, 49, 134, 1402, 2812, 2314, 1397, 516, 5280, 3076, 3512, 3592, 6091, 2860, 3189, 4836, 3904, 5326, 5124, 1594, 3480, 4666, 655, 4634, 3619, 2206, 4908, 462, 16, 5258, 3549, 1267, 5940, 4172, 3911, 6165, 4492, 1000, 4071, 118, 4004, 5975, 277, 4953, 5289, 4777, 4632, 657, 130, 5426, 3773, 1852, 2241, 2014, 911, 2885, 2982, 3102, 417, 1181, 4762, 1840, 1229, 5892, 4509, 4527, 998, 4494, 3510, 3078, 6347, 4297, 1929, 2269, 4270, 4500, 1625, 2506, 113, 6242, 59, 1537, 4093, 2515, 501, 1913, 2244, 1527, 4912, 2042, 3642, 6217, 4289, 4011, 3526, 3930, 774, 5677, 1072, 177, 2670, 1211, 2924, 2075, 3210, 6207, 1360, 901, 3556, 666, 2576, 4575, 750, 3271, 2306, 3820, 4996, 1381, 3281, 4732, 2568, 6141, 3059, 3172, 6057, 1054, 1162, 2034, 2505, 1678, 4501, 3746, 432, 2353, 3697, 2156, 5, 5177, 1439, 2987, 3426, 5238, 2330, 6024, 5686, 2274, 790, 4170, 5942, 4151, 909, 2016, 1892, 4970, 1862, 6134, 5911, 686, 3708, 3479, 1735, 5125, 3636, 3740, 917, 6083, 5080, 5642, 6119, 5935, 426, 2295, 5087, 2085, 5413, 4039, 4903, 1138, 3714, 2282, 2267, 1931, 4337, 3458, 1811, 2431, 4893, 5334, 2601, 1064, 4264, 4743, 6010, 453, 4943, 4805, 4430, 2483, 5197, 180, 1763, 1389, 831, 5965, 5380, 6073, 2142, 4064, 583, 1966, 2789, 2623, 404, 1299, 6222, 552, 4092, 1673, 60, 5285, 980, 3890, 6170, 4394, 3263, 6017, 4911, 1667, 2245, 5863, 3450, 3244, 5109, 5572, 1466, 6193, 4760, 1183, 3797, 48, 1754, 2521, 138, 3424, 2989, 1807, 4255, 3330, 5692, 6113, 638, 6035, 4578, 4870, 4610, 4056, 5152, 5523, 3004, 3019, 3229, 5295, 6201, 5771, 2977, 2979, 597, 728, 3743, 3545, 4398, 4222, 5924, 3100, 2984, 2649, 1477, 1478, 2650, 4833, 5091, 3152, 3805, 2593, 481, 3566, 1368, 6192, 1520, 5573, 5453, 4147, 2423, 3940, 5632, 458, 3180, 5106, 619, 744, 5958, 3534, 6363, 2138, 943, 345, 77, 86, 5794, 2120, 1189, 3397, 5635, 2647, 2986, 1616, 5178, 2312, 2814, 2225, 159, 5047, 5593, 6375, 5714, 6094, 6402, 3671, 2062, 6311, 5038, 879, 4690, 42, 156, 4522, 3288, 3569, 2168, 3144, 967, 2223, 2816, 914, 731, 1825, 4447, 4625, 2805, 1222, 5534, 2811, 1751, 135, 2350, 5725, 515, 1748, 2315, 3087, 5857, 5192, 387, 4883, 830, 1553, 1764, 2162, 2285, 4175, 4889, 4387, 3280, 1637, 4997, 3320, 2007, 363, 1196, 5373, 2239, 1854, 487, 799, 5799, 6191, 1468, 3567, 3290, 5014, 5853, 3226, 4949, 900, 1648, 6208, 349, 521, 6322, 6427, 6317, 2513, 4095, 5411, 2087, 2770, 1144, 4735, 4878, 2836, 5497, 2551, 3537, 141, 2663, 3777, 4104, 6378, 2419, 355, 166, 1288, 2679, 823, 1802, 1779, 6431, 3577, 3194, 2957, 2881, 368, 6137, 5828, 2414, 4973, 949, 6062, 2259, 65, 4381, 854, 3085, 2317, 767, 4101, 491, 2334, 3813, 5582, 6048, 632, 5212, 3131, 6221, 1541, 405, 2941, 5391, 6465, 4854, 5033, 4160, 3406, 1888, 2678, 1333, 167, 5735, 5810, 2996, 5264, 6369, 4595, 613, 5078, 6085, 6252, 2685, 3987, 4915, 6292, 3803, 3154, 2453, 4414, 5939, 1723, 3550, 2606, 6260, 652, 4695, 3025, 5838, 5169, 3341, 2705, 2702, 2049, 223, 3251, 394, 4550, 5517, 566, 2185, 4440, 1035, 27, 5273, 1100, 3113, 987, 5927, 372, 5445, 3963, 6360, 2554, 3044, 4858, 4142, 4361, 5891, 1692, 1841, 2539, 5699, 3875, 6269, 5533, 1405, 2806, 6003, 2237, 5375, 2113, 3137, 5708, 6454, 4746, 2923, 1653, 2671, 5897, 3474, 5188, 103, 2263, 3378, 2256, 6233, 4470, 6238, 6443, 5227, 5372, 1376, 364, 1015, 3979, 5954, 4725, 3396, 1444, 2121, 6410, 4936, 5492, 3796, 1517, 4761, 1695, 418, 6146, 5750, 3241, 4978, 271, 5731, 3517, 2498, 2760, 820, 73, 1154, 983, 5576, 4008, 4284, 2033, 1628, 1055, 4656, 2621, 2791, 5625, 3888, 982, 1168, 74, 3761, 3258, 3030, 1900, 3165, 5866, 2566, 4734, 1348, 2771, 4531, 960, 3971, 3713, 1577, 4904, 3871, 3361, 3147, 4327, 2409, 625, 2631, 5994, 288, 294, 24, 3506, 3993, 3051, 3827, 3403, 2747, 2437, 5526, 6128, 5826, 6139, 2570, 2869, 2825, 4133, 6435, 2856, 6283, 2054, 5586, 2046, 3344, 770, 2598, 3112, 1243, 5274, 5096, 4233, 5253, 4359, 4144, 2495, 505, 4921, 399, 2742, 245, 2616, 2052, 6285, 670, 282, 4567, 3529, 5175, 7, 926, 4480, 4087, 260, 2714, 176, 1656, 5678, 1883, 6258, 2608, 6027, 2212, 4263, 1565, 2602, 5842, 2375, 5120, 4385, 4891, 2433, 4655, 1161, 1629, 6058, 3811, 2336, 38, 2896, 174, 2716, 6340, 4766, 2699, 3161, 6383, 679, 5947, 3410, 3301, 3504, 26, 1246, 4441, 2640, 6150, 874, 4628, 3934, 4700, 6098, 5233, 2509, 216, 4704, 812, 3356, 5486, 897, 5007, 2325, 3978, 1194, 365, 2820, 3693, 5695, 796, 3781, 1819, 4483, 2344, 1760, 2755, 4191, 4486, 4070, 1717, 4493, 1688, 4528, 4318, 2832, 1786, 4468, 6235, 5614, 3036, 3098, 5926, 1241, 3114, 5451, 5575, 1167, 1155, 3889, 1534, 5286, 2676, 1890, 2018, 3634, 5127, 3921, 4478, 928, 4554, 2066, 2222, 1414, 3145, 3363, 5590, 1783, 2734, 3970, 1141, 4532, 4023, 3337, 570, 1920, 5221, 5906, 5885, 6327, 6061, 1318, 4974, 3468, 4033, 5353, 344, 1450, 2139, 4605, 2178, 201, 5248, 5067, 3661, 2626, 2192, 2118, 5796, 3472, 5899, 4553, 971, 4479, 1078, 8, 4045, 864, 4412, 2455, 3056, 3010, 6082, 1590, 3741, 730, 1411, 2817, 2884, 1700, 2015, 1604, 4152, 5706, 3139, 781, 3017, 3006, 3555, 1647, 1361, 4950, 5006, 1019, 5487, 5305, 2464, 5665, 1925, 3628, 2657, 5166, 424, 5937, 4416, 5365, 4426, 4321, 3107, 5507, 4689, 1423, 5039, 97, 2803, 4627, 1031, 6151, 714, 5719, 3202, 4182, 3187, 2862, 2798, 4411, 923, 4046, 2533, 1874, 5860, 1999, 235, 5480, 3436, 3084, 1313, 4382, 3703, 4027, 5769, 6203, 2361, 3679, 5314, 2584, 2518, 6155, 2124, 4537, 2530, 5011, 6014, 3073, 5029, 3825, 3053, 4083, 5964, 1552, 1390, 4884, 353, 2421, 4149, 5944, 1801, 1331, 2680, 72, 1170, 2761, 2994, 5812, 6343, 2107, 4067, 3355, 1022, 4705, 4311, 3884, 5973, 4006, 5578, 4547, 1870, 1832, 4031, 3470, 5798, 1371, 488, 3780, 1010, 5696, 4814, 5400, 4589, 4169, 1608, 2275, 4563, 3861, 446, 4861, 4198, 2127, 3016, 905, 3140, 4965, 359, 2777, 5460, 5676, 1658, 3931, 5245, 2597, 1103, 3345, 4100, 1310, 2318, 5564, 3333, 5256, 18, 4674, 5916, 2365, 95, 5041, 378, 3613, 190, 5756, 5600, 3270, 1642, 4576, 6037, 4120, 5072, 5957, 1455, 620, 1974, 6199, 5297, 2955, 3196, 6303, 5185, 662, 5914, 4676, 1824, 1410, 915, 3742, 1487, 598, 4275, 689, 171, 4239, 324, 5293, 3231, 4623, 4449, 3624, 6280, 5718, 872, 6152, 1757, 83, 2574, 668, 6287, 4445, 1827, 3649, 2780, 2443, 5621, 269, 4980, 3495, 6173, 3914, 3296, 3105, 4323, 1880, 2304, 3273, 170, 725, 4276, 3707, 1597, 5912, 664, 3558, 6451, 1799, 5946, 1041, 6384, 5025, 4352, 5539, 3000, 5671, 5101, 281, 1084, 6286, 709, 2575, 1645, 3557, 684, 5913, 735, 5186, 3476, 5654, 129, 1707, 4633, 1732, 4667, 4694, 1263, 6261, 3081, 5881, 6460, 3596, 342, 5355, 333, 5150, 4058, 2720, 3686, 6034, 1504, 6114, 6307, 2358, 3445, 5211, 1303, 6049, 3868, 5409, 4097, 32, 2630, 1131, 2410, 53, 2199, 1973, 743, 1456, 5107, 3246, 2252, 3383, 5077, 1280, 4596, 5611, 4473, 4225, 4946, 3022, 3305, 5324, 3906, 4525, 4511, 2470, 6416, 4274, 727, 1488, 2980, 2887, 6350, 4514, 3033, 3389, 5822, 12, 541, 564, 5519, 145, 1965, 1546, 4065, 2109, 5241, 4780, 1963, 147, 46, 3799, 5262, 2998, 5541, 1919, 956, 3338, 252, 2184, 1249, 5518, 587, 542, 6101, 336, 4873, 5786, 5808, 5737, 1796, 5711, 4107, 4091, 1539, 6223, 4078, 1996, 2248, 4989, 3372, 5483, 5231, 6100, 563, 588, 13, 2490, 519, 351, 4886, 6046, 5584, 2056, 5203, 4749, 2300, 4865, 2321, 5646, 4671, 5791, 5431, 3062, 6321, 1357, 350, 538, 2491, 5279, 1747, 1398, 5726, 5017, 2938, 242, 1793, 4649, 2387, 5639, 4920, 1092, 2496, 3519, 1912, 1670, 2516, 2586, 5663, 2466, 4758, 6195, 2481, 4432, 2333, 1308, 4102, 3779, 798, 1372, 1855, 4131, 2827, 256, 3565, 1470, 2594, 204, 3839, 5342, 6184, 2635, 466, 4236, 2899, 2740, 401, 3664, 5251, 4235, 474, 2636, 2488, 15, 1727, 4909, 6019, 3179, 1459, 5633, 3399, 3207, 4942, 1561, 6011, 3293, 3430, 2037, 4140, 4860, 786, 3862, 5404, 4260, 2172, 4544, 2845, 193, 2784, 5832, 4968, 1894, 5723, 2352, 1622, 3747, 3997, 4490, 6167, 2294, 1584, 5936, 888, 5167, 5840, 2604, 3552, 6145, 1180, 1696, 3103, 3298, 4841, 5418, 2661, 143, 5521, 5154, 4213, 240, 2940, 1298, 1542, 2624, 3663, 470, 2741, 1090, 4922, 4330, 1868, 4549, 1252, 3252, 4253, 1809, 3460, 5553, 4882, 1392, 5193, 220, 2619, 4658, 4042, 2878, 4729, 3612, 756, 5042, 70, 2682, 1770, 5444, 1239, 5928, 5909, 6136, 1323, 2882, 2819, 1014, 1195, 1377, 2008, 4116, 2776, 778, 4966, 5834, 165, 1335, 2420, 828, 4885, 537, 520, 1358, 6209, 3759, 76, 1449, 944, 5354, 646, 3597, 2081, 3580, 4608, 4872, 561, 6102, 5149, 644, 5356, 3902, 4838, 3413, 3463, 2918, 6052, 5292, 722, 4240, 3830, 5439, 5598, 5758, 4715, 3952, 5628, 4348, 63, 2261, 105, 3945, 2911, 22, 296, 2559, 4752, 1980, 6043, 4178, 2580, 4939, 2078, 2975, 5773, 2558, 308, 23, 1127, 289, 3091, 4217, 3090, 293, 1128, 5995, 3837, 206, 4367, 4566, 1083, 671, 5102, 5004, 4952, 1712, 5976, 3991, 3508, 4496, 5730, 1175, 4979, 701, 5622, 4111, 3028, 3260, 4822, 5112, 6123, 2713, 1075, 4088, 2795, 3564, 483, 2828, 4808, 2183, 568, 3339, 5171, 4931, 5920, 2394, 2615, 1088, 2743, 1792, 511, 2939, 407, 4214, 5269, 2002, 5479, 858, 2000, 5271, 29, 3348, 6357, 4796, 6413, 3121, 116, 4073, 3250, 1254, 2050, 2618, 385, 5194, 3787, 4703, 1024, 2510, 4587, 5402, 3864, 5207, 5820, 3391, 126, 4366, 285, 3838, 479, 2595, 5247, 939, 2179, 2190, 2628, 34, 3617, 4636, 2783, 439, 2846, 5755, 754, 3614, 5363, 4418, 5386, 5802, 5763, 2027, 2753, 1762, 1555, 5198, 2669, 1655, 1073, 2715, 1048, 2897, 4238, 724, 690, 3274, 5734, 1287, 1334, 356, 5835, 4114, 2010, 4408, 5046, 1434, 2226, 4521, 1420, 43, 5117, 3959, 1886, 3408, 5949, 5115, 45, 577, 1964, 585, 5520, 411, 2662, 1341, 3538, 3423, 1512, 2522, 2349, 1401, 1752, 50, 3754, 5425, 1706, 658, 5655, 4365, 208, 3392, 4787, 2175, 3583, 5877, 1958, 4003, 1715, 4072, 226, 3122, 6241, 1676, 2507, 5235, 3918, 2936, 5019, 4334, 3944, 312, 2262, 1206, 5189, 1877, 4379, 67, 2802, 877, 5040, 758, 2366, 5134, 4053, 3523, 3926, 3309, 5429, 5793, 1447, 78, 2573, 711, 1758, 2346, 2867, 2572, 85, 1448, 346, 3760, 1153, 1169, 821, 2681, 376, 5043, 2801, 99, 4380, 1315, 2260, 314, 4349, 5284, 1536, 1674, 6243, 3351, 4000, 5871, 2198, 623, 2411, 3753, 133, 1753, 1515, 3798, 576, 148, 5116, 155, 1421, 4691, 5143, 2895, 1050, 2337, 5361, 3616, 197, 2629, 627, 4098, 3347, 232, 5272, 1245, 1036, 3505, 1126, 295, 309, 2912, 5789, 4673, 762, 5257, 1726, 463, 2489, 540, 589, 5823, 2876, 4044, 925, 1079, 5176, 1618, 2157, 3235, 6469]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..538a527c9917f49545828bd6d4237db40289419e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 6469, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b54b70fd31aeaeba854b1934846f1526e8dbe50 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 4801, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c0be5bdf9c4487b64ceffc4b129c2b9f9e30d499 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 2402, 3202, 3602, 3842, 4002, 687, 4202, 1068, 4322, 874, 4402, 1109, 344, 4482, 4502, 3390, 2935, 4044, 4562, 1830, 2838, 836, 4602, 4610, 555, 1957, 2573, 1491, 4642, 1240, 4652, 292, 4096, 3979, 1468, 4283, 4423, 3571, 4682, 1172, 3316, 2569, 3820, 3095, 2819, 2044, 4702, 99, 4706, 2731, 278, 3715, 979, 2096, 1287, 2949, 746, 652, 4722, 1339, 3021, 2211, 4727, 2143, 2547, 2509, 4449, 3480, 1990, 3382, 3135, 2829, 2142, 4738, 2212, 3555, 1786, 1338, 4742, 653, 2987, 1852, 4059, 1639, 1285, 2098, 4311, 972, 1548, 1531, 1410, 414, 3423, 2730, 4752, 100, 50, 98, 4754, 2045, 1366, 3963, 2540, 1327, 1858, 1033, 490, 3833, 3449, 4629, 644, 3230, 1475, 168, 2774, 1191, 2727, 1171, 4762, 3572, 670, 3592, 1511, 1883, 1106, 2307, 2364, 857, 1072, 3446, 1274, 3322, 1255, 4233, 2225, 3996, 4141, 2177, 3396, 682, 4092, 2284, 1568, 299, 1415, 1634, 3472, 291, 4770, 1241, 3507, 911, 1778, 1209, 3294, 2111, 3070, 1239, 4772, 1492, 327, 325, 1494, 3900, 3327, 116, 2030, 3410, 820, 2584, 643, 4691, 3450, 2717, 2156, 218, 2887, 752, 3175, 1062, 766, 447, 3106, 3738, 2608, 1182, 1712, 2338, 3766, 554, 4777, 4603, 2451, 715, 2426, 4144, 2450, 4609, 4778, 837, 1023, 4329, 3084, 4076, 1982, 2761, 3671, 805, 664, 1571, 3330, 1128, 517, 2435, 2646, 178, 1917, 2544, 1725, 631, 2315, 367, 2723, 1580, 4016, 424, 738, 1804, 2485, 2786, 3788, 784, 596, 2330, 1364, 2047, 586, 1829, 4782, 4045, 4187, 3419, 2736, 1941, 4197, 312, 756, 618, 942, 2851, 2954, 4005, 1154, 547, 3583, 3924, 429, 4042, 2937, 700, 4124, 2867, 3038, 1704, 4062, 1925, 628, 1875, 2117, 1560, 1113, 511, 4399, 420, 2071, 53, 1089, 1739, 4099, 3401, 2742, 1443, 4447, 2511, 3543, 1540, 3185, 1330, 150, 34, 708, 1148, 3218, 3972, 4137, 3234, 146, 3389, 4786, 4483, 621, 3883, 1754, 2189, 456, 2034, 3290, 2922, 605, 248, 4048, 952, 1056, 443, 3936, 940, 620, 4501, 4787, 345, 3147, 4475, 164, 3310, 163, 4479, 3148, 4408, 4351, 3192, 1664, 3144, 2459, 2423, 3416, 2893, 4106, 4278, 2811, 1423, 3693, 15, 322, 1657, 2346, 2865, 4126, 3729, 1359, 1998, 3479, 4734, 2510, 4518, 1444, 391, 2777, 2903, 1588, 3246, 2932, 4392, 2784, 2487, 224, 2081, 3954, 1198, 4270, 3275, 3705, 3502, 2992, 3829, 3257, 4178, 3570, 4764, 4284, 2370, 2678, 3912, 2389, 1672, 2302, 3487, 1226, 3358, 358, 2027, 3614, 4350, 4473, 3149, 3626, 1428, 2305, 1108, 4790, 875, 419, 4528, 512, 3012, 2165, 3009, 3943, 2783, 4439, 2933, 3392, 94, 1381, 4212, 1836, 3927, 403, 276, 2733, 594, 786, 228, 4066, 2249, 2965, 878, 259, 762, 1218, 881, 3724, 4170, 2490, 3301, 959, 803, 3673, 4288, 863, 3746, 316, 868, 1158, 4036, 184, 1698, 1362, 2332, 3191, 4472, 4409, 3615, 2613, 307, 2770, 957, 3303, 3505, 1243, 4073, 3794, 2977, 4295, 2004, 2793, 3959, 2699, 1731, 3566, 3905, 3083, 4599, 1024, 1507, 2694, 2014, 915, 873, 4792, 1069, 2023, 498, 2094, 981, 1710, 1184, 3769, 109, 971, 4714, 2099, 3760, 2557, 2901, 2779, 484, 2710, 4167, 2872, 3240, 1426, 3628, 3878, 1370, 2003, 4338, 2978, 3689, 274, 405, 1792, 862, 4363, 3674, 215, 2369, 4422, 4765, 1469, 3816, 2751, 2810, 4463, 4107, 1434, 2898, 3920, 1081, 3253, 3274, 4432, 1199, 963, 3088, 2715, 3452, 938, 3938, 1059, 1625, 3181, 1955, 557, 3648, 256, 1221, 2200, 1750, 2611, 3617, 1036, 192, 27, 2847, 545, 1156, 870, 3153, 2050, 1995, 1701, 2943, 3772, 1607, 722, 780, 2224, 4667, 1256, 3339, 1772, 3386, 3171, 2915, 1593, 3712, 3066, 1535, 2476, 2323, 2418, 1648, 2755, 239, 2975, 3796, 4010, 1835, 4387, 1382, 2069, 422, 4018, 235, 2474, 1537, 1695, 1067, 4794, 688, 2242, 1880, 311, 4556, 1942, 2358, 3278, 3044, 1095, 2374, 2629, 2891, 3418, 4560, 4046, 250, 3862, 319, 303, 921, 2525, 3569, 4425, 3258, 2877, 269, 2929, 3077, 222, 2489, 4369, 3725, 2871, 4303, 2711, 2963, 2251, 1977, 2394, 2218, 173, 113, 1574, 4013, 2238, 1819, 2483, 1806, 4056, 60, 82, 1817, 2240, 690, 3975, 2449, 4605, 2427, 2176, 4664, 3997, 211, 3233, 4506, 3973, 692, 1230, 123, 1212, 1432, 4109, 3575, 1447, 3728, 4454, 2866, 4540, 701, 1406, 142, 712, 1681, 1847, 800, 8, 602, 2562, 656, 829, 668, 3574, 4130, 1433, 4277, 4464, 2894, 1865, 262, 680, 3398, 3400, 4522, 1740, 3978, 4768, 293, 3656, 2283, 4660, 683, 3123, 2351, 196, 2378, 1389, 3811, 1452, 2505, 3195, 567, 4024, 1349, 3867, 1981, 4597, 3085, 3793, 4341, 1244, 3541, 2513, 1645, 1041, 2248, 4378, 229, 3000, 1924, 4536, 1705, 1638, 4718, 1853, 59, 4152, 1807, 3897, 2206, 1915, 180, 1629, 951, 4490, 249, 4186, 4561, 4783, 2936, 4543, 430, 3586, 2606, 3740, 183, 4357, 1159, 1195, 2517, 3237, 2909, 3552, 2858, 1744, 2163, 3014, 1348, 4080, 568, 2580, 3800, 1014, 234, 4208, 423, 4576, 1581, 2237, 4157, 1575, 1834, 4214, 3797, 3115, 2169, 1153, 4549, 2955, 686, 4796, 3843, 438, 1131, 210, 4140, 4665, 2226, 2657, 3081, 3907, 3251, 1083, 2121, 1505, 1026, 1972, 2663, 1392, 171, 2220, 1691, 1467, 4767, 4097, 1741, 2448, 4146, 691, 4136, 4507, 3219, 3319, 854, 1964, 24, 202, 3781, 2539, 4699, 1367, 2039, 2698, 4335, 2794, 1643, 2515, 1197, 4434, 2082, 1125, 3527, 1483, 834, 2840, 2438, 130, 3732, 2782, 4394, 3010, 514, 441, 1058, 4263, 939, 4486, 444, 3646, 559, 1651, 3887, 480, 12, 402, 4385, 1837, 428, 4545, 3584, 432, 1080, 4274, 2899, 2559, 2925, 2835, 3687, 2980, 2388, 4419, 2679, 2493, 2130, 3250, 3992, 3082, 4331, 3567, 2527, 1596, 3326, 4637, 1495, 2205, 4054, 1808, 3701, 1307, 1295, 154, 3026, 3786, 2788, 479, 3931, 1652, 1179, 1753, 4499, 622, 2279, 2037, 1369, 4298, 3629, 1489, 2575, 2148, 2740, 3403, 2533, 1397, 3284, 1980, 4078, 1350, 539, 866, 318, 4184, 251, 1953, 3183, 1542, 3349, 2300, 1674, 2913, 3173, 754, 314, 3748, 2268, 3408, 2032, 458, 1501, 437, 4001, 4797, 3603, 535, 1716, 1012, 3802, 2650, 1272, 3448, 4693, 491, 90, 3256, 4427, 2993, 1104, 1885, 1087, 55, 2708, 486, 3094, 4758, 2570, 1050, 2750, 4281, 1470, 1279, 3035, 1451, 4085, 1390, 2665, 2643, 2843, 3756, 1123, 2084, 2649, 3837, 1013, 4021, 2581, 3114, 4009, 4215, 2976, 4340, 4074, 3086, 965, 1002, 783, 4570, 2787, 3890, 3027, 1845, 1683, 2538, 3965, 203, 475, 3297, 816, 2832, 2689, 2182, 1606, 4238, 2944, 108, 4314, 1185, 553, 4612, 2339, 2383, 3157, 735, 2556, 4309, 2100, 1376, 1122, 3806, 2844, 2232, 985, 2054, 3459, 3118, 2267, 3850, 315, 4361, 864, 541, 3179, 1627, 182, 4038, 2607, 4617, 3107, 600, 10, 482, 2781, 3945, 131, 1358, 4453, 4127, 1448, 2870, 4169, 4370, 882, 530, 1551, 813, 2683, 1591, 2917, 978, 4749, 279, 3065, 4225, 1594, 2529, 1758, 611, 2430, 3501, 4430, 3276, 2360, 1306, 3895, 1809, 976, 2919, 127, 2497, 400, 14, 4460, 1424, 3242, 273, 4293, 2979, 3915, 2836, 1832, 1577, 1168, 3426, 1046, 998, 2720, 851, 1277, 1472, 214, 4287, 4364, 804, 4594, 2762, 2107, 2791, 2006, 3513, 3189, 2334, 1843, 3029, 1419, 1670, 2391, 3287, 2282, 4094, 294, 1586, 2905, 1458, 2633, 797, 255, 4257, 558, 3934, 445, 768, 3609, 3639, 1163, 1162, 3642, 3610, 2078, 3225, 1120, 1378, 2075, 120, 42, 1488, 3877, 4299, 1427, 4406, 3150, 918, 3051, 2194, 188, 3092, 488, 1035, 4251, 2612, 4349, 4410, 2028, 118, 2077, 3638, 3643, 769, 2287, 848, 370, 534, 3841, 4798, 3203, 2745, 3493, 3522, 1770, 3341, 3024, 156, 1510, 4679, 671, 3372, 1319, 3580, 2605, 4040, 431, 3923, 4546, 548, 2604, 3588, 1320, 1315, 389, 1446, 4129, 4110, 669, 4681, 4763, 4424, 4179, 2526, 3904, 4332, 1732, 160, 32, 152, 1297, 461, 731, 1263, 3005, 1785, 4725, 2213, 2857, 4030, 2910, 1439, 1480, 135, 571, 1465, 1693, 1539, 4516, 2512, 4071, 1245, 1799, 2185, 1762, 1863, 2896, 1436, 1677, 2152, 968, 1356, 133, 1482, 3951, 1126, 3332, 989, 1769, 3598, 3494, 3510, 3163, 87, 2706, 57, 1855, 3188, 3666, 2007, 3162, 3520, 3495, 910, 4650, 1242, 4343, 3304, 2991, 4429, 3706, 2431, 2127, 2442, 1101, 909, 3509, 3521, 3599, 2746, 3469, 1988, 3482, 1225, 4415, 2303, 1430, 1214, 1224, 3489, 1989, 4733, 4450, 1999, 2262, 106, 2946, 1617, 290, 4654, 1635, 1987, 3491, 2747, 1346, 3016, 80, 62, 1783, 3007, 2167, 3117, 3751, 2055, 1336, 1788, 778, 724, 937, 4265, 2716, 4628, 4692, 3834, 1273, 4671, 1073, 351, 2806, 3104, 449, 2472, 237, 2757, 103, 841, 2765, 924, 506, 2801, 1920, 2405, 2669, 2702, 1045, 3682, 1169, 2729, 4708, 415, 592, 2735, 4559, 4188, 2892, 4466, 2424, 717, 993, 2139, 819, 4633, 2031, 3848, 2269, 933, 1520, 2532, 3872, 2741, 4521, 4100, 3399, 4101, 681, 4662, 2178, 3271, 93, 4390, 2934, 4785, 4503, 147, 3170, 4229, 1773, 1142, 3134, 4731, 1991, 342, 1111, 1562, 503, 1176, 398, 2499, 1318, 3590, 672, 695, 527, 1906, 1269, 3127, 1892, 1253, 3324, 1598, 2060, 284, 357, 4413, 1227, 675, 1076, 1934, 1767, 991, 719, 2299, 3857, 1543, 1928, 1897, 1151, 2171, 2209, 3023, 3596, 1771, 4231, 1257, 3111, 823, 37, 521, 988, 3525, 1127, 4590, 1572, 115, 4636, 3901, 1597, 3363, 1254, 4669, 1275, 853, 3970, 3220, 2568, 4760, 1173, 927, 2229, 30, 162, 4477, 165, 904, 2599, 1949, 2990, 3504, 4344, 958, 4367, 2491, 2681, 815, 3778, 476, 2110, 4646, 1210, 125, 2921, 4494, 2035, 2281, 3658, 2392, 1979, 3869, 1398, 2272, 3047, 2616, 3043, 4194, 2359, 3704, 4431, 4271, 3254, 92, 3394, 2179, 1736, 580, 2328, 598, 3109, 1259, 288, 1619, 945, 1455, 2876, 4177, 4426, 3830, 91, 3273, 4272, 1082, 3991, 3908, 2131, 3075, 2931, 4441, 1589, 2685, 272, 3691, 1425, 4301, 2873, 2908, 4032, 2518, 145, 4505, 4138, 212, 1474, 4689, 645, 791, 2970, 1119, 3636, 2079, 226, 788, 2567, 3318, 3971, 4508, 1149, 1899, 361, 1558, 2119, 1085, 1887, 577, 1092, 2275, 901, 1478, 1441, 2744, 3601, 4799, 2403, 1922, 3002, 2620, 1030, 566, 4082, 2506, 1663, 4471, 4352, 2333, 3665, 3514, 1856, 1329, 4514, 1541, 3859, 1954, 4260, 1626, 3743, 542, 1623, 1061, 4622, 753, 3853, 2914, 4228, 3387, 148, 1332, 2817, 3097, 743, 86, 3519, 3511, 2008, 846, 2289, 734, 3763, 2384, 584, 2049, 4243, 871, 917, 3625, 4407, 4474, 4480, 346, 2458, 4469, 1665, 2254, 2296, 1610, 333, 1660, 2550, 2828, 4730, 3383, 1143, 2413, 386, 2502, 948, 1891, 3366, 1270, 2652, 2350, 4090, 684, 2957, 1020, 2266, 3750, 3460, 2168, 4008, 3798, 2582, 822, 3337, 1258, 3265, 599, 3737, 4618, 448, 3442, 2807, 563, 1861, 1764, 266, 742, 3166, 2818, 4757, 3821, 487, 3620, 189, 2466, 2714, 4267, 964, 3792, 4075, 4598, 4330, 3906, 3993, 2658, 2258, 221, 4173, 2930, 3248, 2132, 2103, 470, 1238, 4644, 2112, 2623, 1534, 4224, 3713, 280, 705, 826, 2356, 1944, 775, 2641, 2667, 2407, 2587, 2602, 550, 2193, 3623, 919, 305, 2615, 3281, 2273, 1094, 4193, 3279, 2617, 1266, 2941, 1703, 4538, 2868, 1450, 3813, 1280, 1206, 1463, 573, 1418, 3662, 1844, 3785, 3891, 155, 3595, 3342, 2210, 4740, 1340, 1797, 1247, 79, 3466, 1347, 4026, 2164, 4397, 513, 3942, 4395, 2166, 3462, 1784, 3557, 1264, 2619, 3199, 1923, 4064, 230, 2319, 650, 748, 907, 1103, 3828, 4428, 3503, 3305, 1950, 1851, 4720, 654, 2564, 648, 2321, 2478, 2387, 3914, 3688, 4294, 4339, 3795, 4216, 240, 22, 1966, 1118, 3227, 792, 590, 417, 877, 4376, 2250, 4165, 2712, 2468, 1140, 1775, 1019, 3121, 685, 4004, 4550, 2852, 1815, 84, 745, 4745, 1288, 1616, 3475, 107, 3771, 4239, 1702, 3040, 1267, 1908, 699, 4542, 4043, 4784, 3391, 4391, 4440, 3247, 3076, 4174, 270, 2687, 2834, 3917, 2560, 604, 4493, 3291, 126, 3698, 977, 3717, 1592, 4227, 3172, 3854, 1675, 1438, 3551, 4031, 3238, 2874, 1457, 3653, 1587, 4443, 2778, 4307, 2558, 3919, 4275, 1435, 3535, 1864, 4105, 4465, 3417, 4189, 2630, 2596, 751, 4624, 219, 2260, 2001, 1372, 2399, 1603, 1802, 740, 268, 4176, 3259, 1456, 2907, 3239, 4302, 4168, 3726, 1449, 3037, 4539, 4125, 4455, 2347, 2066, 246, 607, 2446, 1743, 4029, 3553, 2214, 2203, 1497, 1814, 2953, 4551, 943, 1621, 544, 4247, 28, 2231, 3755, 3807, 2644, 2437, 3948, 835, 4780, 1831, 3686, 3916, 2926, 2688, 3776, 817, 2141, 4729, 3136, 2551, 640, 2410, 1518, 935, 726, 207, 2043, 4756, 3096, 3167, 1333, 1313, 1322, 71, 1422, 4462, 4279, 2752, 562, 3103, 3443, 352, 1325, 2542, 1919, 3432, 507, 466, 2011, 1136, 1291, 1642, 3958, 4336, 2005, 3668, 2108, 478, 3889, 3787, 4571, 2486, 4438, 4393, 3944, 3733, 483, 4306, 2902, 4444, 392, 1190, 4686, 169, 1394, 956, 4346, 308, 1514, 2523, 923, 3435, 842, 2106, 3670, 4595, 1983, 48, 102, 3438, 238, 4218, 1649, 561, 2809, 4280, 3817, 1051, 1345, 3468, 3492, 3600, 3204, 1442, 4520, 3402, 3873, 2149, 2455, 1940, 4558, 3420, 593, 4382, 277, 4751, 4707, 3424, 1170, 4684, 1192, 1166, 1579, 4578, 368, 850, 3679, 999, 2155, 4627, 3451, 4266, 3089, 2467, 2962, 4166, 4304, 485, 3823, 56, 3517, 88, 493, 1044, 3428, 2670, 1730, 4334, 3960, 2040, 1134, 2013, 4326, 1508, 158, 1734, 2181, 3775, 2833, 2927, 271, 3244, 1590, 3719, 814, 3299, 2492, 3911, 4420, 2371, 1304, 2362, 2309, 894, 1554, 1729, 2701, 3429, 2406, 3057, 2642, 3809, 1391, 3985, 1973, 75, 66, 2257, 3080, 3994, 2227, 929, 2064, 2349, 3125, 1271, 3836, 3803, 2085, 177, 4586, 2436, 2842, 3808, 2666, 3058, 776, 1790, 407, 1795, 1342, 1687, 796, 3651, 1459, 2595, 2890, 4190, 2375, 661, 140, 1408, 1533, 3068, 2113, 1029, 3198, 3003, 1265, 3042, 3280, 3048, 306, 4348, 3616, 4252, 1751, 1181, 4616, 3739, 4039, 3587, 3581, 549, 3054, 2588, 1948, 3307, 905, 750, 2889, 2631, 1460, 1781, 64, 77, 1249, 1947, 2601, 3055, 2408, 642, 4631, 821, 3113, 3799, 4022, 569, 137, 808, 2147, 3875, 1490, 4774, 1958, 1049, 3819, 4759, 3317, 3221, 789, 647, 2985, 655, 4114, 603, 2924, 3918, 2900, 4308, 3761, 736, 426, 1839, 639, 2827, 3137, 1661, 2508, 4736, 2144, 1724, 4583, 1918, 2803, 1326, 4698, 3964, 3782, 1684, 1054, 954, 1396, 3871, 3404, 1521, 1757, 3710, 1595, 3903, 3568, 4180, 922, 2767, 1515, 1146, 710, 144, 3236, 4033, 1196, 3956, 1644, 4070, 3542, 4517, 4448, 4735, 2548, 1662, 3194, 4083, 1453, 947, 3130, 387, 1317, 3374, 399, 3696, 128, 2440, 2129, 3910, 2680, 3300, 4368, 4171, 223, 4437, 2785, 4572, 1805, 4154, 1820, 2326, 582, 2386, 2982, 2322, 4222, 1536, 4206, 236, 3440, 450, 1613, 1139, 2961, 2713, 3090, 190, 1038, 2421, 2461, 2462, 2422, 4468, 3145, 347, 1939, 2738, 2150, 1679, 714, 4608, 4604, 4145, 3976, 1742, 2860, 608, 1526, 1100, 3498, 2128, 2495, 129, 3947, 2841, 2645, 4587, 518, 382, 2126, 3500, 3707, 612, 2175, 4143, 4606, 716, 3415, 4467, 2460, 2463, 1039, 1647, 4220, 2324, 1822, 890, 385, 3132, 1144, 1517, 2825, 641, 2586, 3056, 2668, 3430, 1921, 3201, 4800, 3, 1602, 2882, 1373, 2135, 1747, 2217, 4162, 1978, 3286, 3659, 1671, 4418, 3913, 2981, 2479, 583, 3156, 3764, 2340, 2343, 336, 1388, 4087, 197, 660, 2628, 4191, 1096, 1303, 2677, 4421, 4285, 216, 2158, 1962, 856, 4674, 2308, 2675, 1305, 3703, 3277, 4195, 1943, 3061, 827, 658, 199, 195, 4089, 3124, 2653, 2065, 2864, 4456, 1658, 335, 2381, 2341, 2342, 2382, 3765, 4613, 1713, 2090, 1842, 3664, 3190, 4353, 1363, 4567, 597, 3267, 581, 2481, 1821, 2417, 4221, 2477, 2983, 649, 2998, 231, 2018, 366, 4580, 632, 435, 1503, 2123, 893, 2674, 2363, 4675, 1107, 4404, 1429, 3486, 4416, 1673, 3856, 3350, 720, 1609, 3141, 2255, 68, 355, 286, 1261, 733, 3159, 847, 3607, 770, 1567, 4659, 4093, 3657, 3288, 2036, 3881, 623, 1235, 900, 3208, 1093, 3046, 3282, 1399, 932, 3407, 3849, 3749, 3119, 1021, 839, 105, 3477, 2000, 2885, 220, 3079, 2659, 67, 2295, 3142, 1666, 1976, 4164, 2964, 4377, 4067, 1042, 495, 1903, 885, 1879, 4200, 689, 4148, 1818, 4156, 4014, 1582, 1486, 44, 984, 3754, 2845, 29, 3313, 928, 2656, 3995, 4666, 4234, 781, 1004, 1690, 3982, 172, 4161, 2395, 1748, 2202, 2856, 3554, 4726, 4739, 3022, 3343, 2172, 1914, 4053, 3898, 1496, 2855, 2215, 1749, 4254, 1222, 1216, 764, 1064, 187, 3622, 3052, 551, 1187, 455, 4497, 1755, 1523, 1761, 3538, 1800, 1605, 3774, 2690, 1735, 3270, 3395, 4663, 4142, 2428, 613, 1913, 2208, 3344, 1152, 4007, 3116, 3461, 3008, 4396, 3013, 4027, 1745, 2137, 995, 1961, 2367, 217, 4626, 2718, 1000, 967, 3532, 1678, 2454, 2739, 3874, 2576, 809, 1723, 2546, 4737, 4728, 2830, 818, 3412, 994, 2161, 1746, 2397, 1374, 2102, 3074, 3249, 3909, 2494, 2441, 3499, 2432, 383, 892, 2311, 1504, 3989, 1084, 3213, 1559, 4532, 1876, 1970, 1028, 2622, 3069, 4645, 3295, 477, 2790, 3669, 2763, 843, 469, 3073, 2133, 1375, 3759, 4310, 4715, 1286, 4747, 980, 4318, 499, 637, 1841, 2336, 1714, 537, 1352, 176, 2648, 3804, 1124, 3953, 4435, 225, 3224, 3637, 3611, 119, 3633, 1379, 96, 52, 4526, 421, 4210, 1383, 245, 2863, 2348, 2654, 930, 1401, 283, 3361, 1599, 1203, 1311, 1335, 3458, 3752, 986, 523, 1994, 4242, 3154, 585, 4565, 1365, 4701, 4755, 2820, 208, 1133, 2697, 3961, 1368, 3880, 2280, 3289, 4495, 457, 3847, 3409, 4634, 117, 3613, 4411, 359, 1901, 497, 4320, 1070, 859, 410, 365, 2317, 232, 1016, 914, 4325, 2695, 1135, 2798, 467, 845, 3161, 3512, 3667, 2792, 4337, 4296, 1371, 2884, 2261, 3478, 4451, 1360, 1700, 4241, 2051, 524, 341, 3381, 4732, 3481, 3490, 3470, 1636, 1707, 47, 2760, 4596, 4077, 3868, 3285, 2393, 4163, 2252, 1667, 74, 2662, 3986, 1027, 2115, 1877, 887, 1117, 2972, 23, 3968, 855, 2366, 2159, 996, 1048, 2572, 4775, 556, 4259, 3182, 3860, 252, 1850, 2989, 3306, 2600, 2589, 1250, 774, 3060, 2357, 4196, 4557, 2737, 2456, 348, 678, 264, 1766, 3354, 1077, 635, 501, 1564, 1896, 3347, 1544, 627, 4535, 4063, 3001, 3200, 2404, 3431, 2802, 2543, 4584, 179, 4052, 2207, 2173, 614, 1386, 338, 698, 2939, 1268, 3368, 528, 884, 2245, 496, 2025, 360, 3216, 1150, 3346, 1929, 1565, 772, 1252, 3365, 3128, 949, 1631, 576, 3211, 1086, 3826, 1105, 4677, 1512, 310, 4199, 2243, 886, 1969, 2116, 4533, 629, 1727, 1556, 363, 412, 1412, 19, 760, 261, 4104, 2895, 3536, 1763, 3101, 564, 1032, 4696, 1328, 3187, 3515, 58, 4058, 4719, 2988, 1951, 253, 799, 4118, 1682, 3784, 3028, 3663, 2335, 2091, 638, 2553, 427, 3926, 4386, 4213, 4011, 1576, 3685, 2837, 4781, 4563, 587, 1008, 464, 509, 1115, 889, 2416, 2325, 2482, 4155, 2239, 4149, 83, 2952, 2853, 1498, 1300, 375, 975, 3700, 3896, 4055, 4153, 2484, 4573, 739, 2880, 1604, 2184, 3539, 1246, 3019, 1341, 2637, 408, 861, 4290, 406, 2639, 777, 3456, 1337, 4724, 3556, 3006, 3463, 63, 2593, 1461, 1208, 4648, 912, 1018, 2959, 1141, 3385, 4230, 3340, 3597, 3523, 990, 3353, 1935, 265, 3100, 1862, 3537, 2186, 1524, 610, 3709, 2530, 1522, 2188, 4498, 3884, 1180, 2610, 4253, 2201, 2216, 2396, 2136, 2162, 4028, 2859, 2447, 3977, 4098, 4523, 1090, 579, 3269, 2180, 2691, 159, 3565, 4333, 2700, 2671, 1555, 1873, 630, 4582, 2545, 2145, 810, 897, 473, 205, 728, 1011, 3839, 536, 2089, 2337, 4614, 1183, 4316, 982, 46, 1985, 1637, 4061, 4537, 3039, 2942, 4240, 1996, 1361, 4355, 185, 1066, 4204, 1538, 3545, 1466, 3981, 2221, 1005, 795, 2635, 1343, 1053, 2537, 3783, 1846, 4119, 713, 2453, 2151, 3533, 1437, 2912, 3855, 2301, 4417, 2390, 3660, 1420, 73, 1975, 2253, 3143, 4470, 3193, 2507, 2549, 3138, 334, 2345, 4457, 323, 329, 396, 1178, 3886, 3932, 560, 2754, 4219, 2419, 1040, 4069, 2514, 3957, 2795, 1292, 1284, 4717, 4060, 1706, 1986, 3471, 4655, 1416, 575, 1889, 950, 4050, 181, 3742, 3180, 4261, 1060, 3177, 543, 2849, 944, 3262, 289, 3474, 2947, 1289, 1138, 2470, 451, 332, 3140, 2297, 721, 4237, 3773, 2183, 1801, 2881, 2400, 4, 1202, 2059, 3362, 3325, 3902, 2528, 3711, 4226, 2916, 3718, 2684, 3245, 4442, 2904, 3654, 295, 832, 1485, 2236, 4015, 4577, 2724, 1167, 3684, 1833, 4012, 4158, 114, 3329, 4591, 665, 298, 4658, 2285, 771, 1895, 1930, 502, 3378, 1112, 4531, 2118, 3214, 362, 1872, 1728, 2672, 895, 812, 3721, 531, 1530, 4712, 973, 377, 626, 1927, 3348, 3858, 3184, 4515, 3544, 1694, 4205, 2475, 4223, 3067, 2624, 1409, 4711, 1549, 532, 372, 1099, 2444, 609, 1760, 2187, 1756, 2531, 3405, 934, 2824, 2411, 1145, 2522, 2768, 309, 1882, 4678, 3593, 157, 2693, 4327, 1025, 3988, 2122, 2312, 436, 3845, 459, 1299, 1813, 2854, 2204, 3899, 4638, 326, 4641, 4773, 2574, 3876, 3630, 43, 2235, 1583, 833, 3950, 3528, 134, 3549, 1440, 3206, 902, 167, 4688, 3231, 213, 3676, 1278, 3815, 4282, 4766, 3980, 1692, 3546, 572, 3032, 1207, 1780, 2594, 2632, 3652, 2906, 2875, 3260, 946, 2504, 4084, 3812, 3036, 2869, 3727, 4128, 3576, 390, 4446, 4519, 2743, 3205, 1479, 3550, 2911, 1676, 3534, 2897, 4276, 4108, 4131, 1213, 3485, 2304, 4405, 3627, 4300, 3241, 3692, 4461, 2812, 72, 1669, 3661, 3030, 574, 1633, 4656, 300, 18, 1869, 413, 4710, 1532, 2625, 141, 4122, 702, 1404, 703, 282, 2062, 931, 2271, 3283, 3870, 2534, 955, 2772, 170, 3984, 2664, 3810, 4086, 2379, 337, 1911, 615, 244, 2068, 4211, 4388, 95, 2074, 3634, 1121, 3758, 2101, 2134, 2398, 2883, 2002, 4297, 3879, 2038, 3962, 4700, 2046, 4566, 2331, 4354, 1699, 1997, 4452, 3730, 132, 3530, 969, 111, 175, 2087, 538, 3866, 4079, 4025, 3015, 3467, 2748, 1052, 1686, 2636, 1796, 3020, 4741, 4723, 1787, 3457, 2056, 1312, 2816, 3168, 149, 4513, 3186, 1857, 4697, 2541, 2804, 353, 70, 2814, 1314, 3579, 3589, 3373, 2500, 388, 3578, 1321, 2815, 1334, 2057, 1204, 1282, 1294, 3894, 3702, 2361, 2676, 2372, 1097, 374, 1812, 1499, 460, 3561, 153, 3893, 1308, 1283, 1641, 2796, 1137, 1615, 2948, 4746, 2097, 4716, 1640, 1293, 1309, 1205, 3034, 3814, 1471, 3677, 852, 3321, 4670, 3447, 3835, 2651, 3126, 3367, 1907, 2940, 3041, 2618, 3004, 3558, 732, 2291, 287, 3264, 3110, 3338, 4232, 4668, 3323, 3364, 1893, 773, 1946, 2590, 78, 3018, 1798, 3540, 4072, 4342, 3506, 4651, 4771, 4643, 3071, 471, 899, 2277, 624, 379, 40, 122, 4134, 693, 674, 3357, 4414, 3488, 3483, 1215, 2199, 4255, 257, 880, 4372, 763, 2198, 1223, 3484, 1431, 4132, 124, 3293, 4647, 1779, 1462, 3033, 1281, 1310, 2058, 1600, 5, 962, 4269, 4433, 3955, 2516, 4034, 1160, 1165, 2726, 4685, 2775, 393, 454, 2191, 552, 3768, 4315, 1711, 4615, 2609, 1752, 3885, 1653, 397, 3376, 504, 926, 3315, 4761, 4683, 2728, 3425, 3683, 1578, 2725, 1193, 1161, 3641, 3640, 1164, 1194, 4035, 4358, 869, 4245, 546, 4548, 4006, 2170, 3345, 1898, 3217, 4509, 709, 2521, 1516, 2412, 3133, 3384, 1774, 2960, 2469, 1614, 1290, 2797, 2012, 2696, 2041, 209, 3999, 439, 516, 4589, 3331, 3526, 3952, 2083, 3805, 3757, 1377, 3635, 3226, 2971, 1967, 888, 1824, 510, 4530, 1561, 3379, 343, 4789, 4403, 2306, 4676, 1884, 3827, 2994, 908, 3497, 2443, 1527, 373, 1302, 2373, 4192, 3045, 2274, 3209, 578, 1738, 4524, 54, 3825, 1886, 3212, 2120, 3990, 3252, 4273, 3921, 433, 634, 1933, 3355, 676, 350, 3445, 4672, 858, 2022, 4321, 4793, 4203, 1696, 186, 2196, 765, 4621, 3176, 1624, 4262, 3939, 442, 4488, 953, 2536, 1685, 1344, 2749, 3818, 2571, 1959, 997, 3681, 3427, 2703, 494, 2247, 4068, 1646, 2420, 2464, 191, 4250, 3618, 489, 4695, 1859, 565, 3197, 2621, 2114, 1971, 3987, 1506, 4328, 4600, 838, 2265, 3120, 2958, 1776, 913, 2016, 233, 4020, 3801, 3838, 1717, 729, 463, 1827, 588, 794, 1689, 2222, 782, 3790, 966, 2154, 2719, 3680, 1047, 1960, 2160, 2138, 3413, 718, 3352, 1768, 3524, 3333, 522, 2053, 3753, 2233, 45, 1709, 4317, 2095, 4748, 3716, 2918, 3699, 1810, 376, 1547, 4713, 4312, 110, 1355, 3531, 2153, 1001, 3791, 3087, 4268, 1200, 6, 802, 4366, 3302, 4345, 2771, 1395, 2535, 1055, 4489, 4049, 1630, 1890, 3129, 2503, 1454, 3261, 1620, 2850, 4552, 619, 4485, 3937, 4264, 3453, 725, 2823, 1519, 3406, 2270, 1400, 2063, 2655, 2228, 3314, 1174, 505, 3434, 2766, 2524, 4181, 304, 3050, 3624, 3151, 872, 4324, 2015, 1017, 1777, 4649, 3508, 3496, 1102, 2995, 749, 2598, 3308, 166, 1477, 3207, 2276, 1236, 472, 1721, 811, 1553, 2673, 2310, 2124, 384, 2415, 1823, 1116, 1968, 1878, 2244, 1904, 529, 3723, 4371, 1219, 258, 4375, 2966, 418, 4401, 4791, 4323, 916, 3152, 4244, 1157, 4359, 317, 3864, 540, 3745, 4362, 4289, 1793, 409, 2021, 1071, 4673, 2365, 1963, 3969, 3320, 1276, 3678, 2721, 369, 3606, 2288, 3160, 2009, 468, 2105, 2764, 3436, 104, 2264, 1022, 4601, 4779, 2839, 3949, 1484, 1584, 296, 667, 4112, 657, 2355, 3062, 706, 36, 3336, 3112, 2583, 4632, 3411, 2140, 2831, 3777, 3298, 2682, 3720, 1552, 896, 1722, 2146, 2577, 138, 663, 4593, 3672, 4365, 960, 7, 4117, 1848, 254, 3650, 2634, 1688, 1006, 589, 2969, 3228, 646, 2566, 3222, 227, 4380, 595, 4569, 3789, 1003, 2223, 4235, 723, 3455, 1789, 2640, 3059, 1945, 1251, 1894, 1566, 2286, 3608, 3644, 446, 4620, 1063, 2197, 1217, 4373, 260, 1867, 20, 242, 617, 4554, 313, 3852, 3174, 4623, 2888, 2597, 906, 2996, 651, 4744, 2950, 85, 3165, 3098, 267, 2879, 1803, 4574, 425, 2555, 3762, 3158, 2290, 1262, 3559, 462, 1010, 1718, 206, 2822, 936, 3454, 779, 4236, 1608, 2298, 3351, 992, 3414, 2425, 4607, 2452, 1680, 4120, 143, 2520, 1147, 4510, 35, 825, 3063, 281, 1403, 1405, 4123, 4541, 2938, 1909, 339, 526, 3370, 673, 1229, 4135, 3974, 4147, 2241, 4201, 4795, 4003, 2956, 3122, 4091, 4661, 3397, 4102, 263, 1937, 349, 1075, 3356, 1228, 694, 3371, 3591, 4680, 3573, 4111, 830, 297, 1570, 4592, 806, 139, 2627, 2376, 198, 2354, 828, 4113, 2563, 2986, 4721, 4743, 747, 2997, 2320, 2984, 2565, 790, 3229, 4690, 4630, 2585, 2409, 2826, 2552, 1840, 2092, 500, 1932, 1078, 434, 2314, 4581, 1726, 1874, 4534, 1926, 1545, 378, 1234, 2278, 3882, 4500, 4484, 941, 4553, 757, 243, 1385, 1912, 2174, 2429, 3708, 1759, 1525, 2445, 2861, 247, 4492, 2923, 2561, 4115, 9, 3736, 3108, 3266, 2329, 4568, 785, 4381, 2734, 3421, 416, 2968, 793, 1007, 1828, 4564, 2048, 3155, 2385, 2480, 2327, 3268, 1737, 1091, 3210, 1888, 1632, 1417, 3031, 1464, 3547, 136, 2579, 4023, 4081, 3196, 1031, 1860, 3102, 2808, 2753, 1650, 3933, 3647, 4258, 1956, 4776, 4611, 3767, 1186, 2192, 3053, 2603, 3582, 4547, 1155, 4246, 2848, 1622, 3178, 3744, 865, 3865, 1351, 2088, 1715, 3840, 3604, 371, 1529, 1550, 3722, 883, 1905, 3369, 696, 340, 1993, 2052, 987, 3334, 38, 381, 2434, 4588, 1129, 440, 3941, 3011, 4398, 4529, 1114, 1825, 465, 2800, 3433, 925, 1175, 3377, 1563, 1931, 636, 2093, 4319, 2024, 1902, 2246, 1043, 2704, 89, 3832, 4694, 1034, 3619, 3093, 3822, 2709, 4305, 2780, 3734, 11, 3930, 3888, 2789, 2109, 3296, 3779, 204, 1720, 898, 1237, 3072, 2104, 844, 2010, 2799, 508, 1826, 1009, 730, 3560, 1298, 1500, 3846, 2033, 4496, 2190, 1188, 394, 331, 1612, 2471, 3441, 3105, 4619, 767, 3645, 3935, 4487, 1057, 3940, 515, 1130, 4000, 3844, 1502, 2313, 633, 1079, 3922, 3585, 4041, 4544, 3925, 1838, 2554, 737, 4575, 4017, 4209, 2070, 4527, 4400, 876, 2967, 591, 3422, 4709, 1411, 1870, 364, 2020, 860, 1794, 2638, 1791, 4291, 275, 4384, 3928, 13, 3695, 2498, 3375, 1177, 1654, 330, 453, 1189, 2776, 4445, 1445, 3577, 1316, 2501, 3131, 2414, 891, 2125, 2433, 519, 39, 1233, 625, 1546, 974, 1811, 1301, 1098, 1528, 533, 3605, 849, 2722, 4579, 2316, 2019, 411, 1871, 1557, 3215, 1900, 2026, 4412, 3359, 285, 2293, 69, 1324, 2805, 3444, 1074, 677, 1938, 2457, 3146, 4481, 4788, 1110, 3380, 1992, 525, 697, 1910, 1387, 2380, 2344, 1659, 3139, 1611, 452, 395, 1655, 324, 4640, 1493, 4639, 328, 1656, 4458, 16, 302, 4183, 3863, 867, 4360, 3747, 3851, 755, 4555, 4198, 1881, 1513, 2769, 4347, 2614, 3049, 920, 4182, 320, 17, 1414, 4657, 1569, 666, 831, 1585, 3655, 4095, 4769, 4653, 3473, 1618, 3263, 1260, 2292, 356, 3360, 2061, 1402, 704, 3064, 3714, 4750, 2732, 4383, 404, 4292, 3690, 3243, 2686, 2928, 4175, 2878, 741, 3099, 1765, 1936, 679, 4103, 1866, 761, 4374, 879, 1220, 4256, 3649, 798, 1849, 1952, 3861, 4185, 4047, 4491, 606, 2862, 2067, 1384, 616, 758, 21, 2974, 4217, 2756, 3439, 2473, 4207, 4019, 1015, 2017, 2318, 2999, 4065, 4379, 787, 3223, 2080, 4436, 2488, 4172, 3078, 2259, 2886, 4625, 2157, 2368, 4286, 3675, 1473, 3232, 4139, 3998, 1132, 2042, 2821, 727, 1719, 474, 3780, 3966, 25, 194, 2353, 659, 2377, 4088, 2352, 200, 26, 4249, 1037, 2465, 3091, 3621, 2195, 1065, 1697, 4356, 4037, 3741, 1628, 4051, 1916, 4585, 2647, 2086, 1353, 112, 4160, 2219, 3983, 1393, 2773, 4687, 1476, 903, 3309, 4478, 4476, 3311, 31, 3564, 1733, 2692, 1509, 3594, 3025, 3892, 1296, 3562, 33, 4512, 1331, 3169, 3388, 4504, 3235, 2519, 711, 4121, 1407, 2626, 662, 807, 2578, 570, 3548, 1481, 3529, 1357, 3731, 3946, 2439, 2496, 3697, 2920, 3292, 1211, 4133, 1231, 41, 3632, 2076, 3612, 2029, 4635, 3328, 1573, 4159, 174, 1354, 970, 4313, 3770, 2945, 3476, 2263, 840, 3437, 2758, 49, 4705, 4753, 4703, 51, 2073, 1380, 4389, 3393, 3272, 3255, 3831, 492, 2705, 3518, 3164, 744, 2951, 1816, 4150, 61, 3465, 3017, 1248, 2591, 65, 2661, 1974, 1668, 1421, 2813, 1323, 354, 2294, 2256, 2660, 76, 2592, 1782, 3464, 81, 4151, 4057, 1854, 3516, 2707, 3824, 1088, 4525, 2072, 97, 4704, 101, 2759, 1984, 1708, 983, 2234, 1487, 3631, 121, 1232, 380, 520, 3335, 824, 707, 4511, 151, 3563, 161, 3312, 2230, 2846, 4248, 193, 201, 3967, 1965, 2973, 241, 759, 1868, 1413, 301, 321, 4459, 3694, 401, 3929, 481, 3735, 601, 4116, 801, 961, 1201, 1601, 2401, 4801]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b54b70fd31aeaeba854b1934846f1526e8dbe50 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 4801, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf8f70fad4b63ca4de21b07fae0bcbe9509e0a4e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 5717, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4ddba3b8774f888d2682f73f7c0603d9e0ecfd1d --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 2860, 1907, 4289, 2288, 954, 3268, 2145, 2542, 4003, 2080, 3336, 3959, 4493, 2669, 1073, 3364, 4130, 3010, 2002, 1090, 3899, 1741, 4527, 5032, 1980, 848, 2247, 1381, 1335, 3505, 537, 694, 4541, 5228, 4924, 5409, 4364, 3226, 3860, 3487, 3404, 2926, 1950, 2796, 871, 4380, 2264, 5368, 5375, 1122, 3849, 4100, 3283, 3847, 1124, 1004, 691, 970, 668, 1688, 1753, 364, 269, 1936, 3206, 257, 2271, 581, 5473, 1853, 5321, 1489, 2705, 1678, 5041, 298, 4472, 3547, 4789, 2189, 1744, 1723, 4561, 1817, 4322, 461, 3834, 4626, 4257, 4650, 436, 1169, 5049, 4033, 3991, 4775, 5543, 232, 2688, 2718, 3420, 5607, 1925, 3649, 4909, 5344, 1642, 1050, 1924, 5615, 3421, 4352, 3361, 349, 346, 1076, 3344, 4565, 3193, 190, 3703, 1163, 877, 3294, 3041, 2837, 135, 976, 3827, 4016, 4462, 2881, 129, 4744, 1136, 4174, 291, 2222, 2737, 5272, 927, 1920, 2661, 277, 745, 1790, 1353, 2495, 3698, 1364, 2521, 4186, 3008, 4132, 5095, 4662, 1774, 3273, 2395, 1883, 1095, 3333, 3731, 1283, 862, 4691, 2281, 1185, 909, 2241, 5020, 3570, 231, 5620, 4776, 324, 5172, 3642, 2129, 2212, 5184, 2469, 3077, 2226, 585, 5504, 2525, 122, 2017, 4401, 1996, 4622, 2388, 646, 2772, 1423, 2975, 3707, 4203, 1992, 4218, 3465, 4569, 2985, 2804, 2100, 963, 1314, 1825, 3144, 2455, 2524, 5531, 586, 3680, 2135, 3384, 497, 3821, 1579, 2808, 5436, 1711, 560, 5035, 681, 1681, 2148, 175, 100, 3032, 1007, 3397, 4307, 4531, 1183, 2283, 3613, 1597, 428, 2954, 2636, 1852, 5648, 582, 1112, 439, 575, 4506, 2962, 1521, 4317, 1419, 2512, 68, 3449, 3347, 2407, 1914, 2060, 4867, 1327, 5090, 4251, 1441, 5354, 65, 3784, 5231, 4178, 3427, 5362, 4946, 3057, 146, 4975, 3970, 2296, 1369, 1710, 5495, 2809, 464, 1345, 3819, 499, 1331, 1544, 139, 3498, 373, 4079, 3754, 3625, 677, 78, 1248, 3653, 4708, 2869, 3541, 4718, 1261, 4912, 4952, 839, 4363, 5681, 4925, 3604, 2548, 3307, 5190, 1217, 3746, 2598, 1637, 4804, 1198, 1782, 942, 178, 548, 388, 1667, 4162, 1866, 2260, 642, 1970, 3290, 3778, 2346, 2339, 1141, 5243, 593, 3357, 455, 1359, 1121, 5668, 5369, 117, 4644, 2357, 116, 5374, 5669, 2265, 5247, 2155, 3021, 4945, 5445, 3428, 4680, 2119, 1065, 4071, 3965, 64, 5451, 1442, 1235, 3210, 1539, 2294, 3972, 2220, 293, 1641, 5611, 4910, 1263, 2306, 2920, 3395, 1009, 2852, 2201, 5106, 3857, 4634, 5170, 326, 4053, 4410, 3182, 3130, 4245, 3245, 712, 2997, 1488, 5646, 1854, 961, 2102, 1555, 3855, 5108, 4968, 1582, 1733, 3611, 2285, 1273, 1493, 1392, 4261, 4223, 3909, 4919, 482, 2647, 3516, 615, 913, 4523, 4431, 1758, 1228, 2651, 4121, 242, 2766, 4452, 3152, 2057, 4699, 1625, 1068, 93, 4551, 4606, 249, 5145, 1911, 2503, 790, 4221, 4263, 926, 5577, 2738, 856, 1478, 3139, 3956, 2518, 2361, 341, 4361, 841, 5080, 3933, 1396, 88, 1886, 2909, 285, 4375, 1378, 504, 4959, 1699, 1671, 2154, 5366, 2266, 3905, 592, 5381, 1142, 4903, 1807, 2030, 799, 417, 3073, 2534, 4336, 4386, 4177, 5448, 3785, 4923, 5683, 4542, 3150, 4454, 3415, 2334, 220, 1899, 288, 4389, 5112, 3470, 4340, 467, 761, 5118, 2159, 4207, 710, 3247, 4115, 1847, 2893, 4559, 1725, 3409, 1674, 2478, 1204, 5002, 3816, 3677, 3889, 2701, 2434, 1874, 664, 1216, 5404, 3308, 2126, 3920, 721, 2468, 5536, 2213, 33, 5026, 4751, 4127, 2616, 3055, 4948, 738, 1714, 3641, 5540, 325, 5332, 4635, 1529, 1879, 2932, 2141, 2488, 4554, 4844, 4979, 4007, 226, 685, 3741, 3714, 1118, 2748, 3158, 1405, 1947, 3091, 2965, 673, 1633, 1910, 5279, 250, 1214, 666, 972, 3631, 3447, 70, 247, 4608, 3492, 187, 216, 2040, 1832, 4736, 1389, 1813, 475, 339, 2363, 2898, 4344, 3483, 3142, 1827, 2158, 5213, 762, 1435, 4476, 1771, 3469, 5218, 4390, 631, 4967, 5315, 3856, 5335, 2202, 420, 4807, 2182, 733, 2841, 4739, 2463, 4512, 4661, 5562, 4133, 1803, 1654, 4250, 5454, 1328, 609, 753, 4732, 4860, 4158, 2855, 819, 3932, 5261, 842, 3458, 331, 3750, 3513, 3330, 196, 2948, 4154, 3133, 2168, 3053, 2618, 834, 4396, 4940, 804, 3792, 2072, 3989, 4035, 3180, 4412, 3844, 527, 4504, 577, 4748, 61, 4032, 5624, 1170, 2753, 571, 4087, 2622, 2093, 297, 5642, 1679, 683, 228, 4039, 680, 5492, 561, 1979, 5693, 4528, 2685, 4714, 59, 4750, 5181, 34, 1179, 2732, 2917, 3569, 5546, 2242, 2835, 3043, 1133, 2091, 2624, 3342, 1078, 3656, 1511, 509, 2473, 395, 2723, 2639, 4573, 3815, 5199, 1205, 1060, 1798, 533, 3252, 2036, 2049, 1983, 2343, 2891, 1849, 2726, 2785, 3580, 3536, 618, 2879, 4464, 3789, 770, 544, 4006, 5161, 4845, 2277, 3969, 5441, 147, 3930, 821, 2098, 2806, 1581, 5314, 5109, 632, 988, 4012, 1417, 4319, 3981, 1698, 5251, 505, 602, 4285, 2601, 1101, 838, 5412, 4913, 1929, 737, 5176, 3056, 5444, 5363, 3022, 3114, 2027, 803, 5064, 4397, 4450, 2768, 4424, 2593, 2123, 3220, 1623, 4701, 3215, 443, 1499, 2256, 3603, 5408, 5682, 5229, 3786, 3688, 481, 5303, 3910, 3691, 778, 656, 1928, 4951, 5413, 1262, 5343, 5612, 3650, 1573, 867, 3299, 1806, 5241, 1143, 2863, 637, 1788, 747, 3622, 3555, 2210, 2131, 4831, 2112, 2939, 1955, 1663, 2460, 1659, 3100, 653, 1324, 939, 4617, 766, 308, 1357, 457, 640, 2262, 4382, 2216, 3668, 3738, 28, 3473, 937, 1326, 5456, 2061, 4210, 2980, 449, 4242, 4157, 5085, 4733, 4435, 167, 1029, 3830, 2350, 4145, 813, 2421, 3393, 2922, 47, 1340, 2276, 4978, 5162, 4555, 125, 2426, 2573, 3266, 956, 4816, 1252, 2034, 3254, 1209, 2111, 4893, 2132, 3673, 3322, 3838, 2789, 4444, 4228, 3016, 3287, 3124, 3598, 4656, 1570, 1251, 4837, 957, 4118, 2730, 1181, 4533, 171, 3479, 2181, 5103, 421, 1197, 5399, 1638, 1967, 2208, 3557, 2085, 2903, 2186, 3802, 1023, 1455, 446, 143, 3800, 2188, 5638, 3548, 4496, 3111, 1202, 2480, 2245, 850, 4394, 836, 1103, 3936, 323, 5542, 5621, 3992, 2312, 1953, 2941, 3155, 995, 2691, 4678, 3430, 7, 2452, 881, 904, 1602, 3874, 3864, 400, 3618, 209, 4406, 1537, 3212, 4126, 5180, 5027, 60, 5052, 578, 2089, 1135, 5583, 130, 1893, 1657, 2462, 5099, 2842, 1388, 5130, 1833, 4434, 4859, 5086, 754, 1708, 1371, 4026, 1449, 2969, 2563, 950, 3029, 3003, 2633, 2195, 1260, 5415, 3542, 4594, 58, 5029, 2686, 234, 2323, 381, 2868, 5418, 3654, 1080, 1553, 2104, 4124, 3214, 4931, 1624, 5286, 2058, 1916, 924, 4265, 1447, 4028, 2280, 5551, 863, 1890, 1705, 4304, 3696, 2497, 4098, 3851, 3461, 2118, 5360, 3429, 4767, 2692, 1839, 1174, 1945, 1407, 1351, 1792, 4076, 110, 3796, 2612, 3191, 4567, 3467, 1773, 5561, 5096, 4513, 719, 3922, 1569, 4819, 3599, 361, 1649, 4093, 435, 5627, 4258, 1107, 3049, 17, 2356, 5372, 118, 2376, 707, 2064, 1013, 4167, 4417, 1528, 5169, 5333, 3858, 3228, 1116, 3716, 22, 1821, 4256, 5629, 3835, 163, 2387, 5525, 1997, 2318, 3117, 765, 4882, 940, 1784, 4325, 1460, 1071, 2671, 4103, 3491, 5136, 248, 5281, 4552, 2490, 1088, 2004, 564, 2972, 4359, 343, 52, 1871, 57, 4716, 3543, 3418, 2720, 4233, 1986, 4438, 2675, 703, 3629, 974, 137, 1546, 3038, 1483, 3379, 337, 477, 817, 2857, 3814, 5004, 2640, 3495, 2984, 5514, 3466, 4665, 3192, 5599, 3345, 3451, 1816, 5634, 1724, 5205, 2894, 2015, 124, 4843, 5163, 2489, 4605, 5282, 94, 671, 2967, 1451, 3879, 1044, 3775, 3149, 5227, 5684, 695, 2988, 907, 1187, 238, 3437, 170, 4811, 1182, 5482, 4308, 2684, 5031, 5694, 1742, 2191, 4430, 5297, 914, 321, 3938, 2695, 2607, 934, 3240, 519, 718, 4660, 5097, 2464, 886, 3609, 1735, 2961, 5468, 576, 5054, 528, 316, 1974, 2484, 3162, 2658, 3110, 4787, 3549, 2668, 5704, 3960, 425, 3069, 2392, 2404, 1241, 3950, 4276, 367, 2510, 1421, 2774, 2370, 3314, 1232, 1770, 5115, 1436, 2331, 3546, 5640, 299, 2067, 4148, 902, 883, 3686, 3788, 4984, 2880, 5586, 4017, 3523, 1000, 305, 808, 377, 3414, 5225, 3151, 5289, 2767, 4938, 4398, 1428, 3433, 410, 4227, 4825, 2790, 2631, 3005, 3280, 2674, 4588, 1987, 166, 4858, 4734, 1834, 1757, 5296, 4524, 2192, 2957, 2875, 4333, 2592, 4936, 2769, 1567, 3924, 3943, 2448, 1527, 4637, 4168, 2401, 3276, 3843, 5057, 3181, 5329, 4054, 3261, 1536, 4755, 210, 3895, 2553, 1995, 5527, 2018, 1427, 4449, 4939, 5065, 835, 4781, 851, 264, 630, 5111, 5219, 289, 4176, 5233, 4337, 31, 2215, 4875, 2263, 5671, 872, 3444, 2819, 1377, 5254, 286, 1901, 2044, 2399, 4170, 4311, 1047, 3928, 149, 3225, 5680, 5410, 840, 5263, 342, 4599, 2973, 1425, 2020, 152, 3199, 3360, 5605, 3422, 281, 4010, 990, 1694, 2847, 3482, 5123, 2899, 1343, 466, 5216, 3471, 30, 4385, 5234, 2535, 2591, 4426, 2876, 982, 590, 3907, 4225, 412, 1459, 4614, 1785, 460, 5632, 1818, 3980, 4962, 1418, 5465, 1522, 2560, 567, 3773, 1046, 4369, 4171, 2683, 4530, 5483, 3398, 3695, 4687, 1706, 756, 1401, 255, 3208, 1237, 2946, 198, 2745, 1362, 3700, 1320, 1271, 2287, 5714, 1908, 1635, 2600, 4956, 603, 1244, 3389, 2583, 3758, 1467, 267, 366, 4485, 3951, 3877, 1453, 1025, 1692, 992, 2751, 1172, 1841, 1446, 4695, 925, 5274, 4222, 5306, 1393, 1106, 4649, 5628, 4627, 1822, 3168, 1960, 1440, 5453, 5091, 1655, 1895, 1610, 3244, 5326, 3131, 4156, 4862, 450, 2581, 3391, 2423, 2680, 1139, 2341, 1985, 4590, 2721, 397, 74, 3015, 4824, 4445, 411, 4328, 3908, 5305, 4262, 5275, 791, 3464, 5516, 1993, 2555, 3063, 3175, 1718, 3353, 2979, 4865, 2062, 709, 5211, 2160, 3636, 1991, 5518, 3708, 3340, 2626, 2756, 253, 1403, 3160, 2486, 2143, 3270, 1301, 1083, 551, 3841, 3278, 3007, 5565, 2522, 2457, 1312, 965, 2508, 369, 3426, 5447, 5232, 4387, 290, 5581, 1137, 2682, 4310, 4370, 2400, 4416, 4638, 1014, 3616, 402, 1865, 5391, 1668, 2199, 2854, 5084, 4861, 4243, 3132, 5071, 2949, 1297, 1796, 1062, 901, 4469, 2068, 812, 4853, 2351, 2531, 1608, 1897, 222, 2912, 750, 406, 3987, 2074, 1802, 5094, 5563, 3009, 5700, 3365, 2615, 5179, 4752, 3213, 4703, 2105, 241, 5292, 2652, 2729, 4814, 958, 1846, 5208, 3248, 2644, 3187, 1577, 3823, 1472, 2476, 1676, 2707, 3719, 3490, 4610, 2672, 3282, 5665, 3850, 4684, 2498, 787, 1019, 434, 4652, 1650, 3304, 3762, 4058, 2621, 5045, 572, 3810, 1432, 3120, 319, 916, 3753, 5425, 374, 109, 4670, 1793, 1778, 3883, 3964, 5357, 1066, 1627, 2416, 2418, 3915, 627, 1470, 3825, 978, 3258, 832, 2620, 4089, 3763, 830, 3260, 4409, 5330, 327, 1558, 3521, 4019, 470, 3566, 2309, 517, 3242, 1612, 3013, 76, 679, 5037, 229, 3572, 3179, 5059, 3990, 5623, 5050, 62, 3967, 2279, 4693, 1448, 4728, 1372, 2873, 2959, 1737, 759, 469, 4049, 3522, 4461, 5587, 3828, 1031, 1416, 4964, 989, 4349, 282, 225, 5160, 4980, 545, 2079, 5708, 2543, 1506, 2367, 3666, 2218, 3974, 84, 1159, 515, 2311, 4774, 5622, 4034, 5060, 2073, 4136, 407, 2109, 1211, 2759, 1697, 4961, 4320, 1819, 24, 1193, 3529, 83, 3997, 2219, 5348, 2295, 5440, 4976, 2278, 4030, 63, 5356, 4072, 3884, 1287, 424, 4492, 5705, 3337, 2517, 5267, 3140, 3485, 3862, 3876, 4275, 4486, 1242, 605, 2251, 1056, 159, 2447, 4420, 3925, 1645, 1837, 2694, 4520, 322, 4778, 1104, 1395, 5260, 5081, 820, 4973, 148, 4367, 1048, 1644, 3942, 4421, 1568, 4658, 720, 5187, 2127, 3644, 1585, 626, 4066, 2419, 815, 479, 3690, 4918, 5304, 4224, 4329, 591, 5245, 2267, 1157, 86, 1398, 1740, 5696, 1091, 1464, 2552, 4404, 211, 2576, 599, 3562, 2700, 5196, 3678, 588, 984, 1286, 3963, 4073, 1779, 3026, 1043, 4546, 1452, 4274, 3952, 3863, 4760, 1603, 512, 2827, 728, 2994, 3082, 245, 72, 399, 4759, 3875, 3953, 3486, 5678, 3227, 4633, 5334, 5107, 5316, 1556, 329, 3460, 4683, 4099, 5666, 1123, 5663, 3284, 526, 5056, 4413, 3277, 4189, 552, 2788, 4827, 3323, 162, 4625, 5630, 462, 2811, 2349, 4855, 1030, 4015, 5588, 977, 4063, 1471, 4110, 1578, 5498, 498, 5432, 1346, 3676, 5198, 5003, 4574, 2858, 4, 1431, 4085, 573, 441, 3217, 3311, 261, 3660, 1022, 4796, 2187, 4791, 144, 3059, 2611, 4668, 111, 105, 2071, 5062, 805, 769, 4983, 4465, 3687, 4922, 5230, 5449, 66, 2514, 3711, 2889, 2345, 5385, 3291, 3148, 4544, 1045, 4313, 568, 2629, 2792, 45, 2924, 3406, 947, 2779, 829, 4057, 4090, 3305, 2550, 1466, 4280, 2584, 3553, 3624, 5424, 4080, 917, 3512, 5076, 332, 2430, 2597, 5402, 1218, 3236, 2887, 3713, 5157, 686, 27, 4872, 3669, 725, 3377, 1485, 1130, 1282, 5554, 3334, 2082, 1515, 202, 1502, 3165, 1317, 193, 1098, 3402, 3489, 4105, 2708, 21, 4630, 1117, 5156, 3742, 2888, 3781, 2515, 3339, 4202, 5519, 2976, 2824, 1162, 5596, 191, 1319, 4293, 1363, 5568, 2496, 4686, 4305, 3399, 2604, 777, 4917, 3911, 480, 4921, 3787, 4466, 884, 2466, 723, 3671, 2134, 5502, 587, 3888, 5197, 3817, 1347, 3321, 4829, 2133, 3682, 724, 3737, 4873, 2217, 3999, 2368, 2776, 2566, 432, 1021, 3804, 262, 853, 1510, 5011, 1079, 4707, 5419, 1249, 1572, 4908, 5613, 1926, 658, 1731, 1584, 3918, 2128, 5539, 5173, 1715, 12, 2384, 1990, 4205, 2161, 920, 2817, 3446, 5140, 973, 4585, 704, 3096, 676, 5423, 3755, 3554, 4897, 748, 2914, 208, 4757, 401, 4165, 1015, 1596, 5479, 2284, 5311, 1734, 4509, 887, 827, 2781, 2547, 5407, 4926, 2257, 1038, 360, 4655, 4820, 3125, 785, 2500, 2410, 531, 1800, 2076, 181, 3508, 825, 889, 2047, 2038, 218, 2336, 2814, 3535, 4988, 2786, 554, 3232, 1525, 2450, 9, 3178, 4037, 230, 5545, 5021, 2918, 2308, 4047, 471, 354, 2699, 3891, 600, 507, 1513, 2084, 4800, 2209, 4896, 3623, 3756, 2585, 650, 2667, 4495, 4788, 5639, 4473, 2332, 3417, 4593, 4717, 5416, 2870, 2239, 911, 617, 4987, 3581, 2815, 922, 1918, 929, 82, 3976, 1194, 1290, 2763, 3085, 999, 4460, 4018, 4050, 1559, 2866, 383, 614, 5300, 2648, 3329, 5075, 3751, 918, 2163, 824, 3589, 182, 536, 5687, 1336, 845, 2052, 1721, 1746, 372, 5427, 140, 2983, 4571, 2641, 186, 5135, 4609, 4104, 3720, 3403, 5677, 3861, 3954, 3141, 5122, 4345, 2848, 2180, 4809, 172, 700, 2885, 3238, 936, 4870, 29, 4339, 5217, 5113, 1772, 4664, 4568, 5515, 4219, 792, 2117, 4682, 3852, 330, 5078, 843, 1338, 49, 352, 473, 1815, 4563, 3346, 5461, 69, 5139, 3632, 2818, 4378, 873, 742, 1751, 1690, 1027, 169, 4535, 239, 2107, 409, 4447, 1429, 6, 4766, 4679, 5361, 5446, 4179, 370, 1748, 280, 4351, 5606, 5616, 2719, 4592, 3544, 2333, 5224, 4455, 378, 2800, 2152, 1673, 5203, 1726, 946, 3767, 2925, 5676, 3488, 3721, 1099, 2603, 3694, 4306, 5484, 1008, 5339, 2921, 4850, 2422, 4239, 2582, 4282, 1245, 2174, 2303, 496, 5500, 2136, 2906, 3372, 336, 4579, 1484, 3735, 726, 2829, 1940, 335, 3381, 2907, 1888, 865, 1575, 3189, 2614, 4129, 5701, 1074, 348, 5604, 4353, 3200, 454, 5379, 594, 2822, 2978, 4212, 1719, 2054, 2944, 1239, 2406, 5460, 3450, 4564, 5600, 1077, 5013, 2625, 4201, 3709, 2516, 3958, 5706, 2081, 3730, 5555, 1096, 195, 5074, 3514, 2649, 1230, 3316, 2445, 161, 3837, 4828, 3674, 1348, 1550, 1304, 2444, 3326, 1231, 4479, 2371, 260, 3806, 3218, 2125, 5189, 5405, 2549, 3761, 4091, 1651, 3302, 1652, 1805, 4905, 868, 2327, 1481, 3040, 5593, 878, 3147, 3777, 5386, 1971, 3123, 4822, 3017, 525, 3846, 5664, 4101, 2673, 4440, 3006, 4188, 3842, 4414, 2402, 2394, 5559, 1775, 1300, 4193, 2144, 5711, 955, 4839, 2574, 213, 3196, 1535, 4408, 4055, 831, 4061, 979, 621, 1208, 4834, 2035, 4997, 534, 184, 2643, 4114, 5209, 711, 5325, 4246, 1611, 4044, 518, 4516, 935, 3475, 2886, 3744, 1219, 2558, 1524, 3577, 555, 1166, 1115, 4632, 3859, 5679, 4365, 150, 2022, 1034, 1622, 4933, 2124, 3310, 3807, 442, 4930, 4702, 4125, 4753, 1538, 5351, 1236, 4299, 256, 5652, 1937, 2009, 2381, 1762, 453, 3359, 4354, 153, 1534, 3263, 214, 189, 5598, 4566, 4666, 2613, 3367, 1576, 4112, 2645, 484, 1384, 3129, 5328, 4411, 5058, 4036, 3573, 10, 1717, 4214, 3064, 2937, 2114, 313, 2413, 1959, 4254, 1823, 1316, 3725, 1503, 2657, 4499, 2485, 4196, 1404, 5153, 2749, 994, 4770, 2942, 2056, 5288, 4453, 5226, 4543, 3776, 3292, 879, 2454, 5507, 1826, 5121, 3484, 3955, 5268, 1479, 2329, 1438, 1962, 2167, 5070, 4155, 4244, 5327, 3183, 1385, 1294, 784, 3597, 4821, 3288, 1972, 318, 4083, 1433, 764, 4619, 2319, 2026, 4943, 3023, 1201, 4786, 4497, 2659, 1922, 1052, 2529, 2353, 1591, 541, 2665, 652, 4886, 1660, 1631, 675, 3627, 705, 2378, 1519, 2964, 5150, 1948, 2928, 1277, 2715, 998, 3525, 2764, 244, 3868, 2995, 714, 1147, 2225, 5534, 2470, 1606, 2533, 5236, 418, 2204, 2391, 4490, 426, 1599, 2991, 2936, 3174, 4215, 2556, 1221, 2610, 3798, 145, 5443, 4947, 5177, 2617, 5068, 2169, 1225, 16, 4647, 1108, 1617, 2438, 1280, 1132, 5017, 2836, 5592, 3295, 1482, 4581, 1547, 1410, 1190, 689, 1006, 5486, 101, 3002, 4723, 951, 1042, 3881, 1780, 1200, 3113, 4944, 5364, 2156, 1829, 524, 3286, 4823, 4229, 75, 4042, 1613, 2001, 5699, 4131, 5564, 4187, 3279, 4441, 2632, 4722, 3030, 102, 2300, 1128, 1487, 5323, 713, 3081, 3869, 729, 2935, 3066, 1600, 906, 4539, 696, 2803, 5513, 4570, 3496, 141, 448, 4864, 4211, 3354, 2823, 3706, 5520, 1424, 4358, 4600, 565, 2562, 4726, 1450, 4548, 672, 5149, 3092, 1520, 5467, 4507, 1736, 4023, 2874, 4428, 2193, 2635, 5476, 429, 1268, 782, 1296, 4153, 5072, 197, 4297, 1238, 3350, 2055, 3154, 4771, 1954, 4891, 2113, 3173, 3065, 2992, 730, 2140, 5166, 1880, 893, 1276, 3089, 1949, 5675, 3405, 3768, 46, 4849, 3394, 5340, 2307, 3568, 5022, 2733, 207, 3620, 749, 4139, 223, 284, 5256, 1887, 3371, 3382, 2137, 2185, 4798, 2086, 2274, 1342, 4343, 5124, 2364, 2742, 2014, 4558, 5206, 1848, 4992, 2344, 3780, 3712, 3743, 3237, 3476, 701, 2677, 128, 5585, 4463, 4985, 619, 981, 4332, 4427, 2958, 4024, 1373, 2238, 3540, 5417, 4709, 382, 3519, 1560, 636, 4901, 1144, 1906, 5716, 3, 3813, 4575, 818, 5083, 4159, 2200, 5337, 1010, 302, 2179, 3481, 4346, 1695, 2761, 1292, 1387, 4738, 5100, 734, 1256, 134, 5591, 3042, 5018, 2243, 2482, 1976, 2007, 1939, 3375, 727, 3871, 513, 1161, 3705, 2977, 3355, 595, 1376, 4377, 3445, 3633, 921, 3534, 3582, 2337, 2348, 3832, 463, 5435, 5496, 1580, 4970, 2099, 5512, 2986, 697, 2151, 3412, 379, 2325, 870, 5673, 1951, 2314, 44, 3770, 2630, 4443, 4826, 3839, 553, 3579, 4989, 2727, 2654, 2546, 3606, 828, 3765, 948, 2565, 3664, 2369, 4481, 1422, 5522, 647, 1566, 4423, 4937, 4451, 5290, 243, 3084, 3526, 1291, 2845, 1696, 3983, 1212, 252, 4199, 2627, 570, 5047, 1171, 4269, 993, 3157, 5154, 1119, 1361, 4295, 199, 2013, 2896, 2365, 1508, 855, 5271, 5578, 2223, 1149, 206, 2916, 5023, 1180, 4813, 4119, 2653, 2784, 4990, 1850, 2638, 5006, 396, 4232, 4591, 3419, 5617, 2689, 997, 3087, 1278, 2440, 1532, 155, 1588, 20, 3718, 4106, 1677, 5644, 1490, 896, 2433, 5195, 3890, 3563, 355, 775, 2606, 4519, 3939, 1838, 4677, 4768, 996, 2717, 5618, 233, 4713, 5030, 4529, 4309, 4172, 1138, 4237, 2424, 127, 2883, 702, 4587, 4439, 3281, 4102, 4611, 1072, 5703, 4494, 3550, 651, 3102, 542, 772, 276, 5574, 1921, 3109, 4498, 3163, 1504, 2545, 2783, 2728, 4120, 5293, 1229, 3328, 3515, 5301, 483, 3186, 4113, 3249, 185, 3494, 4572, 5005, 2724, 1851, 5475, 2955, 2194, 4721, 3004, 4442, 2791, 3771, 569, 2755, 4200, 3341, 5014, 2092, 5044, 4088, 4059, 833, 5067, 3054, 5178, 4128, 3366, 3190, 4667, 3797, 3060, 1222, 933, 4518, 2696, 776, 3693, 3400, 1100, 4955, 4286, 1636, 5401, 3747, 2431, 898, 2122, 4935, 4425, 4334, 2536, 392, 1475, 1564, 649, 3552, 3757, 4281, 3390, 4240, 451, 1764, 2235, 598, 3893, 212, 3265, 4840, 2427, 1943, 1176, 493, 1266, 431, 3663, 2777, 949, 4725, 2970, 566, 4315, 1523, 3234, 1220, 3062, 4216, 1994, 4403, 3896, 1465, 3760, 3306, 5406, 3605, 2782, 2655, 1505, 4002, 5709, 2146, 1683, 661, 1308, 391, 2590, 4335, 5235, 3074, 1607, 4143, 2352, 3106, 1053, 1153, 121, 5530, 5505, 2456, 4185, 5566, 1365, 2360, 5266, 3957, 3338, 3710, 3782, 67, 5463, 1420, 4483, 368, 4181, 966, 1594, 1017, 789, 5277, 1912, 2409, 3595, 786, 4097, 4685, 3697, 5569, 1354, 40, 1860, 1087, 4604, 4553, 5164, 2142, 4195, 3161, 4500, 1975, 2833, 2244, 4784, 1203, 5201, 1675, 4108, 1473, 394, 5008, 510, 1605, 3076, 5535, 5185, 722, 3684, 885, 4511, 5098, 4740, 1658, 4888, 1664, 1311, 4184, 2523, 5506, 3145, 880, 4764, 8, 3575, 1526, 4419, 3944, 160, 3325, 3317, 1305, 1877, 1531, 2713, 1279, 3046, 1618, 55, 1873, 5194, 2702, 897, 2596, 3748, 333, 1942, 2572, 4841, 126, 2679, 4238, 3392, 4851, 814, 3914, 4067, 2417, 4068, 1628, 1958, 3170, 314, 530, 3594, 2501, 1913, 5459, 3348, 1240, 4488, 2393, 3275, 4415, 4169, 4371, 2045, 891, 1882, 5558, 3274, 2403, 4489, 3070, 2205, 645, 5524, 4623, 164, 1989, 3638, 13, 1761, 3203, 2010, 1518, 3094, 706, 4642, 119, 1155, 2269, 259, 3313, 4480, 2775, 3665, 4000, 1507, 2741, 2897, 5125, 340, 5265, 2519, 1366, 115, 5371, 4645, 18, 1590, 3105, 2530, 4144, 4854, 3831, 2812, 2338, 5384, 3779, 2890, 4993, 1984, 4235, 1140, 5383, 2347, 2813, 3583, 219, 5223, 3416, 3545, 4474, 1437, 3137, 1480, 3297, 869, 2798, 380, 4711, 235, 1413, 2025, 3116, 4620, 1998, 2231, 43, 2794, 1952, 4773, 3993, 516, 4046, 3567, 2919, 5341, 1264, 495, 3386, 2175, 1127, 3000, 103, 113, 1368, 5439, 3971, 5349, 1540, 273, 358, 1040, 953, 5713, 4290, 1272, 5310, 3612, 5480, 1184, 5550, 4692, 4029, 3968, 4977, 4846, 1341, 2901, 2087, 580, 5650, 258, 2373, 1156, 3904, 5246, 5367, 5670, 4381, 4876, 641, 5389, 1867, 1037, 3602, 4927, 1500, 204, 1151, 1055, 3947, 606, 502, 1380, 5690, 849, 4783, 2481, 2834, 5019, 5547, 910, 3539, 2871, 1374, 597, 2578, 1765, 1858, 42, 2316, 1999, 1615, 1110, 584, 5533, 3078, 1148, 2736, 5579, 292, 5347, 3973, 3998, 3667, 4874, 4383, 32, 5183, 5537, 2130, 4895, 3556, 4801, 1968, 644, 2390, 3071, 419, 5105, 5336, 2853, 4160, 1669, 1701, 1259, 4720, 2634, 2956, 4429, 4525, 1743, 5637, 4790, 3801, 4797, 2904, 2138, 732, 5102, 4808, 3480, 2849, 303, 1002, 1126, 2302, 3387, 1246, 80, 931, 1224, 3052, 5069, 3134, 1963, 2096, 823, 3510, 919, 3635, 4206, 5212, 5119, 1828, 3020, 5365, 5248, 1672, 3411, 2801, 698, 174, 5489, 1682, 2541, 5710, 3269, 4194, 2487, 5165, 2933, 731, 2184, 2905, 3383, 5501, 3681, 3672, 4830, 4894, 2211, 5538, 3643, 3919, 5188, 3309, 3219, 4934, 2594, 899, 1064, 5359, 4681, 3462, 793, 312, 3172, 2938, 4892, 4832, 1210, 3985, 408, 3435, 240, 4123, 4704, 1554, 5318, 962, 5511, 2805, 4971, 822, 2165, 1964, 296, 5043, 2623, 5015, 1134, 4746, 579, 2273, 2902, 4799, 3558, 1514, 3729, 3335, 5707, 4004, 546, 180, 3591, 1801, 4135, 3988, 5061, 3793, 106, 811, 4147, 4470, 300, 1012, 4640, 708, 4209, 4866, 5457, 1915, 4698, 5287, 3153, 2943, 3351, 1720, 3502, 846, 1982, 4995, 2037, 3586, 890, 2398, 4372, 1902, 522, 1831, 5132, 217, 3585, 2048, 4996, 3253, 4835, 1253, 1932, 798, 5239, 1808, 802, 4942, 3115, 2320, 1414, 1033, 3223, 151, 4356, 1426, 4400, 5528, 123, 4557, 2895, 2743, 200, 1517, 2380, 3204, 1938, 2831, 1977, 563, 4602, 1089, 5698, 3011, 1614, 2230, 2317, 4621, 5526, 4402, 2554, 4217, 5517, 4204, 3637, 2385, 165, 4437, 4589, 4234, 2342, 4994, 2050, 847, 5692, 5033, 562, 2006, 2832, 2483, 4501, 317, 3122, 3289, 5387, 643, 2207, 4802, 1639, 295, 2095, 2166, 3135, 1439, 4253, 3169, 2414, 1629, 1662, 4890, 2940, 4772, 2313, 2795, 5674, 2927, 3090, 5151, 1406, 4674, 1175, 2571, 2428, 334, 3374, 2830, 2008, 3205, 5653, 270, 489, 797, 2032, 1254, 736, 4950, 4914, 657, 3648, 5614, 5608, 1051, 3108, 2660, 5575, 928, 3532, 923, 4697, 2059, 5458, 2408, 2502, 5278, 5146, 1634, 4288, 5715, 2861, 1145, 716, 521, 2043, 4373, 287, 5221, 221, 4141, 1609, 4248, 1656, 4742, 131, 1704, 4689, 864, 3370, 2908, 5257, 89, 1094, 5557, 2396, 892, 2931, 5167, 1530, 2442, 1306, 663, 5193, 2435, 56, 4596, 53, 1620, 1036, 2259, 5390, 4163, 403, 612, 385, 1086, 2492, 41, 2233, 1766, 1844, 960, 5320, 5647, 5474, 2637, 2725, 4991, 2892, 5207, 4116, 959, 1856, 1767, 1445, 4267, 1173, 4676, 2693, 3940, 1646, 1756, 4433, 4735, 5131, 2041, 523, 3019, 2157, 5120, 3143, 5508, 1315, 3167, 4255, 4628, 23, 3979, 4321, 5633, 4562, 3452, 474, 5128, 1390, 1495, 415, 801, 2029, 5240, 4904, 3300, 1653, 5093, 4134, 2075, 3592, 532, 4999, 1061, 4151, 1298, 1777, 4075, 4671, 1352, 5571, 746, 4899, 638, 459, 4324, 4615, 941, 5397, 1199, 3025, 3882, 4074, 1794, 1299, 3272, 5560, 4663, 3468, 5114, 4477, 1233, 1444, 1843, 1857, 2234, 2579, 452, 3202, 2382, 14, 1227, 5295, 4432, 1835, 1647, 363, 5656, 1689, 3441, 743, 279, 3424, 371, 3500, 1722, 5636, 2190, 4526, 5695, 3900, 1399, 758, 4022, 2960, 4508, 3610, 5312, 1583, 3646, 659, 1685, 97, 945, 3408, 5204, 4560, 5635, 1745, 3501, 2053, 3352, 4213, 3176, 11, 3640, 5174, 739, 559, 5494, 5437, 1370, 4730, 755, 4303, 4688, 1891, 132, 1258, 2197, 1670, 5250, 4960, 3982, 2760, 2846, 4347, 991, 4271, 1026, 3440, 1752, 5657, 669, 96, 1729, 660, 2540, 2147, 5490, 682, 5040, 5643, 2706, 4107, 2477, 5202, 3410, 2153, 5249, 1700, 2198, 4161, 5392, 389, 1310, 2459, 4889, 1956, 1630, 3099, 4887, 2461, 4741, 1894, 4249, 5092, 1804, 3301, 3303, 4092, 4653, 362, 1755, 1836, 3941, 3926, 1049, 5610, 5345, 294, 1966, 4803, 5400, 2599, 4287, 1909, 5147, 674, 3098, 1661, 1957, 2415, 4069, 1067, 5285, 4700, 4932, 3221, 1035, 1869, 54, 2437, 3047, 1109, 2229, 2000, 3012, 4043, 3243, 4247, 1896, 4142, 2532, 3075, 2471, 511, 3873, 4761, 905, 2990, 3067, 427, 5478, 3614, 1016, 2506, 967, 540, 3104, 2354, 19, 2710, 156, 625, 3917, 3645, 1732, 5313, 4969, 2807, 5497, 3822, 4111, 3188, 3368, 866, 4907, 3651, 1250, 4818, 4657, 3923, 4422, 2770, 648, 2587, 1476, 858, 635, 2865, 3520, 4051, 328, 3854, 5317, 2103, 4705, 1081, 1303, 3319, 1349, 1409, 3037, 4582, 138, 5429, 1332, 487, 272, 2293, 5350, 3211, 4754, 4407, 3262, 3197, 154, 2712, 2441, 1878, 5168, 4636, 4418, 2449, 3576, 3233, 2559, 4316, 5466, 2963, 3093, 2379, 2011, 201, 3728, 2083, 3559, 508, 5010, 3657, 854, 2740, 2366, 4001, 2544, 2656, 3164, 3726, 203, 2255, 4928, 444, 1457, 414, 1811, 1391, 5308, 1274, 895, 2704, 5645, 5322, 2998, 1129, 3734, 3378, 4580, 3039, 3296, 2328, 3138, 5269, 857, 1563, 2588, 393, 2475, 4109, 3824, 4064, 628, 266, 4279, 3759, 2551, 3897, 1092, 91, 1070, 4613, 4326, 413, 1497, 445, 4794, 1024, 4273, 3878, 4547, 2968, 4727, 4027, 4694, 4266, 1842, 1768, 1234, 5353, 5452, 4252, 1961, 3136, 2330, 4475, 5116, 763, 3119, 4084, 3811, 5, 3432, 4448, 4399, 2019, 4357, 2974, 5521, 2773, 4482, 2511, 5464, 4318, 4963, 4013, 1032, 2024, 2321, 236, 1189, 3036, 1548, 1350, 4673, 1946, 5152, 3159, 4197, 254, 4301, 757, 1739, 3901, 87, 5259, 3934, 1105, 4260, 5307, 1494, 1812, 5129, 4737, 2843, 1293, 3128, 3184, 485, 1334, 5689, 2248, 503, 5253, 4376, 2820, 596, 2237, 2872, 4025, 4729, 1709, 5438, 2297, 114, 2359, 2520, 5567, 3699, 4294, 2746, 1120, 5377, 456, 4879, 309, 39, 2494, 5570, 1791, 4672, 1408, 1549, 3320, 3675, 3818, 5433, 465, 4342, 2900, 2275, 4847, 48, 3456, 844, 3504, 5688, 1382, 486, 1543, 5430, 500, 608, 5089, 5455, 4868, 938, 4884, 654, 780, 1270, 4292, 3701, 192, 3724, 3166, 1824, 5509, 964, 4183, 2458, 1665, 390, 2538, 662, 1876, 2443, 3318, 1551, 1082, 4192, 3271, 1776, 1795, 4152, 2950, 783, 3127, 1386, 2844, 2762, 3527, 1195, 423, 3962, 3885, 985, 861, 5553, 3732, 1131, 3045, 2439, 2714, 3088, 2929, 894, 1492, 5309, 2286, 4291, 1321, 781, 2952, 430, 2568, 494, 2305, 5342, 4911, 5414, 4719, 2196, 1702, 133, 2839, 735, 1931, 2033, 4836, 4817, 1571, 3652, 5420, 79, 2173, 3388, 4283, 604, 3949, 4487, 2405, 3349, 2945, 4298, 3209, 5352, 1443, 1769, 4478, 3315, 3327, 2650, 5294, 1759, 15, 3051, 2170, 932, 2609, 3061, 2557, 3235, 3745, 5403, 5191, 665, 5143, 251, 2758, 3984, 2110, 4833, 3255, 622, 1059, 5001, 5200, 2479, 4785, 3112, 3024, 1781, 5398, 4805, 422, 1289, 3528, 3977, 25, 688, 3035, 1411, 237, 4537, 908, 5549, 2282, 5481, 4532, 4812, 2731, 5024, 35, 492, 2570, 1944, 4675, 1840, 4268, 2752, 5048, 5625, 437, 1114, 3230, 556, 876, 5595, 3704, 2825, 514, 3995, 85, 3903, 2268, 2374, 120, 2527, 1054, 2253, 205, 2735, 2224, 3079, 715, 1905, 2862, 4902, 5242, 5382, 2340, 4236, 2681, 4173, 5582, 4745, 2090, 5016, 3044, 1281, 3733, 1486, 2999, 2301, 2176, 1003, 5662, 3848, 5667, 5376, 1360, 2747, 5155, 3715, 4631, 3229, 1167, 438, 5471, 583, 2228, 1616, 3048, 4648, 4259, 1394, 3935, 4779, 837, 4954, 2602, 3401, 3722, 194, 3332, 5556, 1884, 90, 1463, 3898, 5697, 2003, 4603, 2491, 1861, 386, 550, 4191, 1302, 1552, 4706, 3655, 5012, 3343, 5601, 347, 3363, 5702, 2670, 4612, 1461, 92, 5284, 1626, 4070, 5358, 2120, 900, 4150, 1797, 5000, 1206, 623, 158, 3946, 2252, 1152, 2528, 3107, 1923, 5609, 1643, 3927, 4368, 4312, 3774, 4545, 3880, 3027, 952, 2290, 359, 3601, 2258, 1868, 1621, 3222, 2023, 1415, 4014, 3829, 4856, 168, 3439, 1691, 4272, 1454, 4795, 3803, 3661, 433, 4095, 788, 2505, 1595, 3615, 4166, 4639, 2065, 301, 2851, 5338, 3396, 5485, 3033, 690, 5661, 1125, 2177, 304, 4459, 3524, 3086, 2716, 2690, 4769, 3156, 2750, 4270, 1693, 4348, 4011, 4965, 633, 860, 1285, 3886, 589, 4331, 2877, 620, 3257, 4062, 3826, 5589, 136, 4584, 3630, 5141, 667, 5659, 692, 539, 1593, 2507, 4182, 1313, 5510, 2101, 5319, 1855, 1845, 4117, 4815, 4838, 3267, 5712, 2289, 1041, 3028, 4724, 2564, 2778, 3766, 3407, 1727, 98, 177, 5396, 1783, 4616, 4883, 1325, 4869, 3474, 3239, 4517, 2608, 1223, 2171, 81, 3531, 1919, 5576, 5273, 4264, 4696, 1917, 3533, 2816, 3634, 2162, 3511, 3752, 4081, 320, 4522, 5298, 616, 3538, 2240, 5548, 1186, 4538, 2989, 1601, 4762, 882, 4468, 4149, 1063, 2121, 2595, 2432, 2703, 1491, 1275, 2930, 1881, 2397, 2046, 3587, 826, 3608, 4510, 2465, 3685, 4467, 903, 4763, 2453, 3146, 3293, 5594, 1164, 557, 741, 3443, 4379, 5672, 2797, 2326, 3298, 4906, 1574, 3369, 1889, 4690, 5552, 1284, 986, 634, 1562, 1477, 5270, 2739, 1509, 3658, 263, 4393, 4782, 2246, 5691, 1981, 2051, 3503, 1337, 3457, 5079, 5262, 4362, 5411, 4953, 1102, 4780, 4395, 5066, 2619, 4060, 3259, 4056, 3764, 2780, 3607, 888, 3588, 3509, 2164, 2097, 4972, 3931, 5082, 2856, 4576, 478, 3913, 2420, 4852, 4146, 2069, 107, 376, 4457, 306, 768, 3791, 5063, 4941, 2028, 1809, 416, 5238, 2031, 1933, 490, 37, 311, 2116, 3463, 4220, 5276, 2504, 1018, 4096, 2499, 3596, 3126, 1295, 2951, 1269, 1322, 655, 4916, 3692, 2605, 2697, 356, 275, 2663, 543, 4982, 3790, 806, 307, 4881, 4618, 3118, 1434, 5117, 5214, 468, 4021, 1738, 1400, 4302, 1707, 4731, 5087, 610, 405, 4138, 2913, 3621, 4898, 1789, 5572, 278, 1750, 3442, 874, 558, 1713, 5175, 4949, 1930, 1255, 2840, 5101, 2183, 2139, 2934, 2993, 3870, 2828, 3376, 3736, 3670, 3683, 2467, 5186, 3921, 4659, 4514, 520, 1904, 1146, 3080, 2996, 5324, 3246, 5210, 4208, 2063, 4641, 2377, 3095, 3628, 4586, 2676, 2884, 3477, 173, 2150, 2802, 2987, 4540, 5685, 538, 969, 5660, 1005, 3034, 1191, 26, 3740, 5158, 227, 5039, 1680, 5491, 5036, 4040, 77, 5422, 3626, 3097, 1632, 5148, 2966, 4549, 95, 1687, 5658, 971, 5142, 1215, 5192, 1875, 1307, 2539, 1684, 1730, 3647, 1927, 4915, 779, 1323, 4885, 3101, 2666, 3551, 2586, 1565, 2771, 5523, 2389, 2206, 1969, 5388, 2261, 4877, 458, 1787, 4900, 2864, 1561, 859, 987, 4966, 5110, 4391, 265, 1469, 4065, 3916, 1586, 157, 1058, 1207, 3256, 980, 2878, 4986, 3537, 912, 5299, 3517, 384, 1863, 404, 752, 5088, 1329, 501, 2250, 3948, 1243, 4284, 4957, 506, 3561, 3892, 2577, 2236, 1375, 2821, 3356, 5380, 5244, 3906, 4330, 983, 3887, 3679, 5503, 5532, 2227, 1111, 5472, 5649, 2272, 2088, 4747, 5053, 4505, 5469, 440, 3809, 4086, 5046, 2754, 2628, 3772, 4314, 2561, 2971, 4601, 2005, 1978, 5034, 5493, 1712, 740, 875, 1165, 3231, 3578, 2787, 3840, 4190, 1084, 387, 5394, 179, 2078, 4005, 4981, 771, 2664, 3103, 1592, 968, 693, 5686, 3506, 183, 3251, 4998, 1799, 3593, 2411, 315, 4503, 5055, 3845, 3285, 3018, 1830, 2042, 1903, 717, 4515, 3241, 4045, 2310, 3994, 1160, 2826, 3872, 1604, 2472, 5009, 1512, 3560, 601, 4958, 5252, 1379, 2249, 607, 1330, 5431, 3820, 5499, 3385, 2304, 1265, 2569, 1177, 36, 796, 1934, 271, 1542, 1333, 1383, 3185, 2646, 5302, 4920, 3689, 3912, 816, 4577, 338, 5127, 1814, 3453, 353, 3565, 4048, 4020, 760, 5215, 4341, 1344, 5434, 2810, 3833, 5631, 4323, 1786, 639, 4878, 1358, 5378, 3358, 3201, 1763, 2580, 4241, 4863, 2981, 142, 4793, 1456, 1498, 4929, 3216, 3808, 574, 5470, 1113, 1168, 5626, 4651, 4094, 1020, 3662, 2567, 1267, 2953, 5477, 1598, 3068, 4491, 3961, 1288, 1196, 4806, 5104, 2203, 3072, 5237, 800, 1810, 1496, 1458, 4327, 4226, 4446, 3434, 2108, 3986, 4137, 751, 611, 1864, 4164, 3617, 4758, 3865, 73, 4231, 2722, 5007, 2474, 1474, 2589, 2537, 1309, 1666, 5393, 549, 1085, 1862, 613, 3518, 2867, 4710, 2324, 2799, 3413, 4456, 809, 108, 4078, 5426, 3499, 1747, 3425, 4180, 2509, 4484, 4277, 268, 5655, 1754, 1648, 4654, 3600, 1039, 2291, 274, 774, 2698, 3564, 472, 3454, 50, 345, 5603, 3362, 1075, 5602, 350, 51, 4598, 4360, 5264, 2362, 5126, 476, 4578, 3380, 3373, 1941, 2429, 3749, 5077, 3459, 3853, 1557, 4052, 5331, 5171, 5541, 4777, 3937, 4521, 915, 4082, 3121, 1973, 4502, 529, 2412, 3171, 2115, 794, 38, 1356, 4880, 767, 807, 4458, 1001, 2178, 2850, 1011, 2066, 4471, 5641, 5042, 2094, 1965, 1640, 5346, 2221, 5580, 4175, 4388, 5220, 1900, 4374, 5255, 2910, 224, 4009, 4350, 3423, 1749, 744, 5573, 2662, 773, 357, 2292, 1541, 488, 1935, 5654, 365, 4278, 1468, 629, 4392, 852, 3659, 3805, 3312, 2372, 2270, 5651, 3207, 4300, 1402, 4198, 2757, 1213, 5144, 5280, 4607, 5137, 71, 3867, 3083, 2765, 5291, 4122, 2106, 3436, 4536, 1188, 1412, 2322, 4712, 2687, 5619, 5544, 3571, 4038, 5038, 684, 5159, 4008, 283, 2911, 4140, 1898, 5222, 2335, 3584, 2039, 5133, 188, 3195, 3264, 2575, 3894, 4405, 4756, 3619, 2915, 2734, 1150, 2254, 1501, 3727, 1516, 2012, 2744, 4296, 2947, 5073, 3331, 1097, 3723, 1318, 3702, 5597, 3194, 215, 5134, 3493, 2642, 3250, 535, 3507, 3590, 2077, 547, 5395, 943, 99, 5488, 2149, 699, 3478, 4810, 4534, 3438, 1028, 4857, 4436, 1988, 2386, 4624, 3836, 3324, 2446, 3945, 1057, 624, 1587, 2711, 1533, 3198, 4355, 2021, 3224, 4366, 3929, 4974, 5442, 3058, 3799, 4792, 447, 2982, 3497, 5428, 1545, 4583, 975, 5590, 2838, 1257, 1703, 1892, 4743, 5584, 2882, 2678, 2425, 4842, 4556, 2016, 5529, 2526, 1154, 2375, 4643, 5373, 5370, 2358, 1367, 2298, 104, 3795, 4669, 4077, 375, 810, 2070, 3794, 112, 2299, 3001, 3031, 5487, 176, 944, 1728, 1686, 670, 4550, 5283, 1069, 1462, 1093, 1885, 5258, 1397, 3902, 1158, 3996, 3975, 3530, 930, 2172, 1247, 5421, 678, 4041, 3014, 4230, 398, 3866, 246, 5138, 3448, 5462, 2513, 3783, 5450, 5355, 3966, 4031, 5051, 4749, 5028, 4715, 4595, 1872, 2436, 1619, 1870, 4597, 344, 351, 3455, 1339, 4848, 2923, 3769, 2793, 2315, 2232, 1859, 2493, 1355, 310, 795, 491, 1178, 5025, 5182, 2214, 4384, 4338, 3472, 4871, 3739, 687, 1192, 3978, 1820, 4629, 3717, 2709, 1589, 2355, 4646, 3050, 1226, 1760, 2383, 3639, 1716, 3177, 3574, 2451, 4765, 3431, 1430, 3812, 2859, 5717]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf8f70fad4b63ca4de21b07fae0bcbe9509e0a4e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 5717, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a731a0735732d4028270f65005d32130118dbee1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 512, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9d28dcacf9fe02c196a99f8e8b2f406757246e00 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [512, 1, 510, 3, 508, 5, 506, 7, 504, 9, 502, 11, 500, 13, 498, 15, 496, 17, 494, 19, 492, 21, 490, 23, 488, 25, 486, 27, 484, 29, 482, 31, 480, 33, 478, 35, 476, 37, 474, 39, 472, 41, 470, 43, 468, 45, 466, 47, 464, 49, 462, 51, 460, 53, 458, 55, 456, 57, 454, 59, 452, 61, 450, 63, 448, 65, 446, 67, 444, 69, 442, 71, 440, 73, 438, 75, 436, 77, 434, 79, 432, 81, 430, 83, 428, 85, 426, 87, 424, 89, 422, 91, 420, 93, 418, 95, 416, 97, 414, 99, 412, 101, 410, 103, 408, 105, 406, 107, 404, 109, 402, 111, 400, 113, 398, 115, 396, 117, 394, 119, 392, 121, 390, 123, 388, 125, 386, 127, 384, 129, 382, 131, 380, 133, 378, 135, 376, 137, 374, 139, 372, 141, 370, 143, 368, 145, 366, 147, 364, 149, 362, 151, 360, 153, 358, 155, 356, 157, 354, 159, 352, 161, 350, 163, 348, 165, 346, 167, 344, 169, 342, 171, 340, 173, 338, 175, 336, 177, 334, 179, 332, 181, 330, 183, 328, 185, 326, 187, 324, 189, 322, 191, 320, 193, 318, 195, 316, 197, 314, 199, 312, 201, 310, 203, 308, 205, 306, 207, 304, 209, 302, 211, 300, 213, 298, 215, 296, 217, 294, 219, 292, 221, 290, 223, 288, 225, 286, 227, 284, 229, 282, 231, 280, 233, 278, 235, 276, 237, 274, 239, 272, 241, 270, 243, 268, 245, 266, 247, 264, 249, 262, 251, 260, 253, 258, 255, 256, 257, 254, 259, 252, 261, 250, 263, 248, 265, 246, 267, 244, 269, 242, 271, 240, 273, 238, 275, 236, 277, 234, 279, 232, 281, 230, 283, 228, 285, 226, 287, 224, 289, 222, 291, 220, 293, 218, 295, 216, 297, 214, 299, 212, 301, 210, 303, 208, 305, 206, 307, 204, 309, 202, 311, 200, 313, 198, 315, 196, 317, 194, 319, 192, 321, 190, 323, 188, 325, 186, 327, 184, 329, 182, 331, 180, 333, 178, 335, 176, 337, 174, 339, 172, 341, 170, 343, 168, 345, 166, 347, 164, 349, 162, 351, 160, 353, 158, 355, 156, 357, 154, 359, 152, 361, 150, 363, 148, 365, 146, 367, 144, 369, 142, 371, 140, 373, 138, 375, 136, 377, 134, 379, 132, 381, 130, 383, 128, 385, 126, 387, 124, 389, 122, 391, 120, 393, 118, 395, 116, 397, 114, 399, 112, 401, 110, 403, 108, 405, 106, 407, 104, 409, 102, 411, 100, 413, 98, 415, 96, 417, 94, 419, 92, 421, 90, 423, 88, 425, 86, 427, 84, 429, 82, 431, 80, 433, 78, 435, 76, 437, 74, 439, 72, 441, 70, 443, 68, 445, 66, 447, 64, 449, 62, 451, 60, 453, 58, 455, 56, 457, 54, 459, 52, 461, 50, 463, 48, 465, 46, 467, 44, 469, 42, 471, 40, 473, 38, 475, 36, 477, 34, 479, 32, 481, 30, 483, 28, 485, 26, 487, 24, 489, 22, 491, 20, 493, 18, 495, 16, 497, 14, 499, 12, 501, 10, 503, 8, 505, 6, 507, 4, 509, 2, 511]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a731a0735732d4028270f65005d32130118dbee1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 512, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ac46199e22801308fbbd8f2800c131813119fd0 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 602, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24f3af1009b35ce381865b4fb84d488170058c5f --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [602, 1, 600, 3, 598, 5, 596, 7, 594, 9, 592, 11, 590, 13, 588, 15, 586, 17, 584, 19, 582, 21, 580, 23, 578, 25, 576, 27, 574, 29, 572, 31, 570, 33, 568, 35, 566, 37, 564, 39, 562, 41, 560, 43, 558, 45, 556, 47, 554, 49, 552, 51, 550, 53, 548, 55, 546, 57, 544, 59, 542, 61, 540, 63, 538, 65, 536, 67, 534, 69, 532, 71, 530, 73, 528, 75, 526, 77, 524, 79, 522, 81, 520, 83, 518, 85, 516, 87, 514, 89, 512, 91, 510, 93, 508, 95, 506, 97, 504, 99, 502, 101, 500, 103, 498, 105, 496, 107, 494, 109, 492, 111, 490, 113, 488, 115, 486, 117, 484, 119, 482, 121, 480, 123, 478, 125, 476, 127, 474, 129, 472, 131, 470, 133, 468, 135, 466, 137, 464, 139, 462, 141, 460, 143, 458, 145, 456, 147, 454, 149, 452, 151, 450, 153, 448, 155, 446, 157, 444, 159, 442, 161, 440, 163, 438, 165, 436, 167, 434, 169, 432, 171, 430, 173, 428, 175, 426, 177, 424, 179, 422, 181, 420, 183, 418, 185, 416, 187, 414, 189, 412, 191, 410, 193, 408, 195, 406, 197, 404, 199, 402, 201, 400, 203, 398, 205, 396, 207, 394, 209, 392, 211, 390, 213, 388, 215, 386, 217, 384, 219, 382, 221, 380, 223, 378, 225, 376, 227, 374, 229, 372, 231, 370, 233, 368, 235, 366, 237, 364, 239, 362, 241, 360, 243, 358, 245, 356, 247, 354, 249, 352, 251, 350, 253, 348, 255, 346, 257, 344, 259, 342, 261, 340, 263, 338, 265, 336, 267, 334, 269, 332, 271, 330, 273, 328, 275, 326, 277, 324, 279, 322, 281, 320, 283, 318, 285, 316, 287, 314, 289, 312, 291, 310, 293, 308, 295, 306, 297, 304, 299, 302, 301, 300, 303, 298, 305, 296, 307, 294, 309, 292, 311, 290, 313, 288, 315, 286, 317, 284, 319, 282, 321, 280, 323, 278, 325, 276, 327, 274, 329, 272, 331, 270, 333, 268, 335, 266, 337, 264, 339, 262, 341, 260, 343, 258, 345, 256, 347, 254, 349, 252, 351, 250, 353, 248, 355, 246, 357, 244, 359, 242, 361, 240, 363, 238, 365, 236, 367, 234, 369, 232, 371, 230, 373, 228, 375, 226, 377, 224, 379, 222, 381, 220, 383, 218, 385, 216, 387, 214, 389, 212, 391, 210, 393, 208, 395, 206, 397, 204, 399, 202, 401, 200, 403, 198, 405, 196, 407, 194, 409, 192, 411, 190, 413, 188, 415, 186, 417, 184, 419, 182, 421, 180, 423, 178, 425, 176, 427, 174, 429, 172, 431, 170, 433, 168, 435, 166, 437, 164, 439, 162, 441, 160, 443, 158, 445, 156, 447, 154, 449, 152, 451, 150, 453, 148, 455, 146, 457, 144, 459, 142, 461, 140, 463, 138, 465, 136, 467, 134, 469, 132, 471, 130, 473, 128, 475, 126, 477, 124, 479, 122, 481, 120, 483, 118, 485, 116, 487, 114, 489, 112, 491, 110, 493, 108, 495, 106, 497, 104, 499, 102, 501, 100, 503, 98, 505, 96, 507, 94, 509, 92, 511, 90, 513, 88, 515, 86, 517, 84, 519, 82, 521, 80, 523, 78, 525, 76, 527, 74, 529, 72, 531, 70, 533, 68, 535, 66, 537, 64, 539, 62, 541, 60, 543, 58, 545, 56, 547, 54, 549, 52, 551, 50, 553, 48, 555, 46, 557, 44, 559, 42, 561, 40, 563, 38, 565, 36, 567, 34, 569, 32, 571, 30, 573, 28, 575, 26, 577, 24, 579, 22, 581, 20, 583, 18, 585, 16, 587, 14, 589, 12, 591, 10, 593, 8, 595, 6, 597, 4, 599, 2, 601]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ac46199e22801308fbbd8f2800c131813119fd0 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 602, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..985015d5c71292977ab9697bde33d0d8a9dbee4a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c82ddbf701da36b393a87d82ea7e9e6fdef67e49 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..985015d5c71292977ab9697bde33d0d8a9dbee4a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4efdd09b4d0dcabb575b879e91607ba9b2a1214e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 4, "k": 2, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9669c8f46bdf0041a7e0cbc4fba1a737a0bd0968 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4efdd09b4d0dcabb575b879e91607ba9b2a1214e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 4, "k": 2, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2f40662eb6a81135042badac01bef94309bd7f92 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..820ae7d5b03f068e52f2d28eee6ffb79545c2ac2 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2f40662eb6a81135042badac01bef94309bd7f92 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f40c704a53d544b491f382232d7462f757d07692 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 531, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d533638f6851449beba16ca7f1edc0ea999ef7f3 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f40c704a53d544b491f382232d7462f757d07692 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 531, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e838de8248793a909267f3e20cbb04fb14636bae --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 735, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e4ab6e8e71dd9404d9b2d4b613a5edac9315f60d --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e838de8248793a909267f3e20cbb04fb14636bae --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 735, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..635a31759ed7ea24ee0f44437e57f740de53828e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 495, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eea6056ca7e74ce1161284a96defd494cc6ad7ea --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..635a31759ed7ea24ee0f44437e57f740de53828e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 495, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..44ed3ff28bbc52d4d40fa4df447e8ef315b84e0f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"F0": 49, "A": 10, "B": 4169, "S": 56861845230554, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..deeac098af09903be93595c4ff2987f85e94e4b8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [4, 5, 7, 9, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..44ed3ff28bbc52d4d40fa4df447e8ef315b84e0f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"F0": 49, "A": 10, "B": 4169, "S": 56861845230554, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5b87e9faaea27094c7a4d7fcb1c625eaaa90ec1 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"F0": 128, "A": 1, "B": 13209, "S": 238146, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a41ecc4d9a6757829e4bfaf57263c9d4a68b0429 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [4, 5, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5b87e9faaea27094c7a4d7fcb1c625eaaa90ec1 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"F0": 128, "A": 1, "B": 13209, "S": 238146, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f321e6f632e6d127a1b57dd0b17f229e15d5bb65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"W": [9, 12, 15, 6, 12, 3, 9, 17, 16], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..60c29f81904dd5c7f01c6ad3a11b35668d49608a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": ["010210102", "102112200", "200202220", "010002101", "112202010", "200000000", "100122010", "220212102", "022122200"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f321e6f632e6d127a1b57dd0b17f229e15d5bb65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"W": [9, 12, 15, 6, 12, 3, 9, 17, 16], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-round-robin-scores-l3-s0/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..21634335f825f75056cb95e7818e21ef8cac2470 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"W": [8, 8, 10, 7, 8, 8, 8, 7, 10], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8250f80458529ea7ff842afa03c5a7729d04cd3d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": ["011111111", "101111111", "110111121", "111011110", "111101111", "111110111", "111111011", "110111101", "111211110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..21634335f825f75056cb95e7818e21ef8cac2470 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"W": [8, 8, 10, 7, 8, 8, 8, 7, 10], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-round-robin-scores-l3-s7/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a541f82eb05c1f43431fe4e0dd70c5e033370c8 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"W": [15, 9, 7, 4, 13, 7, 17, 6, 15], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9cf4d6e7d166fb851f3792d71a0c2a6d93570def --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": ["012122012", "100201120", "020110011", "101011000", "021102121", "012100011", "212212020", "101201000", "021211220"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a541f82eb05c1f43431fe4e0dd70c5e033370c8 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"W": [15, 9, 7, 4, 13, 7, 17, 6, 15], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-round-robin-scores-l3-s9/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f88137295a113702b6a569301021403a20046a18 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"K": 828250231, "n_max": 183, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..084cd6214a85066632f92e391e96e992149d4044 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 90, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f88137295a113702b6a569301021403a20046a18 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"K": 828250231, "n_max": 183, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l4-s2/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3e8440e47635ab7e02d5b7b45c4b5f32d4346032 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"K": 72380104, "n_max": 165, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7b1ce6283aaebaecfe1cf7fe59e35497cebfbf82 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 81, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3e8440e47635ab7e02d5b7b45c4b5f32d4346032 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"K": 72380104, "n_max": 165, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l4-s5/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c4009fc34f699b99690f2c522e185647af619254 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 19], [1, 29], [4, 7], [5, 3], [7, 2], [8, 4], [8, 6], [9, 17], [10, 3], [10, 21], [16, 16], [21, 0], [22, 5], [26, 5], [28, 20]], "r_opt": 17.61758260922649, "r2_num": 1490441, "r2_den": 4802, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dbca17a5b5e122f488b94aa9b72bd1d961da57d9 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 11.295918367346939, "y": 14.704081632653061, "r": 17.61758261022649} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c4009fc34f699b99690f2c522e185647af619254 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 19], [1, 29], [4, 7], [5, 3], [7, 2], [8, 4], [8, 6], [9, 17], [10, 3], [10, 21], [16, 16], [21, 0], [22, 5], [26, 5], [28, 20]], "r_opt": 17.61758260922649, "r2_num": 1490441, "r2_den": 4802, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..17551bdab2fd98f92b9851ec0578dc9670ef9ece --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 13], [3, 5], [3, 9], [6, 15], [7, 19], [8, 4], [8, 16], [9, 18], [10, 27], [14, 7], [17, 27], [22, 1], [25, 13], [25, 22], [30, 11]], "r_opt": 15.0556433503924, "r2_num": 685684, "r2_den": 3025, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2f39fa13a6d3033be39cc7a0feb920d296dcc263 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 15.054545454545455, "y": 12.818181818181818, "r": 15.0556433513924} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..17551bdab2fd98f92b9851ec0578dc9670ef9ece --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 13], [3, 5], [3, 9], [6, 15], [7, 19], [8, 4], [8, 16], [9, 18], [10, 27], [14, 7], [17, 27], [22, 1], [25, 13], [25, 22], [30, 11]], "r_opt": 15.0556433503924, "r2_num": 685684, "r2_den": 3025, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b53152d14de459c5737331c2eb3b0ded2a25a8b7 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 16.986486486486488, "y": 18.22972972972973, "r": 15.453469356472445} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0cc572d5594860e185b58363b9b9f42b2eb2896d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[2, 22], [3, 13], [7, 28], [9, 5], [10, 9], [14, 17], [14, 28], [15, 6], [17, 4], [18, 15], [20, 20], [27, 17], [27, 30], [29, 20], [30, 23]], "r_opt": 15.453469355472444, "r2_num": 653861, "r2_den": 2738, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p42-sum-difference-i/environment/Dockerfile b/tasks/optimize-ae-p42-sum-difference-i/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p42-sum-difference-i/environment/instance.json b/tasks/optimize-ae-p42-sum-difference-i/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3e766e9bb454a138a73f443c5ef75f335f4b8997 --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/environment/instance.json @@ -0,0 +1 @@ +{"max_size": 3000, "max_abs": 1000000000000, "direction": "maximize", "family": "ae_p42_sum_difference_i", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p42-sum-difference-i/solution/solve.sh b/tasks/optimize-ae-p42-sum-difference-i/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..83fd07c63b559e603d453d6101b1e448d490d756 --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": [-129, -142, 30, 5, -113, -49, 19, -45, -66, 58, 56, -104, -37, -102, -136, -122, -103, 54, -16, -148, -53, -76, -7, 50, -60, 7, -2, -127, -118, -78, -24, -86, -111, -114, -145, -85, 13, 17, -116, -121, -119, -89, -94, -79, -3, 0, -58, -67, -46, -52, -50, -36, -8, -106, -29, -27, -25, -91, -81, -48, 8, -47, -82, -40, -35, -30, 20, -101, -1, -75, -32, -17, -14, -15, -18, -38, -68, -77, -59, -151, -132, -140, -150, 26, 22, -22, -69, -73, -11, -99, -28, 15, -90, 31, 33, 34, -23, -100, -56, 2, 384, -4, 27, -62, -6, 51, 1, 44, 41, 40, -31, -13, -34, -33, 386, -108, -80, -117, -138, -125, -93, -74, -126, -65, -134, 237, 83, -43, 224, -88, -57, -54, -131, -98, 25, 276, 18, 14, 12, -95, -128, -124, 24, 36, -10, -110, 317, 48, 21, 23, -130, 46, -123, -149, -147, -143, 70, -20, 49, 185, -141, -97, -42, 359, 55, 47, 258, 248, -51, -9, -139, -137, 378, 4, 43, 38, -107, 333, -5, 59, 371, 104, -146, -144, 379, 373, -135, 202, 199, 52, 35, 329, -72, 334, 61, 62, 192, 45, -434, -152, 350, 206, 98, 92, 71, 73, 81, 97, 60, -19, 96, 75, 77, 79, 76, 91, 64, 74, 68, 67, 90, 85, 78, 63, 313, 311, 309, 72, 328, 42, 94, 103, 95, 100, 110, 336, 348, 337, 107, 109, 93, -70, 377, 376, 87, 88, 101, -133, 99, 108, 6, -84, -112, -63, -61, -26, -41, 3, 39, -12, 84, 89, 28, 37, 102, -96, -87, -55, -115, -64, 16, 9, 80, 82, -105, 57, 69, 66, 53, 10, -109, 65, -21, 11, 29, -39, -120, -71, -44, -83, 32, -92, 362, 353, 86, -158, -161, -159, -157, -155, -153, 106, 105, 111, -154, -156, 113, 305, 383]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p42-sum-difference-i/tests/check.py b/tasks/optimize-ae-p42-sum-difference-i/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3189e36f895e4008e38eae3e94d0f3ce813d5022 --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/tests/check.py @@ -0,0 +1,23 @@ +"""Sum-difference problem I (AlphaEvolve problem 42): maximize log(|A+A|/|A|) / log(|A-A|/|A|).""" +import math + +import numpy as np + +from run import Invalid, int_list + + +def sizes(ans, max_size, max_abs): + a = ans.get("A") + if not isinstance(a, list) or not (2 <= len(a) <= max_size): + raise Invalid(f"A must be a list of 2..{max_size} integers") + int_list(a, None, -max_abs, max_abs, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(a, dtype=np.int64) + return len(a), int(np.unique(np.add.outer(x, x)).size), int(np.unique(np.subtract.outer(x, x)).size) + + +def check(inst, ans): + n, s, d = sizes(ans, inst["max_size"], inst["max_abs"]) + # |A-A| >= 2|A|-1 > |A| for |A| >= 2, so the denominator is positive + return math.log(s / n) / math.log(d / n), {"size": n, "sumset": s, "diffset": d} diff --git a/tasks/optimize-ae-p42-sum-difference-i/tests/instance.json b/tasks/optimize-ae-p42-sum-difference-i/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8be3e40f47dc53ae674764a40a27647a3d2f7ccd --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/tests/instance.json @@ -0,0 +1 @@ +{"max_size": 3000, "max_abs": 1000000000000, "direction": "maximize", "best_known": 1.1219357374860444, "baseline": 1.0, "family": "ae_p42_sum_difference_i", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p42-sum-difference-i/tests/run.py b/tasks/optimize-ae-p42-sum-difference-i/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p42-sum-difference-i/tests/test.sh b/tasks/optimize-ae-p42-sum-difference-i/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p42-sum-difference-i/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ea-flat-polynomials-n70/environment/Dockerfile b/tasks/optimize-ea-flat-polynomials-n70/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-flat-polynomials-n70/environment/instance.json b/tasks/optimize-ea-flat-polynomials-n70/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf8d2029c3a64f18a397bb3996dffb9594559dc2 --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/environment/instance.json @@ -0,0 +1 @@ +{"n_coeffs": 70, "grid": 1000000, "direction": "minimize", "family": "ea_flat_polynomials_70", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-flat-polynomials-n70/solution/solve.sh b/tasks/optimize-ea-flat-polynomials-n70/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..efbfa09783a8786af64fcc3edeb07709924d2997 --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coefficients": [1, 1, -1, -1, -1, 1, 1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, 1, -1, 1, -1]} +RLMATH_EOF diff --git a/tasks/optimize-ea-flat-polynomials-n70/tests/test.sh b/tasks/optimize-ea-flat-polynomials-n70/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/environment/Dockerfile b/tasks/optimize-ea-heilbronn-triangle-n11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/environment/instance.json b/tasks/optimize-ea-heilbronn-triangle-n11/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15b40ef3a9bdb796b9d6b364d8ed40078215ec06 --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "direction": "maximize", "family": "ea_heilbronn_triangle_11", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/solution/solve.sh b/tasks/optimize-ea-heilbronn-triangle-n11/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ebe3cb73c045b8ecd39c4aa739afce254e129210 --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"points": [[0.8559690591062891, 2.886579864025407e-13], [0.2956511458815386, 2.886579864025407e-13], [0.508438680253399, 0.738488241180943], [0.43284084825616725, 0.32744948893266446], [0.6757703386422415, 0.2918847665632347], [0.13872648895811435, 0.24028132723051948], [0.11466976286791358, 0.05646046982789066], [0.6478255729405182, 0.6099840007929047], [0.36127351104238703, 0.6257440765536328], [0.5851055464996742, 0.13484874011462628], [0.9279845295528961, 0.12473445374478148]]} +RLMATH_EOF diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/tests/check.py b/tasks/optimize-ea-heilbronn-triangle-n11/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bec363ff8110410dc65b11937058857ce9d80d3a --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/tests/check.py @@ -0,0 +1,23 @@ +"""Heilbronn problem in the unit equilateral triangle, n = 11 (EinsteinArena heilbronn-triangles, MIT). + +Upstream bug fixed: containment in the triangle with vertices (0,0), (1,0), (1/2, sqrt3/2) was tested in +float64 against a rounded sqrt(3); here it is exact (y >= 0, y^2 <= 3x^2, y^2 <= 3(1-x)^2 with x, 1-x >= 0, +on the rational values of the floats). The minimum triangle area is computed exactly, then divided by +sqrt(3)/4 in floating point.""" +import itertools +import math +from fractions import Fraction + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + p = float_matrix(ans.get("points"), n, 2, "points") + P = [(Fraction(x), Fraction(y)) for x, y in p] + for x, y in P: + if not (y >= 0 and x >= 0 and x <= 1 and y * y <= 3 * x * x and y * y <= 3 * (1 - x) ** 2): + raise Invalid(f"point ({float(x)}, {float(y)}) is outside the triangle") + m = min(abs(a[0] * (b[1] - c[1]) + b[0] * (c[1] - a[1]) + c[0] * (a[1] - b[1])) + for a, b, c in itertools.combinations(P, 3)) / 2 + return float(m) / (math.sqrt(3) / 4), {} diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/tests/instance.json b/tasks/optimize-ea-heilbronn-triangle-n11/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c76d28f94a35133cdaf1bcafcd9a20095ef85cdc --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "direction": "maximize", "best_known": 0.036529889880030156, "baseline": 0.007928157248347962, "family": "ea_heilbronn_triangle_11", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/tests/run.py b/tasks/optimize-ea-heilbronn-triangle-n11/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ea-heilbronn-triangle-n11/tests/test.sh b/tasks/optimize-ea-heilbronn-triangle-n11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-heilbronn-triangle-n11/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ea-prime-number-theorem/environment/Dockerfile b/tasks/optimize-ea-prime-number-theorem/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-prime-number-theorem/environment/instance.json b/tasks/optimize-ea-prime-number-theorem/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..43e014cbf726f9ae37bcb2c88b503582fa74e789 --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/environment/instance.json @@ -0,0 +1 @@ +{"max_keys": 2000, "max_key": 100000, "tol": 1e-09, "direction": "maximize", "family": "ea_prime_number_theorem", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-prime-number-theorem/solution/solve.sh b/tasks/optimize-ea-prime-number-theorem/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8e39d4c9a8660d225b3bc6952b4a7975d2790760 --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"partial_function": {"2": -0.9999999999999885, "3": -0.9999999999999954, "5": -0.9999999999999978, "6": 1.0000000000000162, "7": -1.0000000000004639, "10": 1.0000000000004625, "11": -1.0000000000000193, "13": -1.000000000000113, "14": 1.0000000000002922, "15": 1.0000000000007208, "17": -0.9999999999998903, "19": -1.0000000000001827, "21": 1.0000000000000888, "22": 0.9999999999997524, "23": -1.0000000000008864, "26": 1.0000000000003613, "29": -0.9999999999999583, "30": -1.0000000000007558, "31": -1.0000000000000069, "33": 1.0000000000000289, "34": 0.9999999999998935, "35": 1.0000000000003284, "37": -0.9999999999999206, "38": 0.9999999999993081, "39": 1.0000000000007394, "41": -0.9999999999999967, "42": -0.9999999999995978, "43": -1.0000000000001783, "46": 0.9999999999999987, "47": -0.9999999999998298, "51": 0.9999999999999852, "53": -1.0000000000004157, "55": 0.999999999999933, "57": 1.0000000000011842, "58": 0.9999999999999167, "59": -1.0000000000002227, "61": -1.000000000000511, "62": 0.9999999999998725, "65": 1.0000000000002494, "66": -1.0000000000008467, "67": -0.9999999999994109, "69": 1.000000000000768, "70": -1.0000000000001148, "71": -1.0000000000001374, "73": -1.0000000000003357, "74": 1.0000000000003588, "77": 1.0000000000001403, "78": -1.000000000001001, "79": -1.0000000000001141, "82": 0.9999999999999816, "83": -1.000000000000032, "85": 0.9999999999999146, "86": 1.000000000000405, "87": 1.0000000000010647, "89": -1.00000000000006, "91": 0.9999999999998926, "93": 0.9999999999999966, "94": 0.9999999999995068, "95": 0.9999999999999798, "97": -0.9999999999999124, "101": -1.000000000000046, "102": -0.9999999999999988, "103": -1.0000000000002378, "105": -1.0000000000012785, "106": 1.0000000000007134, "107": -1.0000000000002647, "109": -1.0000000000001799, "110": -1.000000000000094, "111": 0.9999999999998842, "113": -0.9999999999997358, "114": -0.999999999999966, "115": 1.000000000000255, "118": 1.0000000000002165, "119": 0.9999999999997029, "122": 0.9999999999723052, "123": 1.0000000000283626, "127": -1.000000000000134, "129": 1.0000000000001772, "130": -1.0000000000000169, "131": -0.9999999999999704, "133": 1.000000000000221, "134": 0.9999999999995832, "137": -1.0000000000000415, "138": -0.999999999999952, "139": -1.000000000000401, "141": 0.9999999999997989, "142": 1.0000000000002047, "143": 0.9999999999999141, "145": 1.000000000000131, "146": 1.0000000000000615, "149": -1.0000000000003295, "151": -0.9999999999985679, "154": -1.0000000000011307, "155": 0.9999999999998671, "157": -1.0000000000000613, "158": 0.9999999999999727, "159": 1.0000000000008789, "161": 1.0000000000001135, "163": -1.0000000000001181, "165": -1.000000000000569, "166": 0.9999999999997663, "167": -1.0000000000002114, "170": -0.9999999999998757, "173": -0.9999999999998587, "174": -1.00000000000077, "177": 1.0000000000005933, "178": 1.0000000000004634, "179": -1.0000000000004536, "181": -0.9999999999989512, "182": -0.9999999999964778, "183": 0.9999999999976371, "185": 0.9999999999993499, "186": -0.9999999999997183, "187": 1.0000000000000036, "190": -0.9999999999992968, "191": -1.0000000000000064, "193": -0.9999999999997048, "194": 0.9999999999997229, "195": -0.9999999999997632, "197": -0.9999999999996114, "199": -0.9999999999991814, "201": 0.9999999999983968, "202": 1.0000000000006142, "203": 1.0000000000009253, "205": 1.0000000000004796, "206": 0.9999999999991276, "209": 0.9999999999986344, "210": 1.000000000002333, "211": -1.0000000000000986, "213": 0.9999999999997929, "214": 1.0000000000006837, "215": 0.9999999999988586, "217": -0.3121715538456784, "218": 0.7754823601161234, "219": 0.8107568429512324, "221": 1.3416969256003017, "222": -0.9999999999996743, "223": -0.12835075832584625, "226": 0.862789180032796, "227": -0.3639799284536307, "229": -0.9862230680747985, "230": -1.0000000000002438, "231": -1.0000000000012161, "233": -1.0000000000023148, "235": 0.9999999999992538, "237": 1.0000000000004126, "238": -0.9999999999999067, "239": -1.0000000000001215, "241": -0.9999999999724429, "246": -1.0000000000282094, "247": 1.0000000000014095, "249": 1.0000000000003935, "251": -1.0000000000002323, "253": 0.9686117226791598, "254": 0.9999999999741681, "255": -1.312058669861987, "257": -0.6565530527895052, "258": -1.000000000000481, "259": 0.9999999999999428, "262": 0.9999999999994381, "263": -1.0000000000017235, "265": 1.0000000000005898, "266": -1.0000000000003895, "267": 0.9999999999997355, "269": -1.0000000000001712, "271": -0.9999999999999157, "273": -0.9999999999999937, "274": 1.0000000000000024, "277": -1.000000000000109, "278": 0.3937769682348524, "281": -0.3937769682353929, "282": -0.9999999999988016, "283": -1.0000000000001703, "285": -1.000000000000854, "286": -0.999999999999652, "287": 0.9999999999994243, "290": -0.9999999999999365, "291": 0.9999999999996819, "293": -0.999999999999031, "295": 0.9999999999996277, "298": 1.000000000000263, "299": 0.9999999999994429, "301": 1.0000000000001832, "302": 0.9999999999995058, "303": 0.9049184693884075, "305": 0.575328216637249, "307": -0.480246686022751, "309": 0.9999999999996154, "310": -1.0000000000001283, "311": -0.9999999999992145, "313": -1.0000000000002958, "314": 1.0000000000005467, "317": -0.9999999999998307, "318": -1.0000000000011948, "319": 0.9999999999999073, "321": 1.0000000000002205, "322": -1.0000000000007074, "323": 0.9999999999996371, "326": 0.9999999999998817, "327": 1.0000000000001765, "329": 0.5082310563216393, "330": 0.9100575429740038, "331": -0.502380949277207, "334": 1.0000000000002527, "335": 0.9999999999998591, "337": -1.5101784903632227, "339": 0.43350628651400636, "341": 1.9999999999999483, "345": -1.3194585078756575, "346": 1.0000000000000897, "347": -0.5197769382940551, "349": -1.0000000000004088, "353": -1.000000000000065, "354": -1.0000000000001785, "355": 0.999999999999732, "357": -1.0000000000000022, "358": 0.9999999999996668, "359": -0.9999999999991758, "362": 0.9999999999957743, "365": 1.0000000000003253, "366": -0.9999999999689472, "367": -0.999999999999961, "370": -1.0000000000282268, "371": 0.5956659983153916, "373": -0.5956659983152055, "374": -1.0000000000001024, "377": 0.49421972317631285, "379": -0.4942197231764428, "381": 1.0000000000001779, "382": 1.0000000000000748, "383": -1.0000000000000981, "385": -0.9999999999998631, "386": 0.9999999999996954, "389": -0.9999999999998039, "390": 0.9999999999994446, "391": 0.9999999999999669, "393": 0.9999999999998288, "394": 0.9999999999998638, "395": 0.9999999999999659, "397": -1.0000000000000386, "398": 0.9999999999995083, "399": -1.0000000000004037, "401": -0.9999999999993049, "402": -0.9999999999978172, "403": 0.9999999999999819, "406": -1.0000000000003333, "407": 0.9999999999957541, "409": -0.9999999999957238, "410": -1.0000000000001703, "411": 0.9999999999988198, "413": 0.8724640681609377, "415": 0.8493889481598835, "417": 1.115446592986928, "418": -0.8372996093080507, "419": -1.0000000000002622, "421": -0.9999999999993828, "422": 1.0000000000008678, "426": -0.999999999999936, "427": 0.9999999999994678, "429": -1.000000000000422, "430": -1.4913411803362147, "431": -0.5558026885244265, "433": -0.9528561311392193, "434": 0.3121715538451611, "435": -1.0000000000000542, "437": 1.2245176398846138, "438": -0.8107568429489781, "439": -1.0000000000019982, "442": -1.341696925600137, "443": -1.0000000000002276, "445": 0.9999999999991299, "446": 0.12835075832565163, "447": 1.0000000000005587, "449": -1.0000000000000588, "451": 0.999999999999702, "453": 0.07587028947667797, "454": 0.08007256960175269, "455": -0.6547521106585091, "458": 0.9862230680743254, "461": -1.0000000000000715, "462": 1.0000000000012277, "463": -1.000000000000093, "465": -0.9999999999992845, "466": 1.0000000000000815, "467": -0.9999999999957415, "469": 0.9999999999983837, "470": -0.9999999999992412, "471": 0.9999999999997858, "473": 1.0000000000003575, "474": -1.0000000000000882, "478": 0.8177936021439342, "479": -0.8177936021435595, "481": 0.9999999999997669, "482": 0.9999999999714474, "483": -0.9999999999997073, "485": 0.9999999999999076, "487": -0.9999999999999278, "489": 0.9562555277983152, "491": -1.23920741978773, "493": 0.9707683869756996, "494": -0.8956332385635335, "497": 1.207816743606518, "498": -1.2414793193350258, "499": -0.7585206806669194, "501": 1.0000000000007685, "502": 0.8187698708893039, "503": -0.8187698708904201, "505": 0.9999999999998037, "506": -0.9686117226774463, "509": -0.9999999999739858, "510": 1.3120586698620957, "511": 0.9999999999995539, "514": 0.6565530527893771, "515": 0.8848333749675146, "517": 0.7957081171567042, "518": -0.680541492126794, "519": 0.2615176092134341, "521": -0.261517609214554, "523": -0.9999999999994785, "526": 1.0000000000017475, "527": 0.9999999999995349, "530": -0.9999999999997693, "533": 0.42287016349655626, "534": -0.42287016349628564, "535": 1.0000000000004954, "537": 0.9107635237240582, "538": 1.089236476278069, "541": -1.000000000000221, "542": 1.000000000000544, "543": -0.6612982664646193, "545": -0.29511499525602974, "546": 0.9999999999956379, "547": 0.6649931053528848, "551": 1.1296375557279574, "553": 0.38756856768439624, "554": 0.19955471176928033, "555": -0.9999999999990905, "557": -0.002562529053118571, "559": 1.2498769785037969, "561": -1.1801433723633414, "562": 0.39377696823469793, "563": -1.000000000001972, "565": 0.24763529444618518, "566": 0.9999999999990327, "569": -0.03525238606357694, "570": 1.0000000000006224, "571": -0.2818668251836254, "573": 1.0000000000002673, "574": -0.7231037356203126, "577": -0.23469989218802711, "579": -0.3455258247675718, "581": 1.154454725654414, "582": -0.9687848595541585, "583": 0.9999999999826943, "586": 0.9133405547970083, "587": -0.5433711715878685, "589": 0.49513808866000353, "590": -1.340773624289565, "591": 0.925202767134316, "593": -0.12286582043814159, "595": -0.9999999999994451, "597": 0.6206870131013965, "598": -0.7633597439013391, "599": -0.7906591637163968, "601": -0.09248412060243918, "602": -0.9999999999976934, "606": -1.506344374333004, "607": -0.39857409505631236, "609": -1.0000000000003177, "610": -0.5753282166042772, "611": 0.20429188284250502, "613": -0.4850275551528937, "614": 0.48270202275346213, "615": -0.7217196644497542, "617": -1.0000000000012046, "618": -0.9999999999994238, "619": -0.9999999999988206, "622": 1.0000000000000904, "623": 0.9999999999996455, "626": 1.0000000000009586, "627": -1.0000000000003528, "629": 0.18582204796634397, "631": -0.18582204796576107, "633": 0.9999999999973018, "634": 0.7673048611701463, "635": 0.879136725245193, "638": -1.5270079853668705, "641": -0.11943360104484797, "642": -1.0592936587486115, "643": -0.940706341252351, "645": -1.0000000000007867, "646": -0.9999999999989999, "647": -0.9999999999995257, "649": 0.9999999999999424, "651": 0.31217155384535433, "653": -1.0000000000007931, "654": -0.7754823601162991, "655": 1.000000000001131, "658": -0.31898789927197396, "659": -0.9999999999999842, "661": -0.9100575429737742, "662": 0.5023809492784195, "663": -1.341696925601419, "665": -1.0000000000003295, "667": 1.0000000000000533, "669": 0.12835075832544268, "670": -0.9999999999999878, "671": 0.9999999999996726, "673": -1.000000000000077, "674": 1.5101784903637019, "677": -1.000000000000512, "678": -0.29629546654971595, "679": 1.0000000000020253, "681": 0.36397992845202304, "682": -1.9999999999997435, "683": -0.9999999999991017, "685": 1.0000000000041773, "687": 0.986223068073545, "689": 0.99999999999692, "690": 1.3194585078752268, "691": -0.9999999999999578, "694": 0.5197769382945057, "695": 1.0000000000010183, "697": 0.07218076556497993, "698": 1.0000000000016347, "699": 0.9987088836494686, "701": -0.34861357965500533, "703": -0.5208942627358129, "705": -1.000000000008229, "706": 1.0114819165180018, "707": 1.5467923651624245, "709": 0.24034391150660359, "710": -1.000000000000217, "713": 0.44560255450392866, "714": 1.5543974455066687, "715": -1.000000000010634, "717": 0.14089116066653903, "718": 1.858282216319165, "719": -0.9991733769856078, "721": 0.11516662503196376, "723": 1.0254756917980314, "727": -0.46290730952368553, "730": -1.4809876694952169, "731": -0.8894524734525876, "733": -0.04202983135735641, "734": 1.8371236439916938, "737": 0.25894549169183384, "739": -0.22259587999109548, "741": -0.7583912801678914, "742": 0.023986993159984513, "743": -0.9999999999991138, "745": 0.5668408636889884, "746": 1.028825134625888, "749": 1.0000000000068663, "751": -1.000000000006555, "753": 0.9999999999999659, "754": -0.4942197231811485, "755": 1.0000000000004348, "757": -0.9999999999999785, "758": 0.4942197231757512, "759": -0.9686117226785081, "761": -0.9999999999999015, "762": -0.9999999999741934, "763": 1.0000000000004905, "766": 1.312058669862948, "767": 0.9999999999981474, "769": -0.9999999999959207, "770": 1.0000000000008915, "771": 0.6565530527902913, "773": -0.9999999999984481, "777": -1.326645387965521, "778": 0.8808020764213829, "779": 0.9376356215747469, "781": 1.3495284556638012, "782": -2.391796071288983, "785": 0.4518944928300431, "786": -0.999999999943802, "787": -1.417882994732678e-12, "789": -0.039638358143315434, "790": -1.0221675303467552, "791": 0.7523647055525725, "793": 0.3286370643990365, "794": 0.7727172639301387, "795": -1.000000000005098, "797": -0.4767399218769394, "798": 1.9677138628357624, "799": -0.9777038481441211, "802": 0.4561140548399056, "803": 0.03926214212080735, "805": -1.1558328559487212, "806": -1.2883970410655172, "807": 0.9999999999998616, "809": 0.8579352412476628, "811": 1.8680792650461966, "813": 1.0000000000001399, "814": -0.9999999999960797, "815": 0.5689645517281062, "817": 0.22201252457173862, "818": 0.08644148667145, "821": 0.6953396338827366, "822": -1.000000000002167, "823": 0.44347857141059255, "826": -0.8724640681620832, "827": -0.9999999999995748, "829": -0.9999999999953675, "830": -0.8493889481647409, "831": 1.0000000000001712, "834": -0.5092235612209364, "835": 0.6219219938930799, "838": 0.19003302720575257, "839": -0.257044705349209, "842": 1.1244005004450965, "843": 0.5517657613499837, "849": 0.9999999999979965, "851": 1.0000000000004334, "853": -1.000000000000375, "854": -0.9999999999678849, "857": -1.000000000003752, "858": 0.959185360177644, "859": -0.9591853601776583, "861": -0.7849479059878204, "862": 0.5558026885252996, "863": -0.7237109137039087, "865": 0.9999999999993736, "866": 0.952856131139811, "869": 1.0000000000007536, "870": 0.9999999999998856, "871": 0.831648687578831, "874": -1.5022820913926027, "877": -0.3293665961881758, "878": 1.0000000000033402, "879": -0.21194453601887867, "881": 0.21194453601788096, "883": -1.00000000000013, "885": -0.9999999999995296, "886": 0.9287754215674886, "887": -0.9287754215692187, "889": 0.9999999999999414, "890": -0.9999999999995832, "893": 0.9999999999987015, "894": -1.0000000000004698, "895": 1.000000000000583, "897": -1.0000000000001823, "898": 0.24559221459039557, "899": 1.3134626701982564, "901": 1.2582040384805093, "902": -1.0488184997118124, "903": -0.8177936021439738, "905": 0.15948698349971283, "906": -0.3953287973519782, "907": -0.5847750750853343, "910": 0.96505159813789, "911": -2.9008105774261772e-12, "913": -0.6521242995039389, "915": -0.5753282166332837, "917": 0.517442811723084, "919": 0.02618335213598504, "921": -0.7518421862663658, "922": 0.9253894284914879, "923": 0.47712932016770115, "926": 0.9999999999998037, "929": -0.7887402047664325, "930": 1.0000000000010623, "933": 0.9999999999977199, "934": 0.9999999999958884, "935": -0.8419277603832152, "938": -1.1154465929843167, "939": 0.4568465147303029, "941": -0.5989930086512744, "942": -0.8564018057369345, "943": -0.4023299690764182, "946": -1.32673750539937, "947": -0.43782703076264573, "949": 1.3802670711901246, "951": 0.47022218865366916, "953": 0.407693358127835, "955": 1.6218022787947637, "957": -2.1999791419193966, "958": 0.7500288889668221, "959": 0.15795165008832485, "962": -2.3130567885375632, "965": 0.9679467885012577, "966": 0.9999999999935748, "967": -0.056540685228911286, "969": -0.9867220302140495, "970": -1.0000000000000269, "971": 1.3702869794727366, "973": 1.8279674011350826, "974": 0.28186682518316525, "977": -0.25705857768481016, "978": -1.0249974815578047, "979": -0.5777359607717379, "982": 1.2392074197882177, "983": 0.46270079953385235, "985": -0.4844499568230302, "986": -0.9707683869758531, "987": -1.0048102990295638, "989": -0.9661383724258313, "991": -0.19706709052975563, "993": 0.4982982605402192, "994": -0.466927864748637, "995": 0.8256707189287927, "997": -0.7960993900344622, "998": 0.5525564315658624, "1001": -0.7967737693158683, "1002": -0.9075158793981244, "1003": -0.021340279160316784, "1005": -1.6584886621413597, "1006": 0.1163444494713193, "1007": -0.4762323972721697, "1009": 0.2494045161887589, "1010": -0.3306050112602658, "1011": 1.840746279397375, "1013": 0.7062484399785977, "1015": 0.5680954965501808, "1018": 0.9009936915892365, "1019": 0.30739826752519955, "1021": 1.2035565473801324e-12, "1022": -0.9999999999995534, "1023": -2.000000000000221, "1027": 0.7331921513035198, "1030": -0.8694513232015793, "1031": -0.748574203067484, "1033": -1.0000000000035254, "1034": -0.7957081171538666, "1037": 0.9999999999973501, "1038": -0.2615176092132025, "1039": -0.9999999999986547, "1041": 0.5197769382934789, "1042": 0.2615176092144508, "1043": 0.9999999999998155, "1045": -0.9999999999990138, "1046": 0.9999999999996928, "1047": 1.0000000000014124, "1049": -0.9999999999996476, "1051": -1.0000000000036504, "1054": -0.9999999999974415, "1055": 1.0000000000017333, "1057": 0.9999999999999947, "1059": -0.07048308378912323, "1061": -0.8993747937416788, "1063": -0.030142122474774123, "1065": -0.9999999999935791, "1066": -1.0009909427312509, "1067": -0.05269812013924562, "1069": 0.05368906286485618, "1070": -1.0000000000016174, "1073": 0.9107635237225763, "1074": -0.9107635237234069, "1077": 1.0000000000000808, "1079": 1.0000000000005569, "1081": 0.9999999999996766, "1082": 1.0000000000015477, "1086": 0.5868253968115389, "1087": -0.6133555764987365, "1090": 0.5196326351407381, "1091": -0.999999999995418, "1093": -1.0000000000045446, "1094": -0.6649931053538745, "1095": -0.8107568429478692, "1097": -1.0000000000001315, "1099": 0.9834532129284228, "1101": 0.46811333537397215, "1102": -1.268142440801188, "1103": -0.31306166323179724, "1105": -1.3416969255998634, "1106": -0.38756856768480485, "1109": -0.1995547117970026, "1110": 1.0000000000291496, "1111": 0.9999999999999927, "1113": 0.010557033450446335, "1114": 0.0025625290525611443, "1115": 0.12835075833643902, "1117": -1.0000000000072224, "1118": -1.2498769785036519, "1119": 0.5956659983164048, "1121": 0.9999999999903659, "1122": 1.1801433723679036, "1123": -1.0000000000101374, "1126": 1.0000000000001945, "1129": -0.999999999996728, "1130": -0.11042447447315647, "1131": -0.494219723176305, "1133": 1.000000000000279, "1135": 0.3639799284533285, "1137": 0.3353449020032279, "1138": 0.19412720724063526, "1139": 0.9999999999973803, "1141": 1.0000000000004328, "1142": 0.28186682517734746, "1145": 0.7404477576878623, "1146": -1.507692022549977, "1147": -0.9999999999964722, "1149": -0.08805814268098588, "1151": -0.6853642515790802, "1153": -0.058687083093797866, "1154": 1.2926521688934554, "1155": 1.7473820140556073, "1157": 1.449582549285482, "1158": 0.39928953062729683, "1159": 0.33270647755205524, "1162": -1.2367251699561594, "1163": -0.2816511736893143, "1165": 1.000000000000215, "1166": -0.9999999999829774, "1167": 0.956675525104968, "1169": 1.0433244748938981, "1171": -1.0000000000012121, "1173": -2.729117620699717, "1174": -0.2835987866856631, "1177": -0.07282335300322612, "1178": -0.6693949887401109, "1181": -0.8714998042842962, "1182": -0.9252027671176809, "1185": -2.256466066089746, "1186": -0.42510561947934933, "1187": -0.5588402194039997, "1189": 1.3922510053810664, "1190": 0.8146185198292392, "1191": 1.7235005061035416, "1193": -0.7063210870694893, "1194": -0.6206870131023055, "1195": 0.8591088393338817, "1198": 0.7906591637153185, "1199": 0.3065222638909835, "1201": 1.2908789286850855, "1202": 0.09248412060113058, "1203": 0.6137800784493825, "1205": -0.33925794997938324, "1207": -0.1371403636360758, "1209": -1.4516014387455562, "1211": -0.23308273710981184, "1213": -0.3102994874834598, "1214": -0.49882479781757183, "1217": 1.7425052787087891, "1218": 1.3937769682352004, "1219": 0.38203171480256215, "1221": -0.9999999999951547, "1222": -1.0653243657711065, "1223": -2.8400855482418277, "1226": 0.5341855783832333, "1227": 1.8825773135129715, "1229": 0.08766896434773518, "1230": 0.7217196644485375, "1231": 0.8636854105720828, "1234": 1.0000000000011304, "1235": -0.2416087198329107, "1237": 0.013570155958412199, "1238": 0.6843759238541395, "1239": -0.851123789000906, "1241": -0.3775977066368215, "1243": -0.3793526514231199, "1245": -0.7842330768174355, "1246": -1.4289373184199174, "1247": 0.49973927296274373, "1249": -0.005734769475403474, "1253": 0.2721258820925795, "1254": 0.8372996093090321, "1255": 0.3266453879652229, "1257": 1.522525650108089, "1258": 0.31655890128445324, "1259": -0.6189831964185714, "1262": -0.09198081090025004, "1263": 0.8877176617175986, "1265": -1.7095006015353307, "1266": -1.0000000000026408, "1267": 0.9335746548897211, "1270": -0.05966175794693993, "1271": -0.7569600982783597, "1273": -0.23559276754547465, "1277": -0.9344706921433804, "1279": -0.8604529335216031, "1281": 0.46101439845102216, "1282": 0.1194336010444504, "1283": 0.21992500744017549, "1285": -1.0981648325428266, "1286": 0.9407063412512265, "1289": 1.1517686343025044, "1290": 1.1009418756253357, "1291": 0.9337194108386851, "1293": -0.4778722734013378, "1294": 0.9999999999926922, "1295": -1.1194393250157364, "1297": 0.7537470125898419, "1298": -0.12242923970416512, "1299": 0.5449345898938671, "1301": 0.3760508640530901, "1302": -0.3121715538437604, "1303": -0.9219384839781629, "1306": 1.0000000000061025, "1307": -0.8151866389058241, "1309": -0.8198566276328226, "1310": -1.0076952878870808, "1311": -1.2689245698129619, "1313": -0.36210022775996814, "1315": -1.2515459008534444, "1317": 1.9178007689133452, "1318": 0.8543549469906883, "1319": 0.12748512311070392, "1321": 0.5760411796538327, "1322": 0.9100575429725903, "1326": 2.462633909792223, "1327": 0.47756813064783776, "1329": 1.460516112462602, "1330": 0.575117320599425, "1333": 0.41723302638242127, "1334": -1.0420298313574392, "1335": -1.9624030824042191, "1337": -0.4379052431155042, "1338": -1.1283507583261034, "1339": -0.13492827739132734, "1342": -0.4268046656836632, "1343": -0.0010239018820188746, "1345": 1.000000000002139, "1346": 1.0075985177810785, "1347": 0.742745209622715, "1349": 0.48502755513996676, "1351": -0.3931344405658458, "1353": -1.2150520940376706, "1355": 0.651769292121749, "1357": 0.20418567167729249, "1358": -1.5366367640013456, "1361": 0.4635656994728954, "1362": -0.05354375672310444, "1363": -0.062299270151628956, "1365": 1.2766167721843507, "1366": 1.4125070483494067, "1370": -1.0000000000020905, "1371": -0.44347857141105707, "1373": 0.1239248604488325, "1374": -1.802909846410515, "1378": -0.6478556532854871, "1379": -1.0709218914201715, "1381": -0.24938232064982263, "1382": 0.4965792427057747, "1383": 1.000000000002908, "1385": 1.0907531282135856, "1387": 0.18924315704912292, "1389": -1.4972854847869153, "1390": -0.24245729038410455, "1391": 0.4603094524449517, "1393": -0.8418771944475076, "1394": -0.02336226585127055, "1397": -0.4241740135964532, "1398": -1.3426837023922145, "1401": 1.205660986254728, "1402": -0.2778028588683769, "1403": 0.4246717833647646, "1405": -0.7336634690801532, "1406": 0.5208942627642342, "1407": -0.26189646211848805, "1409": 0.2835987866848516, "1410": 1.0000000000085265, "1411": -0.8493889481587109, "1414": -1.5467923651627595, "1415": 1.9407063412015793, "1417": 0.6345336816392362, "1418": -0.9465923514994663, "1419": -2.556470619343939, "1423": -0.2482591579392319, "1426": -0.4456025545052863, "1429": 0.6886841795048444, "1430": 0.873214185012993, "1433": -0.47727054233914107, "1434": 0.04131523718558006, "1435": -0.20889163286046425, "1437": 1.4974495025970793, "1438": 0.6618722853923911, "1439": 0.7486522440952725, "1441": 0.5256729048340106, "1442": -0.11516662503182581, "1443": -1.45132513862857, "1446": -1.5478074196089735, "1447": -1.9362676326715784e-12, "1451": -0.1024871317823905, "1453": -0.7089449817201888, "1454": 0.08685644547126943, "1455": -0.9999999999997492, "1457": 2.235707374595393, "1461": 1.0950271036616201, "1462": 0.511940361711916, "1463": -1.8927140261600142, "1465": 1.4010823995629273, "1466": 0.04202983135753861, "1469": 0.3704642654083645, "1471": -1.2558349450550716, "1473": 0.8008536326225544, "1474": -0.2589454916956612, "1477": -0.9119543819275472, "1478": 0.22259587999108182, "1479": 0.2935405161758538, "1481": 1.3163883175605922, "1482": 0.37500671557266746, "1483": 0.10112106083525318, "1486": 0.7843279609157131, "1487": -0.5027601725581512, "1489": 0.06641623987798666, "1490": -0.5627581749495413, "1491": -1.6123772120357127, "1493": 0.4470275117361083, "1495": -1.7956641715262618, "1497": -0.21404152015786695, "1498": -1.390508741333014, "1499": -1.3937769682369325, "1501": -7.405718135106941e-12, "1502": 1.796773769332388, "1505": 0.5126814594969691, "1506": -1.0822814993344687, "1507": 0.2786758170132837, "1509": 1.638480206060128, "1510": -0.7369276225430961, "1511": -0.523767602724839, "1513": -0.2494045162048218, "1514": 1.0000000000147315, "1515": -0.5135716383002414, "1517": 0.039449133458543326, "1518": 0.6893791409028943, "1522": 1.4319045034500175, "1526": -0.20898864663128702, "1527": -0.7433493495570266, "1529": -0.28762910053948326, "1531": -0.31205866986937414, "1533": -0.5149724448490437, "1534": -0.9999999999997161, "1535": -0.0024553367317742074, "1537": 1.7217196644249873, "1538": -0.02930832198455972, "1541": -0.7038838293223741, "1542": -0.6565530527926265, "1545": -0.42437711290144375, "1546": 1.802772029369492, "1547": -0.3340744702447118, "1549": 0.07580369309127019, "1551": -1.5259764207997168, "1553": -0.1797919847832188, "1554": 1.727243162703205, "1555": 1.0643552542888821, "1558": -0.8282045579117395, "1559": 0.12272760698750845, "1561": 0.28643631277670883, "1563": 0.41476035949355267, "1565": -3.729014495161399e-12, "1567": 0.22371795555555357, "1569": -0.18924315704985686, "1570": -0.21890812775872948, "1571": 0.0756017386807383, "1574": -0.5151733631778367, "1577": 0.0526265587013618, "1578": -1.4559489330580324, "1579": -1.000000000001743, "1581": -2.594232972661043e-12, "1582": -1.6151538855853211, "1583": -0.5064947820707696, "1585": 0.23269513883080678, "1586": -0.3286370643611611, "1589": 0.27854195738952087, "1590": 4.330614451081738e-12, "1591": -0.5561013147682745, "1594": 0.7887985917374741, "1595": 0.527007985370173, "1597": -0.7940357508975927, "1598": 1.7332736666732147, "1599": 1.732920948288684, "1601": 1.5101784903610547, "1603": 0.1833132216604765, "1605": -0.17912563172268126, "1606": -0.039262142123244546, "1607": 0.004808309986086068, "1609": 1.3021161753963013, "1610": 1.7266438800712234, "1613": 3.0919754638839815e-12, "1614": -1.0892364762807694, "1615": -1.0000000000028377, "1618": -1.5948628637860716, "1619": -1.0115767321051203, "1621": -0.2514956453552809, "1622": -2.1364180025746116, "1623": 2.650885715149021e-12, "1626": -0.6237232633901891, "1627": -0.10793799908213636, "1630": 1.0923337147341439, "1631": 1.0000000000013065, "1633": 0.9241686168366036, "1634": -0.14618114140510216, "1635": 0.045308438424029776, "1637": 0.16336507015631482, "1639": 1.0000000000029476, "1641": -0.6649931053519903, "1642": -0.6953396338860925, "1643": 0.9999999999985736, "1645": -0.5082310563206909, "1646": -0.44347857140504393, "1649": 0.8683655411675094, "1651": 0.15708900489008165, "1653": -0.06514964475511602, "1654": 0.9999999999995598, "1655": 0.5023809492770257, "1657": -0.9999999999997237, "1658": 0.9999999999953677, "1659": -0.38756856768509323, "1661": 1.0000000000040532, "1662": -0.19955471176919176, "1663": -1.0000000000006803, "1667": -1.118102137322801, "1669": -0.8818978626780463, "1670": -0.6219219938912842, "1671": -0.16013786163867832, "1673": 0.9999999999974909, "1677": -0.5054306211405317, "1678": 0.25704470534730334, "1679": -0.10873122639360325, "1685": 1.3241000022650293, "1686": -0.551765761334419, "1689": 1.0000000000007951, "1691": 0.7744355653001292, "1693": 0.8130206351648017, "1695": -0.7748087270503599, "1697": -0.18590104526681336, "1698": -1.6039771842805517, "1699": -0.7585206806718907, "1702": -0.923583467559448, "1703": 0.3591447252658149, "1705": -0.773753683232373, "1706": 1.17823334400769, "1707": 0.03525238606394245, "1709": -0.36935786083894884, "1711": 1.0000000000006761, "1713": 0.2818668251830721, "1714": 1.0000000000013856, "1717": 0.12144439475818303, "1718": 0.8124717232736249, "1721": -2.8269253876549794e-12, "1722": 0.06547670391298716, "1726": 1.0431694215844118, "1727": 1.0000000000013418, "1729": -1.1043667614388162, "1730": -0.9999999999997945, "1731": -0.3287352346048631, "1733": -0.33219811176870184, "1735": 0.5197769382944484, "1738": -0.7369170683593957, "1739": 0.2059245208982271, "1741": -0.6016861170665652, "1742": -0.8316486875783496, "1743": 0.3237497636363865, "1745": -0.28186682518363204, "1747": 0.23776041295286857, "1749": -0.4848266368028057, "1751": 1.0000000000002034, "1753": -1.000000000002175, "1754": 0.32936659618814224, "1757": 0.18123012911186875, "1758": 1.1173738521101597, "1759": -1.000000000000173, "1761": 0.5433711715898807, "1762": -0.2119445360216538, "1763": 1.0000000000025064, "1765": 1.000000000000487, "1766": 1.0000000000001756, "1767": -0.49513808866104636, "1769": 2.31999146556123e-11, "1770": 1.340773624289644, "1771": -6.1469168592790375e-12, "1774": 0.8266390327683576, "1777": -0.7204535226003035, "1778": -0.9999999999739746, "1779": 0.122865820438, "1781": -5.932794803463776e-12, "1783": -0.0829986216322256, "1785": -0.3632811958862824, "1786": -0.24166151262206215, "1787": 9.488365471168199e-12, "1789": -0.9999999999940177, "1790": -1.2936789129355188, "1794": 1.1099667369144255, "1795": 0.5495185760764869, "1797": 8.206567036053012e-12, "1798": -0.8491045145895939, "1799": 0.011576732103167162, "1801": 0.48005617004679757, "1802": -0.8124229118368442, "1803": -0.9999999999989089, "1806": 1.2528320234142778, "1807": -0.24672306360193266, "1810": -0.7445166982814582, "1811": -0.2778299215796244, "1814": 1.036376513832969, "1817": 1.345414943774662, "1819": 0.06433321446676153, "1821": 0.39977984215157025, "1822": 2.797724617315862e-12, "1826": 0.6521242995053385, "1829": -0.49257924134888426, "1830": 0.575328216599205, "1831": 1.0000000000047922, "1833": 0.9030623142845966, "1834": -0.6358792654303432, "1835": 1.1213983579549311, "1837": -4.784386312382872e-11, "1838": -1.0261833520876547, "1839": -0.04915802323021539, "1841": 0.1174226864827539, "1842": 1.4904413578442748, "1843": -0.7008868389939247, "1846": -1.3408147307333254, "1847": -1.7774041199810566, "1853": 0.22451763988500817, "1855": -0.18953301603449685, "1857": 1.3821124351092664, "1858": 0.33912803451259516, "1861": 0.4282718910895996, "1865": 0.08981706510110213, "1866": -1.999999999999684, "1867": -0.06515587134243499, "1869": -0.6479317910470659, "1870": 0.8419277603865827, "1871": -5.6371431585516934e-12, "1873": 2.4269177605015733e-11, "1874": 0.005734769450265893, "1877": -0.10387507083353806, "1878": -0.4568465147446318, "1879": -1.2868821585894792, "1882": 0.9491766587060696, "1883": -1.043492810535975, "1885": -1.4797902945931958, "1886": 0.7438104922113898, "1887": -0.5023809492436859, "1889": 0.16310268872065278, "1891": 1.0716646290664025, "1893": 0.7941904232661481, "1894": 0.9359768510174624, "1895": 0.20460250947224376, "1897": 0.3482307078783894, "1898": -0.3513079617770019, "1901": 0.7277236115771274, "1902": -0.23752704982282571, "1903": 0.10902403437053364, "1905": 0.46618132565742165, "1906": -0.3656635267710341, "1907": 0.12678581499391903, "1909": 1.1114853826003908, "1910": -1.9846330025774397, "1913": 0.31053476375848726, "1914": 2.743253898066874, "1915": -0.3120586698612901, "1918": -0.15795165008989837, "1919": 0.8604529335222798, "1921": -1.5845088444559539, "1923": 0.39866618282010624, "1927": 0.9829917998108259, "1930": -0.6813462033473556, "1931": -1.458624540190016, "1933": 0.27056434454398404, "1934": 0.0565406852309388, "1937": 0.059793617034364616, "1938": 1.109710644012282, "1939": 0.8004452882338144, "1941": 0.03367496193224399, "1942": -0.622726840525466, "1943": -0.05522243855331635, "1945": 0.1191979235780249, "1946": -1.2217443693696177, "1947": -1.4259453883648872, "1949": -5.397653131651599e-12, "1954": -0.6548832796368196, "1955": -0.582389635794376, "1957": -0.10890880188370894, "1958": -0.3200851311565708, "1959": 1.1763376364436034e-12, "1961": 9.32838235664385e-12, "1963": 0.9969530635136794, "1965": -1.4550055117037441, "1967": 0.044406929923550435, "1969": 0.9999999999997166, "1970": 0.9416317151939779, "1973": 1.2911842589963567, "1974": 0.8155671419808429, "1977": 1.1456450530083475, "1978": 0.8386532493211707, "1981": 1.5139012773717682, "1982": 0.15512564054752745, "1983": -0.8620238310534978, "1985": 0.22728273606965402, "1986": -1.3137949999084484, "1987": 0.9536708763262354, "1990": -1.7973078443622146, "1991": 0.06642534511230815, "1993": 1.0164378274861297, "1994": 0.5002607270348338, "1995": -0.5428311834371882, "1997": 1.5763422156311314e-12, "1999": -0.1122980419932096, "2001": -0.3850384383795547, "2002": 0.8646886631121661, "2003": -0.1300810381919587, "2005": 1.5438859451580873, "2006": -0.5407544777230325, "2010": 0.6584886621405898, "2011": -0.33256369306407524, "2013": -0.9318367050723186, "2014": -0.005950403634602679, "2015": -0.6428904631644814, "2017": -0.7503091377542005, "2018": -0.41018946124333877, "2019": 0.08772327363996807, "2021": 0.7600672701274429, "2022": -1.1099740725782128, "2026": -0.706248439980968, "2027": -0.36093173963009784, "2029": -0.11887026297502085, "2030": -0.23417313956600444, "2031": 1.9908452046393377, "2033": 0.20293077760971326, "2035": -0.10517936326354335, "2037": -0.3820120655261158, "2038": 0.4765808454437821, "2039": -0.1370462633912193, "2041": -1.4604230078496576, "2042": -0.02229615186996554, "2045": 0.9135585133242172, "2046": 1.7881765679325292, "2047": -0.5771298365160463, "2049": -0.4125070483694743, "2051": -0.013014190367834832, "2053": -7.387000065881564e-12, "2054": -0.7331921512976234, "2055": -0.4566288284087804, "2059": 0.860693087787273, "2062": 1.0512125143506492, "2063": 0.23791122315341676, "2065": 0.43394433337668886, "2066": 3.393890885406713e-12, "2067": -0.35214434671621675, "2069": 1.1159598382563765, "2073": 0.6915188826136434, "2074": -0.7962380092532491, "2077": -0.7292170420997658, "2078": -0.9405493662032499, "2081": -0.19397920175014527, "2082": 0.32576833605275873, "2083": 0.14156440220307528, "2085": -0.2856110999181322, "2086": -1.1119702495759098, "2087": 0.7410545083043093, "2089": 0.3616496818808616, "2090": 1.0899424570256437, "2091": -1.048818499707591, "2093": 0.6062491381284444, "2094": -0.7181331748180138, "2095": 0.15628039661598056, "2098": 0.8134139242345308, "2099": -0.6792573646367829, "2102": 0.09350340450771676, "2103": -0.3735835614770624, "2105": 2.3797918648151493, "2109": 1.326261913967513, "2110": -1.2928879433927463, "2111": 0.7063210870688093, "2113": 3.289404824896877e-12, "2114": -1.0848754938106757, "2117": -0.6116533637049197, "2118": 0.08718042409599035, "2119": -0.1939300280597266, "2121": -1.451710834537982, "2122": 0.6910688760477068, "2123": 1.0352263372822883, "2126": -0.9698578775234464, "2127": -0.24034391151132933, "2129": 0.9999999999961597, "2130": 0.5623202162383836, "2131": -0.5083446646890646, "2134": 1.0214829796962237, "2135": -1.844829270705553, "2137": -0.1833132216601628, "2138": -0.2736140702915935, "2139": -0.2851068920319063, "2143": 0.19551212984291969, "2145": 0.6717004724874353, "2146": -0.45812020381821716, "2147": 0.885490458330243, "2149": -0.002455336732061113, "2153": 0.12870367627128151, "2154": -1.128560784775938, "2155": 0.5558026885205022, "2157": 0.736100999528161, "2158": -1.0249413303894952, "2159": -1.097701381818733, "2161": -1.3583344078778323, "2162": -0.14391695935369087, "2163": -0.6251043428407669, "2165": 1.4079215412403292, "2167": 2.0747972328666537, "2170": 0.5023809492772784, "2171": 1.928836608016831e-12, "2173": -0.04839295078542155, "2174": -0.2637786030636041, "2177": -0.7429384877217828, "2179": -1.2601325621604026e-12, "2181": 0.08499584577425097, "2182": 0.9999999999954313, "2185": -0.6033690070858329, "2186": 0.301979136804984, "2189": -1.1458426954793906e-11, "2190": 2.291744512446512, "2191": 0.7347806230585212, "2193": 0.767911416455246, "2194": 0.19498652785350262, "2195": 0.9252027671202981, "2198": -1.198386890294704, "2199": -0.5237414644961701, "2201": -0.06284051413584361, "2202": -1.7869239452880703, "2206": 1.1068193643509598, "2207": -0.10260110709980602, "2210": 1.0395932698006043, "2211": 0.0029509704296260706, "2213": -0.21474062324065304, "2215": 0.05661679744927451, "2217": -0.9999999999993403, "2218": 1.046557443974622, "2219": 0.33025363856026335, "2221": -0.4172330263820545, "2222": -0.39857409504662245, "2226": 1.1234949059304122, "2229": 0.813540435267773, "2230": -0.9461443604823525, "2231": -0.010517701148368608, "2233": -0.42031915673167386, "2234": 1.8809109022315254, "2235": 0.24312610910260304, "2238": -0.29619555817425747, "2239": -0.780826098261499, "2242": -0.9999999999610697, "2243": 0.809790887791236, "2245": 0.6212347188299467, "2246": 0.6030766447568146, "2247": -0.9271766470205596, "2249": 0.7384823907898566, "2251": 0.3207595935997384, "2253": 0.5520547963230225, "2255": -0.9406245103010406, "2257": -1.46109182460832, "2258": 0.919408840162031, "2261": -1.6450999221418208, "2262": 1.1393196453263048, "2263": 0.020802681326397107, "2265": -0.5482395417970456, "2266": 0.5253164321345589, "2267": 0.333243029722818, "2269": 0.3775731420720924, "2270": -1.4528039015096577, "2271": 0.9999999999965439, "2273": -0.018494414759985544, "2274": -0.02228811346263122, "2278": -0.9999999999960272, "2279": -0.37358356147682253, "2281": -1.000000000003065, "2282": -1.9728763386169752, "2283": 1.000000000030982, "2285": 0.4392690737534908, "2287": -1.0831102206273164, "2289": -2.1214443947585377, "2290": -0.9237609793521271, "2291": 0.14671363690358138, "2293": 0.5076920225579583, "2294": 0.02864038079639639, "2297": 1.402489260893164, "2298": 0.5913073353706366, "2301": -0.6626989084011701, "2302": 1.0180509584021502, "2305": 0.12835075831429557, "2306": -0.12713496487088266, "2307": 0.7241638500491551, "2309": 0.42200435205922116, "2310": -1.0803097205299679, "2311": 4.835599915094713e-12, "2314": -1.0206452308683267, "2315": 0.9462362941405372, "2317": -0.005869364163357939, "2318": -1.0573090370140075, "2319": -0.58968536455413, "2321": -0.27582919524486754, "2323": -0.06001518127178135, "2326": 0.7388639524017531, "2327": 0.13598755104843352, "2329": 0.5132411245063128, "2330": -0.6560251812862139, "2333": -1.0000000000017268, "2334": -0.8374776015217098, "2335": -1.1754568874349305, "2337": 0.5000771867727829, "2338": -0.04332447489532402, "2339": -0.47299201463264384, "2341": 0.14887621099739332, "2342": 1.1274404373150553, "2343": -1.3495284556619436, "2345": 1.1016152533843349, "2346": 4.201095973764415, "2347": -0.013776931914249878, "2351": 3.309106706807608e-12, "2353": 0.6498163499448085, "2354": 0.3629591815814641, "2355": -0.45189449282885946, "2359": -1.3305677890337206, "2361": 1.000000000001763, "2362": 0.871499804286366, "2363": 1.2120252973801242, "2365": -0.03900493000118672, "2369": 1.2896172137053186, "2370": 2.278633596437424, "2371": 0.7585206806622529, "2373": 0.36210044785683676, "2374": -0.21676013470821748, "2377": -0.22439964589040576, "2378": -1.392251005380625, "2379": -0.33437183384540997, "2381": -0.8088837503808475, "2382": -1.4962177700333052, "2383": -0.9999999999967677, "2386": 0.018492640912625143, "2387": 4.258415490816782e-12, "2389": -1.000000000000989, "2390": -0.6769024414775611, "2391": 0.24009966578007913, "2393": -1.9677138628318345, "2395": 0.8177936021461841, "2397": 0.9777038481439173, "2398": -0.08200462400634062, "2399": -1.00000000000382, "2402": -1.2908789286868523, "2405": -1.0000000000175304, "2406": -0.06989413326959276, "2407": 1.0000000000060674, "2409": 0.14311431075946165, "2410": 0.2338423158635234, "2411": -0.8877176617243258, "2413": 1.0000000000006128, "2414": 0.13714036363770013, "2415": 0.4752913638265757, "2418": 1.7399984798085033, "2419": 0.9999999999997345, "2422": -0.3303523896835997, "2423": -0.43656487320659815, "2426": 0.9117253924275667, "2427": -0.8579352412475604, "2429": 0.3970420718487999, "2431": -0.3215631662809552, "2433": -1.8680792650462208, "2434": -1.7425052787112218, "2435": 0.6062230317645638, "2437": -0.9999999999994567, "2438": -0.38203171479934783, "2441": -1.000000000005818, "2442": 1.0000000000018963, "2443": 0.9999999999953281, "2445": 0.33581240340231416, "2446": 2.840085548241631, "2447": -1.0000000000002007, "2449": 0.23147304654528106, "2451": -0.11051501301902919, "2453": 0.736222176994665, "2454": -0.9690188001918123, "2455": 1.2367520830575351, "2458": -0.34293655663073, "2459": -0.7447324077165165, "2461": 0.9999999999986601, "2462": -1.3548876227326418, "2463": -0.20413742171624236, "2465": -1.0829499645273903, "2467": -0.8878184224454381, "2469": -0.4434785714104724, "2470": 0.13724195839518397, "2471": 0.9999999999999304, "2473": -0.9999999999989992, "2474": -0.013570155959326194, "2477": -0.6843759238523694, "2478": 0.8511237889983237, "2479": 1.0000000000017022, "2481": 0.9458234104493616, "2482": 0.27307641432856633, "2483": 0.20966444955322658, "2485": -0.3202955336956909, "2486": 0.5780756937822524, "2487": 1.0000000000019356, "2489": 1.0000000000004876, "2490": 1.0257123961510834, "2491": 0.9781096004265394, "2494": -0.048911554969013504, "2495": 0.7585206806669551, "2497": 0.3639799284531777, "2498": -0.9942652305228583, "2501": 1.1154179527536485, "2503": -0.11541795275613664, "2505": -0.6219219938871705, "2506": -0.27212588209601524, "2507": 1.0000000000002718, "2509": 0.8231633770592429, "2510": -0.9561721017839964, "2513": -0.19979355418652836, "2514": -0.7125586773037641, "2515": 0.057345358501402426, "2517": -0.5404806884810844, "2518": 0.6189831964181387, "2519": 1.712113602490744, "2521": -0.059843066982410154, "2522": -2.2115640813162076, "2526": -2.9985618233481244, "2530": 0.04971653092472085, "2533": -0.9999999999899043, "2534": -0.6858461048164703, "2537": 0.4836193005256538, "2539": -0.7386457298361295, "2542": 1.1816318816418285, "2543": 0.08220283163372366, "2545": 0.4419423635126054, "2546": 0.5941650420527016, "2549": 0.20738672268001462, "2553": -0.68054149211917, "2554": 0.9667568293057015, "2555": -0.4817889548053015, "2557": 0.13397493501768734, "2558": 0.8202204609128966, "2559": 1.0000000000137026, "2561": 0.07479723286376908, "2562": -2.173055961712833, "2563": 0.3439748187450209, "2566": -0.6107749544354838, "2567": 1.6445832331232955, "2569": -0.12139835795476775, "2570": -0.19661046813882976, "2571": 2.338230296691613, "2573": -0.6506486451266993, "2577": -0.04620795161542539, "2578": -1.1517686342977542, "2579": 0.2697807993947085, "2581": 1.4865925937505284, "2582": -1.5958466411546952, "2585": 1.5047396994546043, "2586": -0.5221277265978976, "2587": 0.37931298690058135, "2589": 0.31034059289046234, "2590": 0.39938304239495903, "2591": -0.7925654369945158, "2593": 2.378000587474111e-12, "2594": 0.24625298741035392, "2595": 0.07999526195741889, "2598": -0.667662196901747, "2599": 0.3261498020017307, "2602": -0.5792770947351573, "2603": 0.4859059853731488, "2605": -0.07727744028253117, "2606": 1.4400707270466049, "2607": -3.4348808775581574, "2609": -0.0174240816115254, "2611": 0.48909854065822117, "2613": -0.11361336323522017, "2614": -0.03741476460141782, "2615": -0.08139710551329547, "2617": 0.15201361796790366, "2618": 1.6323610905725223, "2621": -0.856648625299593, "2622": 1.5466890213197766, "2623": 1.1865860757944453, "2626": -0.6585166064632204, "2627": -1.0935331871010774, "2629": -1.2555064105161011, "2630": 2.7835441529877816, "2631": 0.02754108909714186, "2634": -1.9178007689094196, "2635": -2.0000000000046083, "2638": -0.23103744506530394, "2639": 0.5959686500231558, "2641": 0.9955568277346069, "2642": -0.9241873415918727, "2643": -1.3744783573277621, "2647": -0.7932612266728495, "2649": 0.9824462585743785, "2651": 0.46062858847326726, "2653": -0.08326462048063386, "2654": -0.10763726689260969, "2657": 0.16143467020657, "2658": -1.7140295897282574, "2659": 1.6591593314032964, "2661": 0.8604882941559794, "2663": 6.3094776424700894e-12, "2665": -0.256612030279197, "2666": -0.1731071632851648, "2667": -1.8109872904622226, "2669": 0.6304981188230824, "2670": 1.3852732459018793, "2671": 0.29239967339414624, "2674": 1.945597265669334, "2677": -1.0057347694513472, "2678": -0.3510830366696114, "2679": -3.1423390269100993, "2681": 0.5678102433329985, "2683": -0.13298399335844344, "2685": 0.04209260741558857, "2686": -0.007952216509388406, "2687": 0.26968361842381955, "2689": -0.037875045464627465, "2690": 0.4442077214902609, "2693": 0.8311181561448474, "2694": 0.011662575786964453, "2697": -0.47686450248264084, "2698": -0.48502755513945117, "2701": 1.0844241348958799, "2702": -0.6218234212532554, "2703": -0.9084819261766995, "2705": 0.22556443470307785, "2706": 2.01095443847033, "2707": 0.012918778063889125, "2710": -0.8054501487025739, "2711": -0.0773479912314741, "2713": -0.7410545083034423, "2714": 0.22361716301965198, "2715": 1.1895259391921416, "2717": -0.2670671521300079, "2719": 0.03592520255646702, "2721": 0.5847750750909835, "2722": -0.46356569948361714, "2723": 0.6469674113705198, "2726": -0.21541314655193927, "2729": 1.234007613030201e-12, "2730": -1.603210648407504, "2731": -0.4017999412788522, "2733": 1.1585954478433458e-12, "2734": 1.0212899407964245e-12, "2735": -0.6649931053526288, "2737": -1.000000000002601, "2739": 0.6521242995725115, "2741": -1.0000000000587856, "2742": 0.4434785714083345, "2743": 0.9999999999982317, "2746": -0.12392486044476654, "2747": 0.945068189529339, "2749": -0.1283814111964354, "2751": -0.5174428117225206, "2753": -1.000000000000188, "2755": -1.4817819024442431, "2757": -0.026183352131681423, "2758": 1.0709218914207956, "2759": 0.9999999999994242, "2761": -0.7364883715586995, "2762": 1.7600955606503261, "2765": 0.7783565817437819, "2766": -0.9253894284922801, "2767": -0.20464038829008657, "2769": -0.4771293201678879, "2770": -0.2903078399816541, "2771": 0.9999999999992941, "2773": 0.9999999999983039, "2774": -1.2330602350240798, "2777": 0.04381707797633402, "2778": 1.497285484787342, "2779": 0.5140352322553142, "2782": -1.8793206381594096, "2785": -0.9337322932324594, "2786": 2.003428756083856, "2787": 0.7887402047640795, "2789": 0.5109693138648316, "2791": -0.9999999999999807, "2794": -0.0812566075186116, "2795": -0.7444463573640021, "2797": -0.6560251812546959, "2801": -0.9999999999999825, "2802": -2.199612730967788, "2803": -0.00604825528710661, "2805": 1.9605462411349572, "2806": -0.42467178333538275, "2807": 0.9999999999987251, "2810": -0.02624911165122703, "2811": 0.7599125807433271, "2813": 0.5577121286698754, "2814": 0.8196309263923478, "2815": 0.4985362222001453, "2818": -0.28359878668446736, "2819": 0.04461726307185085, "2821": -0.3109637263769969, "2822": 0.849388948158912, "2823": 1.2106463723565217, "2827": 1.2653195640781485, "2829": 0.4023299690482183, "2830": -1.940706341200703, "2831": -0.1630502966517111, "2833": 0.1630502966482001, "2834": -0.4100160417516641, "2837": -0.2937515600074391, "2838": 2.8832081247439185, "2839": 0.5716106600681217, "2841": 0.8662163706940444, "2843": -1.0000000000002984, "2845": 0.03525238606360854, "2846": 0.24825915793916173, "2847": -1.1910239141420285, "2849": -0.9999999999955332, "2851": -0.9999999999969783, "2854": 0.5297778113432717, "2855": -0.2725306203262681, "2857": -0.9999999999964214, "2858": -0.8323351816995063, "2859": -0.26404235593554604, "2861": -0.8732141850019298, "2863": 0.9999999999980513, "2865": -1.621802278795143, "2866": 0.47727054233920707, "2867": 1.0000000000008638, "2869": 1.0000000000038642, "2870": -0.06800463152494429, "2874": -1.724907610752364, "2877": 0.1729618085542859, "2878": -1.0703723798691387, "2879": -0.3766694099468219, "2881": 0.8295121438576564, "2882": -0.35518504868375456, "2885": -0.539898972574619, "2886": 2.0443256445569475, "2887": 0.4946551473727012, "2893": 0.13893412468318522, "2894": 0.9999999999899303, "2895": -0.34036429101271004, "2897": 0.22887686226392664, "2899": -0.15808555445025216, "2901": 0.34297699801088516, "2902": 0.102487131782805, "2903": -0.9999999999993161, "2905": -1.0038436738157501, "2906": 0.6956670119335152, "2909": -0.6239491359475603, "2910": 0.9687848595539125, "2911": 0.9999999999959901, "2913": -1.3702869794710897, "2914": -2.2357073745946194, "2915": -1.8106005904183067, "2917": -0.18939940956423215, "2919": -1.9434139941215243, "2921": 1.480987669495117, "2922": -0.3768939288686711, "2923": 1.000000000015936, "2926": 1.7300136354721494, "2927": -0.6224878882538158, "2929": 0.622487888258233, "2930": -2.3144229543607926, "2931": 0.48907169382683, "2933": 1.8217333607889319, "2935": 0.09875511616633369, "2937": 0.5777359607716606, "2938": -0.23325344544125995, "2939": -0.999999999999912, "2942": 1.2558349450448545, "2945": 0.17425690009062755, "2946": -0.4702486213621183, "2947": 1.0000000000006581, "2949": -0.4627007995294947, "2951": -0.05793780160951868, "2953": -0.23730864565439302, "2954": 0.9119543819292372, "2955": 0.559247189688152, "2957": -0.999999999999961, "2958": -0.2935405161753224, "2959": 0.9999999999912512, "2962": -1.014644754164418, "2963": -0.8051643206616347, "2965": 0.4018836236024187, "2966": -0.1011210608376855, "2967": 0.3464853809503524, "2969": -0.9999999999821811, "2971": -0.9100575429851439, "2973": 0.41273912960401804, "2974": 0.5027601725785943, "2977": 0.9862230680415417, "2978": -0.06641623985514082, "2981": 0.6421755921400413, "2982": 1.229312741035635, "2983": 0.5668408636897131, "2985": -0.44635773203085116, "2986": -0.44702751173537925, "2987": 0.9818641724092654, "2990": 1.1148403739380612, "2991": 0.29583866299967065, "2993": 0.337071723676293, "2994": -0.6618732343478314, "2995": 0.5787146276834828, "2998": 1.3937769682417345, "2999": 1.5513199727307312}} +RLMATH_EOF diff --git a/tasks/optimize-ea-prime-number-theorem/tests/check.py b/tasks/optimize-ea-prime-number-theorem/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d102c8e6d2d57cee4c45d23d1ce1004d5d45f260 --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/tests/check.py @@ -0,0 +1,44 @@ +"""Prime number theorem certificate (EinsteinArena prime-number-theorem, MIT). + +f: finite partial function on positive integers; f(1) is adjusted so that sum f(k)/k = 0; the constraint is +F(x) = sum_k f(k) floor(x/k) <= 1; score S = -sum f(k) log(k)/k (maximize). + +Upstream weakness fixed: the constraint was checked on 10^7 Monte-Carlo samples x ~ U(1, 10 max k) with +tolerance 1e-4, so narrow violations could slip through. F is a step function that only changes at +integers, so here it is checked at EVERY integer 1 <= x <= 10 max k (sieve + cumulative sum), with +tolerance 1e-9 (float round-off of the f(1) normalisation). Other changes: values must lie in [-10, 10] +(upstream silently clipped), keys must be canonical decimal strings <= inst["max_key"].""" +import math + +import numpy as np + +from run import Invalid, num + + +def check(inst, ans): + pf = ans.get("partial_function") + if not isinstance(pf, dict) or not 1 <= len(pf) <= inst["max_keys"]: + raise Invalid(f"partial_function must be an object with 1..{inst['max_keys']} keys") + f = {} + for k, v in pf.items(): + if not (isinstance(k, str) and k.isascii() and k.isdigit() and k[0] != "0"): + raise Invalid(f"key {k!r} is not a canonical positive integer string") + kk = int(k) + if kk > inst["max_key"]: + raise Invalid(f"keys must be at most {inst['max_key']}") + x = num(v, "value") + if abs(x) > 10: + raise Invalid("values must lie in [-10, 10]") + f[kk] = x + f[1] = f.get(1, 0.0) - sum(v / k for k, v in f.items()) + X = 10 * max(f) + g = np.zeros(X + 1) + for k, v in f.items(): + g[k::k] += v + F = np.cumsum(g) + worst = float(F[1:].max()) + if worst > 1 + inst["tol"]: + n = int(np.argmax(F[1:])) + 1 + raise Invalid(f"constraint violated: sum f(k) floor(x/k) = {worst:.12g} > 1 at x = {n}") + s = -sum(v * math.log(k) / k for k, v in f.items()) + return float(s), {"max_F": worst, "checked_up_to": X} diff --git a/tasks/optimize-ea-prime-number-theorem/tests/instance.json b/tasks/optimize-ea-prime-number-theorem/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64f5557bf48d98b6d2d416993cfcb20333c69487 --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/tests/instance.json @@ -0,0 +1 @@ +{"max_keys": 2000, "max_key": 100000, "tol": 1e-09, "direction": "maximize", "best_known": 0.994179461377618, "baseline": 0.34657359027997264, "family": "ea_prime_number_theorem", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-prime-number-theorem/tests/run.py b/tasks/optimize-ea-prime-number-theorem/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ea-prime-number-theorem/tests/test.sh b/tasks/optimize-ea-prime-number-theorem/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-prime-number-theorem/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-finch-sidon-set-n121/environment/Dockerfile b/tasks/optimize-finch-sidon-set-n121/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-finch-sidon-set-n121/environment/instance.json b/tasks/optimize-finch-sidon-set-n121/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b6aba7962566d3008b6d487c51508f41e452fa4 --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/environment/instance.json @@ -0,0 +1 @@ +{"N": 121, "direction": "maximize", "family": "finch_sidon_set_121", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-sidon-set-n121/solution/solve.sh b/tasks/optimize-finch-sidon-set-n121/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c334584c6b518d6e23b3e4084645234ea7d21234 --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"set": [0, 2, 5, 25, 37, 43, 59, 70, 85, 89, 98, 99, 106]} +RLMATH_EOF diff --git a/tasks/optimize-finch-sidon-set-n121/tests/check.py b/tasks/optimize-finch-sidon-set-n121/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1de835ec9dc6dee0499e53d1c31cae499811a8ac --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/tests/check.py @@ -0,0 +1,22 @@ +"""Largest Sidon set in {0,...,120} (Finch/EFT skydiscover erdos_difference_bases_N121, Apache-2.0). +Exact integer check (all pairwise sums a+a', a<=a', distinct), as upstream. Change: entries must be JSON +integers (upstream cast with int()).""" +from run import Invalid, int_list + + +def check(inst, ans): + a = ans.get("set") + N = inst["N"] + if not isinstance(a, list) or not 1 <= len(a) <= N: + raise Invalid(f"set must be a list of 1..{N} integers") + int_list(a, None, 0, N - 1, "set") + if len(set(a)) != len(a): + raise Invalid("elements must be distinct") + sums = set() + for i in range(len(a)): + for j in range(i, len(a)): + s = a[i] + a[j] + if s in sums: + raise Invalid(f"not a Sidon set: the sum {s} occurs twice") + sums.add(s) + return float(len(a)), {} diff --git a/tasks/optimize-finch-sidon-set-n121/tests/instance.json b/tasks/optimize-finch-sidon-set-n121/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b83456e1957e0a064a4d56617003fd9d670620da --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/tests/instance.json @@ -0,0 +1 @@ +{"N": 121, "direction": "maximize", "best_known": 13, "baseline": 11.0, "family": "finch_sidon_set_121", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-sidon-set-n121/tests/run.py b/tasks/optimize-finch-sidon-set-n121/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-finch-sidon-set-n121/tests/test.sh b/tasks/optimize-finch-sidon-set-n121/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-sidon-set-n121/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-fs-cap-set-n3/environment/Dockerfile b/tasks/optimize-fs-cap-set-n3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-fs-cap-set-n3/environment/instance.json b/tasks/optimize-fs-cap-set-n3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b1d236bad13b7824b932fd0be1ad817b1ec8b25 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "direction": "maximize", "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n3/solution/solve.sh b/tasks/optimize-fs-cap-set-n3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2bd7e70f8fcfa2910dacbaba1fd91d61700c10f7 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"vectors": [[0, 0, 1], [0, 1, 1], [0, 1, 2], [0, 2, 2], [1, 0, 0], [1, 0, 2], [1, 2, 0], [1, 2, 1], [2, 1, 0]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cap-set-n3/tests/check.py b/tasks/optimize-fs-cap-set-n3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e0b4309ffc9678bb5a2f8e30718868e5c68b1874 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/tests/check.py @@ -0,0 +1,21 @@ +"""Cap set in F_3^n: no three distinct vectors x, y, z with x + y + z = 0 (mod 3). Score = size.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + vecs = ans.get("vectors") + if not isinstance(vecs, list) or not vecs or len(vecs) > 3 ** n: + raise Invalid(f"vectors must be a non-empty list of at most 3^{n} vectors") + pts = [tuple(int_list(v, n, 0, 2, "vector")) for v in vecs] + if len(set(pts)) != len(pts): + raise Invalid("duplicate vectors") + # incremental check (as in the FunSearch notebook's is_cap_set): a point may not be the third point of a + # line through two earlier points; O(c^2 n) and stops at the first violation + blocked = set() + for i, p in enumerate(pts): + if p in blocked: + raise Invalid(f"vector {list(p)} completes a line with two earlier vectors") + for q in pts[:i]: + blocked.add(tuple((-a - b) % 3 for a, b in zip(p, q))) + return float(len(pts)), {"size": len(pts)} diff --git a/tasks/optimize-fs-cap-set-n3/tests/instance.json b/tasks/optimize-fs-cap-set-n3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f54131f27f8ff8dc2504fa760029d3c7aa6a8c0 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "direction": "maximize", "best_known": 9, "baseline": 8, "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n3/tests/run.py b/tasks/optimize-fs-cap-set-n3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-fs-cap-set-n3/tests/test.sh b/tasks/optimize-fs-cap-set-n3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-fs-cap-set-n4/environment/Dockerfile b/tasks/optimize-fs-cap-set-n4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-fs-cap-set-n4/environment/instance.json b/tasks/optimize-fs-cap-set-n4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a1a4a956e86c02b561bb1d6948f4e3e48b080dd --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/environment/instance.json @@ -0,0 +1 @@ +{"n": 4, "direction": "maximize", "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n4/solution/solve.sh b/tasks/optimize-fs-cap-set-n4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..43cfe7d3337247153d93b4eca3150ed6633a655a --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"vectors": [[0, 0, 0, 1], [0, 0, 0, 2], [0, 0, 1, 1], [0, 2, 0, 0], [0, 2, 0, 2], [0, 2, 2, 0], [1, 0, 0, 1], [1, 0, 1, 2], [1, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 2], [1, 2, 0, 0], [1, 2, 0, 1], [1, 2, 1, 0], [2, 0, 0, 2], [2, 0, 1, 1], [2, 0, 1, 2], [2, 1, 1, 0], [2, 1, 1, 1], [2, 1, 2, 0]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cap-set-n4/tests/check.py b/tasks/optimize-fs-cap-set-n4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e0b4309ffc9678bb5a2f8e30718868e5c68b1874 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/tests/check.py @@ -0,0 +1,21 @@ +"""Cap set in F_3^n: no three distinct vectors x, y, z with x + y + z = 0 (mod 3). Score = size.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + vecs = ans.get("vectors") + if not isinstance(vecs, list) or not vecs or len(vecs) > 3 ** n: + raise Invalid(f"vectors must be a non-empty list of at most 3^{n} vectors") + pts = [tuple(int_list(v, n, 0, 2, "vector")) for v in vecs] + if len(set(pts)) != len(pts): + raise Invalid("duplicate vectors") + # incremental check (as in the FunSearch notebook's is_cap_set): a point may not be the third point of a + # line through two earlier points; O(c^2 n) and stops at the first violation + blocked = set() + for i, p in enumerate(pts): + if p in blocked: + raise Invalid(f"vector {list(p)} completes a line with two earlier vectors") + for q in pts[:i]: + blocked.add(tuple((-a - b) % 3 for a, b in zip(p, q))) + return float(len(pts)), {"size": len(pts)} diff --git a/tasks/optimize-fs-cap-set-n4/tests/instance.json b/tasks/optimize-fs-cap-set-n4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f14c8c5f615e2a1ee60204c4768962fd5696a88d --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/tests/instance.json @@ -0,0 +1 @@ +{"n": 4, "direction": "maximize", "best_known": 20, "baseline": 16, "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n4/tests/run.py b/tasks/optimize-fs-cap-set-n4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-fs-cap-set-n4/tests/test.sh b/tasks/optimize-fs-cap-set-n4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt