diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s0/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s0/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..868bc2ea936c1bb45e3322ef40bb63d23a5bc198 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"N": 568, "t": 174, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s0/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6ceab9f51613030d8814d7407e1c1f86aed397c2 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [348, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 174, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 175, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 177, 177, 177, 177, 177, 177, 177, 177, 177, 178, 178, 178, 178, 178, 178, 179, 179, 179, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 181, 181, 181, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, 183, 183, 183, 183, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 189, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 191, 191, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 193, 193, 194, 194, 194, 194, 197, 197, 199, 199, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202, 202, 202, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 206, 206, 206, 206, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 213, 213, 213, 213, 213, 213, 213, 213, 214, 214, 214, 214, 214, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 217, 217, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 223, 223, 226, 226, 226, 226, 226, 227, 227, 229, 229, 233, 233, 237, 237, 237, 237, 237, 237, 237, 239, 239, 241, 241, 249, 249, 249, 249, 249, 249, 251, 251, 254, 254, 254, 254, 257, 257, 262, 262, 262, 262, 263, 263, 269, 269, 271, 271, 274, 274, 274, 274, 277, 277, 278, 278, 278, 278, 281, 281, 283, 283, 291, 293, 298, 298, 298, 302, 302, 302, 307, 309, 311, 313, 314, 314, 314, 317, 323, 326, 326, 326, 331, 334, 334, 334, 337, 346, 346, 346, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s0/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-s0/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..868bc2ea936c1bb45e3322ef40bb63d23a5bc198 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"N": 568, "t": 174, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s0/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p54-touching-cylinders-l1-s0/environment/Dockerfile b/tasks/construct-ae-p54-touching-cylinders-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-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-ae-p54-touching-cylinders-l1-s0/environment/instance.json b/tasks/construct-ae-p54-touching-cylinders-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..721df07528b0a9790618b6bdf9a0ab22afcfab4b --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "unit_radius": true, "tol": 1e-09, "family": "ae_p54_touching_cylinders", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p54-touching-cylinders-l1-s0/solution/solve.sh b/tasks/construct-ae-p54-touching-cylinders-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ed82e27af52c6c24c62020ea79edb542a4b4e5c9 --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-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' +{"cylinders": [[-0.895079798222949, -0.218667037637932, -2.698674434206914, 0.455691112272712, -0.886598452747669, -0.079301915368401], [2.312489793725001, 3.147856283569415, 0.748107205326668, -0.664105297845157, 0.595346549216158, -0.452246215805514], [3.170115696452898, -1.572941214905496, 0.275241501569553, 0.101170430028976, 0.365792590480751, 0.925181238913292], [1.406156005670123, -0.503509206206139, -1.138840951658002, 0.278750862076112, 0.957110225796107, -0.078980836715941], [3.310296433116253, -4.04403876669603, 1.793851653115256, 0.391295737183334, 0.621396411266488, 0.678788734531799], [0.571615889126358, 0.70496184855727, 0.536647055898052, 0.303154750428934, -0.720544668653402, 0.623628557530466], [0.91063644953714, 1.170580327427548, -3.796585078946353, 0.071052005884345, 0.948268376505215, 0.30941670701495]]} +RLMATH_EOF diff --git a/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/check.py b/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e962bc1c6d7d6cbc46f7da71f3af8200128b3b21 --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/check.py @@ -0,0 +1,62 @@ +"""Pairwise touching infinite cylinders (AlphaEvolve problem 54). + +Each cylinder: a point on its axis, an axis direction and a radius. Two cylinders touch (externally) when the +distance between their axes equals r_i + r_j. Checked in floating point with an absolute tolerance +(inst["tol"]); contact points (midpoints of closest approach) must lie in [-100, 100]^3 as upstream, which rules +out near-parallel pairs "touching at infinity".""" +import itertools +import math + +from run import Invalid, float_matrix + + +def _sub(a, b): + return [a[0] - b[0], a[1] - b[1], a[2] - b[2]] + + +def _dot(a, b): + return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + + +def _cross(a, b): + return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]] + + +def check(inst, ans): + n, unit, tol = inst["n"], inst["unit_radius"], inst["tol"] + rows = float_matrix(ans.get("cylinders"), n, 6 if unit else 7, "cylinders") + cyl = [] + for r in rows: + p, v = r[:3], r[3:6] + nv = math.sqrt(_dot(v, v)) + if nv < 1e-9: + raise Invalid("zero axis direction") + v = [c / nv for c in v] + rad = 1.0 if unit else r[6] + if not unit and not (inst["r_min"] <= rad <= inst["r_max"]): + raise Invalid(f"radius {rad} outside [{inst['r_min']}, {inst['r_max']}]") + if max(abs(c) for c in p) > 1000: + raise Invalid("axis point too far from the origin") + cyl.append((p, v, rad)) + worst = 0.0 + for (p1, v1, r1), (p2, v2, r2) in itertools.combinations(cyl, 2): + w = _sub(p2, p1) + c = _cross(v1, v2) + nc = math.sqrt(_dot(c, c)) + if nc < 1e-9: + d = math.sqrt(_dot(_cross(w, v1), _cross(w, v1))) + mid = [(p1[i] + p2[i]) / 2 for i in range(3)] + else: + d = abs(_dot(w, c)) / nc + b = _dot(v1, v2) + den = 1 - b * b + t1 = (_dot(w, v1) - b * _dot(w, v2)) / den + t2 = (b * _dot(w, v1) - _dot(w, v2)) / den + mid = [(p1[i] + t1 * v1[i] + p2[i] + t2 * v2[i]) / 2 for i in range(3)] + if max(abs(m) for m in mid) > 100: + raise Invalid("a contact point lies outside [-100, 100]^3") + err = abs(d - (r1 + r2)) + worst = max(worst, err) + if err > tol: + raise Invalid(f"axis distance {d:.12g} differs from r_i + r_j = {r1 + r2:.12g} by {err:.3g} > {tol}") + return None, {"max_error": worst} diff --git a/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/instance.json b/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..721df07528b0a9790618b6bdf9a0ab22afcfab4b --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "unit_radius": true, "tol": 1e-09, "family": "ae_p54_touching_cylinders", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/run.py b/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-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-ae-p54-touching-cylinders-l1-s0/tests/test.sh b/tasks/construct-ae-p54-touching-cylinders-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p54-touching-cylinders-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-mc-bibd-l3-s3/environment/Dockerfile b/tasks/construct-mc-bibd-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s3/environment/instance.json b/tasks/construct-mc-bibd-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..93d7c860a3c1c2c5e1d15845898d2769d56bc52b --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"v": 16, "k": 4, "lambda": 1, "b": 20, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s3/solution/solve.sh b/tasks/construct-mc-bibd-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5c37dae09d41a8c4782a81935e80ce35043ec038 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[0, 4, 8, 12], [1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [0, 5, 10, 15], [1, 4, 11, 14], [2, 7, 8, 13], [3, 6, 9, 12], [0, 6, 11, 13], [1, 7, 10, 12], [2, 4, 9, 15], [3, 5, 8, 14], [0, 7, 9, 14], [1, 6, 8, 15], [2, 5, 11, 12], [3, 4, 10, 13], [0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l3-s3/tests/check.py b/tasks/construct-mc-bibd-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s3/tests/check.py @@ -0,0 +1,25 @@ +"""Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0). +Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly +lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream +(its 0/1 incidence-matrix model does not forbid equal columns).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"] + blocks = ans.get("blocks") + if not isinstance(blocks, list) or len(blocks) != b: + raise Invalid(f"blocks must be a list of exactly {b} blocks") + pair = {} + for B in blocks: + B = int_list(B, k, 0, v - 1, "block") + if len(set(B)) != k: + raise Invalid("a block contains a repeated point") + for p in itertools.combinations(sorted(B), 2): + pair[p] = pair.get(p, 0) + 1 + for p in itertools.combinations(range(v), 2): + if pair.get(p, 0) != lam: + raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}") + return None, {} diff --git a/tasks/construct-mc-bibd-l3-s3/tests/instance.json b/tasks/construct-mc-bibd-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..93d7c860a3c1c2c5e1d15845898d2769d56bc52b --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"v": 16, "k": 4, "lambda": 1, "b": 20, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s3/tests/run.py b/tasks/construct-mc-bibd-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s3/tests/test.sh b/tasks/construct-mc-bibd-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s4/environment/Dockerfile b/tasks/construct-mc-bibd-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s4/environment/instance.json b/tasks/construct-mc-bibd-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef8355a096633fa1494974e1aa57abd4a79249a1 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"v": 10, "k": 3, "lambda": 4, "b": 60, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s4/solution/solve.sh b/tasks/construct-mc-bibd-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..19e47e63d621be25aeb485984df702160f74ffda --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[3, 5, 9], [2, 8, 9], [1, 5, 9], [2, 8, 9], [1, 3, 8], [7, 8, 9], [2, 8, 9], [1, 5, 9], [5, 7, 9], [0, 2, 5], [0, 2, 5], [1, 2, 8], [1, 5, 8], [3, 5, 8], [5, 7, 8], [2, 3, 7], [3, 5, 7], [0, 2, 5], [0, 3, 7], [0, 5, 7], [2, 5, 6], [1, 3, 9], [3, 5, 6], [1, 3, 6], [0, 6, 8], [4, 5, 8], [2, 4, 7], [0, 6, 8], [2, 3, 6], [0, 6, 8], [6, 7, 9], [1, 4, 5], [4, 5, 6], [4, 5, 6], [0, 1, 7], [2, 4, 7], [6, 7, 9], [3, 4, 8], [0, 2, 3], [4, 6, 9], [1, 2, 4], [0, 4, 9], [2, 3, 9], [0, 3, 4], [0, 1, 6], [1, 4, 7], [3, 6, 7], [4, 6, 9], [1, 3, 4], [1, 7, 8], [1, 2, 6], [6, 7, 8], [3, 4, 8], [0, 1, 7], [2, 4, 7], [1, 2, 6], [0, 1, 9], [0, 4, 9], [0, 3, 9], [0, 4, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l3-s4/tests/check.py b/tasks/construct-mc-bibd-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s4/tests/check.py @@ -0,0 +1,25 @@ +"""Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0). +Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly +lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream +(its 0/1 incidence-matrix model does not forbid equal columns).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"] + blocks = ans.get("blocks") + if not isinstance(blocks, list) or len(blocks) != b: + raise Invalid(f"blocks must be a list of exactly {b} blocks") + pair = {} + for B in blocks: + B = int_list(B, k, 0, v - 1, "block") + if len(set(B)) != k: + raise Invalid("a block contains a repeated point") + for p in itertools.combinations(sorted(B), 2): + pair[p] = pair.get(p, 0) + 1 + for p in itertools.combinations(range(v), 2): + if pair.get(p, 0) != lam: + raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}") + return None, {} diff --git a/tasks/construct-mc-bibd-l3-s4/tests/instance.json b/tasks/construct-mc-bibd-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef8355a096633fa1494974e1aa57abd4a79249a1 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"v": 10, "k": 3, "lambda": 4, "b": 60, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s4/tests/run.py b/tasks/construct-mc-bibd-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s4/tests/test.sh b/tasks/construct-mc-bibd-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-mc-golomb-l1-s3/environment/Dockerfile b/tasks/construct-mc-golomb-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l1-s3/environment/instance.json b/tasks/construct-mc-golomb-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ebd9160b20068897821157425b16cc02d548efa --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "max_length": 25, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l1-s3/solution/solve.sh b/tasks/construct-mc-golomb-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d21413bb162e3499adaeb0af776b499b48dc02df --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 1, 4, 10, 18, 23, 25]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l1-s3/tests/check.py b/tasks/construct-mc-golomb-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s3/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l1-s3/tests/instance.json b/tasks/construct-mc-golomb-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ebd9160b20068897821157425b16cc02d548efa --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "max_length": 25, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l1-s3/tests/run.py b/tasks/construct-mc-golomb-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l1-s3/tests/test.sh b/tasks/construct-mc-golomb-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l5-s2/environment/Dockerfile b/tasks/construct-mc-golomb-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l5-s2/environment/instance.json b/tasks/construct-mc-golomb-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7be1f75e1449b015dac5bb48dfe7f7413a1b4e6b --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "max_length": 177, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l5-s2/solution/solve.sh b/tasks/construct-mc-golomb-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0917792f11112621b9cb2042cb1dbc9b8fed2521 --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 1, 4, 11, 26, 32, 56, 68, 76, 115, 117, 134, 150, 163, 168, 177]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l5-s2/tests/check.py b/tasks/construct-mc-golomb-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s2/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l5-s2/tests/instance.json b/tasks/construct-mc-golomb-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7be1f75e1449b015dac5bb48dfe7f7413a1b4e6b --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "max_length": 177, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l5-s2/tests/run.py b/tasks/construct-mc-golomb-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l5-s2/tests/test.sh b/tasks/construct-mc-golomb-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-graceful-graph-l3-s0/environment/Dockerfile b/tasks/construct-mc-graceful-graph-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graceful-graph-l3-s0/environment/instance.json b/tasks/construct-mc-graceful-graph-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b4ee562cfc49e14b14d09123a55fe89f83f6efef --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"k": 4, "p": 3, "num_vertices": 12, "edges": [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l3-s0/solution/solve.sh b/tasks/construct-mc-graceful-graph-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b98d0e93560dee4b28454a954328e7259ea1cbad --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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' +{"labels": [9, 4, 23, 17, 24, 0, 3, 26, 2, 12, 19, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-graceful-graph-l3-s0/tests/check.py b/tasks/construct-mc-graceful-graph-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f4d33af1d63c0495c3b32d34db6ae10f0fb45923 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s0/tests/check.py @@ -0,0 +1,19 @@ +"""Graceful labelling of K_k x P_p (MathConstraint graceful_graph, CC-BY-4.0): distinct vertex labels in +0..m (m = number of edges) whose edge differences |l(u) - l(v)| are all distinct.""" +from run import Invalid, int_list + + +def check(inst, ans): + nv, edges = inst["num_vertices"], inst["edges"] + m = len(edges) + x = int_list(ans.get("labels"), nv, 0, m, "labels") + if len(set(x)) != nv: + raise Invalid("vertex labels must be distinct") + d = [abs(x[u] - x[v]) for u, v in edges] + if len(set(d)) != m: + raise Invalid("edge labels are not distinct") + seqs = {"labels": 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-graceful-graph-l3-s0/tests/instance.json b/tasks/construct-mc-graceful-graph-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b4ee562cfc49e14b14d09123a55fe89f83f6efef --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"k": 4, "p": 3, "num_vertices": 12, "edges": [[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3], [4, 5], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11], [0, 4], [1, 5], [2, 6], [3, 7], [4, 8], [5, 9], [6, 10], [7, 11]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l3-s0/tests/run.py b/tasks/construct-mc-graceful-graph-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graceful-graph-l3-s0/tests/test.sh b/tasks/construct-mc-graceful-graph-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graph-k-coloring-l3-s0/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-graph-k-coloring-l3-s0/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d6cf8244f35f3e395e1fd2b8de040124380d9a1 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 4, "edges": [[0, 14], [0, 15], [0, 25], [0, 29], [0, 30], [0, 43], [0, 44], [0, 49], [1, 2], [1, 21], [1, 24], [1, 28], [1, 36], [2, 7], [2, 16], [2, 20], [2, 22], [2, 29], [2, 30], [2, 36], [2, 41], [2, 47], [2, 49], [3, 10], [3, 13], [3, 17], [3, 18], [3, 30], [3, 44], [4, 6], [4, 13], [4, 18], [4, 28], [4, 32], [4, 35], [4, 38], [4, 42], [4, 49], [5, 9], [5, 13], [5, 19], [5, 21], [5, 24], [5, 30], [5, 39], [5, 43], [6, 17], [6, 20], [6, 38], [6, 49], [7, 35], [8, 17], [8, 18], [8, 22], [8, 23], [8, 28], [8, 31], [8, 34], [8, 37], [8, 45], [8, 49], [9, 17], [9, 19], [9, 21], [9, 32], [9, 46], [9, 49], [10, 17], [10, 22], [10, 26], [10, 27], [10, 31], [10, 40], [10, 41], [11, 12], [11, 13], [11, 14], [11, 15], [11, 40], [11, 41], [12, 28], [12, 33], [12, 34], [12, 36], [12, 37], [12, 41], [12, 46], [12, 47], [12, 49], [13, 14], [13, 18], [13, 26], [13, 41], [13, 47], [14, 15], [14, 20], [14, 26], [14, 27], [14, 30], [14, 36], [14, 38], [14, 39], [14, 43], [14, 45], [14, 48], [15, 17], [15, 19], [15, 28], [15, 35], [15, 44], [15, 47], [16, 18], [16, 35], [16, 37], [16, 40], [16, 43], [17, 32], [17, 36], [17, 46], [18, 19], [18, 44], [19, 22], [19, 23], [19, 30], [19, 34], [19, 45], [21, 30], [21, 35], [21, 43], [21, 44], [22, 42], [22, 46], [23, 37], [23, 45], [23, 49], [24, 30], [24, 38], [24, 48], [25, 37], [25, 41], [25, 43], [25, 47], [25, 49], [26, 31], [26, 39], [26, 46], [27, 38], [27, 40], [27, 45], [27, 47], [28, 29], [28, 32], [28, 33], [28, 36], [28, 38], [29, 37], [29, 41], [29, 48], [30, 42], [30, 43], [30, 46], [30, 48], [31, 36], [31, 42], [31, 44], [32, 45], [32, 46], [32, 47], [34, 35], [34, 39], [34, 47], [34, 49], [35, 38], [35, 40], [35, 42], [35, 43], [36, 41], [36, 45], [38, 47], [39, 41], [39, 45], [40, 42], [40, 49], [41, 44], [41, 45], [43, 44], [43, 47], [46, 49]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s0/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d150c4327fbfa6d9c08ad85be77c5a0f366c876e --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [0, 0, 3, 3, 3, 0, 1, 0, 3, 3, 0, 0, 3, 1, 2, 3, 2, 2, 0, 2, 0, 2, 1, 1, 2, 1, 3, 1, 2, 1, 1, 2, 1, 0, 0, 1, 1, 0, 0, 1, 3, 2, 0, 3, 1, 0, 0, 2, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l3-s0/tests/check.py b/tasks/construct-mc-graph-k-coloring-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s0/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-s0/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d6cf8244f35f3e395e1fd2b8de040124380d9a1 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 4, "edges": [[0, 14], [0, 15], [0, 25], [0, 29], [0, 30], [0, 43], [0, 44], [0, 49], [1, 2], [1, 21], [1, 24], [1, 28], [1, 36], [2, 7], [2, 16], [2, 20], [2, 22], [2, 29], [2, 30], [2, 36], [2, 41], [2, 47], [2, 49], [3, 10], [3, 13], [3, 17], [3, 18], [3, 30], [3, 44], [4, 6], [4, 13], [4, 18], [4, 28], [4, 32], [4, 35], [4, 38], [4, 42], [4, 49], [5, 9], [5, 13], [5, 19], [5, 21], [5, 24], [5, 30], [5, 39], [5, 43], [6, 17], [6, 20], [6, 38], [6, 49], [7, 35], [8, 17], [8, 18], [8, 22], [8, 23], [8, 28], [8, 31], [8, 34], [8, 37], [8, 45], [8, 49], [9, 17], [9, 19], [9, 21], [9, 32], [9, 46], [9, 49], [10, 17], [10, 22], [10, 26], [10, 27], [10, 31], [10, 40], [10, 41], [11, 12], [11, 13], [11, 14], [11, 15], [11, 40], [11, 41], [12, 28], [12, 33], [12, 34], [12, 36], [12, 37], [12, 41], [12, 46], [12, 47], [12, 49], [13, 14], [13, 18], [13, 26], [13, 41], [13, 47], [14, 15], [14, 20], [14, 26], [14, 27], [14, 30], [14, 36], [14, 38], [14, 39], [14, 43], [14, 45], [14, 48], [15, 17], [15, 19], [15, 28], [15, 35], [15, 44], [15, 47], [16, 18], [16, 35], [16, 37], [16, 40], [16, 43], [17, 32], [17, 36], [17, 46], [18, 19], [18, 44], [19, 22], [19, 23], [19, 30], [19, 34], [19, 45], [21, 30], [21, 35], [21, 43], [21, 44], [22, 42], [22, 46], [23, 37], [23, 45], [23, 49], [24, 30], [24, 38], [24, 48], [25, 37], [25, 41], [25, 43], [25, 47], [25, 49], [26, 31], [26, 39], [26, 46], [27, 38], [27, 40], [27, 45], [27, 47], [28, 29], [28, 32], [28, 33], [28, 36], [28, 38], [29, 37], [29, 41], [29, 48], [30, 42], [30, 43], [30, 46], [30, 48], [31, 36], [31, 42], [31, 44], [32, 45], [32, 46], [32, 47], [34, 35], [34, 39], [34, 47], [34, 49], [35, 38], [35, 40], [35, 42], [35, 43], [36, 41], [36, 45], [38, 47], [39, 41], [39, 45], [40, 42], [40, 49], [41, 44], [41, 45], [43, 44], [43, 47], [46, 49]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s0/tests/run.py b/tasks/construct-mc-graph-k-coloring-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-graph-k-coloring-l3-s0/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-hadamard-l3-s0/environment/Dockerfile b/tasks/construct-mc-hadamard-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l3-s0/environment/instance.json b/tasks/construct-mc-hadamard-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..edd3892179e5c3a3c7e2d2e735e40898b6262975 --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 17, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l3-s0/solution/solve.sh b/tasks/construct-mc-hadamard-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f4e734a44f91b25b19a96b579d53295a8d153245 --- /dev/null +++ b/tasks/construct-mc-hadamard-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' +{"x": [1, 1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1], "y": [1, -1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l3-s0/tests/check.py b/tasks/construct-mc-hadamard-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Legendre pair of odd length n (MathConstraint hadamard, CC-BY-4.0): x, y in {-1,+1}^n with +sum(x) = sum(y) = 1 and PAF_x(k) + PAF_y(k) = -2 for k = 1..(n-1)/2 (periodic autocorrelation).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, -1, 1, "x") + y = int_list(ans.get("y"), n, -1, 1, "y") + if 0 in x or 0 in y: + raise Invalid("entries must be -1 or +1") + if sum(x) != 1 or sum(y) != 1: + raise Invalid("sum(x) and sum(y) must both equal 1") + for k in range(1, (n - 1) // 2 + 1): + p = sum(x[i] * x[(i + k) % n] for i in range(n)) + sum(y[i] * y[(i + k) % n] for i in range(n)) + if p != -2: + raise Invalid(f"PAF_x({k}) + PAF_y({k}) = {p}, need -2") + return None, {} diff --git a/tasks/construct-mc-hadamard-l3-s0/tests/instance.json b/tasks/construct-mc-hadamard-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..edd3892179e5c3a3c7e2d2e735e40898b6262975 --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 17, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l3-s0/tests/run.py b/tasks/construct-mc-hadamard-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l3-s0/tests/test.sh b/tasks/construct-mc-hadamard-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-low-autocorrelation-l1-s2/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-mc-low-autocorrelation-l1-s2/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a11dee5284112d71a2f63bc7047e0a34a07dbbfa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "bound": 20, "fixed": [["seq", 0, -1], ["seq", 8, 1], ["c", 6, -1]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l1-s2/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a1cd91b3b4905f754c15c1cd7dfbe7e2105211e9 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-1, -1, 1, 1, -1, 1, -1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l1-s2/tests/check.py b/tasks/construct-mc-low-autocorrelation-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s2/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l1-s2/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a11dee5284112d71a2f63bc7047e0a34a07dbbfa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "bound": 20, "fixed": [["seq", 0, -1], ["seq", 8, 1], ["c", 6, -1]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l1-s2/tests/run.py b/tasks/construct-mc-low-autocorrelation-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-mc-low-autocorrelation-l1-s2/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-mc-low-autocorrelation-l5-s3/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-mc-low-autocorrelation-l5-s3/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b3d72fad8dc13a9b534b19d6e5c09dfd74d47bd --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "bound": 64, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l5-s3/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7f4dad8d241b654313698f8f29746d9dd9ae15b6 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l5-s3/tests/check.py b/tasks/construct-mc-low-autocorrelation-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s3/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l5-s3/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b3d72fad8dc13a9b534b19d6e5c09dfd74d47bd --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "bound": 64, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l5-s3/tests/run.py b/tasks/construct-mc-low-autocorrelation-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-mc-low-autocorrelation-l5-s3/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-mc-magic-sequence-l2-s2/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-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-magic-sequence-l2-s2/environment/instance.json b/tasks/construct-mc-magic-sequence-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b33509b8f4942d4a037db98e0ef401c4dcecb5d --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s2/solution/solve.sh b/tasks/construct-mc-magic-sequence-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9795329042bf0b2da395275cab96943ab304d978 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-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": [6, 2, 1, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l2-s2/tests/check.py b/tasks/construct-mc-magic-sequence-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s2/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-s2/tests/instance.json b/tasks/construct-mc-magic-sequence-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b33509b8f4942d4a037db98e0ef401c4dcecb5d --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s2/tests/run.py b/tasks/construct-mc-magic-sequence-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-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-magic-sequence-l2-s2/tests/test.sh b/tasks/construct-mc-magic-sequence-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-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-s3/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-mc-max-clique-l5-s3/environment/instance.json b/tasks/construct-mc-max-clique-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..961a64ac6cc4a9ef77d3f40115d0e4f91cb809f8 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 12], [0, 13], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 26], [0, 27], [0, 28], [0, 30], [0, 31], [0, 34], [0, 35], [0, 38], [0, 41], [0, 42], [0, 43], [0, 44], [0, 45], [0, 50], [0, 54], [0, 60], [0, 61], [0, 64], [0, 66], [0, 68], [0, 69], [0, 71], [0, 73], [0, 75], [0, 77], [0, 78], [0, 79], [0, 80], [0, 81], [0, 84], [0, 86], [0, 89], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 13], [1, 14], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 28], [1, 32], [1, 34], [1, 36], [1, 37], [1, 39], [1, 42], [1, 45], [1, 46], [1, 47], [1, 48], [1, 50], [1, 53], [1, 57], [1, 59], [1, 60], [1, 62], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 71], [1, 73], [1, 79], [1, 80], [1, 81], [1, 83], [1, 85], [1, 88], [2, 3], [2, 5], [2, 7], [2, 8], [2, 10], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 29], [2, 30], [2, 32], [2, 33], [2, 34], [2, 40], [2, 42], [2, 45], [2, 47], [2, 48], [2, 49], [2, 53], [2, 56], [2, 58], [2, 61], [2, 65], [2, 68], [2, 72], [2, 73], [2, 76], [2, 78], [2, 79], [2, 80], [2, 81], [2, 82], [2, 83], [2, 84], [2, 86], [2, 88], [3, 11], [3, 15], [3, 16], [3, 20], [3, 21], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 39], [3, 41], [3, 46], [3, 48], [3, 50], [3, 53], [3, 56], [3, 57], [3, 59], [3, 60], [3, 61], [3, 63], [3, 66], [3, 68], [3, 69], [3, 72], [3, 73], [3, 77], [3, 78], [3, 79], [3, 81], [3, 84], [3, 85], [3, 86], [3, 87], [3, 89], [4, 6], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 22], [4, 25], [4, 26], [4, 28], [4, 29], [4, 31], [4, 32], [4, 35], [4, 36], [4, 37], [4, 38], [4, 40], [4, 42], [4, 46], [4, 49], [4, 51], [4, 52], [4, 54], [4, 55], [4, 56], [4, 60], [4, 62], [4, 64], [4, 68], [4, 69], [4, 70], [4, 72], [4, 74], [4, 77], [4, 78], [4, 80], [4, 83], [4, 84], [4, 87], [4, 88], [4, 89], [5, 6], [5, 7], [5, 8], [5, 12], [5, 13], [5, 15], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [5, 25], [5, 26], [5, 29], [5, 32], [5, 33], [5, 36], [5, 37], [5, 38], [5, 39], [5, 41], [5, 43], [5, 45], [5, 46], [5, 47], [5, 48], [5, 52], [5, 55], [5, 56], [5, 58], [5, 61], [5, 64], [5, 66], [5, 67], [5, 68], [5, 70], [5, 71], [5, 74], [5, 76], [5, 77], [5, 78], [5, 79], [5, 80], [5, 83], [5, 87], [5, 88], [6, 7], [6, 8], [6, 9], [6, 13], [6, 14], [6, 16], [6, 19], [6, 20], [6, 27], [6, 28], [6, 37], [6, 38], [6, 39], [6, 41], [6, 42], [6, 43], [6, 44], [6, 47], [6, 48], [6, 49], [6, 55], [6, 58], [6, 60], [6, 61], [6, 63], [6, 64], [6, 67], [6, 75], [6, 76], [6, 78], [6, 81], [6, 82], [6, 84], [6, 85], [6, 89], [7, 8], [7, 11], [7, 15], [7, 16], [7, 20], [7, 23], [7, 24], [7, 26], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 51], [7, 52], [7, 53], [7, 54], [7, 55], [7, 56], [7, 60], [7, 61], [7, 62], [7, 64], [7, 67], [7, 68], [7, 73], [7, 74], [7, 75], [7, 78], [7, 79], [7, 83], [7, 86], [7, 89], [8, 9], [8, 11], [8, 13], [8, 15], [8, 17], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 31], [8, 33], [8, 36], [8, 37], [8, 38], [8, 41], [8, 44], [8, 45], [8, 46], [8, 49], [8, 50], [8, 51], [8, 52], [8, 58], [8, 60], [8, 64], [8, 68], [8, 69], [8, 72], [8, 73], [8, 76], [8, 79], [8, 80], [8, 82], [8, 83], [8, 85], [8, 87], [8, 88], [9, 10], [9, 12], [9, 13], [9, 14], [9, 15], [9, 21], [9, 24], [9, 25], [9, 26], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 36], [9, 37], [9, 39], [9, 40], [9, 42], [9, 45], [9, 46], [9, 48], [9, 49], [9, 50], [9, 52], [9, 54], [9, 56], [9, 57], [9, 58], [9, 59], [9, 61], [9, 63], [9, 65], [9, 66], [9, 68], [9, 69], [9, 73], [9, 77], [9, 78], [9, 82], [9, 83], [9, 84], [9, 85], [9, 86], [9, 88], [9, 89], [10, 17], [10, 18], [10, 20], [10, 25], [10, 26], [10, 27], [10, 28], [10, 32], [10, 37], [10, 39], [10, 42], [10, 43], [10, 44], [10, 46], [10, 47], [10, 48], [10, 49], [10, 50], [10, 51], [10, 52], [10, 53], [10, 55], [10, 56], [10, 57], [10, 60], [10, 63], [10, 66], [10, 71], [10, 74], [10, 78], [10, 82], [10, 84], [10, 85], [10, 86], [10, 88], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 20], [11, 24], [11, 29], [11, 31], [11, 33], [11, 34], [11, 35], [11, 36], [11, 39], [11, 42], [11, 45], [11, 47], [11, 49], [11, 50], [11, 53], [11, 54], [11, 55], [11, 56], [11, 60], [11, 61], [11, 62], [11, 65], [11, 68], [11, 69], [11, 71], [11, 74], [11, 77], [11, 80], [11, 81], [11, 82], [11, 83], [11, 85], [11, 86], [11, 88], [11, 89], [12, 14], [12, 15], [12, 18], [12, 19], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 32], [12, 33], [12, 34], [12, 36], [12, 39], [12, 41], [12, 42], [12, 43], [12, 44], [12, 46], [12, 49], [12, 51], [12, 52], [12, 54], [12, 55], [12, 57], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 65], [12, 66], [12, 68], [12, 69], [12, 71], [12, 72], [12, 73], [12, 76], [12, 77], [12, 78], [12, 79], [12, 81], [12, 82], [12, 85], [12, 86], [12, 89], [13, 14], [13, 18], [13, 20], [13, 24], [13, 27], [13, 29], [13, 31], [13, 33], [13, 36], [13, 37], [13, 38], [13, 39], [13, 41], [13, 45], [13, 46], [13, 50], [13, 51], [13, 53], [13, 54], [13, 55], [13, 58], [13, 61], [13, 67], [13, 68], [13, 69], [13, 70], [13, 73], [13, 76], [13, 77], [13, 79], [13, 80], [13, 83], [13, 89], [14, 17], [14, 23], [14, 24], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 33], [14, 34], [14, 35], [14, 37], [14, 39], [14, 42], [14, 43], [14, 44], [14, 46], [14, 47], [14, 48], [14, 51], [14, 52], [14, 53], [14, 54], [14, 59], [14, 60], [14, 62], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 74], [14, 76], [14, 77], [14, 79], [14, 84], [14, 85], [14, 86], [14, 88], [15, 19], [15, 22], [15, 23], [15, 25], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 35], [15, 38], [15, 40], [15, 44], [15, 46], [15, 47], [15, 51], [15, 52], [15, 54], [15, 56], [15, 57], [15, 58], [15, 60], [15, 62], [15, 64], [15, 68], [15, 69], [15, 81], [15, 84], [15, 85], [15, 87], [15, 88], [15, 89], [16, 17], [16, 18], [16, 19], [16, 21], [16, 23], [16, 24], [16, 26], [16, 27], [16, 29], [16, 31], [16, 34], [16, 36], [16, 39], [16, 40], [16, 42], [16, 43], [16, 46], [16, 50], [16, 52], [16, 53], [16, 58], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 69], [16, 70], [16, 72], [16, 75], [16, 77], [16, 78], [16, 79], [16, 80], [16, 82], [16, 85], [16, 86], [16, 87], [16, 89], [17, 18], [17, 19], [17, 22], [17, 23], [17, 25], [17, 27], [17, 31], [17, 32], [17, 33], [17, 37], [17, 40], [17, 42], [17, 43], [17, 44], [17, 47], [17, 48], [17, 51], [17, 53], [17, 54], [17, 61], [17, 63], [17, 66], [17, 67], [17, 74], [17, 76], [17, 77], [17, 78], [17, 86], [17, 88], [18, 19], [18, 20], [18, 21], [18, 23], [18, 26], [18, 27], [18, 30], [18, 31], [18, 33], [18, 34], [18, 35], [18, 36], [18, 39], [18, 42], [18, 44], [18, 48], [18, 49], [18, 52], [18, 54], [18, 55], [18, 56], [18, 57], [18, 58], [18, 61], [18, 62], [18, 65], [18, 66], [18, 73], [18, 76], [18, 77], [18, 80], [18, 81], [18, 82], [18, 84], [18, 85], [18, 87], [18, 88], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 29], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 38], [19, 40], [19, 42], [19, 43], [19, 44], [19, 47], [19, 48], [19, 50], [19, 51], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 58], [19, 59], [19, 62], [19, 65], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [19, 75], [19, 76], [19, 78], [19, 80], [19, 81], [19, 83], [19, 85], [19, 86], [19, 88], [19, 89], [20, 21], [20, 22], [20, 23], [20, 24], [20, 27], [20, 29], [20, 31], [20, 33], [20, 34], [20, 36], [20, 37], [20, 38], [20, 40], [20, 41], [20, 43], [20, 45], [20, 46], [20, 47], [20, 52], [20, 53], [20, 55], [20, 61], [20, 64], [20, 65], [20, 66], [20, 69], [20, 70], [20, 71], [20, 73], [20, 76], [20, 77], [20, 79], [20, 81], [20, 82], [20, 83], [20, 86], [20, 87], [20, 88], [20, 89], [21, 22], [21, 23], [21, 26], [21, 27], [21, 29], [21, 31], [21, 33], [21, 35], [21, 37], [21, 39], [21, 41], [21, 42], [21, 47], [21, 50], [21, 51], [21, 53], [21, 54], [21, 55], [21, 56], [21, 57], [21, 58], [21, 62], [21, 68], [21, 69], [21, 74], [21, 75], [21, 76], [21, 77], [21, 80], [21, 82], [21, 83], [21, 86], [21, 87], [21, 88], [21, 89], [22, 25], [22, 27], [22, 28], [22, 33], [22, 37], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 47], [22, 49], [22, 50], [22, 53], [22, 57], [22, 60], [22, 61], [22, 65], [22, 67], [22, 68], [22, 69], [22, 71], [22, 76], [22, 77], [22, 78], [22, 79], [22, 84], [22, 86], [22, 87], [22, 88], [22, 89], [23, 24], [23, 25], [23, 26], [23, 29], [23, 30], [23, 31], [23, 33], [23, 35], [23, 38], [23, 42], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 52], [23, 53], [23, 54], [23, 55], [23, 58], [23, 59], [23, 61], [23, 62], [23, 66], [23, 67], [23, 68], [23, 69], [23, 72], [23, 73], [23, 75], [23, 76], [23, 77], [23, 79], [23, 80], [23, 83], [23, 88], [24, 25], [24, 28], [24, 29], [24, 30], [24, 32], [24, 34], [24, 36], [24, 39], [24, 42], [24, 45], [24, 47], [24, 48], [24, 52], [24, 55], [24, 56], [24, 64], [24, 67], [24, 70], [24, 71], [24, 72], [24, 77], [24, 78], [24, 86], [24, 87], [24, 88], [25, 26], [25, 28], [25, 29], [25, 31], [25, 32], [25, 34], [25, 36], [25, 39], [25, 41], [25, 43], [25, 44], [25, 45], [25, 46], [25, 49], [25, 52], [25, 54], [25, 55], [25, 56], [25, 59], [25, 60], [25, 61], [25, 62], [25, 64], [25, 66], [25, 67], [25, 68], [25, 71], [25, 72], [25, 73], [25, 74], [25, 75], [25, 78], [25, 79], [25, 82], [25, 86], [25, 87], [25, 88], [25, 89], [26, 27], [26, 30], [26, 32], [26, 33], [26, 35], [26, 37], [26, 38], [26, 39], [26, 40], [26, 43], [26, 44], [26, 45], [26, 49], [26, 52], [26, 56], [26, 70], [26, 71], [26, 73], [26, 74], [26, 75], [26, 77], [26, 78], [26, 79], [26, 82], [26, 84], [26, 85], [26, 89], [27, 29], [27, 30], [27, 31], [27, 33], [27, 35], [27, 38], [27, 40], [27, 42], [27, 43], [27, 46], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 53], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 61], [27, 62], [27, 65], [27, 67], [27, 68], [27, 69], [27, 71], [27, 72], [27, 79], [27, 81], [27, 84], [27, 85], [27, 88], [27, 89], [28, 29], [28, 30], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 40], [28, 42], [28, 43], [28, 47], [28, 48], [28, 50], [28, 53], [28, 55], [28, 59], [28, 61], [28, 65], [28, 66], [28, 68], [28, 72], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 80], [28, 81], [28, 83], [28, 84], [28, 85], [28, 87], [28, 88], [29, 30], [29, 33], [29, 36], [29, 38], [29, 39], [29, 41], [29, 44], [29, 45], [29, 48], [29, 49], [29, 52], [29, 53], [29, 56], [29, 62], [29, 63], [29, 65], [29, 66], [29, 68], [29, 69], [29, 74], [29, 75], [29, 76], [29, 77], [29, 78], [29, 79], [29, 80], [29, 82], [29, 86], [29, 88], [29, 89], [30, 31], [30, 33], [30, 34], [30, 36], [30, 37], [30, 38], [30, 39], [30, 42], [30, 43], [30, 44], [30, 50], [30, 54], [30, 56], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 65], [30, 66], [30, 72], [30, 74], [30, 76], [30, 78], [30, 79], [30, 80], [30, 82], [30, 83], [30, 84], [30, 89], [31, 32], [31, 36], [31, 37], [31, 42], [31, 45], [31, 46], [31, 48], [31, 49], [31, 51], [31, 52], [31, 56], [31, 58], [31, 59], [31, 61], [31, 62], [31, 63], [31, 64], [31, 65], [31, 66], [31, 68], [31, 70], [31, 72], [31, 73], [31, 76], [31, 77], [31, 78], [31, 79], [31, 80], [31, 87], [32, 35], [32, 37], [32, 39], [32, 43], [32, 44], [32, 45], [32, 46], [32, 50], [32, 52], [32, 53], [32, 60], [32, 63], [32, 68], [32, 71], [32, 74], [32, 75], [32, 76], [32, 77], [32, 82], [32, 84], [32, 85], [32, 86], [32, 87], [32, 89], [33, 34], [33, 35], [33, 37], [33, 41], [33, 44], [33, 45], [33, 50], [33, 51], [33, 52], [33, 56], [33, 58], [33, 59], [33, 61], [33, 62], [33, 63], [33, 64], [33, 67], [33, 69], [33, 70], [33, 71], [33, 74], [33, 75], [33, 76], [33, 79], [33, 80], [33, 81], [33, 82], [33, 83], [33, 86], [33, 87], [33, 88], [33, 89], [34, 38], [34, 39], [34, 41], [34, 42], [34, 43], [34, 44], [34, 46], [34, 48], [34, 49], [34, 50], [34, 51], [34, 53], [34, 54], [34, 56], [34, 58], [34, 61], [34, 62], [34, 64], [34, 65], [34, 66], [34, 68], [34, 70], [34, 72], [34, 74], [34, 77], [34, 79], [34, 81], [34, 82], [34, 83], [34, 85], [34, 86], [34, 87], [34, 89], [35, 42], [35, 43], [35, 45], [35, 50], [35, 51], [35, 52], [35, 53], [35, 55], [35, 57], [35, 59], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 68], [35, 69], [35, 71], [35, 73], [35, 75], [35, 77], [35, 79], [35, 80], [35, 81], [35, 82], [35, 83], [35, 88], [35, 89], [36, 37], [36, 40], [36, 41], [36, 42], [36, 43], [36, 49], [36, 51], [36, 53], [36, 59], [36, 60], [36, 63], [36, 67], [36, 68], [36, 71], [36, 72], [36, 73], [36, 74], [36, 75], [36, 76], [36, 79], [36, 80], [36, 82], [36, 83], [36, 84], [36, 85], [36, 86], [36, 88], [36, 89], [37, 38], [37, 41], [37, 42], [37, 43], [37, 44], [37, 47], [37, 49], [37, 50], [37, 53], [37, 56], [37, 57], [37, 58], [37, 59], [37, 61], [37, 62], [37, 63], [37, 65], [37, 67], [37, 68], [37, 70], [37, 72], [37, 74], [37, 75], [37, 76], [37, 77], [37, 78], [37, 80], [37, 81], [37, 82], [37, 85], [38, 40], [38, 43], [38, 45], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 54], [38, 55], [38, 56], [38, 60], [38, 61], [38, 63], [38, 64], [38, 65], [38, 66], [38, 68], [38, 70], [38, 72], [38, 74], [38, 77], [38, 78], [38, 79], [38, 82], [38, 83], [38, 84], [38, 85], [38, 89], [39, 41], [39, 42], [39, 43], [39, 45], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 54], [39, 55], [39, 56], [39, 57], [39, 60], [39, 61], [39, 65], [39, 66], [39, 67], [39, 68], [39, 69], [39, 72], [39, 75], [39, 78], [39, 81], [39, 86], [39, 88], [39, 89], [40, 42], [40, 43], [40, 45], [40, 46], [40, 47], [40, 50], [40, 52], [40, 53], [40, 54], [40, 57], [40, 58], [40, 59], [40, 61], [40, 67], [40, 68], [40, 70], [40, 71], [40, 73], [40, 74], [40, 75], [40, 76], [40, 77], [40, 78], [40, 79], [40, 80], [40, 82], [40, 84], [40, 88], [41, 42], [41, 43], [41, 46], [41, 50], [41, 52], [41, 53], [41, 54], [41, 59], [41, 60], [41, 63], [41, 64], [41, 65], [41, 66], [41, 68], [41, 69], [41, 72], [41, 73], [41, 74], [41, 77], [41, 78], [41, 80], [41, 84], [41, 87], [41, 88], [42, 44], [42, 45], [42, 47], [42, 49], [42, 50], [42, 54], [42, 58], [42, 59], [42, 62], [42, 66], [42, 68], [42, 70], [42, 71], [42, 72], [42, 73], [42, 76], [42, 77], [42, 78], [42, 79], [42, 80], [42, 82], [42, 84], [42, 88], [42, 89], [43, 44], [43, 45], [43, 48], [43, 49], [43, 51], [43, 53], [43, 55], [43, 59], [43, 60], [43, 61], [43, 63], [43, 66], [43, 70], [43, 71], [43, 75], [43, 76], [43, 77], [43, 78], [43, 79], [43, 80], [43, 81], [43, 83], [43, 84], [43, 85], [44, 48], [44, 49], [44, 51], [44, 53], [44, 55], [44, 58], [44, 59], [44, 62], [44, 63], [44, 65], [44, 68], [44, 70], [44, 72], [44, 74], [44, 76], [44, 80], [44, 84], [44, 86], [44, 89], [45, 48], [45, 49], [45, 50], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 59], [45, 61], [45, 63], [45, 66], [45, 67], [45, 68], [45, 72], [45, 73], [45, 75], [45, 76], [45, 77], [45, 78], [45, 79], [45, 81], [45, 83], [45, 84], [45, 86], [46, 47], [46, 48], [46, 49], [46, 52], [46, 54], [46, 56], [46, 58], [46, 59], [46, 61], [46, 62], [46, 63], [46, 65], [46, 67], [46, 69], [46, 70], [46, 73], [46, 74], [46, 80], [46, 83], [46, 84], [46, 89], [47, 48], [47, 49], [47, 50], [47, 51], [47, 52], [47, 53], [47, 54], [47, 58], [47, 59], [47, 60], [47, 62], [47, 65], [47, 66], [47, 68], [47, 70], [47, 71], [47, 72], [47, 75], [47, 79], [47, 80], [47, 81], [47, 87], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 61], [48, 63], [48, 66], [48, 67], [48, 68], [48, 71], [48, 73], [48, 74], [48, 77], [48, 78], [48, 80], [48, 81], [48, 84], [48, 87], [48, 88], [49, 50], [49, 51], [49, 54], [49, 55], [49, 56], [49, 57], [49, 59], [49, 60], [49, 65], [49, 66], [49, 67], [49, 68], [49, 71], [49, 73], [49, 77], [49, 78], [49, 81], [49, 83], [49, 85], [49, 86], [49, 88], [50, 52], [50, 57], [50, 60], [50, 61], [50, 62], [50, 65], [50, 67], [50, 68], [50, 70], [50, 71], [50, 72], [50, 73], [50, 74], [50, 77], [50, 86], [50, 87], [50, 89], [51, 52], [51, 56], [51, 57], [51, 58], [51, 59], [51, 61], [51, 65], [51, 66], [51, 71], [51, 72], [51, 75], [51, 77], [51, 78], [51, 84], [51, 86], [51, 87], [51, 88], [51, 89], [52, 57], [52, 60], [52, 66], [52, 67], [52, 68], [52, 69], [52, 71], [52, 72], [52, 75], [52, 79], [52, 80], [52, 82], [52, 84], [52, 88], [52, 89], [53, 54], [53, 55], [53, 56], [53, 57], [53, 59], [53, 60], [53, 61], [53, 62], [53, 66], [53, 69], [53, 70], [53, 72], [53, 73], [53, 75], [53, 80], [53, 82], [53, 86], [53, 87], [53, 89], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 62], [54, 63], [54, 64], [54, 65], [54, 67], [54, 68], [54, 70], [54, 73], [54, 74], [54, 77], [54, 78], [54, 79], [54, 82], [54, 85], [54, 86], [54, 89], [55, 58], [55, 63], [55, 64], [55, 65], [55, 67], [55, 69], [55, 70], [55, 71], [55, 72], [55, 75], [55, 76], [55, 78], [55, 80], [55, 81], [55, 83], [55, 84], [55, 86], [55, 88], [55, 89], [56, 58], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 69], [56, 70], [56, 73], [56, 74], [56, 75], [56, 76], [56, 77], [56, 78], [56, 79], [56, 80], [56, 81], [56, 82], [56, 83], [56, 84], [56, 85], [56, 86], [56, 88], [56, 89], [57, 58], [57, 60], [57, 61], [57, 62], [57, 64], [57, 66], [57, 68], [57, 69], [57, 81], [57, 82], [57, 86], [58, 60], [58, 62], [58, 64], [58, 66], [58, 68], [58, 69], [58, 73], [58, 76], [58, 78], [58, 80], [58, 81], [58, 82], [58, 83], [58, 84], [58, 85], [58, 86], [58, 87], [58, 89], [59, 61], [59, 62], [59, 63], [59, 64], [59, 68], [59, 69], [59, 72], [59, 73], [59, 74], [59, 75], [59, 76], [59, 77], [59, 81], [59, 82], [59, 83], [59, 84], [59, 89], [60, 61], [60, 62], [60, 67], [60, 69], [60, 70], [60, 71], [60, 72], [60, 76], [60, 80], [60, 81], [60, 83], [60, 85], [60, 86], [60, 87], [61, 65], [61, 66], [61, 71], [61, 73], [61, 75], [61, 76], [61, 77], [61, 81], [61, 87], [61, 89], [62, 65], [62, 66], [62, 68], [62, 69], [62, 70], [62, 72], [62, 74], [62, 75], [62, 79], [62, 80], [62, 82], [62, 83], [62, 86], [62, 87], [62, 88], [62, 89], [63, 69], [63, 70], [63, 71], [63, 73], [63, 74], [63, 75], [63, 76], [63, 77], [63, 78], [63, 82], [63, 83], [63, 84], [63, 85], [63, 86], [63, 88], [63, 89], [64, 67], [64, 68], [64, 70], [64, 71], [64, 73], [64, 76], [64, 77], [64, 79], [64, 80], [64, 81], [64, 82], [64, 83], [64, 84], [64, 85], [64, 86], [64, 87], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 81], [65, 82], [65, 85], [65, 87], [65, 89], [66, 69], [66, 71], [66, 77], [66, 78], [66, 79], [66, 83], [66, 84], [66, 85], [66, 87], [66, 88], [67, 68], [67, 69], [67, 72], [67, 73], [67, 75], [67, 76], [67, 77], [67, 79], [67, 81], [67, 82], [67, 86], [67, 87], [67, 88], [67, 89], [68, 70], [68, 71], [68, 73], [68, 75], [68, 82], [68, 84], [68, 85], [68, 86], [69, 70], [69, 71], [69, 72], [69, 75], [69, 78], [69, 79], [69, 80], [69, 81], [69, 84], [69, 85], [69, 86], [69, 87], [69, 88], [69, 89], [70, 71], [70, 72], [70, 75], [70, 76], [70, 78], [70, 79], [70, 81], [70, 82], [70, 84], [70, 88], [70, 89], [71, 72], [71, 73], [71, 75], [71, 77], [71, 80], [71, 82], [71, 84], [71, 87], [72, 73], [72, 74], [72, 76], [72, 78], [72, 80], [72, 81], [72, 82], [72, 83], [72, 87], [72, 88], [72, 89], [73, 77], [73, 78], [73, 79], [73, 80], [73, 84], [73, 89], [74, 75], [74, 76], [74, 77], [74, 79], [74, 81], [74, 82], [74, 83], [74, 84], [74, 85], [74, 87], [75, 76], [75, 80], [75, 82], [75, 83], [75, 85], [75, 86], [75, 88], [75, 89], [76, 78], [76, 82], [76, 83], [76, 85], [76, 89], [77, 83], [77, 84], [77, 85], [77, 87], [77, 89], [78, 79], [78, 80], [78, 81], [78, 82], [78, 86], [79, 81], [79, 83], [79, 84], [79, 85], [79, 88], [80, 82], [80, 83], [80, 84], [80, 86], [80, 88], [80, 89], [81, 82], [81, 83], [81, 84], [81, 85], [81, 87], [82, 84], [82, 85], [82, 86], [82, 87], [83, 85], [83, 88], [84, 86], [84, 87], [84, 89], [85, 88], [85, 89], [86, 88], [86, 89], [87, 89], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s3/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0086913665cf95c5a6947c3662ce2e5d9ffe367d --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [19, 21, 29, 33, 56, 62, 69, 75, 80, 86, 88, 89]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s3/tests/check.py b/tasks/construct-mc-max-clique-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-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-l5-s3/tests/instance.json b/tasks/construct-mc-max-clique-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..961a64ac6cc4a9ef77d3f40115d0e4f91cb809f8 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 12], [0, 13], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 26], [0, 27], [0, 28], [0, 30], [0, 31], [0, 34], [0, 35], [0, 38], [0, 41], [0, 42], [0, 43], [0, 44], [0, 45], [0, 50], [0, 54], [0, 60], [0, 61], [0, 64], [0, 66], [0, 68], [0, 69], [0, 71], [0, 73], [0, 75], [0, 77], [0, 78], [0, 79], [0, 80], [0, 81], [0, 84], [0, 86], [0, 89], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 13], [1, 14], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 28], [1, 32], [1, 34], [1, 36], [1, 37], [1, 39], [1, 42], [1, 45], [1, 46], [1, 47], [1, 48], [1, 50], [1, 53], [1, 57], [1, 59], [1, 60], [1, 62], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 71], [1, 73], [1, 79], [1, 80], [1, 81], [1, 83], [1, 85], [1, 88], [2, 3], [2, 5], [2, 7], [2, 8], [2, 10], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 29], [2, 30], [2, 32], [2, 33], [2, 34], [2, 40], [2, 42], [2, 45], [2, 47], [2, 48], [2, 49], [2, 53], [2, 56], [2, 58], [2, 61], [2, 65], [2, 68], [2, 72], [2, 73], [2, 76], [2, 78], [2, 79], [2, 80], [2, 81], [2, 82], [2, 83], [2, 84], [2, 86], [2, 88], [3, 11], [3, 15], [3, 16], [3, 20], [3, 21], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 39], [3, 41], [3, 46], [3, 48], [3, 50], [3, 53], [3, 56], [3, 57], [3, 59], [3, 60], [3, 61], [3, 63], [3, 66], [3, 68], [3, 69], [3, 72], [3, 73], [3, 77], [3, 78], [3, 79], [3, 81], [3, 84], [3, 85], [3, 86], [3, 87], [3, 89], [4, 6], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 22], [4, 25], [4, 26], [4, 28], [4, 29], [4, 31], [4, 32], [4, 35], [4, 36], [4, 37], [4, 38], [4, 40], [4, 42], [4, 46], [4, 49], [4, 51], [4, 52], [4, 54], [4, 55], [4, 56], [4, 60], [4, 62], [4, 64], [4, 68], [4, 69], [4, 70], [4, 72], [4, 74], [4, 77], [4, 78], [4, 80], [4, 83], [4, 84], [4, 87], [4, 88], [4, 89], [5, 6], [5, 7], [5, 8], [5, 12], [5, 13], [5, 15], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [5, 25], [5, 26], [5, 29], [5, 32], [5, 33], [5, 36], [5, 37], [5, 38], [5, 39], [5, 41], [5, 43], [5, 45], [5, 46], [5, 47], [5, 48], [5, 52], [5, 55], [5, 56], [5, 58], [5, 61], [5, 64], [5, 66], [5, 67], [5, 68], [5, 70], [5, 71], [5, 74], [5, 76], [5, 77], [5, 78], [5, 79], [5, 80], [5, 83], [5, 87], [5, 88], [6, 7], [6, 8], [6, 9], [6, 13], [6, 14], [6, 16], [6, 19], [6, 20], [6, 27], [6, 28], [6, 37], [6, 38], [6, 39], [6, 41], [6, 42], [6, 43], [6, 44], [6, 47], [6, 48], [6, 49], [6, 55], [6, 58], [6, 60], [6, 61], [6, 63], [6, 64], [6, 67], [6, 75], [6, 76], [6, 78], [6, 81], [6, 82], [6, 84], [6, 85], [6, 89], [7, 8], [7, 11], [7, 15], [7, 16], [7, 20], [7, 23], [7, 24], [7, 26], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 51], [7, 52], [7, 53], [7, 54], [7, 55], [7, 56], [7, 60], [7, 61], [7, 62], [7, 64], [7, 67], [7, 68], [7, 73], [7, 74], [7, 75], [7, 78], [7, 79], [7, 83], [7, 86], [7, 89], [8, 9], [8, 11], [8, 13], [8, 15], [8, 17], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 31], [8, 33], [8, 36], [8, 37], [8, 38], [8, 41], [8, 44], [8, 45], [8, 46], [8, 49], [8, 50], [8, 51], [8, 52], [8, 58], [8, 60], [8, 64], [8, 68], [8, 69], [8, 72], [8, 73], [8, 76], [8, 79], [8, 80], [8, 82], [8, 83], [8, 85], [8, 87], [8, 88], [9, 10], [9, 12], [9, 13], [9, 14], [9, 15], [9, 21], [9, 24], [9, 25], [9, 26], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 36], [9, 37], [9, 39], [9, 40], [9, 42], [9, 45], [9, 46], [9, 48], [9, 49], [9, 50], [9, 52], [9, 54], [9, 56], [9, 57], [9, 58], [9, 59], [9, 61], [9, 63], [9, 65], [9, 66], [9, 68], [9, 69], [9, 73], [9, 77], [9, 78], [9, 82], [9, 83], [9, 84], [9, 85], [9, 86], [9, 88], [9, 89], [10, 17], [10, 18], [10, 20], [10, 25], [10, 26], [10, 27], [10, 28], [10, 32], [10, 37], [10, 39], [10, 42], [10, 43], [10, 44], [10, 46], [10, 47], [10, 48], [10, 49], [10, 50], [10, 51], [10, 52], [10, 53], [10, 55], [10, 56], [10, 57], [10, 60], [10, 63], [10, 66], [10, 71], [10, 74], [10, 78], [10, 82], [10, 84], [10, 85], [10, 86], [10, 88], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 20], [11, 24], [11, 29], [11, 31], [11, 33], [11, 34], [11, 35], [11, 36], [11, 39], [11, 42], [11, 45], [11, 47], [11, 49], [11, 50], [11, 53], [11, 54], [11, 55], [11, 56], [11, 60], [11, 61], [11, 62], [11, 65], [11, 68], [11, 69], [11, 71], [11, 74], [11, 77], [11, 80], [11, 81], [11, 82], [11, 83], [11, 85], [11, 86], [11, 88], [11, 89], [12, 14], [12, 15], [12, 18], [12, 19], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 32], [12, 33], [12, 34], [12, 36], [12, 39], [12, 41], [12, 42], [12, 43], [12, 44], [12, 46], [12, 49], [12, 51], [12, 52], [12, 54], [12, 55], [12, 57], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 65], [12, 66], [12, 68], [12, 69], [12, 71], [12, 72], [12, 73], [12, 76], [12, 77], [12, 78], [12, 79], [12, 81], [12, 82], [12, 85], [12, 86], [12, 89], [13, 14], [13, 18], [13, 20], [13, 24], [13, 27], [13, 29], [13, 31], [13, 33], [13, 36], [13, 37], [13, 38], [13, 39], [13, 41], [13, 45], [13, 46], [13, 50], [13, 51], [13, 53], [13, 54], [13, 55], [13, 58], [13, 61], [13, 67], [13, 68], [13, 69], [13, 70], [13, 73], [13, 76], [13, 77], [13, 79], [13, 80], [13, 83], [13, 89], [14, 17], [14, 23], [14, 24], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 33], [14, 34], [14, 35], [14, 37], [14, 39], [14, 42], [14, 43], [14, 44], [14, 46], [14, 47], [14, 48], [14, 51], [14, 52], [14, 53], [14, 54], [14, 59], [14, 60], [14, 62], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 74], [14, 76], [14, 77], [14, 79], [14, 84], [14, 85], [14, 86], [14, 88], [15, 19], [15, 22], [15, 23], [15, 25], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 35], [15, 38], [15, 40], [15, 44], [15, 46], [15, 47], [15, 51], [15, 52], [15, 54], [15, 56], [15, 57], [15, 58], [15, 60], [15, 62], [15, 64], [15, 68], [15, 69], [15, 81], [15, 84], [15, 85], [15, 87], [15, 88], [15, 89], [16, 17], [16, 18], [16, 19], [16, 21], [16, 23], [16, 24], [16, 26], [16, 27], [16, 29], [16, 31], [16, 34], [16, 36], [16, 39], [16, 40], [16, 42], [16, 43], [16, 46], [16, 50], [16, 52], [16, 53], [16, 58], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 69], [16, 70], [16, 72], [16, 75], [16, 77], [16, 78], [16, 79], [16, 80], [16, 82], [16, 85], [16, 86], [16, 87], [16, 89], [17, 18], [17, 19], [17, 22], [17, 23], [17, 25], [17, 27], [17, 31], [17, 32], [17, 33], [17, 37], [17, 40], [17, 42], [17, 43], [17, 44], [17, 47], [17, 48], [17, 51], [17, 53], [17, 54], [17, 61], [17, 63], [17, 66], [17, 67], [17, 74], [17, 76], [17, 77], [17, 78], [17, 86], [17, 88], [18, 19], [18, 20], [18, 21], [18, 23], [18, 26], [18, 27], [18, 30], [18, 31], [18, 33], [18, 34], [18, 35], [18, 36], [18, 39], [18, 42], [18, 44], [18, 48], [18, 49], [18, 52], [18, 54], [18, 55], [18, 56], [18, 57], [18, 58], [18, 61], [18, 62], [18, 65], [18, 66], [18, 73], [18, 76], [18, 77], [18, 80], [18, 81], [18, 82], [18, 84], [18, 85], [18, 87], [18, 88], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 29], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 38], [19, 40], [19, 42], [19, 43], [19, 44], [19, 47], [19, 48], [19, 50], [19, 51], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 58], [19, 59], [19, 62], [19, 65], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [19, 75], [19, 76], [19, 78], [19, 80], [19, 81], [19, 83], [19, 85], [19, 86], [19, 88], [19, 89], [20, 21], [20, 22], [20, 23], [20, 24], [20, 27], [20, 29], [20, 31], [20, 33], [20, 34], [20, 36], [20, 37], [20, 38], [20, 40], [20, 41], [20, 43], [20, 45], [20, 46], [20, 47], [20, 52], [20, 53], [20, 55], [20, 61], [20, 64], [20, 65], [20, 66], [20, 69], [20, 70], [20, 71], [20, 73], [20, 76], [20, 77], [20, 79], [20, 81], [20, 82], [20, 83], [20, 86], [20, 87], [20, 88], [20, 89], [21, 22], [21, 23], [21, 26], [21, 27], [21, 29], [21, 31], [21, 33], [21, 35], [21, 37], [21, 39], [21, 41], [21, 42], [21, 47], [21, 50], [21, 51], [21, 53], [21, 54], [21, 55], [21, 56], [21, 57], [21, 58], [21, 62], [21, 68], [21, 69], [21, 74], [21, 75], [21, 76], [21, 77], [21, 80], [21, 82], [21, 83], [21, 86], [21, 87], [21, 88], [21, 89], [22, 25], [22, 27], [22, 28], [22, 33], [22, 37], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 47], [22, 49], [22, 50], [22, 53], [22, 57], [22, 60], [22, 61], [22, 65], [22, 67], [22, 68], [22, 69], [22, 71], [22, 76], [22, 77], [22, 78], [22, 79], [22, 84], [22, 86], [22, 87], [22, 88], [22, 89], [23, 24], [23, 25], [23, 26], [23, 29], [23, 30], [23, 31], [23, 33], [23, 35], [23, 38], [23, 42], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 52], [23, 53], [23, 54], [23, 55], [23, 58], [23, 59], [23, 61], [23, 62], [23, 66], [23, 67], [23, 68], [23, 69], [23, 72], [23, 73], [23, 75], [23, 76], [23, 77], [23, 79], [23, 80], [23, 83], [23, 88], [24, 25], [24, 28], [24, 29], [24, 30], [24, 32], [24, 34], [24, 36], [24, 39], [24, 42], [24, 45], [24, 47], [24, 48], [24, 52], [24, 55], [24, 56], [24, 64], [24, 67], [24, 70], [24, 71], [24, 72], [24, 77], [24, 78], [24, 86], [24, 87], [24, 88], [25, 26], [25, 28], [25, 29], [25, 31], [25, 32], [25, 34], [25, 36], [25, 39], [25, 41], [25, 43], [25, 44], [25, 45], [25, 46], [25, 49], [25, 52], [25, 54], [25, 55], [25, 56], [25, 59], [25, 60], [25, 61], [25, 62], [25, 64], [25, 66], [25, 67], [25, 68], [25, 71], [25, 72], [25, 73], [25, 74], [25, 75], [25, 78], [25, 79], [25, 82], [25, 86], [25, 87], [25, 88], [25, 89], [26, 27], [26, 30], [26, 32], [26, 33], [26, 35], [26, 37], [26, 38], [26, 39], [26, 40], [26, 43], [26, 44], [26, 45], [26, 49], [26, 52], [26, 56], [26, 70], [26, 71], [26, 73], [26, 74], [26, 75], [26, 77], [26, 78], [26, 79], [26, 82], [26, 84], [26, 85], [26, 89], [27, 29], [27, 30], [27, 31], [27, 33], [27, 35], [27, 38], [27, 40], [27, 42], [27, 43], [27, 46], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 53], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 61], [27, 62], [27, 65], [27, 67], [27, 68], [27, 69], [27, 71], [27, 72], [27, 79], [27, 81], [27, 84], [27, 85], [27, 88], [27, 89], [28, 29], [28, 30], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 40], [28, 42], [28, 43], [28, 47], [28, 48], [28, 50], [28, 53], [28, 55], [28, 59], [28, 61], [28, 65], [28, 66], [28, 68], [28, 72], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 80], [28, 81], [28, 83], [28, 84], [28, 85], [28, 87], [28, 88], [29, 30], [29, 33], [29, 36], [29, 38], [29, 39], [29, 41], [29, 44], [29, 45], [29, 48], [29, 49], [29, 52], [29, 53], [29, 56], [29, 62], [29, 63], [29, 65], [29, 66], [29, 68], [29, 69], [29, 74], [29, 75], [29, 76], [29, 77], [29, 78], [29, 79], [29, 80], [29, 82], [29, 86], [29, 88], [29, 89], [30, 31], [30, 33], [30, 34], [30, 36], [30, 37], [30, 38], [30, 39], [30, 42], [30, 43], [30, 44], [30, 50], [30, 54], [30, 56], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 65], [30, 66], [30, 72], [30, 74], [30, 76], [30, 78], [30, 79], [30, 80], [30, 82], [30, 83], [30, 84], [30, 89], [31, 32], [31, 36], [31, 37], [31, 42], [31, 45], [31, 46], [31, 48], [31, 49], [31, 51], [31, 52], [31, 56], [31, 58], [31, 59], [31, 61], [31, 62], [31, 63], [31, 64], [31, 65], [31, 66], [31, 68], [31, 70], [31, 72], [31, 73], [31, 76], [31, 77], [31, 78], [31, 79], [31, 80], [31, 87], [32, 35], [32, 37], [32, 39], [32, 43], [32, 44], [32, 45], [32, 46], [32, 50], [32, 52], [32, 53], [32, 60], [32, 63], [32, 68], [32, 71], [32, 74], [32, 75], [32, 76], [32, 77], [32, 82], [32, 84], [32, 85], [32, 86], [32, 87], [32, 89], [33, 34], [33, 35], [33, 37], [33, 41], [33, 44], [33, 45], [33, 50], [33, 51], [33, 52], [33, 56], [33, 58], [33, 59], [33, 61], [33, 62], [33, 63], [33, 64], [33, 67], [33, 69], [33, 70], [33, 71], [33, 74], [33, 75], [33, 76], [33, 79], [33, 80], [33, 81], [33, 82], [33, 83], [33, 86], [33, 87], [33, 88], [33, 89], [34, 38], [34, 39], [34, 41], [34, 42], [34, 43], [34, 44], [34, 46], [34, 48], [34, 49], [34, 50], [34, 51], [34, 53], [34, 54], [34, 56], [34, 58], [34, 61], [34, 62], [34, 64], [34, 65], [34, 66], [34, 68], [34, 70], [34, 72], [34, 74], [34, 77], [34, 79], [34, 81], [34, 82], [34, 83], [34, 85], [34, 86], [34, 87], [34, 89], [35, 42], [35, 43], [35, 45], [35, 50], [35, 51], [35, 52], [35, 53], [35, 55], [35, 57], [35, 59], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 68], [35, 69], [35, 71], [35, 73], [35, 75], [35, 77], [35, 79], [35, 80], [35, 81], [35, 82], [35, 83], [35, 88], [35, 89], [36, 37], [36, 40], [36, 41], [36, 42], [36, 43], [36, 49], [36, 51], [36, 53], [36, 59], [36, 60], [36, 63], [36, 67], [36, 68], [36, 71], [36, 72], [36, 73], [36, 74], [36, 75], [36, 76], [36, 79], [36, 80], [36, 82], [36, 83], [36, 84], [36, 85], [36, 86], [36, 88], [36, 89], [37, 38], [37, 41], [37, 42], [37, 43], [37, 44], [37, 47], [37, 49], [37, 50], [37, 53], [37, 56], [37, 57], [37, 58], [37, 59], [37, 61], [37, 62], [37, 63], [37, 65], [37, 67], [37, 68], [37, 70], [37, 72], [37, 74], [37, 75], [37, 76], [37, 77], [37, 78], [37, 80], [37, 81], [37, 82], [37, 85], [38, 40], [38, 43], [38, 45], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 54], [38, 55], [38, 56], [38, 60], [38, 61], [38, 63], [38, 64], [38, 65], [38, 66], [38, 68], [38, 70], [38, 72], [38, 74], [38, 77], [38, 78], [38, 79], [38, 82], [38, 83], [38, 84], [38, 85], [38, 89], [39, 41], [39, 42], [39, 43], [39, 45], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 54], [39, 55], [39, 56], [39, 57], [39, 60], [39, 61], [39, 65], [39, 66], [39, 67], [39, 68], [39, 69], [39, 72], [39, 75], [39, 78], [39, 81], [39, 86], [39, 88], [39, 89], [40, 42], [40, 43], [40, 45], [40, 46], [40, 47], [40, 50], [40, 52], [40, 53], [40, 54], [40, 57], [40, 58], [40, 59], [40, 61], [40, 67], [40, 68], [40, 70], [40, 71], [40, 73], [40, 74], [40, 75], [40, 76], [40, 77], [40, 78], [40, 79], [40, 80], [40, 82], [40, 84], [40, 88], [41, 42], [41, 43], [41, 46], [41, 50], [41, 52], [41, 53], [41, 54], [41, 59], [41, 60], [41, 63], [41, 64], [41, 65], [41, 66], [41, 68], [41, 69], [41, 72], [41, 73], [41, 74], [41, 77], [41, 78], [41, 80], [41, 84], [41, 87], [41, 88], [42, 44], [42, 45], [42, 47], [42, 49], [42, 50], [42, 54], [42, 58], [42, 59], [42, 62], [42, 66], [42, 68], [42, 70], [42, 71], [42, 72], [42, 73], [42, 76], [42, 77], [42, 78], [42, 79], [42, 80], [42, 82], [42, 84], [42, 88], [42, 89], [43, 44], [43, 45], [43, 48], [43, 49], [43, 51], [43, 53], [43, 55], [43, 59], [43, 60], [43, 61], [43, 63], [43, 66], [43, 70], [43, 71], [43, 75], [43, 76], [43, 77], [43, 78], [43, 79], [43, 80], [43, 81], [43, 83], [43, 84], [43, 85], [44, 48], [44, 49], [44, 51], [44, 53], [44, 55], [44, 58], [44, 59], [44, 62], [44, 63], [44, 65], [44, 68], [44, 70], [44, 72], [44, 74], [44, 76], [44, 80], [44, 84], [44, 86], [44, 89], [45, 48], [45, 49], [45, 50], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 59], [45, 61], [45, 63], [45, 66], [45, 67], [45, 68], [45, 72], [45, 73], [45, 75], [45, 76], [45, 77], [45, 78], [45, 79], [45, 81], [45, 83], [45, 84], [45, 86], [46, 47], [46, 48], [46, 49], [46, 52], [46, 54], [46, 56], [46, 58], [46, 59], [46, 61], [46, 62], [46, 63], [46, 65], [46, 67], [46, 69], [46, 70], [46, 73], [46, 74], [46, 80], [46, 83], [46, 84], [46, 89], [47, 48], [47, 49], [47, 50], [47, 51], [47, 52], [47, 53], [47, 54], [47, 58], [47, 59], [47, 60], [47, 62], [47, 65], [47, 66], [47, 68], [47, 70], [47, 71], [47, 72], [47, 75], [47, 79], [47, 80], [47, 81], [47, 87], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 61], [48, 63], [48, 66], [48, 67], [48, 68], [48, 71], [48, 73], [48, 74], [48, 77], [48, 78], [48, 80], [48, 81], [48, 84], [48, 87], [48, 88], [49, 50], [49, 51], [49, 54], [49, 55], [49, 56], [49, 57], [49, 59], [49, 60], [49, 65], [49, 66], [49, 67], [49, 68], [49, 71], [49, 73], [49, 77], [49, 78], [49, 81], [49, 83], [49, 85], [49, 86], [49, 88], [50, 52], [50, 57], [50, 60], [50, 61], [50, 62], [50, 65], [50, 67], [50, 68], [50, 70], [50, 71], [50, 72], [50, 73], [50, 74], [50, 77], [50, 86], [50, 87], [50, 89], [51, 52], [51, 56], [51, 57], [51, 58], [51, 59], [51, 61], [51, 65], [51, 66], [51, 71], [51, 72], [51, 75], [51, 77], [51, 78], [51, 84], [51, 86], [51, 87], [51, 88], [51, 89], [52, 57], [52, 60], [52, 66], [52, 67], [52, 68], [52, 69], [52, 71], [52, 72], [52, 75], [52, 79], [52, 80], [52, 82], [52, 84], [52, 88], [52, 89], [53, 54], [53, 55], [53, 56], [53, 57], [53, 59], [53, 60], [53, 61], [53, 62], [53, 66], [53, 69], [53, 70], [53, 72], [53, 73], [53, 75], [53, 80], [53, 82], [53, 86], [53, 87], [53, 89], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 62], [54, 63], [54, 64], [54, 65], [54, 67], [54, 68], [54, 70], [54, 73], [54, 74], [54, 77], [54, 78], [54, 79], [54, 82], [54, 85], [54, 86], [54, 89], [55, 58], [55, 63], [55, 64], [55, 65], [55, 67], [55, 69], [55, 70], [55, 71], [55, 72], [55, 75], [55, 76], [55, 78], [55, 80], [55, 81], [55, 83], [55, 84], [55, 86], [55, 88], [55, 89], [56, 58], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 69], [56, 70], [56, 73], [56, 74], [56, 75], [56, 76], [56, 77], [56, 78], [56, 79], [56, 80], [56, 81], [56, 82], [56, 83], [56, 84], [56, 85], [56, 86], [56, 88], [56, 89], [57, 58], [57, 60], [57, 61], [57, 62], [57, 64], [57, 66], [57, 68], [57, 69], [57, 81], [57, 82], [57, 86], [58, 60], [58, 62], [58, 64], [58, 66], [58, 68], [58, 69], [58, 73], [58, 76], [58, 78], [58, 80], [58, 81], [58, 82], [58, 83], [58, 84], [58, 85], [58, 86], [58, 87], [58, 89], [59, 61], [59, 62], [59, 63], [59, 64], [59, 68], [59, 69], [59, 72], [59, 73], [59, 74], [59, 75], [59, 76], [59, 77], [59, 81], [59, 82], [59, 83], [59, 84], [59, 89], [60, 61], [60, 62], [60, 67], [60, 69], [60, 70], [60, 71], [60, 72], [60, 76], [60, 80], [60, 81], [60, 83], [60, 85], [60, 86], [60, 87], [61, 65], [61, 66], [61, 71], [61, 73], [61, 75], [61, 76], [61, 77], [61, 81], [61, 87], [61, 89], [62, 65], [62, 66], [62, 68], [62, 69], [62, 70], [62, 72], [62, 74], [62, 75], [62, 79], [62, 80], [62, 82], [62, 83], [62, 86], [62, 87], [62, 88], [62, 89], [63, 69], [63, 70], [63, 71], [63, 73], [63, 74], [63, 75], [63, 76], [63, 77], [63, 78], [63, 82], [63, 83], [63, 84], [63, 85], [63, 86], [63, 88], [63, 89], [64, 67], [64, 68], [64, 70], [64, 71], [64, 73], [64, 76], [64, 77], [64, 79], [64, 80], [64, 81], [64, 82], [64, 83], [64, 84], [64, 85], [64, 86], [64, 87], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 81], [65, 82], [65, 85], [65, 87], [65, 89], [66, 69], [66, 71], [66, 77], [66, 78], [66, 79], [66, 83], [66, 84], [66, 85], [66, 87], [66, 88], [67, 68], [67, 69], [67, 72], [67, 73], [67, 75], [67, 76], [67, 77], [67, 79], [67, 81], [67, 82], [67, 86], [67, 87], [67, 88], [67, 89], [68, 70], [68, 71], [68, 73], [68, 75], [68, 82], [68, 84], [68, 85], [68, 86], [69, 70], [69, 71], [69, 72], [69, 75], [69, 78], [69, 79], [69, 80], [69, 81], [69, 84], [69, 85], [69, 86], [69, 87], [69, 88], [69, 89], [70, 71], [70, 72], [70, 75], [70, 76], [70, 78], [70, 79], [70, 81], [70, 82], [70, 84], [70, 88], [70, 89], [71, 72], [71, 73], [71, 75], [71, 77], [71, 80], [71, 82], [71, 84], [71, 87], [72, 73], [72, 74], [72, 76], [72, 78], [72, 80], [72, 81], [72, 82], [72, 83], [72, 87], [72, 88], [72, 89], [73, 77], [73, 78], [73, 79], [73, 80], [73, 84], [73, 89], [74, 75], [74, 76], [74, 77], [74, 79], [74, 81], [74, 82], [74, 83], [74, 84], [74, 85], [74, 87], [75, 76], [75, 80], [75, 82], [75, 83], [75, 85], [75, 86], [75, 88], [75, 89], [76, 78], [76, 82], [76, 83], [76, 85], [76, 89], [77, 83], [77, 84], [77, 85], [77, 87], [77, 89], [78, 79], [78, 80], [78, 81], [78, 82], [78, 86], [79, 81], [79, 83], [79, 84], [79, 85], [79, 88], [80, 82], [80, 83], [80, 84], [80, 86], [80, 88], [80, 89], [81, 82], [81, 83], [81, 84], [81, 85], [81, 87], [82, 84], [82, 85], [82, 86], [82, 87], [83, 85], [83, 88], [84, 86], [84, 87], [84, 89], [85, 88], [85, 89], [86, 88], [86, 89], [87, 89], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s3/tests/run.py b/tasks/construct-mc-max-clique-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-mc-max-clique-l5-s3/tests/test.sh b/tasks/construct-mc-max-clique-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-mc-max-independent-set-l2-s1/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l2-s1/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd1a2e137ce4545ebf78e37b4f80b264d36ae245 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 1], [0, 9], [0, 11], [0, 13], [0, 27], [1, 2], [1, 9], [1, 17], [1, 18], [1, 27], [1, 29], [2, 6], [2, 7], [2, 9], [2, 14], [2, 20], [2, 21], [2, 22], [2, 23], [2, 28], [2, 29], [3, 4], [3, 5], [3, 10], [3, 11], [3, 16], [3, 19], [3, 21], [3, 24], [3, 26], [3, 27], [3, 28], [4, 11], [4, 14], [4, 15], [4, 16], [4, 26], [4, 29], [5, 6], [5, 7], [5, 8], [5, 9], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 23], [5, 26], [6, 9], [6, 11], [6, 12], [6, 21], [6, 27], [7, 8], [7, 9], [7, 10], [7, 13], [7, 24], [8, 22], [8, 24], [8, 26], [8, 27], [8, 28], [9, 12], [9, 13], [9, 14], [9, 17], [9, 18], [9, 27], [9, 28], [10, 11], [10, 12], [10, 15], [10, 16], [10, 27], [10, 28], [11, 20], [11, 23], [11, 24], [11, 28], [12, 13], [12, 14], [12, 18], [12, 23], [12, 26], [12, 27], [12, 29], [13, 14], [13, 17], [13, 25], [13, 28], [13, 29], [14, 15], [14, 17], [14, 18], [15, 16], [15, 20], [15, 21], [15, 26], [16, 19], [16, 23], [16, 29], [17, 20], [17, 22], [17, 26], [18, 20], [18, 24], [18, 26], [18, 28], [19, 20], [19, 24], [19, 26], [19, 27], [20, 25], [20, 26], [20, 29], [21, 23], [21, 29], [22, 23], [22, 24], [22, 25], [22, 27], [22, 28], [22, 29], [23, 28], [24, 26], [25, 26], [25, 27], [26, 27], [26, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s1/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..25480a4a86f9ed243398a2543520efc45d2b72be --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [0, 6, 7, 15, 17, 18, 19, 23, 29]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s1/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s1/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-s1/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd1a2e137ce4545ebf78e37b4f80b264d36ae245 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 1], [0, 9], [0, 11], [0, 13], [0, 27], [1, 2], [1, 9], [1, 17], [1, 18], [1, 27], [1, 29], [2, 6], [2, 7], [2, 9], [2, 14], [2, 20], [2, 21], [2, 22], [2, 23], [2, 28], [2, 29], [3, 4], [3, 5], [3, 10], [3, 11], [3, 16], [3, 19], [3, 21], [3, 24], [3, 26], [3, 27], [3, 28], [4, 11], [4, 14], [4, 15], [4, 16], [4, 26], [4, 29], [5, 6], [5, 7], [5, 8], [5, 9], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 23], [5, 26], [6, 9], [6, 11], [6, 12], [6, 21], [6, 27], [7, 8], [7, 9], [7, 10], [7, 13], [7, 24], [8, 22], [8, 24], [8, 26], [8, 27], [8, 28], [9, 12], [9, 13], [9, 14], [9, 17], [9, 18], [9, 27], [9, 28], [10, 11], [10, 12], [10, 15], [10, 16], [10, 27], [10, 28], [11, 20], [11, 23], [11, 24], [11, 28], [12, 13], [12, 14], [12, 18], [12, 23], [12, 26], [12, 27], [12, 29], [13, 14], [13, 17], [13, 25], [13, 28], [13, 29], [14, 15], [14, 17], [14, 18], [15, 16], [15, 20], [15, 21], [15, 26], [16, 19], [16, 23], [16, 29], [17, 20], [17, 22], [17, 26], [18, 20], [18, 24], [18, 26], [18, 28], [19, 20], [19, 24], [19, 26], [19, 27], [20, 25], [20, 26], [20, 29], [21, 23], [21, 29], [22, 23], [22, 24], [22, 25], [22, 27], [22, 28], [22, 29], [23, 28], [24, 26], [25, 26], [25, 27], [26, 27], [26, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s1/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l2-s1/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l6-s8/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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-l6-s8/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..81e72424217084e402029cbb60308bd4d0ac9a24 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 1], [0, 3], [0, 4], [0, 6], [0, 8], [0, 14], [0, 15], [0, 18], [0, 19], [0, 21], [0, 24], [0, 25], [0, 30], [0, 31], [0, 41], [0, 44], [0, 45], [0, 53], [0, 55], [0, 58], [0, 67], [0, 68], [0, 71], [0, 80], [0, 81], [0, 83], [0, 84], [0, 86], [0, 103], [0, 104], [0, 106], [0, 110], [0, 112], [0, 113], [0, 116], [0, 119], [0, 124], [0, 129], [0, 132], [1, 3], [1, 10], [1, 13], [1, 15], [1, 17], [1, 18], [1, 20], [1, 24], [1, 27], [1, 38], [1, 40], [1, 43], [1, 51], [1, 52], [1, 56], [1, 60], [1, 61], [1, 62], [1, 64], [1, 68], [1, 70], [1, 77], [1, 79], [1, 82], [1, 83], [1, 84], [1, 87], [1, 89], [1, 92], [1, 95], [1, 97], [1, 102], [1, 103], [1, 113], [1, 114], [1, 118], [1, 121], [1, 124], [1, 125], [1, 137], [1, 139], [2, 7], [2, 9], [2, 10], [2, 19], [2, 20], [2, 22], [2, 31], [2, 34], [2, 35], [2, 38], [2, 39], [2, 41], [2, 43], [2, 46], [2, 50], [2, 59], [2, 61], [2, 62], [2, 63], [2, 66], [2, 71], [2, 72], [2, 73], [2, 74], [2, 76], [2, 79], [2, 80], [2, 81], [2, 82], [2, 84], [2, 87], [2, 89], [2, 93], [2, 95], [2, 98], [2, 107], [2, 112], [2, 114], [2, 116], [2, 117], [2, 121], [2, 125], [2, 128], [2, 130], [2, 138], [3, 5], [3, 6], [3, 12], [3, 16], [3, 18], [3, 21], [3, 22], [3, 28], [3, 34], [3, 35], [3, 37], [3, 40], [3, 41], [3, 42], [3, 55], [3, 57], [3, 61], [3, 64], [3, 67], [3, 74], [3, 80], [3, 85], [3, 88], [3, 90], [3, 91], [3, 92], [3, 93], [3, 96], [3, 99], [3, 100], [3, 105], [3, 112], [3, 117], [3, 118], [3, 121], [3, 123], [3, 124], [3, 129], [3, 131], [3, 133], [3, 135], [3, 136], [4, 5], [4, 8], [4, 9], [4, 17], [4, 18], [4, 23], [4, 26], [4, 29], [4, 33], [4, 34], [4, 37], [4, 39], [4, 47], [4, 49], [4, 53], [4, 62], [4, 69], [4, 76], [4, 79], [4, 86], [4, 87], [4, 88], [4, 89], [4, 92], [4, 97], [4, 99], [4, 103], [4, 106], [4, 107], [4, 112], [4, 113], [4, 115], [4, 117], [4, 118], [4, 121], [4, 124], [4, 125], [4, 126], [4, 129], [4, 131], [4, 136], [4, 137], [4, 138], [5, 7], [5, 11], [5, 14], [5, 15], [5, 21], [5, 22], [5, 23], [5, 25], [5, 26], [5, 29], [5, 35], [5, 38], [5, 40], [5, 41], [5, 42], [5, 44], [5, 47], [5, 56], [5, 59], [5, 69], [5, 72], [5, 73], [5, 76], [5, 83], [5, 89], [5, 91], [5, 93], [5, 97], [5, 102], [5, 103], [5, 104], [5, 106], [5, 107], [5, 109], [5, 115], [5, 116], [5, 117], [5, 118], [5, 119], [5, 120], [5, 123], [5, 124], [5, 127], [5, 130], [5, 131], [5, 132], [5, 133], [5, 136], [5, 137], [6, 7], [6, 10], [6, 11], [6, 14], [6, 18], [6, 21], [6, 25], [6, 27], [6, 29], [6, 31], [6, 32], [6, 34], [6, 38], [6, 41], [6, 49], [6, 50], [6, 53], [6, 54], [6, 56], [6, 58], [6, 59], [6, 61], [6, 64], [6, 67], [6, 70], [6, 71], [6, 73], [6, 75], [6, 76], [6, 77], [6, 82], [6, 86], [6, 88], [6, 90], [6, 97], [6, 98], [6, 101], [6, 103], [6, 104], [6, 109], [6, 116], [6, 118], [6, 122], [6, 124], [6, 126], [6, 132], [6, 137], [6, 138], [7, 10], [7, 11], [7, 16], [7, 25], [7, 26], [7, 36], [7, 44], [7, 47], [7, 50], [7, 51], [7, 52], [7, 61], [7, 70], [7, 72], [7, 75], [7, 77], [7, 78], [7, 79], [7, 82], [7, 84], [7, 89], [7, 90], [7, 91], [7, 105], [7, 106], [7, 114], [7, 118], [7, 119], [7, 122], [7, 125], [8, 9], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 19], [8, 20], [8, 24], [8, 26], [8, 27], [8, 34], [8, 35], [8, 41], [8, 42], [8, 46], [8, 47], [8, 49], [8, 53], [8, 56], [8, 63], [8, 64], [8, 68], [8, 71], [8, 73], [8, 77], [8, 80], [8, 93], [8, 97], [8, 98], [8, 102], [8, 104], [8, 107], [8, 109], [8, 111], [8, 118], [8, 119], [8, 122], [8, 123], [8, 125], [8, 126], [8, 128], [8, 136], [9, 10], [9, 12], [9, 23], [9, 25], [9, 29], [9, 31], [9, 34], [9, 37], [9, 41], [9, 47], [9, 49], [9, 51], [9, 54], [9, 60], [9, 64], [9, 66], [9, 68], [9, 76], [9, 81], [9, 83], [9, 84], [9, 87], [9, 92], [9, 93], [9, 95], [9, 98], [9, 100], [9, 103], [9, 105], [9, 110], [9, 111], [9, 113], [9, 114], [9, 119], [9, 124], [9, 136], [10, 13], [10, 16], [10, 20], [10, 26], [10, 27], [10, 40], [10, 42], [10, 43], [10, 48], [10, 52], [10, 56], [10, 63], [10, 67], [10, 68], [10, 72], [10, 73], [10, 75], [10, 77], [10, 79], [10, 81], [10, 85], [10, 86], [10, 87], [10, 99], [10, 102], [10, 107], [10, 108], [10, 115], [10, 120], [10, 121], [10, 126], [10, 128], [10, 131], [10, 132], [11, 12], [11, 18], [11, 20], [11, 21], [11, 23], [11, 28], [11, 29], [11, 32], [11, 37], [11, 39], [11, 41], [11, 42], [11, 46], [11, 47], [11, 51], [11, 55], [11, 56], [11, 61], [11, 66], [11, 68], [11, 69], [11, 72], [11, 73], [11, 79], [11, 86], [11, 90], [11, 95], [11, 97], [11, 98], [11, 101], [11, 103], [11, 108], [11, 113], [11, 114], [11, 115], [11, 117], [11, 123], [11, 128], [11, 134], [11, 136], [11, 139], [12, 24], [12, 25], [12, 28], [12, 33], [12, 34], [12, 38], [12, 39], [12, 40], [12, 51], [12, 52], [12, 55], [12, 57], [12, 59], [12, 61], [12, 62], [12, 63], [12, 67], [12, 76], [12, 77], [12, 78], [12, 79], [12, 82], [12, 83], [12, 87], [12, 89], [12, 90], [12, 92], [12, 99], [12, 102], [12, 103], [12, 105], [12, 108], [12, 111], [12, 119], [12, 123], [12, 129], [12, 134], [12, 135], [12, 137], [13, 16], [13, 21], [13, 26], [13, 30], [13, 31], [13, 33], [13, 51], [13, 53], [13, 54], [13, 56], [13, 57], [13, 59], [13, 62], [13, 63], [13, 67], [13, 70], [13, 71], [13, 74], [13, 78], [13, 80], [13, 81], [13, 84], [13, 86], [13, 88], [13, 103], [13, 109], [13, 113], [13, 116], [13, 117], [13, 121], [13, 122], [13, 124], [13, 127], [13, 130], [13, 133], [14, 17], [14, 22], [14, 24], [14, 26], [14, 31], [14, 32], [14, 33], [14, 35], [14, 38], [14, 44], [14, 48], [14, 49], [14, 50], [14, 57], [14, 64], [14, 66], [14, 68], [14, 77], [14, 79], [14, 83], [14, 84], [14, 86], [14, 88], [14, 91], [14, 95], [14, 100], [14, 108], [14, 109], [14, 111], [14, 112], [14, 116], [14, 117], [14, 119], [14, 124], [14, 125], [14, 129], [14, 130], [14, 132], [14, 135], [14, 136], [14, 139], [15, 16], [15, 17], [15, 19], [15, 20], [15, 23], [15, 25], [15, 30], [15, 37], [15, 39], [15, 45], [15, 49], [15, 57], [15, 63], [15, 65], [15, 66], [15, 69], [15, 70], [15, 79], [15, 81], [15, 86], [15, 90], [15, 98], [15, 99], [15, 100], [15, 104], [15, 106], [15, 107], [15, 111], [15, 112], [15, 116], [15, 119], [15, 121], [15, 122], [15, 126], [15, 127], [15, 130], [15, 131], [15, 137], [15, 139], [16, 24], [16, 26], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 37], [16, 40], [16, 46], [16, 49], [16, 52], [16, 55], [16, 56], [16, 60], [16, 61], [16, 62], [16, 64], [16, 72], [16, 77], [16, 79], [16, 83], [16, 87], [16, 89], [16, 94], [16, 95], [16, 97], [16, 101], [16, 102], [16, 113], [16, 115], [16, 117], [16, 121], [16, 122], [16, 129], [16, 130], [16, 131], [16, 134], [16, 137], [17, 21], [17, 23], [17, 41], [17, 44], [17, 49], [17, 52], [17, 54], [17, 55], [17, 58], [17, 63], [17, 72], [17, 74], [17, 75], [17, 76], [17, 77], [17, 79], [17, 84], [17, 89], [17, 92], [17, 93], [17, 95], [17, 97], [17, 98], [17, 105], [17, 111], [17, 113], [17, 117], [17, 119], [17, 122], [17, 125], [17, 127], [17, 128], [17, 132], [17, 135], [18, 21], [18, 25], [18, 32], [18, 35], [18, 37], [18, 40], [18, 44], [18, 45], [18, 49], [18, 52], [18, 56], [18, 57], [18, 60], [18, 63], [18, 74], [18, 77], [18, 78], [18, 82], [18, 85], [18, 87], [18, 96], [18, 99], [18, 104], [18, 109], [18, 111], [18, 113], [18, 127], [18, 130], [19, 23], [19, 24], [19, 25], [19, 26], [19, 40], [19, 41], [19, 45], [19, 48], [19, 52], [19, 55], [19, 57], [19, 59], [19, 60], [19, 63], [19, 65], [19, 68], [19, 69], [19, 70], [19, 71], [19, 78], [19, 79], [19, 84], [19, 85], [19, 87], [19, 88], [19, 89], [19, 92], [19, 93], [19, 95], [19, 103], [19, 107], [19, 108], [19, 110], [19, 115], [19, 117], [19, 118], [19, 129], [19, 132], [19, 134], [19, 136], [19, 137], [20, 22], [20, 23], [20, 33], [20, 39], [20, 40], [20, 42], [20, 44], [20, 48], [20, 49], [20, 61], [20, 63], [20, 64], [20, 69], [20, 73], [20, 79], [20, 91], [20, 94], [20, 96], [20, 101], [20, 104], [20, 111], [20, 117], [20, 125], [20, 129], [20, 131], [20, 132], [20, 133], [20, 139], [21, 22], [21, 23], [21, 25], [21, 26], [21, 31], [21, 43], [21, 44], [21, 45], [21, 47], [21, 52], [21, 58], [21, 67], [21, 71], [21, 73], [21, 76], [21, 78], [21, 81], [21, 83], [21, 86], [21, 87], [21, 95], [21, 96], [21, 98], [21, 99], [21, 102], [21, 112], [21, 116], [21, 123], [21, 126], [21, 129], [21, 136], [21, 137], [22, 25], [22, 27], [22, 28], [22, 29], [22, 31], [22, 49], [22, 51], [22, 53], [22, 55], [22, 56], [22, 65], [22, 67], [22, 68], [22, 74], [22, 75], [22, 78], [22, 80], [22, 85], [22, 87], [22, 98], [22, 100], [22, 101], [22, 121], [22, 131], [22, 134], [22, 136], [22, 139], [23, 28], [23, 30], [23, 31], [23, 35], [23, 36], [23, 42], [23, 48], [23, 49], [23, 54], [23, 56], [23, 57], [23, 64], [23, 67], [23, 73], [23, 82], [23, 83], [23, 84], [23, 85], [23, 89], [23, 92], [23, 94], [23, 102], [23, 106], [23, 109], [23, 110], [23, 113], [23, 114], [23, 117], [23, 119], [23, 121], [23, 123], [23, 126], [23, 133], [23, 134], [23, 135], [23, 137], [23, 139], [24, 26], [24, 27], [24, 29], [24, 32], [24, 42], [24, 43], [24, 44], [24, 45], [24, 47], [24, 50], [24, 52], [24, 56], [24, 58], [24, 62], [24, 64], [24, 70], [24, 76], [24, 77], [24, 78], [24, 82], [24, 86], [24, 89], [24, 91], [24, 92], [24, 102], [24, 103], [24, 104], [24, 106], [24, 111], [24, 116], [24, 118], [24, 120], [24, 123], [24, 124], [24, 127], [24, 128], [24, 130], [24, 134], [25, 28], [25, 30], [25, 31], [25, 34], [25, 36], [25, 41], [25, 43], [25, 48], [25, 51], [25, 52], [25, 54], [25, 57], [25, 60], [25, 63], [25, 66], [25, 74], [25, 76], [25, 78], [25, 79], [25, 90], [25, 92], [25, 98], [25, 100], [25, 105], [25, 111], [25, 113], [25, 117], [25, 118], [25, 121], [25, 124], [25, 125], [25, 126], [25, 127], [25, 129], [25, 130], [25, 131], [25, 136], [25, 137], [26, 28], [26, 32], [26, 34], [26, 35], [26, 39], [26, 44], [26, 48], [26, 56], [26, 58], [26, 61], [26, 63], [26, 66], [26, 69], [26, 72], [26, 75], [26, 77], [26, 80], [26, 81], [26, 82], [26, 83], [26, 88], [26, 92], [26, 93], [26, 97], [26, 103], [26, 106], [26, 110], [26, 111], [26, 113], [26, 119], [26, 121], [26, 125], [26, 126], [26, 127], [26, 128], [26, 130], [26, 132], [26, 135], [26, 136], [26, 137], [26, 138], [27, 28], [27, 30], [27, 32], [27, 35], [27, 37], [27, 46], [27, 49], [27, 51], [27, 54], [27, 57], [27, 62], [27, 63], [27, 64], [27, 66], [27, 67], [27, 69], [27, 70], [27, 71], [27, 77], [27, 84], [27, 86], [27, 88], [27, 90], [27, 92], [27, 95], [27, 100], [27, 101], [27, 103], [27, 105], [27, 106], [27, 108], [27, 112], [27, 114], [27, 118], [27, 119], [27, 122], [27, 124], [27, 126], [27, 127], [28, 30], [28, 39], [28, 43], [28, 44], [28, 46], [28, 51], [28, 54], [28, 61], [28, 62], [28, 63], [28, 66], [28, 67], [28, 69], [28, 72], [28, 76], [28, 80], [28, 81], [28, 85], [28, 88], [28, 89], [28, 90], [28, 91], [28, 94], [28, 106], [28, 107], [28, 111], [28, 115], [28, 117], [28, 119], [28, 122], [28, 123], [28, 127], [28, 132], [28, 139], [29, 30], [29, 33], [29, 35], [29, 38], [29, 39], [29, 42], [29, 43], [29, 45], [29, 50], [29, 51], [29, 52], [29, 53], [29, 57], [29, 63], [29, 65], [29, 68], [29, 70], [29, 72], [29, 75], [29, 85], [29, 88], [29, 91], [29, 95], [29, 98], [29, 99], [29, 101], [29, 106], [29, 108], [29, 111], [29, 121], [29, 123], [29, 131], [29, 132], [29, 134], [29, 139], [30, 34], [30, 40], [30, 48], [30, 50], [30, 55], [30, 56], [30, 57], [30, 74], [30, 79], [30, 83], [30, 88], [30, 89], [30, 90], [30, 94], [30, 99], [30, 103], [30, 110], [30, 113], [30, 117], [30, 119], [30, 121], [30, 130], [30, 137], [31, 34], [31, 38], [31, 41], [31, 45], [31, 52], [31, 55], [31, 58], [31, 59], [31, 63], [31, 64], [31, 65], [31, 66], [31, 67], [31, 73], [31, 76], [31, 78], [31, 80], [31, 82], [31, 84], [31, 89], [31, 90], [31, 99], [31, 102], [31, 108], [31, 110], [31, 120], [31, 121], [31, 138], [32, 37], [32, 40], [32, 41], [32, 42], [32, 43], [32, 44], [32, 56], [32, 62], [32, 63], [32, 64], [32, 65], [32, 72], [32, 79], [32, 82], [32, 88], [32, 93], [32, 98], [32, 99], [32, 104], [32, 105], [32, 106], [32, 108], [32, 110], [32, 111], [32, 121], [32, 123], [32, 130], [32, 135], [33, 36], [33, 38], [33, 42], [33, 43], [33, 46], [33, 49], [33, 53], [33, 56], [33, 59], [33, 61], [33, 68], [33, 70], [33, 71], [33, 82], [33, 84], [33, 94], [33, 95], [33, 97], [33, 107], [33, 108], [33, 112], [33, 113], [33, 116], [33, 119], [33, 122], [33, 123], [33, 124], [33, 125], [33, 128], [33, 129], [33, 139], [34, 36], [34, 37], [34, 39], [34, 40], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 51], [34, 55], [34, 61], [34, 63], [34, 64], [34, 66], [34, 76], [34, 84], [34, 86], [34, 88], [34, 89], [34, 95], [34, 96], [34, 97], [34, 104], [34, 106], [34, 110], [34, 111], [34, 114], [34, 116], [34, 117], [34, 120], [34, 122], [34, 123], [34, 125], [34, 129], [34, 132], [34, 133], [34, 134], [34, 135], [34, 136], [34, 138], [35, 42], [35, 43], [35, 46], [35, 48], [35, 51], [35, 53], [35, 57], [35, 58], [35, 62], [35, 65], [35, 66], [35, 67], [35, 69], [35, 71], [35, 74], [35, 76], [35, 79], [35, 80], [35, 85], [35, 94], [35, 97], [35, 101], [35, 103], [35, 105], [35, 106], [35, 109], [35, 110], [35, 111], [35, 116], [35, 118], [35, 122], [35, 124], [35, 133], [35, 134], [35, 137], [35, 138], [36, 37], [36, 41], [36, 50], [36, 54], [36, 76], [36, 77], [36, 78], [36, 83], [36, 86], [36, 92], [36, 94], [36, 96], [36, 98], [36, 101], [36, 102], [36, 104], [36, 105], [36, 109], [36, 115], [36, 116], [36, 120], [36, 121], [36, 126], [36, 135], [36, 138], [36, 139], [37, 41], [37, 42], [37, 43], [37, 45], [37, 48], [37, 50], [37, 54], [37, 57], [37, 58], [37, 60], [37, 61], [37, 62], [37, 65], [37, 80], [37, 84], [37, 85], [37, 91], [37, 101], [37, 102], [37, 103], [37, 104], [37, 118], [37, 122], [37, 130], [38, 39], [38, 41], [38, 46], [38, 47], [38, 50], [38, 53], [38, 62], [38, 68], [38, 70], [38, 75], [38, 78], [38, 83], [38, 85], [38, 86], [38, 91], [38, 95], [38, 103], [38, 104], [38, 105], [38, 106], [38, 107], [38, 109], [38, 111], [38, 113], [38, 117], [38, 120], [38, 123], [38, 124], [38, 128], [38, 129], [38, 130], [38, 135], [38, 137], [39, 40], [39, 41], [39, 43], [39, 44], [39, 46], [39, 53], [39, 59], [39, 66], [39, 67], [39, 68], [39, 69], [39, 70], [39, 72], [39, 81], [39, 84], [39, 89], [39, 94], [39, 99], [39, 103], [39, 107], [39, 108], [39, 109], [39, 112], [39, 115], [39, 118], [39, 121], [39, 125], [39, 127], [39, 128], [39, 130], [39, 131], [39, 139], [40, 42], [40, 45], [40, 48], [40, 50], [40, 51], [40, 53], [40, 57], [40, 59], [40, 64], [40, 69], [40, 71], [40, 74], [40, 76], [40, 79], [40, 80], [40, 87], [40, 88], [40, 95], [40, 100], [40, 105], [40, 107], [40, 108], [40, 109], [40, 114], [40, 117], [40, 120], [40, 122], [40, 123], [40, 125], [40, 126], [40, 127], [40, 128], [40, 132], [41, 44], [41, 51], [41, 52], [41, 54], [41, 55], [41, 57], [41, 64], [41, 68], [41, 73], [41, 75], [41, 76], [41, 82], [41, 84], [41, 88], [41, 92], [41, 100], [41, 101], [41, 102], [41, 104], [41, 109], [41, 110], [41, 113], [41, 114], [41, 115], [41, 122], [41, 126], [41, 127], [41, 129], [41, 133], [41, 134], [41, 139], [42, 43], [42, 53], [42, 54], [42, 55], [42, 58], [42, 60], [42, 61], [42, 62], [42, 67], [42, 69], [42, 70], [42, 74], [42, 76], [42, 77], [42, 79], [42, 83], [42, 90], [42, 93], [42, 94], [42, 97], [42, 98], [42, 99], [42, 102], [42, 103], [42, 108], [42, 112], [42, 116], [42, 117], [42, 118], [42, 121], [42, 128], [42, 129], [42, 138], [43, 44], [43, 46], [43, 47], [43, 48], [43, 54], [43, 56], [43, 57], [43, 60], [43, 63], [43, 69], [43, 73], [43, 78], [43, 82], [43, 83], [43, 84], [43, 89], [43, 90], [43, 91], [43, 92], [43, 93], [43, 94], [43, 95], [43, 98], [43, 104], [43, 109], [43, 111], [43, 113], [43, 115], [43, 123], [43, 126], [43, 129], [43, 138], [43, 139], [44, 48], [44, 49], [44, 50], [44, 55], [44, 57], [44, 61], [44, 64], [44, 68], [44, 70], [44, 73], [44, 76], [44, 79], [44, 81], [44, 91], [44, 93], [44, 94], [44, 95], [44, 100], [44, 101], [44, 104], [44, 106], [44, 108], [44, 115], [44, 118], [44, 119], [44, 122], [44, 127], [44, 133], [44, 134], [45, 46], [45, 47], [45, 51], [45, 56], [45, 59], [45, 60], [45, 73], [45, 75], [45, 82], [45, 84], [45, 96], [45, 98], [45, 109], [45, 110], [45, 115], [45, 125], [45, 131], [45, 138], [45, 139], [46, 49], [46, 52], [46, 58], [46, 59], [46, 62], [46, 63], [46, 67], [46, 80], [46, 81], [46, 83], [46, 89], [46, 91], [46, 98], [46, 99], [46, 108], [46, 112], [46, 113], [46, 114], [46, 120], [46, 134], [46, 138], [46, 139], [47, 50], [47, 52], [47, 56], [47, 59], [47, 60], [47, 61], [47, 69], [47, 70], [47, 71], [47, 75], [47, 79], [47, 80], [47, 82], [47, 85], [47, 100], [47, 103], [47, 107], [47, 109], [47, 110], [47, 122], [47, 129], [47, 131], [47, 135], [47, 139], [48, 51], [48, 55], [48, 57], [48, 58], [48, 61], [48, 62], [48, 73], [48, 75], [48, 78], [48, 79], [48, 82], [48, 85], [48, 88], [48, 96], [48, 97], [48, 98], [48, 104], [48, 108], [48, 113], [48, 116], [48, 118], [48, 119], [48, 125], [48, 128], [48, 134], [48, 138], [49, 50], [49, 53], [49, 54], [49, 56], [49, 57], [49, 58], [49, 61], [49, 62], [49, 70], [49, 72], [49, 78], [49, 86], [49, 90], [49, 117], [49, 128], [49, 134], [50, 52], [50, 53], [50, 62], [50, 63], [50, 64], [50, 67], [50, 69], [50, 77], [50, 78], [50, 79], [50, 81], [50, 83], [50, 85], [50, 89], [50, 94], [50, 97], [50, 98], [50, 101], [50, 103], [50, 105], [50, 114], [50, 126], [50, 127], [50, 132], [51, 56], [51, 57], [51, 63], [51, 64], [51, 66], [51, 68], [51, 71], [51, 74], [51, 76], [51, 79], [51, 86], [51, 94], [51, 96], [51, 99], [51, 104], [51, 107], [51, 112], [51, 124], [51, 132], [52, 54], [52, 57], [52, 60], [52, 63], [52, 64], [52, 67], [52, 68], [52, 69], [52, 85], [52, 87], [52, 89], [52, 90], [52, 92], [52, 98], [52, 105], [52, 112], [52, 113], [52, 115], [52, 118], [52, 122], [52, 125], [52, 128], [52, 131], [52, 133], [52, 137], [52, 138], [53, 55], [53, 56], [53, 62], [53, 63], [53, 64], [53, 65], [53, 70], [53, 74], [53, 76], [53, 78], [53, 79], [53, 82], [53, 83], [53, 84], [53, 86], [53, 94], [53, 100], [53, 102], [53, 103], [53, 107], [53, 111], [53, 116], [53, 121], [53, 124], [53, 125], [53, 126], [53, 127], [53, 134], [53, 135], [53, 136], [54, 57], [54, 58], [54, 66], [54, 67], [54, 69], [54, 76], [54, 77], [54, 79], [54, 86], [54, 88], [54, 89], [54, 92], [54, 96], [54, 106], [54, 111], [54, 113], [54, 115], [54, 116], [54, 120], [54, 124], [54, 126], [54, 130], [54, 137], [55, 56], [55, 59], [55, 60], [55, 62], [55, 71], [55, 73], [55, 74], [55, 77], [55, 82], [55, 89], [55, 95], [55, 96], [55, 97], [55, 101], [55, 103], [55, 104], [55, 106], [55, 107], [55, 114], [55, 116], [55, 118], [55, 125], [55, 129], [55, 130], [55, 132], [55, 133], [55, 134], [55, 135], [55, 139], [56, 60], [56, 64], [56, 71], [56, 72], [56, 78], [56, 82], [56, 88], [56, 90], [56, 93], [56, 94], [56, 96], [56, 97], [56, 98], [56, 99], [56, 101], [56, 103], [56, 107], [56, 113], [56, 114], [56, 116], [56, 127], [56, 128], [56, 129], [56, 132], [56, 136], [57, 60], [57, 61], [57, 64], [57, 68], [57, 72], [57, 76], [57, 84], [57, 85], [57, 86], [57, 92], [57, 95], [57, 96], [57, 98], [57, 101], [57, 102], [57, 106], [57, 109], [57, 111], [57, 112], [57, 120], [57, 122], [57, 123], [57, 126], [58, 59], [58, 63], [58, 66], [58, 71], [58, 72], [58, 77], [58, 81], [58, 82], [58, 89], [58, 95], [58, 96], [58, 97], [58, 99], [58, 100], [58, 102], [58, 106], [58, 108], [58, 121], [58, 123], [58, 124], [58, 125], [58, 126], [58, 127], [58, 129], [58, 130], [58, 132], [58, 133], [58, 135], [59, 60], [59, 62], [59, 67], [59, 68], [59, 71], [59, 75], [59, 78], [59, 79], [59, 80], [59, 81], [59, 82], [59, 84], [59, 86], [59, 88], [59, 89], [59, 90], [59, 92], [59, 95], [59, 99], [59, 100], [59, 103], [59, 104], [59, 106], [59, 107], [59, 109], [59, 113], [59, 117], [59, 121], [59, 127], [59, 131], [59, 133], [60, 63], [60, 64], [60, 65], [60, 69], [60, 73], [60, 80], [60, 81], [60, 82], [60, 84], [60, 86], [60, 92], [60, 93], [60, 95], [60, 97], [60, 99], [60, 108], [60, 113], [60, 116], [60, 118], [60, 121], [60, 122], [60, 128], [60, 132], [60, 133], [60, 137], [61, 63], [61, 64], [61, 65], [61, 70], [61, 73], [61, 81], [61, 83], [61, 87], [61, 88], [61, 98], [61, 99], [61, 100], [61, 102], [61, 104], [61, 107], [61, 111], [61, 122], [61, 123], [61, 132], [61, 134], [61, 135], [62, 63], [62, 65], [62, 70], [62, 73], [62, 75], [62, 77], [62, 81], [62, 87], [62, 89], [62, 90], [62, 92], [62, 93], [62, 105], [62, 109], [62, 110], [62, 115], [62, 123], [62, 124], [62, 127], [62, 132], [62, 133], [62, 134], [63, 64], [63, 68], [63, 69], [63, 70], [63, 72], [63, 75], [63, 76], [63, 84], [63, 89], [63, 90], [63, 96], [63, 108], [63, 110], [63, 115], [63, 116], [63, 118], [63, 120], [63, 121], [63, 124], [63, 126], [63, 127], [63, 130], [63, 135], [63, 136], [64, 73], [64, 74], [64, 76], [64, 83], [64, 84], [64, 86], [64, 87], [64, 88], [64, 89], [64, 96], [64, 97], [64, 100], [64, 101], [64, 103], [64, 106], [64, 108], [64, 113], [64, 115], [64, 116], [64, 117], [64, 118], [64, 119], [64, 127], [64, 128], [64, 133], [65, 71], [65, 73], [65, 76], [65, 90], [65, 93], [65, 99], [65, 101], [65, 102], [65, 104], [65, 105], [65, 106], [65, 107], [65, 113], [65, 116], [65, 118], [65, 119], [65, 125], [65, 131], [65, 133], [65, 139], [66, 70], [66, 71], [66, 72], [66, 78], [66, 80], [66, 81], [66, 82], [66, 86], [66, 89], [66, 94], [66, 95], [66, 96], [66, 97], [66, 103], [66, 104], [66, 114], [66, 115], [66, 116], [66, 121], [66, 123], [66, 124], [66, 125], [66, 126], [66, 129], [66, 139], [67, 72], [67, 76], [67, 77], [67, 81], [67, 82], [67, 83], [67, 84], [67, 85], [67, 86], [67, 87], [67, 89], [67, 95], [67, 96], [67, 97], [67, 98], [67, 101], [67, 103], [67, 104], [67, 105], [67, 107], [67, 108], [67, 109], [67, 114], [67, 115], [67, 116], [67, 120], [67, 126], [67, 132], [67, 136], [68, 75], [68, 88], [68, 98], [68, 99], [68, 100], [68, 105], [68, 109], [68, 115], [68, 116], [68, 117], [68, 120], [68, 123], [68, 129], [68, 130], [68, 131], [69, 71], [69, 75], [69, 76], [69, 81], [69, 84], [69, 85], [69, 94], [69, 95], [69, 96], [69, 100], [69, 106], [69, 107], [69, 108], [69, 110], [69, 111], [69, 113], [69, 115], [69, 123], [69, 130], [69, 134], [69, 137], [69, 139], [70, 72], [70, 77], [70, 83], [70, 84], [70, 95], [70, 99], [70, 100], [70, 101], [70, 103], [70, 105], [70, 106], [70, 115], [70, 118], [70, 121], [70, 131], [70, 132], [70, 134], [70, 139], [71, 74], [71, 83], [71, 84], [71, 92], [71, 101], [71, 105], [71, 118], [71, 120], [71, 128], [71, 129], [71, 131], [71, 137], [71, 138], [72, 75], [72, 78], [72, 79], [72, 80], [72, 85], [72, 95], [72, 96], [72, 98], [72, 114], [72, 119], [72, 134], [72, 138], [72, 139], [73, 74], [73, 78], [73, 80], [73, 82], [73, 83], [73, 86], [73, 87], [73, 88], [73, 92], [73, 97], [73, 98], [73, 102], [73, 103], [73, 104], [73, 105], [73, 106], [73, 108], [73, 111], [73, 112], [73, 119], [73, 121], [73, 123], [73, 128], [73, 129], [73, 136], [73, 139], [74, 75], [74, 77], [74, 78], [74, 84], [74, 94], [74, 95], [74, 104], [74, 108], [74, 112], [74, 116], [74, 117], [74, 121], [74, 122], [74, 128], [74, 131], [74, 135], [74, 136], [74, 139], [75, 76], [75, 79], [75, 80], [75, 81], [75, 85], [75, 86], [75, 87], [75, 93], [75, 97], [75, 99], [75, 103], [75, 107], [75, 112], [75, 115], [75, 117], [75, 119], [75, 120], [75, 129], [75, 130], [75, 132], [75, 135], [75, 139], [76, 78], [76, 79], [76, 81], [76, 85], [76, 89], [76, 92], [76, 94], [76, 95], [76, 96], [76, 99], [76, 105], [76, 107], [76, 109], [76, 110], [76, 111], [76, 114], [76, 117], [76, 129], [76, 136], [76, 138], [76, 139], [77, 84], [77, 86], [77, 89], [77, 90], [77, 92], [77, 95], [77, 97], [77, 99], [77, 108], [77, 109], [77, 112], [77, 113], [77, 115], [77, 116], [77, 119], [77, 120], [77, 122], [77, 123], [77, 128], [77, 129], [78, 79], [78, 80], [78, 83], [78, 84], [78, 87], [78, 89], [78, 95], [78, 100], [78, 101], [78, 106], [78, 109], [78, 115], [78, 116], [78, 117], [78, 123], [78, 126], [78, 130], [78, 132], [78, 133], [78, 138], [79, 80], [79, 83], [79, 84], [79, 86], [79, 87], [79, 89], [79, 90], [79, 91], [79, 97], [79, 101], [79, 105], [79, 113], [79, 115], [79, 116], [79, 120], [79, 122], [79, 124], [79, 127], [79, 128], [79, 135], [79, 136], [79, 137], [80, 87], [80, 90], [80, 92], [80, 94], [80, 95], [80, 98], [80, 102], [80, 104], [80, 111], [80, 115], [80, 116], [80, 128], [80, 129], [80, 139], [81, 83], [81, 88], [81, 90], [81, 91], [81, 92], [81, 94], [81, 99], [81, 100], [81, 103], [81, 105], [81, 107], [81, 109], [81, 116], [81, 121], [81, 122], [81, 125], [81, 131], [81, 134], [81, 135], [81, 137], [81, 139], [82, 83], [82, 84], [82, 86], [82, 87], [82, 90], [82, 92], [82, 93], [82, 94], [82, 106], [82, 109], [82, 117], [82, 119], [82, 124], [82, 126], [82, 128], [82, 130], [82, 134], [82, 137], [83, 84], [83, 86], [83, 90], [83, 92], [83, 94], [83, 99], [83, 100], [83, 104], [83, 106], [83, 107], [83, 109], [83, 110], [83, 114], [83, 121], [83, 122], [83, 123], [83, 127], [83, 130], [83, 133], [83, 138], [83, 139], [84, 92], [84, 98], [84, 99], [84, 101], [84, 106], [84, 109], [84, 113], [84, 114], [84, 116], [84, 117], [84, 121], [84, 124], [84, 131], [84, 132], [84, 137], [85, 87], [85, 92], [85, 95], [85, 103], [85, 108], [85, 109], [85, 111], [85, 119], [85, 123], [85, 126], [85, 129], [85, 132], [85, 137], [86, 88], [86, 89], [86, 90], [86, 91], [86, 92], [86, 93], [86, 95], [86, 98], [86, 101], [86, 103], [86, 106], [86, 108], [86, 109], [86, 111], [86, 114], [86, 115], [86, 119], [86, 123], [86, 124], [86, 128], [86, 129], [86, 130], [86, 131], [86, 135], [86, 138], [87, 89], [87, 97], [87, 101], [87, 113], [87, 117], [87, 118], [87, 119], [87, 127], [87, 129], [87, 133], [87, 134], [87, 139], [88, 98], [88, 100], [88, 103], [88, 106], [88, 107], [88, 110], [88, 116], [88, 118], [88, 119], [88, 120], [88, 121], [88, 123], [88, 127], [88, 128], [88, 133], [88, 135], [88, 138], [89, 91], [89, 93], [89, 103], [89, 104], [89, 106], [89, 107], [89, 110], [89, 113], [89, 116], [89, 119], [89, 124], [89, 126], [89, 127], [89, 132], [90, 93], [90, 95], [90, 96], [90, 98], [90, 100], [90, 101], [90, 104], [90, 106], [90, 109], [90, 118], [90, 119], [90, 120], [90, 122], [90, 134], [90, 136], [91, 95], [91, 99], [91, 103], [91, 114], [91, 117], [91, 118], [91, 119], [91, 120], [91, 122], [91, 128], [91, 131], [91, 132], [91, 136], [91, 139], [92, 94], [92, 97], [92, 103], [92, 105], [92, 108], [92, 109], [92, 110], [92, 111], [92, 116], [92, 119], [92, 120], [92, 121], [92, 122], [92, 129], [92, 131], [92, 132], [92, 136], [92, 139], [93, 97], [93, 100], [93, 110], [93, 112], [93, 115], [93, 116], [93, 131], [93, 136], [93, 139], [94, 96], [94, 98], [94, 101], [94, 104], [94, 106], [94, 107], [94, 110], [94, 115], [94, 116], [94, 119], [94, 122], [94, 123], [94, 125], [94, 126], [94, 128], [94, 129], [94, 132], [94, 133], [94, 136], [94, 137], [94, 139], [95, 97], [95, 99], [95, 100], [95, 101], [95, 106], [95, 112], [95, 115], [95, 119], [95, 122], [95, 123], [95, 124], [95, 131], [95, 134], [95, 135], [96, 103], [96, 104], [96, 110], [96, 114], [96, 119], [96, 124], [96, 125], [96, 128], [96, 133], [96, 138], [97, 98], [97, 101], [97, 103], [97, 115], [97, 118], [97, 123], [97, 130], [97, 135], [98, 99], [98, 102], [98, 104], [98, 111], [98, 112], [98, 120], [98, 123], [98, 125], [98, 128], [98, 133], [99, 109], [99, 111], [99, 113], [99, 115], [99, 121], [99, 123], [99, 124], [99, 125], [99, 137], [100, 104], [100, 107], [100, 109], [100, 112], [100, 115], [100, 120], [100, 127], [100, 130], [100, 133], [100, 134], [100, 135], [100, 137], [100, 139], [101, 104], [101, 107], [101, 109], [101, 110], [101, 117], [101, 120], [101, 123], [101, 125], [101, 131], [101, 132], [101, 134], [101, 139], [102, 103], [102, 104], [102, 105], [102, 109], [102, 110], [102, 111], [102, 113], [102, 118], [102, 123], [102, 124], [102, 126], [102, 128], [102, 130], [102, 131], [102, 132], [102, 133], [102, 135], [103, 107], [103, 108], [103, 109], [103, 112], [103, 113], [103, 117], [103, 124], [103, 129], [103, 133], [103, 136], [103, 138], [103, 139], [104, 112], [104, 116], [104, 117], [104, 120], [104, 122], [104, 125], [104, 127], [104, 130], [105, 106], [105, 107], [105, 108], [105, 118], [105, 125], [105, 128], [105, 130], [105, 131], [105, 132], [105, 137], [105, 139], [106, 107], [106, 113], [106, 121], [106, 125], [106, 127], [106, 128], [106, 134], [106, 136], [107, 110], [107, 112], [107, 139], [108, 112], [108, 114], [108, 117], [108, 118], [108, 119], [108, 127], [108, 129], [108, 132], [108, 133], [108, 137], [109, 111], [109, 112], [109, 117], [109, 120], [109, 121], [109, 125], [109, 126], [109, 136], [110, 118], [110, 126], [110, 127], [110, 135], [110, 138], [111, 116], [111, 119], [111, 122], [111, 126], [111, 128], [111, 136], [112, 115], [112, 123], [112, 125], [112, 132], [112, 137], [112, 139], [113, 118], [113, 120], [113, 121], [113, 126], [114, 116], [114, 118], [114, 125], [114, 126], [114, 128], [114, 129], [114, 134], [114, 135], [114, 137], [115, 116], [115, 122], [115, 124], [115, 133], [115, 134], [115, 139], [116, 117], [116, 119], [116, 121], [116, 124], [116, 125], [116, 133], [116, 136], [116, 137], [117, 120], [117, 126], [117, 132], [117, 139], [118, 119], [118, 120], [118, 125], [118, 126], [118, 129], [118, 132], [118, 134], [118, 135], [118, 136], [118, 137], [119, 121], [119, 123], [119, 126], [119, 131], [119, 134], [119, 138], [120, 121], [120, 122], [120, 124], [120, 125], [120, 129], [120, 131], [120, 139], [121, 123], [121, 126], [121, 128], [121, 130], [121, 135], [121, 139], [122, 126], [122, 129], [122, 130], [122, 133], [122, 137], [123, 124], [123, 129], [123, 135], [123, 138], [123, 139], [124, 125], [124, 128], [124, 133], [124, 134], [124, 135], [125, 128], [125, 129], [125, 130], [126, 128], [126, 132], [126, 136], [127, 132], [127, 135], [128, 129], [128, 138], [128, 139], [129, 136], [129, 137], [129, 138], [130, 131], [130, 132], [131, 137], [131, 138], [131, 139], [132, 133], [132, 136], [132, 139], [133, 135], [134, 138], [136, 138]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s8/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a7f91e5303f2eb1ba2ce1ba3c9926bb5a0251527 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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": [12, 20, 30, 32, 36, 45, 68, 70, 71, 80, 85, 97, 112, 114, 122, 124, 127, 136]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s8/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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-l6-s8/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..81e72424217084e402029cbb60308bd4d0ac9a24 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 1], [0, 3], [0, 4], [0, 6], [0, 8], [0, 14], [0, 15], [0, 18], [0, 19], [0, 21], [0, 24], [0, 25], [0, 30], [0, 31], [0, 41], [0, 44], [0, 45], [0, 53], [0, 55], [0, 58], [0, 67], [0, 68], [0, 71], [0, 80], [0, 81], [0, 83], [0, 84], [0, 86], [0, 103], [0, 104], [0, 106], [0, 110], [0, 112], [0, 113], [0, 116], [0, 119], [0, 124], [0, 129], [0, 132], [1, 3], [1, 10], [1, 13], [1, 15], [1, 17], [1, 18], [1, 20], [1, 24], [1, 27], [1, 38], [1, 40], [1, 43], [1, 51], [1, 52], [1, 56], [1, 60], [1, 61], [1, 62], [1, 64], [1, 68], [1, 70], [1, 77], [1, 79], [1, 82], [1, 83], [1, 84], [1, 87], [1, 89], [1, 92], [1, 95], [1, 97], [1, 102], [1, 103], [1, 113], [1, 114], [1, 118], [1, 121], [1, 124], [1, 125], [1, 137], [1, 139], [2, 7], [2, 9], [2, 10], [2, 19], [2, 20], [2, 22], [2, 31], [2, 34], [2, 35], [2, 38], [2, 39], [2, 41], [2, 43], [2, 46], [2, 50], [2, 59], [2, 61], [2, 62], [2, 63], [2, 66], [2, 71], [2, 72], [2, 73], [2, 74], [2, 76], [2, 79], [2, 80], [2, 81], [2, 82], [2, 84], [2, 87], [2, 89], [2, 93], [2, 95], [2, 98], [2, 107], [2, 112], [2, 114], [2, 116], [2, 117], [2, 121], [2, 125], [2, 128], [2, 130], [2, 138], [3, 5], [3, 6], [3, 12], [3, 16], [3, 18], [3, 21], [3, 22], [3, 28], [3, 34], [3, 35], [3, 37], [3, 40], [3, 41], [3, 42], [3, 55], [3, 57], [3, 61], [3, 64], [3, 67], [3, 74], [3, 80], [3, 85], [3, 88], [3, 90], [3, 91], [3, 92], [3, 93], [3, 96], [3, 99], [3, 100], [3, 105], [3, 112], [3, 117], [3, 118], [3, 121], [3, 123], [3, 124], [3, 129], [3, 131], [3, 133], [3, 135], [3, 136], [4, 5], [4, 8], [4, 9], [4, 17], [4, 18], [4, 23], [4, 26], [4, 29], [4, 33], [4, 34], [4, 37], [4, 39], [4, 47], [4, 49], [4, 53], [4, 62], [4, 69], [4, 76], [4, 79], [4, 86], [4, 87], [4, 88], [4, 89], [4, 92], [4, 97], [4, 99], [4, 103], [4, 106], [4, 107], [4, 112], [4, 113], [4, 115], [4, 117], [4, 118], [4, 121], [4, 124], [4, 125], [4, 126], [4, 129], [4, 131], [4, 136], [4, 137], [4, 138], [5, 7], [5, 11], [5, 14], [5, 15], [5, 21], [5, 22], [5, 23], [5, 25], [5, 26], [5, 29], [5, 35], [5, 38], [5, 40], [5, 41], [5, 42], [5, 44], [5, 47], [5, 56], [5, 59], [5, 69], [5, 72], [5, 73], [5, 76], [5, 83], [5, 89], [5, 91], [5, 93], [5, 97], [5, 102], [5, 103], [5, 104], [5, 106], [5, 107], [5, 109], [5, 115], [5, 116], [5, 117], [5, 118], [5, 119], [5, 120], [5, 123], [5, 124], [5, 127], [5, 130], [5, 131], [5, 132], [5, 133], [5, 136], [5, 137], [6, 7], [6, 10], [6, 11], [6, 14], [6, 18], [6, 21], [6, 25], [6, 27], [6, 29], [6, 31], [6, 32], [6, 34], [6, 38], [6, 41], [6, 49], [6, 50], [6, 53], [6, 54], [6, 56], [6, 58], [6, 59], [6, 61], [6, 64], [6, 67], [6, 70], [6, 71], [6, 73], [6, 75], [6, 76], [6, 77], [6, 82], [6, 86], [6, 88], [6, 90], [6, 97], [6, 98], [6, 101], [6, 103], [6, 104], [6, 109], [6, 116], [6, 118], [6, 122], [6, 124], [6, 126], [6, 132], [6, 137], [6, 138], [7, 10], [7, 11], [7, 16], [7, 25], [7, 26], [7, 36], [7, 44], [7, 47], [7, 50], [7, 51], [7, 52], [7, 61], [7, 70], [7, 72], [7, 75], [7, 77], [7, 78], [7, 79], [7, 82], [7, 84], [7, 89], [7, 90], [7, 91], [7, 105], [7, 106], [7, 114], [7, 118], [7, 119], [7, 122], [7, 125], [8, 9], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 19], [8, 20], [8, 24], [8, 26], [8, 27], [8, 34], [8, 35], [8, 41], [8, 42], [8, 46], [8, 47], [8, 49], [8, 53], [8, 56], [8, 63], [8, 64], [8, 68], [8, 71], [8, 73], [8, 77], [8, 80], [8, 93], [8, 97], [8, 98], [8, 102], [8, 104], [8, 107], [8, 109], [8, 111], [8, 118], [8, 119], [8, 122], [8, 123], [8, 125], [8, 126], [8, 128], [8, 136], [9, 10], [9, 12], [9, 23], [9, 25], [9, 29], [9, 31], [9, 34], [9, 37], [9, 41], [9, 47], [9, 49], [9, 51], [9, 54], [9, 60], [9, 64], [9, 66], [9, 68], [9, 76], [9, 81], [9, 83], [9, 84], [9, 87], [9, 92], [9, 93], [9, 95], [9, 98], [9, 100], [9, 103], [9, 105], [9, 110], [9, 111], [9, 113], [9, 114], [9, 119], [9, 124], [9, 136], [10, 13], [10, 16], [10, 20], [10, 26], [10, 27], [10, 40], [10, 42], [10, 43], [10, 48], [10, 52], [10, 56], [10, 63], [10, 67], [10, 68], [10, 72], [10, 73], [10, 75], [10, 77], [10, 79], [10, 81], [10, 85], [10, 86], [10, 87], [10, 99], [10, 102], [10, 107], [10, 108], [10, 115], [10, 120], [10, 121], [10, 126], [10, 128], [10, 131], [10, 132], [11, 12], [11, 18], [11, 20], [11, 21], [11, 23], [11, 28], [11, 29], [11, 32], [11, 37], [11, 39], [11, 41], [11, 42], [11, 46], [11, 47], [11, 51], [11, 55], [11, 56], [11, 61], [11, 66], [11, 68], [11, 69], [11, 72], [11, 73], [11, 79], [11, 86], [11, 90], [11, 95], [11, 97], [11, 98], [11, 101], [11, 103], [11, 108], [11, 113], [11, 114], [11, 115], [11, 117], [11, 123], [11, 128], [11, 134], [11, 136], [11, 139], [12, 24], [12, 25], [12, 28], [12, 33], [12, 34], [12, 38], [12, 39], [12, 40], [12, 51], [12, 52], [12, 55], [12, 57], [12, 59], [12, 61], [12, 62], [12, 63], [12, 67], [12, 76], [12, 77], [12, 78], [12, 79], [12, 82], [12, 83], [12, 87], [12, 89], [12, 90], [12, 92], [12, 99], [12, 102], [12, 103], [12, 105], [12, 108], [12, 111], [12, 119], [12, 123], [12, 129], [12, 134], [12, 135], [12, 137], [13, 16], [13, 21], [13, 26], [13, 30], [13, 31], [13, 33], [13, 51], [13, 53], [13, 54], [13, 56], [13, 57], [13, 59], [13, 62], [13, 63], [13, 67], [13, 70], [13, 71], [13, 74], [13, 78], [13, 80], [13, 81], [13, 84], [13, 86], [13, 88], [13, 103], [13, 109], [13, 113], [13, 116], [13, 117], [13, 121], [13, 122], [13, 124], [13, 127], [13, 130], [13, 133], [14, 17], [14, 22], [14, 24], [14, 26], [14, 31], [14, 32], [14, 33], [14, 35], [14, 38], [14, 44], [14, 48], [14, 49], [14, 50], [14, 57], [14, 64], [14, 66], [14, 68], [14, 77], [14, 79], [14, 83], [14, 84], [14, 86], [14, 88], [14, 91], [14, 95], [14, 100], [14, 108], [14, 109], [14, 111], [14, 112], [14, 116], [14, 117], [14, 119], [14, 124], [14, 125], [14, 129], [14, 130], [14, 132], [14, 135], [14, 136], [14, 139], [15, 16], [15, 17], [15, 19], [15, 20], [15, 23], [15, 25], [15, 30], [15, 37], [15, 39], [15, 45], [15, 49], [15, 57], [15, 63], [15, 65], [15, 66], [15, 69], [15, 70], [15, 79], [15, 81], [15, 86], [15, 90], [15, 98], [15, 99], [15, 100], [15, 104], [15, 106], [15, 107], [15, 111], [15, 112], [15, 116], [15, 119], [15, 121], [15, 122], [15, 126], [15, 127], [15, 130], [15, 131], [15, 137], [15, 139], [16, 24], [16, 26], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 37], [16, 40], [16, 46], [16, 49], [16, 52], [16, 55], [16, 56], [16, 60], [16, 61], [16, 62], [16, 64], [16, 72], [16, 77], [16, 79], [16, 83], [16, 87], [16, 89], [16, 94], [16, 95], [16, 97], [16, 101], [16, 102], [16, 113], [16, 115], [16, 117], [16, 121], [16, 122], [16, 129], [16, 130], [16, 131], [16, 134], [16, 137], [17, 21], [17, 23], [17, 41], [17, 44], [17, 49], [17, 52], [17, 54], [17, 55], [17, 58], [17, 63], [17, 72], [17, 74], [17, 75], [17, 76], [17, 77], [17, 79], [17, 84], [17, 89], [17, 92], [17, 93], [17, 95], [17, 97], [17, 98], [17, 105], [17, 111], [17, 113], [17, 117], [17, 119], [17, 122], [17, 125], [17, 127], [17, 128], [17, 132], [17, 135], [18, 21], [18, 25], [18, 32], [18, 35], [18, 37], [18, 40], [18, 44], [18, 45], [18, 49], [18, 52], [18, 56], [18, 57], [18, 60], [18, 63], [18, 74], [18, 77], [18, 78], [18, 82], [18, 85], [18, 87], [18, 96], [18, 99], [18, 104], [18, 109], [18, 111], [18, 113], [18, 127], [18, 130], [19, 23], [19, 24], [19, 25], [19, 26], [19, 40], [19, 41], [19, 45], [19, 48], [19, 52], [19, 55], [19, 57], [19, 59], [19, 60], [19, 63], [19, 65], [19, 68], [19, 69], [19, 70], [19, 71], [19, 78], [19, 79], [19, 84], [19, 85], [19, 87], [19, 88], [19, 89], [19, 92], [19, 93], [19, 95], [19, 103], [19, 107], [19, 108], [19, 110], [19, 115], [19, 117], [19, 118], [19, 129], [19, 132], [19, 134], [19, 136], [19, 137], [20, 22], [20, 23], [20, 33], [20, 39], [20, 40], [20, 42], [20, 44], [20, 48], [20, 49], [20, 61], [20, 63], [20, 64], [20, 69], [20, 73], [20, 79], [20, 91], [20, 94], [20, 96], [20, 101], [20, 104], [20, 111], [20, 117], [20, 125], [20, 129], [20, 131], [20, 132], [20, 133], [20, 139], [21, 22], [21, 23], [21, 25], [21, 26], [21, 31], [21, 43], [21, 44], [21, 45], [21, 47], [21, 52], [21, 58], [21, 67], [21, 71], [21, 73], [21, 76], [21, 78], [21, 81], [21, 83], [21, 86], [21, 87], [21, 95], [21, 96], [21, 98], [21, 99], [21, 102], [21, 112], [21, 116], [21, 123], [21, 126], [21, 129], [21, 136], [21, 137], [22, 25], [22, 27], [22, 28], [22, 29], [22, 31], [22, 49], [22, 51], [22, 53], [22, 55], [22, 56], [22, 65], [22, 67], [22, 68], [22, 74], [22, 75], [22, 78], [22, 80], [22, 85], [22, 87], [22, 98], [22, 100], [22, 101], [22, 121], [22, 131], [22, 134], [22, 136], [22, 139], [23, 28], [23, 30], [23, 31], [23, 35], [23, 36], [23, 42], [23, 48], [23, 49], [23, 54], [23, 56], [23, 57], [23, 64], [23, 67], [23, 73], [23, 82], [23, 83], [23, 84], [23, 85], [23, 89], [23, 92], [23, 94], [23, 102], [23, 106], [23, 109], [23, 110], [23, 113], [23, 114], [23, 117], [23, 119], [23, 121], [23, 123], [23, 126], [23, 133], [23, 134], [23, 135], [23, 137], [23, 139], [24, 26], [24, 27], [24, 29], [24, 32], [24, 42], [24, 43], [24, 44], [24, 45], [24, 47], [24, 50], [24, 52], [24, 56], [24, 58], [24, 62], [24, 64], [24, 70], [24, 76], [24, 77], [24, 78], [24, 82], [24, 86], [24, 89], [24, 91], [24, 92], [24, 102], [24, 103], [24, 104], [24, 106], [24, 111], [24, 116], [24, 118], [24, 120], [24, 123], [24, 124], [24, 127], [24, 128], [24, 130], [24, 134], [25, 28], [25, 30], [25, 31], [25, 34], [25, 36], [25, 41], [25, 43], [25, 48], [25, 51], [25, 52], [25, 54], [25, 57], [25, 60], [25, 63], [25, 66], [25, 74], [25, 76], [25, 78], [25, 79], [25, 90], [25, 92], [25, 98], [25, 100], [25, 105], [25, 111], [25, 113], [25, 117], [25, 118], [25, 121], [25, 124], [25, 125], [25, 126], [25, 127], [25, 129], [25, 130], [25, 131], [25, 136], [25, 137], [26, 28], [26, 32], [26, 34], [26, 35], [26, 39], [26, 44], [26, 48], [26, 56], [26, 58], [26, 61], [26, 63], [26, 66], [26, 69], [26, 72], [26, 75], [26, 77], [26, 80], [26, 81], [26, 82], [26, 83], [26, 88], [26, 92], [26, 93], [26, 97], [26, 103], [26, 106], [26, 110], [26, 111], [26, 113], [26, 119], [26, 121], [26, 125], [26, 126], [26, 127], [26, 128], [26, 130], [26, 132], [26, 135], [26, 136], [26, 137], [26, 138], [27, 28], [27, 30], [27, 32], [27, 35], [27, 37], [27, 46], [27, 49], [27, 51], [27, 54], [27, 57], [27, 62], [27, 63], [27, 64], [27, 66], [27, 67], [27, 69], [27, 70], [27, 71], [27, 77], [27, 84], [27, 86], [27, 88], [27, 90], [27, 92], [27, 95], [27, 100], [27, 101], [27, 103], [27, 105], [27, 106], [27, 108], [27, 112], [27, 114], [27, 118], [27, 119], [27, 122], [27, 124], [27, 126], [27, 127], [28, 30], [28, 39], [28, 43], [28, 44], [28, 46], [28, 51], [28, 54], [28, 61], [28, 62], [28, 63], [28, 66], [28, 67], [28, 69], [28, 72], [28, 76], [28, 80], [28, 81], [28, 85], [28, 88], [28, 89], [28, 90], [28, 91], [28, 94], [28, 106], [28, 107], [28, 111], [28, 115], [28, 117], [28, 119], [28, 122], [28, 123], [28, 127], [28, 132], [28, 139], [29, 30], [29, 33], [29, 35], [29, 38], [29, 39], [29, 42], [29, 43], [29, 45], [29, 50], [29, 51], [29, 52], [29, 53], [29, 57], [29, 63], [29, 65], [29, 68], [29, 70], [29, 72], [29, 75], [29, 85], [29, 88], [29, 91], [29, 95], [29, 98], [29, 99], [29, 101], [29, 106], [29, 108], [29, 111], [29, 121], [29, 123], [29, 131], [29, 132], [29, 134], [29, 139], [30, 34], [30, 40], [30, 48], [30, 50], [30, 55], [30, 56], [30, 57], [30, 74], [30, 79], [30, 83], [30, 88], [30, 89], [30, 90], [30, 94], [30, 99], [30, 103], [30, 110], [30, 113], [30, 117], [30, 119], [30, 121], [30, 130], [30, 137], [31, 34], [31, 38], [31, 41], [31, 45], [31, 52], [31, 55], [31, 58], [31, 59], [31, 63], [31, 64], [31, 65], [31, 66], [31, 67], [31, 73], [31, 76], [31, 78], [31, 80], [31, 82], [31, 84], [31, 89], [31, 90], [31, 99], [31, 102], [31, 108], [31, 110], [31, 120], [31, 121], [31, 138], [32, 37], [32, 40], [32, 41], [32, 42], [32, 43], [32, 44], [32, 56], [32, 62], [32, 63], [32, 64], [32, 65], [32, 72], [32, 79], [32, 82], [32, 88], [32, 93], [32, 98], [32, 99], [32, 104], [32, 105], [32, 106], [32, 108], [32, 110], [32, 111], [32, 121], [32, 123], [32, 130], [32, 135], [33, 36], [33, 38], [33, 42], [33, 43], [33, 46], [33, 49], [33, 53], [33, 56], [33, 59], [33, 61], [33, 68], [33, 70], [33, 71], [33, 82], [33, 84], [33, 94], [33, 95], [33, 97], [33, 107], [33, 108], [33, 112], [33, 113], [33, 116], [33, 119], [33, 122], [33, 123], [33, 124], [33, 125], [33, 128], [33, 129], [33, 139], [34, 36], [34, 37], [34, 39], [34, 40], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 51], [34, 55], [34, 61], [34, 63], [34, 64], [34, 66], [34, 76], [34, 84], [34, 86], [34, 88], [34, 89], [34, 95], [34, 96], [34, 97], [34, 104], [34, 106], [34, 110], [34, 111], [34, 114], [34, 116], [34, 117], [34, 120], [34, 122], [34, 123], [34, 125], [34, 129], [34, 132], [34, 133], [34, 134], [34, 135], [34, 136], [34, 138], [35, 42], [35, 43], [35, 46], [35, 48], [35, 51], [35, 53], [35, 57], [35, 58], [35, 62], [35, 65], [35, 66], [35, 67], [35, 69], [35, 71], [35, 74], [35, 76], [35, 79], [35, 80], [35, 85], [35, 94], [35, 97], [35, 101], [35, 103], [35, 105], [35, 106], [35, 109], [35, 110], [35, 111], [35, 116], [35, 118], [35, 122], [35, 124], [35, 133], [35, 134], [35, 137], [35, 138], [36, 37], [36, 41], [36, 50], [36, 54], [36, 76], [36, 77], [36, 78], [36, 83], [36, 86], [36, 92], [36, 94], [36, 96], [36, 98], [36, 101], [36, 102], [36, 104], [36, 105], [36, 109], [36, 115], [36, 116], [36, 120], [36, 121], [36, 126], [36, 135], [36, 138], [36, 139], [37, 41], [37, 42], [37, 43], [37, 45], [37, 48], [37, 50], [37, 54], [37, 57], [37, 58], [37, 60], [37, 61], [37, 62], [37, 65], [37, 80], [37, 84], [37, 85], [37, 91], [37, 101], [37, 102], [37, 103], [37, 104], [37, 118], [37, 122], [37, 130], [38, 39], [38, 41], [38, 46], [38, 47], [38, 50], [38, 53], [38, 62], [38, 68], [38, 70], [38, 75], [38, 78], [38, 83], [38, 85], [38, 86], [38, 91], [38, 95], [38, 103], [38, 104], [38, 105], [38, 106], [38, 107], [38, 109], [38, 111], [38, 113], [38, 117], [38, 120], [38, 123], [38, 124], [38, 128], [38, 129], [38, 130], [38, 135], [38, 137], [39, 40], [39, 41], [39, 43], [39, 44], [39, 46], [39, 53], [39, 59], [39, 66], [39, 67], [39, 68], [39, 69], [39, 70], [39, 72], [39, 81], [39, 84], [39, 89], [39, 94], [39, 99], [39, 103], [39, 107], [39, 108], [39, 109], [39, 112], [39, 115], [39, 118], [39, 121], [39, 125], [39, 127], [39, 128], [39, 130], [39, 131], [39, 139], [40, 42], [40, 45], [40, 48], [40, 50], [40, 51], [40, 53], [40, 57], [40, 59], [40, 64], [40, 69], [40, 71], [40, 74], [40, 76], [40, 79], [40, 80], [40, 87], [40, 88], [40, 95], [40, 100], [40, 105], [40, 107], [40, 108], [40, 109], [40, 114], [40, 117], [40, 120], [40, 122], [40, 123], [40, 125], [40, 126], [40, 127], [40, 128], [40, 132], [41, 44], [41, 51], [41, 52], [41, 54], [41, 55], [41, 57], [41, 64], [41, 68], [41, 73], [41, 75], [41, 76], [41, 82], [41, 84], [41, 88], [41, 92], [41, 100], [41, 101], [41, 102], [41, 104], [41, 109], [41, 110], [41, 113], [41, 114], [41, 115], [41, 122], [41, 126], [41, 127], [41, 129], [41, 133], [41, 134], [41, 139], [42, 43], [42, 53], [42, 54], [42, 55], [42, 58], [42, 60], [42, 61], [42, 62], [42, 67], [42, 69], [42, 70], [42, 74], [42, 76], [42, 77], [42, 79], [42, 83], [42, 90], [42, 93], [42, 94], [42, 97], [42, 98], [42, 99], [42, 102], [42, 103], [42, 108], [42, 112], [42, 116], [42, 117], [42, 118], [42, 121], [42, 128], [42, 129], [42, 138], [43, 44], [43, 46], [43, 47], [43, 48], [43, 54], [43, 56], [43, 57], [43, 60], [43, 63], [43, 69], [43, 73], [43, 78], [43, 82], [43, 83], [43, 84], [43, 89], [43, 90], [43, 91], [43, 92], [43, 93], [43, 94], [43, 95], [43, 98], [43, 104], [43, 109], [43, 111], [43, 113], [43, 115], [43, 123], [43, 126], [43, 129], [43, 138], [43, 139], [44, 48], [44, 49], [44, 50], [44, 55], [44, 57], [44, 61], [44, 64], [44, 68], [44, 70], [44, 73], [44, 76], [44, 79], [44, 81], [44, 91], [44, 93], [44, 94], [44, 95], [44, 100], [44, 101], [44, 104], [44, 106], [44, 108], [44, 115], [44, 118], [44, 119], [44, 122], [44, 127], [44, 133], [44, 134], [45, 46], [45, 47], [45, 51], [45, 56], [45, 59], [45, 60], [45, 73], [45, 75], [45, 82], [45, 84], [45, 96], [45, 98], [45, 109], [45, 110], [45, 115], [45, 125], [45, 131], [45, 138], [45, 139], [46, 49], [46, 52], [46, 58], [46, 59], [46, 62], [46, 63], [46, 67], [46, 80], [46, 81], [46, 83], [46, 89], [46, 91], [46, 98], [46, 99], [46, 108], [46, 112], [46, 113], [46, 114], [46, 120], [46, 134], [46, 138], [46, 139], [47, 50], [47, 52], [47, 56], [47, 59], [47, 60], [47, 61], [47, 69], [47, 70], [47, 71], [47, 75], [47, 79], [47, 80], [47, 82], [47, 85], [47, 100], [47, 103], [47, 107], [47, 109], [47, 110], [47, 122], [47, 129], [47, 131], [47, 135], [47, 139], [48, 51], [48, 55], [48, 57], [48, 58], [48, 61], [48, 62], [48, 73], [48, 75], [48, 78], [48, 79], [48, 82], [48, 85], [48, 88], [48, 96], [48, 97], [48, 98], [48, 104], [48, 108], [48, 113], [48, 116], [48, 118], [48, 119], [48, 125], [48, 128], [48, 134], [48, 138], [49, 50], [49, 53], [49, 54], [49, 56], [49, 57], [49, 58], [49, 61], [49, 62], [49, 70], [49, 72], [49, 78], [49, 86], [49, 90], [49, 117], [49, 128], [49, 134], [50, 52], [50, 53], [50, 62], [50, 63], [50, 64], [50, 67], [50, 69], [50, 77], [50, 78], [50, 79], [50, 81], [50, 83], [50, 85], [50, 89], [50, 94], [50, 97], [50, 98], [50, 101], [50, 103], [50, 105], [50, 114], [50, 126], [50, 127], [50, 132], [51, 56], [51, 57], [51, 63], [51, 64], [51, 66], [51, 68], [51, 71], [51, 74], [51, 76], [51, 79], [51, 86], [51, 94], [51, 96], [51, 99], [51, 104], [51, 107], [51, 112], [51, 124], [51, 132], [52, 54], [52, 57], [52, 60], [52, 63], [52, 64], [52, 67], [52, 68], [52, 69], [52, 85], [52, 87], [52, 89], [52, 90], [52, 92], [52, 98], [52, 105], [52, 112], [52, 113], [52, 115], [52, 118], [52, 122], [52, 125], [52, 128], [52, 131], [52, 133], [52, 137], [52, 138], [53, 55], [53, 56], [53, 62], [53, 63], [53, 64], [53, 65], [53, 70], [53, 74], [53, 76], [53, 78], [53, 79], [53, 82], [53, 83], [53, 84], [53, 86], [53, 94], [53, 100], [53, 102], [53, 103], [53, 107], [53, 111], [53, 116], [53, 121], [53, 124], [53, 125], [53, 126], [53, 127], [53, 134], [53, 135], [53, 136], [54, 57], [54, 58], [54, 66], [54, 67], [54, 69], [54, 76], [54, 77], [54, 79], [54, 86], [54, 88], [54, 89], [54, 92], [54, 96], [54, 106], [54, 111], [54, 113], [54, 115], [54, 116], [54, 120], [54, 124], [54, 126], [54, 130], [54, 137], [55, 56], [55, 59], [55, 60], [55, 62], [55, 71], [55, 73], [55, 74], [55, 77], [55, 82], [55, 89], [55, 95], [55, 96], [55, 97], [55, 101], [55, 103], [55, 104], [55, 106], [55, 107], [55, 114], [55, 116], [55, 118], [55, 125], [55, 129], [55, 130], [55, 132], [55, 133], [55, 134], [55, 135], [55, 139], [56, 60], [56, 64], [56, 71], [56, 72], [56, 78], [56, 82], [56, 88], [56, 90], [56, 93], [56, 94], [56, 96], [56, 97], [56, 98], [56, 99], [56, 101], [56, 103], [56, 107], [56, 113], [56, 114], [56, 116], [56, 127], [56, 128], [56, 129], [56, 132], [56, 136], [57, 60], [57, 61], [57, 64], [57, 68], [57, 72], [57, 76], [57, 84], [57, 85], [57, 86], [57, 92], [57, 95], [57, 96], [57, 98], [57, 101], [57, 102], [57, 106], [57, 109], [57, 111], [57, 112], [57, 120], [57, 122], [57, 123], [57, 126], [58, 59], [58, 63], [58, 66], [58, 71], [58, 72], [58, 77], [58, 81], [58, 82], [58, 89], [58, 95], [58, 96], [58, 97], [58, 99], [58, 100], [58, 102], [58, 106], [58, 108], [58, 121], [58, 123], [58, 124], [58, 125], [58, 126], [58, 127], [58, 129], [58, 130], [58, 132], [58, 133], [58, 135], [59, 60], [59, 62], [59, 67], [59, 68], [59, 71], [59, 75], [59, 78], [59, 79], [59, 80], [59, 81], [59, 82], [59, 84], [59, 86], [59, 88], [59, 89], [59, 90], [59, 92], [59, 95], [59, 99], [59, 100], [59, 103], [59, 104], [59, 106], [59, 107], [59, 109], [59, 113], [59, 117], [59, 121], [59, 127], [59, 131], [59, 133], [60, 63], [60, 64], [60, 65], [60, 69], [60, 73], [60, 80], [60, 81], [60, 82], [60, 84], [60, 86], [60, 92], [60, 93], [60, 95], [60, 97], [60, 99], [60, 108], [60, 113], [60, 116], [60, 118], [60, 121], [60, 122], [60, 128], [60, 132], [60, 133], [60, 137], [61, 63], [61, 64], [61, 65], [61, 70], [61, 73], [61, 81], [61, 83], [61, 87], [61, 88], [61, 98], [61, 99], [61, 100], [61, 102], [61, 104], [61, 107], [61, 111], [61, 122], [61, 123], [61, 132], [61, 134], [61, 135], [62, 63], [62, 65], [62, 70], [62, 73], [62, 75], [62, 77], [62, 81], [62, 87], [62, 89], [62, 90], [62, 92], [62, 93], [62, 105], [62, 109], [62, 110], [62, 115], [62, 123], [62, 124], [62, 127], [62, 132], [62, 133], [62, 134], [63, 64], [63, 68], [63, 69], [63, 70], [63, 72], [63, 75], [63, 76], [63, 84], [63, 89], [63, 90], [63, 96], [63, 108], [63, 110], [63, 115], [63, 116], [63, 118], [63, 120], [63, 121], [63, 124], [63, 126], [63, 127], [63, 130], [63, 135], [63, 136], [64, 73], [64, 74], [64, 76], [64, 83], [64, 84], [64, 86], [64, 87], [64, 88], [64, 89], [64, 96], [64, 97], [64, 100], [64, 101], [64, 103], [64, 106], [64, 108], [64, 113], [64, 115], [64, 116], [64, 117], [64, 118], [64, 119], [64, 127], [64, 128], [64, 133], [65, 71], [65, 73], [65, 76], [65, 90], [65, 93], [65, 99], [65, 101], [65, 102], [65, 104], [65, 105], [65, 106], [65, 107], [65, 113], [65, 116], [65, 118], [65, 119], [65, 125], [65, 131], [65, 133], [65, 139], [66, 70], [66, 71], [66, 72], [66, 78], [66, 80], [66, 81], [66, 82], [66, 86], [66, 89], [66, 94], [66, 95], [66, 96], [66, 97], [66, 103], [66, 104], [66, 114], [66, 115], [66, 116], [66, 121], [66, 123], [66, 124], [66, 125], [66, 126], [66, 129], [66, 139], [67, 72], [67, 76], [67, 77], [67, 81], [67, 82], [67, 83], [67, 84], [67, 85], [67, 86], [67, 87], [67, 89], [67, 95], [67, 96], [67, 97], [67, 98], [67, 101], [67, 103], [67, 104], [67, 105], [67, 107], [67, 108], [67, 109], [67, 114], [67, 115], [67, 116], [67, 120], [67, 126], [67, 132], [67, 136], [68, 75], [68, 88], [68, 98], [68, 99], [68, 100], [68, 105], [68, 109], [68, 115], [68, 116], [68, 117], [68, 120], [68, 123], [68, 129], [68, 130], [68, 131], [69, 71], [69, 75], [69, 76], [69, 81], [69, 84], [69, 85], [69, 94], [69, 95], [69, 96], [69, 100], [69, 106], [69, 107], [69, 108], [69, 110], [69, 111], [69, 113], [69, 115], [69, 123], [69, 130], [69, 134], [69, 137], [69, 139], [70, 72], [70, 77], [70, 83], [70, 84], [70, 95], [70, 99], [70, 100], [70, 101], [70, 103], [70, 105], [70, 106], [70, 115], [70, 118], [70, 121], [70, 131], [70, 132], [70, 134], [70, 139], [71, 74], [71, 83], [71, 84], [71, 92], [71, 101], [71, 105], [71, 118], [71, 120], [71, 128], [71, 129], [71, 131], [71, 137], [71, 138], [72, 75], [72, 78], [72, 79], [72, 80], [72, 85], [72, 95], [72, 96], [72, 98], [72, 114], [72, 119], [72, 134], [72, 138], [72, 139], [73, 74], [73, 78], [73, 80], [73, 82], [73, 83], [73, 86], [73, 87], [73, 88], [73, 92], [73, 97], [73, 98], [73, 102], [73, 103], [73, 104], [73, 105], [73, 106], [73, 108], [73, 111], [73, 112], [73, 119], [73, 121], [73, 123], [73, 128], [73, 129], [73, 136], [73, 139], [74, 75], [74, 77], [74, 78], [74, 84], [74, 94], [74, 95], [74, 104], [74, 108], [74, 112], [74, 116], [74, 117], [74, 121], [74, 122], [74, 128], [74, 131], [74, 135], [74, 136], [74, 139], [75, 76], [75, 79], [75, 80], [75, 81], [75, 85], [75, 86], [75, 87], [75, 93], [75, 97], [75, 99], [75, 103], [75, 107], [75, 112], [75, 115], [75, 117], [75, 119], [75, 120], [75, 129], [75, 130], [75, 132], [75, 135], [75, 139], [76, 78], [76, 79], [76, 81], [76, 85], [76, 89], [76, 92], [76, 94], [76, 95], [76, 96], [76, 99], [76, 105], [76, 107], [76, 109], [76, 110], [76, 111], [76, 114], [76, 117], [76, 129], [76, 136], [76, 138], [76, 139], [77, 84], [77, 86], [77, 89], [77, 90], [77, 92], [77, 95], [77, 97], [77, 99], [77, 108], [77, 109], [77, 112], [77, 113], [77, 115], [77, 116], [77, 119], [77, 120], [77, 122], [77, 123], [77, 128], [77, 129], [78, 79], [78, 80], [78, 83], [78, 84], [78, 87], [78, 89], [78, 95], [78, 100], [78, 101], [78, 106], [78, 109], [78, 115], [78, 116], [78, 117], [78, 123], [78, 126], [78, 130], [78, 132], [78, 133], [78, 138], [79, 80], [79, 83], [79, 84], [79, 86], [79, 87], [79, 89], [79, 90], [79, 91], [79, 97], [79, 101], [79, 105], [79, 113], [79, 115], [79, 116], [79, 120], [79, 122], [79, 124], [79, 127], [79, 128], [79, 135], [79, 136], [79, 137], [80, 87], [80, 90], [80, 92], [80, 94], [80, 95], [80, 98], [80, 102], [80, 104], [80, 111], [80, 115], [80, 116], [80, 128], [80, 129], [80, 139], [81, 83], [81, 88], [81, 90], [81, 91], [81, 92], [81, 94], [81, 99], [81, 100], [81, 103], [81, 105], [81, 107], [81, 109], [81, 116], [81, 121], [81, 122], [81, 125], [81, 131], [81, 134], [81, 135], [81, 137], [81, 139], [82, 83], [82, 84], [82, 86], [82, 87], [82, 90], [82, 92], [82, 93], [82, 94], [82, 106], [82, 109], [82, 117], [82, 119], [82, 124], [82, 126], [82, 128], [82, 130], [82, 134], [82, 137], [83, 84], [83, 86], [83, 90], [83, 92], [83, 94], [83, 99], [83, 100], [83, 104], [83, 106], [83, 107], [83, 109], [83, 110], [83, 114], [83, 121], [83, 122], [83, 123], [83, 127], [83, 130], [83, 133], [83, 138], [83, 139], [84, 92], [84, 98], [84, 99], [84, 101], [84, 106], [84, 109], [84, 113], [84, 114], [84, 116], [84, 117], [84, 121], [84, 124], [84, 131], [84, 132], [84, 137], [85, 87], [85, 92], [85, 95], [85, 103], [85, 108], [85, 109], [85, 111], [85, 119], [85, 123], [85, 126], [85, 129], [85, 132], [85, 137], [86, 88], [86, 89], [86, 90], [86, 91], [86, 92], [86, 93], [86, 95], [86, 98], [86, 101], [86, 103], [86, 106], [86, 108], [86, 109], [86, 111], [86, 114], [86, 115], [86, 119], [86, 123], [86, 124], [86, 128], [86, 129], [86, 130], [86, 131], [86, 135], [86, 138], [87, 89], [87, 97], [87, 101], [87, 113], [87, 117], [87, 118], [87, 119], [87, 127], [87, 129], [87, 133], [87, 134], [87, 139], [88, 98], [88, 100], [88, 103], [88, 106], [88, 107], [88, 110], [88, 116], [88, 118], [88, 119], [88, 120], [88, 121], [88, 123], [88, 127], [88, 128], [88, 133], [88, 135], [88, 138], [89, 91], [89, 93], [89, 103], [89, 104], [89, 106], [89, 107], [89, 110], [89, 113], [89, 116], [89, 119], [89, 124], [89, 126], [89, 127], [89, 132], [90, 93], [90, 95], [90, 96], [90, 98], [90, 100], [90, 101], [90, 104], [90, 106], [90, 109], [90, 118], [90, 119], [90, 120], [90, 122], [90, 134], [90, 136], [91, 95], [91, 99], [91, 103], [91, 114], [91, 117], [91, 118], [91, 119], [91, 120], [91, 122], [91, 128], [91, 131], [91, 132], [91, 136], [91, 139], [92, 94], [92, 97], [92, 103], [92, 105], [92, 108], [92, 109], [92, 110], [92, 111], [92, 116], [92, 119], [92, 120], [92, 121], [92, 122], [92, 129], [92, 131], [92, 132], [92, 136], [92, 139], [93, 97], [93, 100], [93, 110], [93, 112], [93, 115], [93, 116], [93, 131], [93, 136], [93, 139], [94, 96], [94, 98], [94, 101], [94, 104], [94, 106], [94, 107], [94, 110], [94, 115], [94, 116], [94, 119], [94, 122], [94, 123], [94, 125], [94, 126], [94, 128], [94, 129], [94, 132], [94, 133], [94, 136], [94, 137], [94, 139], [95, 97], [95, 99], [95, 100], [95, 101], [95, 106], [95, 112], [95, 115], [95, 119], [95, 122], [95, 123], [95, 124], [95, 131], [95, 134], [95, 135], [96, 103], [96, 104], [96, 110], [96, 114], [96, 119], [96, 124], [96, 125], [96, 128], [96, 133], [96, 138], [97, 98], [97, 101], [97, 103], [97, 115], [97, 118], [97, 123], [97, 130], [97, 135], [98, 99], [98, 102], [98, 104], [98, 111], [98, 112], [98, 120], [98, 123], [98, 125], [98, 128], [98, 133], [99, 109], [99, 111], [99, 113], [99, 115], [99, 121], [99, 123], [99, 124], [99, 125], [99, 137], [100, 104], [100, 107], [100, 109], [100, 112], [100, 115], [100, 120], [100, 127], [100, 130], [100, 133], [100, 134], [100, 135], [100, 137], [100, 139], [101, 104], [101, 107], [101, 109], [101, 110], [101, 117], [101, 120], [101, 123], [101, 125], [101, 131], [101, 132], [101, 134], [101, 139], [102, 103], [102, 104], [102, 105], [102, 109], [102, 110], [102, 111], [102, 113], [102, 118], [102, 123], [102, 124], [102, 126], [102, 128], [102, 130], [102, 131], [102, 132], [102, 133], [102, 135], [103, 107], [103, 108], [103, 109], [103, 112], [103, 113], [103, 117], [103, 124], [103, 129], [103, 133], [103, 136], [103, 138], [103, 139], [104, 112], [104, 116], [104, 117], [104, 120], [104, 122], [104, 125], [104, 127], [104, 130], [105, 106], [105, 107], [105, 108], [105, 118], [105, 125], [105, 128], [105, 130], [105, 131], [105, 132], [105, 137], [105, 139], [106, 107], [106, 113], [106, 121], [106, 125], [106, 127], [106, 128], [106, 134], [106, 136], [107, 110], [107, 112], [107, 139], [108, 112], [108, 114], [108, 117], [108, 118], [108, 119], [108, 127], [108, 129], [108, 132], [108, 133], [108, 137], [109, 111], [109, 112], [109, 117], [109, 120], [109, 121], [109, 125], [109, 126], [109, 136], [110, 118], [110, 126], [110, 127], [110, 135], [110, 138], [111, 116], [111, 119], [111, 122], [111, 126], [111, 128], [111, 136], [112, 115], [112, 123], [112, 125], [112, 132], [112, 137], [112, 139], [113, 118], [113, 120], [113, 121], [113, 126], [114, 116], [114, 118], [114, 125], [114, 126], [114, 128], [114, 129], [114, 134], [114, 135], [114, 137], [115, 116], [115, 122], [115, 124], [115, 133], [115, 134], [115, 139], [116, 117], [116, 119], [116, 121], [116, 124], [116, 125], [116, 133], [116, 136], [116, 137], [117, 120], [117, 126], [117, 132], [117, 139], [118, 119], [118, 120], [118, 125], [118, 126], [118, 129], [118, 132], [118, 134], [118, 135], [118, 136], [118, 137], [119, 121], [119, 123], [119, 126], [119, 131], [119, 134], [119, 138], [120, 121], [120, 122], [120, 124], [120, 125], [120, 129], [120, 131], [120, 139], [121, 123], [121, 126], [121, 128], [121, 130], [121, 135], [121, 139], [122, 126], [122, 129], [122, 130], [122, 133], [122, 137], [123, 124], [123, 129], [123, 135], [123, 138], [123, 139], [124, 125], [124, 128], [124, 133], [124, 134], [124, 135], [125, 128], [125, 129], [125, 130], [126, 128], [126, 132], [126, 136], [127, 132], [127, 135], [128, 129], [128, 138], [128, 139], [129, 136], [129, 137], [129, 138], [130, 131], [130, 132], [131, 137], [131, 138], [131, 139], [132, 133], [132, 136], [132, 139], [133, 135], [134, 138], [136, 138]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s8/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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-l6-s8/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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-non-transitive-dice-l2-s0/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l2-s0/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e4ae19d011874c265025f791c72fc2a3f7f4508 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 4, "m": 4, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l2-s0/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..823c7da6e79748b5f02d2650db414e28c36a7279 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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' +{"dice": [[1, 2, 2, 7], [0, 1, 5, 5], [0, 4, 4, 4], [2, 3, 3, 6]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l2-s0/tests/check.py b/tasks/construct-mc-non-transitive-dice-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-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-l2-s0/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e4ae19d011874c265025f791c72fc2a3f7f4508 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 4, "m": 4, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l2-s0/tests/run.py b/tasks/construct-mc-non-transitive-dice-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l2-s0/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l6-s1/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-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-l6-s1/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..07fff08a2977a7d25ac5618c7e91c0a851eb2c21 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "m": 8, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s1/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..211c0c1e045946ab899571168c0fd5129a62ad47 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-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": [[1, 3, 5, 5, 7, 9, 9, 15], [0, 1, 4, 6, 7, 7, 12, 12], [2, 4, 4, 5, 5, 5, 8, 15], [1, 1, 2, 3, 6, 14, 14, 15], [0, 0, 2, 8, 12, 12, 13, 13], [1, 5, 5, 5, 9, 10, 12, 12], [0, 1, 3, 4, 8, 13, 15, 15], [0, 1, 5, 6, 10, 10, 11, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l6-s1/tests/check.py b/tasks/construct-mc-non-transitive-dice-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-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-l6-s1/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..07fff08a2977a7d25ac5618c7e91c0a851eb2c21 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "m": 8, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s1/tests/run.py b/tasks/construct-mc-non-transitive-dice-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-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-l6-s1/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-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-number-partitioning-l2-s3/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l2-s3/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..87e5c12bfdd07af45e1defae04c2528bbc565ffd --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s3/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8fd6e471e586856c98d654e7ae078b83e8519c41 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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": [1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s3/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-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-l2-s3/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..87e5c12bfdd07af45e1defae04c2528bbc565ffd --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s3/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l2-s3/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l2-s4/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l2-s4/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06f7fa624c1792ddef337f3a05603f1d7eba877d --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 7, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s4/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9023c33779220bf4357f4a4891180c5571f9b3c8 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s4/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-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-l2-s4/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06f7fa624c1792ddef337f3a05603f1d7eba877d --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 7, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s4/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l2-s4/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l6-s2/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s2/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d2ca9d1db611d701eb25746b9b89b75b56d7b2b --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s2/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d7f9f898286696b67e1a0f9b378b33a0fad881c6 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s2/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s2/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-s2/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d2ca9d1db611d701eb25746b9b89b75b56d7b2b --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s2/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s2/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s5/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s5/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d17d34dd8d1fd7e115b977445b0f2c0f266fb117 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 96, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s5/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..87697f65bfadc9d075c24c4d6572389b19b3690d --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s5/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s5/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-s5/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d17d34dd8d1fd7e115b977445b0f2c0f266fb117 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 96, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s5/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s5/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-ortholatin-l4-s2/environment/Dockerfile b/tasks/construct-mc-ortholatin-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-mc-ortholatin-l4-s2/environment/instance.json b/tasks/construct-mc-ortholatin-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de2c015139ccd2935191f1db034e0c80f4265e9b --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l4-s2/solution/solve.sh b/tasks/construct-mc-ortholatin-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..db06dccfe8046e3273c2f30e71e83604742b5bc8 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14], [2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13], [3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12], [4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11], [5, 4, 7, 6, 1, 0, 3, 2, 13, 12, 15, 14, 9, 8, 11, 10], [6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9], [7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8], [8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7], [9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, 2, 5, 4, 7, 6], [10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5], [11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 1, 0, 7, 6, 5, 4], [12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3], [13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2], [14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], "Y": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [2, 3, 0, 1, 6, 7, 4, 5, 10, 11, 8, 9, 14, 15, 12, 13], [4, 5, 6, 7, 0, 1, 2, 3, 12, 13, 14, 15, 8, 9, 10, 11], [6, 7, 4, 5, 2, 3, 0, 1, 14, 15, 12, 13, 10, 11, 8, 9], [8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7], [10, 11, 8, 9, 14, 15, 12, 13, 2, 3, 0, 1, 6, 7, 4, 5], [12, 13, 14, 15, 8, 9, 10, 11, 4, 5, 6, 7, 0, 1, 2, 3], [14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1], [3, 2, 1, 0, 7, 6, 5, 4, 11, 10, 9, 8, 15, 14, 13, 12], [1, 0, 3, 2, 5, 4, 7, 6, 9, 8, 11, 10, 13, 12, 15, 14], [7, 6, 5, 4, 3, 2, 1, 0, 15, 14, 13, 12, 11, 10, 9, 8], [5, 4, 7, 6, 1, 0, 3, 2, 13, 12, 15, 14, 9, 8, 11, 10], [11, 10, 9, 8, 15, 14, 13, 12, 3, 2, 1, 0, 7, 6, 5, 4], [9, 8, 11, 10, 13, 12, 15, 14, 1, 0, 3, 2, 5, 4, 7, 6], [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l4-s2/tests/check.py b/tasks/construct-mc-ortholatin-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s2/tests/check.py @@ -0,0 +1,25 @@ +"""Pair of orthogonal Latin squares of order n (MathConstraint ortholatin, CC-BY-4.0).""" +from run import Invalid, int_list + + +def _square(v, n, name): + if not isinstance(v, list) or len(v) != n: + raise Invalid(f"{name} must be a list of {n} rows") + S = [int_list(r, n, 0, n - 1, f"{name} row") for r in v] + full = list(range(n)) + for i in range(n): + if sorted(S[i]) != full: + raise Invalid(f"{name}: row {i} is not a permutation of 0..{n - 1}") + if sorted(S[r][i] for r in range(n)) != full: + raise Invalid(f"{name}: column {i} is not a permutation of 0..{n - 1}") + return S + + +def check(inst, ans): + n = inst["n"] + X = _square(ans.get("X"), n, "X") + Y = _square(ans.get("Y"), n, "Y") + pairs = {(X[i][j], Y[i][j]) for i in range(n) for j in range(n)} + if len(pairs) != n * n: + raise Invalid("X and Y are not orthogonal (some ordered pair repeats)") + return None, {} diff --git a/tasks/construct-mc-ortholatin-l4-s2/tests/instance.json b/tasks/construct-mc-ortholatin-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de2c015139ccd2935191f1db034e0c80f4265e9b --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l4-s2/tests/run.py b/tasks/construct-mc-ortholatin-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-mc-ortholatin-l4-s2/tests/test.sh b/tasks/construct-mc-ortholatin-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-mc-pysms-chromatic-girth-l4-s2/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-chromatic-girth-l4-s2/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b300e12572697cf1f4491c21dc2fa195a8c400d --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 21, "required_edges": [], "max_chromatic_number": 3, "min_edges": 21, "min_girth": 7, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s2/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c10ad3574072058acdc7e3de62331c09d230021 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [1, 3], [1, 4], [2, 4], [2, 20], [3, 19]], "coloring": [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/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-chromatic-girth-l4-s2/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b300e12572697cf1f4491c21dc2fa195a8c400d --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 21, "required_edges": [], "max_chromatic_number": 3, "min_edges": 21, "min_girth": 7, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-chromatic-girth-l4-s2/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-clique-coloring-l3-s1/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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-pysms-clique-coloring-l3-s1/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9ff832eb7a3a2a04451364eeb64e83261ed6a73 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [[1, 4], [1, 2], [1, 9], [0, 3]], "max_chromatic_number": 5, "max_clique": 4, "min_degree": 1, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s1/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..832958a1c9ae0c570544b497b6cc53d30c596469 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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' +{"edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13]], "coloring": [0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-clique-coloring-l3-s1/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9ff832eb7a3a2a04451364eeb64e83261ed6a73 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [[1, 4], [1, 2], [1, 9], [0, 3]], "max_chromatic_number": 5, "max_clique": 4, "min_degree": 1, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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-pysms-clique-coloring-l3-s1/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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-pysms-girth-degree-l3-s1/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-girth-degree-l3-s1/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecfaa55a0da18ae96c44ebadc621bd82b65d0efe --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 25, "required_edges": [], "max_degree": 4, "min_degree": 3, "min_girth": 6, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s1/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ded952a35cebb6fc0e7013daacca106236a8bc95 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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, 22], [0, 23], [0, 24], [1, 20], [1, 21], [1, 24], [2, 19], [2, 21], [2, 23], [3, 17], [3, 18], [3, 24], [4, 16], [4, 18], [4, 23], [5, 15], [5, 17], [5, 19], [6, 13], [6, 14], [6, 22], [7, 11], [7, 12], [7, 21], [8, 10], [8, 12], [8, 19], [8, 24], [9, 10], [9, 11], [9, 15], [10, 14], [10, 16], [11, 18], [12, 13], [13, 20], [14, 17], [14, 21], [15, 22], [16, 20]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-girth-degree-l3-s1/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecfaa55a0da18ae96c44ebadc621bd82b65d0efe --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 25, "required_edges": [], "max_degree": 4, "min_degree": 3, "min_girth": 6, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-girth-degree-l3-s1/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-min-connectivity-l4-s1/environment/Dockerfile b/tasks/construct-mc-pysms-min-connectivity-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-min-connectivity-l4-s1/environment/instance.json b/tasks/construct-mc-pysms-min-connectivity-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7fd8c1f174a39d7caf207d57fe9a4be7e3f134ee --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "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-s1/solution/solve.sh b/tasks/construct-mc-pysms-min-connectivity-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..752031b11da6795a502d7f36701ee4e3b999221c --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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, 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], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [2, 3], [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], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-connectivity-l4-s1/tests/check.py b/tasks/construct-mc-pysms-min-connectivity-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-min-connectivity-l4-s1/tests/instance.json b/tasks/construct-mc-pysms-min-connectivity-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7fd8c1f174a39d7caf207d57fe9a4be7e3f134ee --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "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-s1/tests/run.py b/tasks/construct-mc-pysms-min-connectivity-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-min-connectivity-l4-s1/tests/test.sh b/tasks/construct-mc-pysms-min-connectivity-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-s8/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s8/environment/instance.json b/tasks/construct-mc-ramsey-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73f38daa2a1491572914ed8b7992c124c5c0f61f --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "r": 4, "s": 4, "fixed": [["colors", 3, 1], ["colors", 6, 0], ["colors", 13, 0], ["colors", 19, 0], ["colors", 27, 0], ["colors", 34, 1], ["colors", 35, 0], ["colors", 43, 1], ["colors", 56, 1], ["colors", 63, 0], ["colors", 65, 1], ["colors", 74, 0], ["colors", 75, 0], ["colors", 76, 0], ["colors", 77, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s8/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7633319595b71884d9418e5736945c83cbfdb61 --- /dev/null +++ b/tasks/construct-mc-ramsey-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' +{"colors": [0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l2-s8/tests/check.py b/tasks/construct-mc-ramsey-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s8/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-s8/tests/instance.json b/tasks/construct-mc-ramsey-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73f38daa2a1491572914ed8b7992c124c5c0f61f --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "r": 4, "s": 4, "fixed": [["colors", 3, 1], ["colors", 6, 0], ["colors", 13, 0], ["colors", 19, 0], ["colors", 27, 0], ["colors", 34, 1], ["colors", 35, 0], ["colors", 43, 1], ["colors", 56, 1], ["colors", 63, 0], ["colors", 65, 1], ["colors", 74, 0], ["colors", 75, 0], ["colors", 76, 0], ["colors", 77, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s8/tests/run.py b/tasks/construct-mc-ramsey-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s8/tests/test.sh b/tasks/construct-mc-ramsey-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s9/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-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-ramsey-l2-s9/environment/instance.json b/tasks/construct-mc-ramsey-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1c4c55a92d36705ff09648607e722c1a077be12c --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "r": 3, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s9/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..30f932ca5fa9e2a42c8370bc364721122a697142 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-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, 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-s9/tests/check.py b/tasks/construct-mc-ramsey-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s9/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-s9/tests/instance.json b/tasks/construct-mc-ramsey-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1c4c55a92d36705ff09648607e722c1a077be12c --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "r": 3, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s9/tests/run.py b/tasks/construct-mc-ramsey-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-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-ramsey-l2-s9/tests/test.sh b/tasks/construct-mc-ramsey-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-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-ramsey-l6-s0/environment/Dockerfile b/tasks/construct-mc-ramsey-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l6-s0/solution/solve.sh b/tasks/construct-mc-ramsey-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..01221647383d0ccbe853aee137cc65cdc556d26e --- /dev/null +++ b/tasks/construct-mc-ramsey-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' +{"colors": [0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l6-s0/tests/check.py b/tasks/construct-mc-ramsey-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s0/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-l6-s0/tests/instance.json b/tasks/construct-mc-ramsey-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cfb585fcca23a477eb88275f436dcc1662f9b590 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s0/tests/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-ramsey-l6-s0/tests/run.py b/tasks/construct-mc-ramsey-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l6-s0/tests/test.sh b/tasks/construct-mc-ramsey-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-social-golfers-l3-s2/environment/Dockerfile b/tasks/construct-mc-social-golfers-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-mc-social-golfers-l3-s2/environment/instance.json b/tasks/construct-mc-social-golfers-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d5efa53eaafc22a46d4b4a1c20f32f631a2e96f0 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 10, "group_size": 3, "n_weeks": 8, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l3-s2/solution/solve.sh b/tasks/construct-mc-social-golfers-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5661a4ff153a93da4587f117dc1ae3d15a4bf350 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"schedule": [[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9], [0, 1, 2, 3, 0, 8, 4, 0, 5, 7, 8, 3, 3, 1, 9, 4, 1, 6, 6, 9, 5, 4, 2, 7, 6, 9, 5, 7, 8, 2], [9, 7, 8, 8, 7, 9, 7, 6, 5, 1, 5, 0, 3, 0, 1, 8, 5, 4, 6, 3, 2, 1, 9, 4, 3, 2, 0, 6, 4, 2], [7, 8, 6, 8, 9, 3, 2, 3, 4, 3, 1, 0, 6, 1, 5, 4, 5, 7, 9, 7, 8, 0, 4, 5, 2, 6, 9, 1, 0, 2], [7, 4, 3, 1, 3, 0, 1, 2, 4, 4, 9, 0, 5, 2, 1, 8, 5, 6, 5, 3, 6, 2, 6, 9, 8, 7, 9, 8, 7, 0], [2, 5, 8, 3, 7, 4, 6, 9, 3, 8, 5, 6, 7, 3, 2, 9, 1, 7, 8, 4, 0, 4, 6, 9, 0, 1, 2, 1, 0, 5], [2, 3, 1, 9, 0, 7, 7, 1, 6, 0, 5, 4, 6, 7, 8, 0, 9, 1, 8, 9, 2, 5, 8, 4, 4, 5, 3, 2, 3, 6], [0, 1, 2, 0, 3, 1, 2, 4, 3, 0, 2, 3, 1, 5, 4, 5, 6, 7, 8, 9, 6, 6, 9, 8, 4, 5, 7, 7, 9, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l3-s2/tests/check.py b/tasks/construct-mc-social-golfers-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s2/tests/check.py @@ -0,0 +1,25 @@ +"""Social golfer problem (MathConstraint social_golfers, CSPLib prob010, CC-BY-4.0): each week partition +the g*s players into g groups of size s; no two players share a group in more than one week.""" +from run import Invalid, int_list + + +def check(inst, ans): + g, s, w = inst["n_groups"], inst["group_size"], inst["n_weeks"] + P = g * s + sched = ans.get("schedule") + if not isinstance(sched, list) or len(sched) != w: + raise Invalid(f"schedule must be a list of {w} weeks") + met = set() + for wk, row in enumerate(sched): + row = int_list(row, P, 0, g - 1, f"week {wk}") + groups = [[p for p in range(P) if row[p] == grp] for grp in range(g)] + for grp, mem in enumerate(groups): + if len(mem) != s: + raise Invalid(f"week {wk}: group {grp} has {len(mem)} players, need {s}") + for i in range(s): + for j in range(i + 1, s): + pr = (mem[i], mem[j]) + if pr in met: + raise Invalid(f"players {pr} play together in more than one week") + met.add(pr) + return None, {} diff --git a/tasks/construct-mc-social-golfers-l3-s2/tests/instance.json b/tasks/construct-mc-social-golfers-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d5efa53eaafc22a46d4b4a1c20f32f631a2e96f0 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 10, "group_size": 3, "n_weeks": 8, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l3-s2/tests/run.py b/tasks/construct-mc-social-golfers-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-mc-social-golfers-l3-s2/tests/test.sh b/tasks/construct-mc-social-golfers-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-mc-van-der-waerden-l2-s2/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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-l2-s2/environment/instance.json b/tasks/construct-mc-van-der-waerden-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97aa4619145e7b4222bc6bdfe6ca667f596fce69 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 3, "n": 15, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l2-s2/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bdae75ebb6aec01469e2bb5645667f7b69b12be --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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, 2, 2, 1, 0, 0, 1, 0, 1, 2, 2, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l2-s2/tests/check.py b/tasks/construct-mc-van-der-waerden-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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-l2-s2/tests/instance.json b/tasks/construct-mc-van-der-waerden-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..97aa4619145e7b4222bc6bdfe6ca667f596fce69 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 3, "n": 15, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l2-s2/tests/run.py b/tasks/construct-mc-van-der-waerden-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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-l2-s2/tests/test.sh b/tasks/construct-mc-van-der-waerden-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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-l2-s5/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l2-s5/environment/instance.json b/tasks/construct-mc-van-der-waerden-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f079235e4639cdf3f7b6307eac4a439f23c582b0 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 28, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l2-s5/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c9787fa5308256ef5d41b5a8ca95289bd9d3a66a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l2-s5/tests/check.py b/tasks/construct-mc-van-der-waerden-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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-l2-s5/tests/instance.json b/tasks/construct-mc-van-der-waerden-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f079235e4639cdf3f7b6307eac4a439f23c582b0 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 28, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l2-s5/tests/run.py b/tasks/construct-mc-van-der-waerden-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l2-s5/tests/test.sh b/tasks/construct-mc-van-der-waerden-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l6-s3/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l6-s3/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ec917048387871a303877b399e500fc604f57699 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 6, "n": 500, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s3/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..64207351dda850b341f795ecabb8c081ca253526 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s3/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s3/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-s3/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ec917048387871a303877b399e500fc604f57699 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 6, "n": 500, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s3/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s3/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l6-s4/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s4/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f736c093935bbbf5b37ddb73629a6703b586de9b --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 5, "n": 700, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s4/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a716157fb554e96f0d022e8431bf25f26581309a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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, 1, 2, 2, 0, 0, 1, 0, 1, 1, 1, 1, 2, 2, 2, 1, 0, 2, 1, 2, 0, 2, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 1, 2, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1, 2, 1, 2, 1, 1, 1, 0, 2, 1, 1, 0, 2, 2, 0, 2, 1, 1, 2, 2, 2, 1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 2, 1, 1, 2, 0, 1, 0, 1, 1, 2, 0, 2, 0, 1, 1, 1, 2, 0, 2, 2, 0, 0, 0, 2, 0, 0, 2, 2, 2, 2, 0, 2, 1, 1, 0, 0, 0, 2, 1, 2, 2, 1, 2, 0, 0, 0, 1, 1, 2, 0, 2, 2, 2, 2, 0, 0, 2, 0, 0, 0, 2, 2, 0, 2, 1, 1, 1, 0, 2, 0, 2, 1, 1, 0, 1, 0, 2, 1, 1, 2, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 2, 2, 2, 1, 1, 2, 0, 2, 2, 0, 1, 1, 2, 0, 1, 1, 1, 2, 1, 2, 1, 2, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 2, 1, 0, 1, 1, 0, 2, 1, 0, 1, 0, 0, 0, 0, 2, 0, 2, 0, 2, 1, 2, 0, 1, 2, 2, 2, 1, 1, 1, 1, 0, 1, 0, 0, 2, 2, 1, 0, 0, 0, 1, 2, 2, 0, 0, 1, 0, 1, 1, 1, 1, 2, 2, 2, 1, 0, 2, 1, 2, 0, 2, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 1, 2, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1, 2, 1, 2, 1, 1, 1, 0, 2, 1, 1, 0, 2, 2, 0, 2, 1, 1, 2, 2, 2, 1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 2, 1, 1, 2, 0, 1, 0, 1, 1, 2, 0, 2, 0, 1, 1, 1, 2, 0, 2, 2, 0, 0, 0, 2, 0, 0, 2, 2, 2, 2, 0, 2, 1, 1, 0, 0, 0, 2, 1, 2, 2, 1, 2, 0, 0, 0, 1, 1, 2, 0, 2, 2, 2, 2, 0, 0, 2, 0, 0, 0, 2, 2, 0, 2, 1, 1, 1, 0, 2, 0, 2, 1, 1, 0, 1, 0, 2, 1, 1, 2, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 2, 2, 2, 1, 1, 2, 0, 2, 2, 0, 1, 1, 2, 0, 1, 1, 1, 2, 1, 2, 1, 2, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 2, 1, 0, 1, 1, 0, 2, 1, 0, 1, 0, 0, 0, 0, 2, 0, 2, 0, 2, 1, 2, 0, 1, 2, 2, 2, 1, 1, 1, 1, 0, 1, 0, 0, 2, 2, 1, 0, 0, 0, 1, 2, 2, 0, 0, 1, 0, 1, 1, 1, 1, 2, 2, 2, 1, 0, 2, 1, 2, 0, 2, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 1, 0, 1, 2, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 2, 1, 2, 1, 2, 1, 1, 1, 0, 2, 1, 1, 0, 2, 2, 0, 2, 1, 1, 2, 2, 2, 1, 1, 0, 2, 2, 0, 2, 2, 0, 1, 2, 1, 1, 2, 0, 1, 0, 1, 1, 2, 0, 2, 0, 1, 1, 1, 2, 0, 2, 2, 0, 0, 0, 2, 0, 0, 2, 2, 2, 2, 0, 2, 1, 1, 0, 0, 0, 2, 1, 2, 2, 1, 2, 0, 0, 0, 1, 1, 2, 0, 2, 2, 2, 2, 0, 0, 2, 0, 0, 0, 2, 2, 0, 2, 1, 1, 1, 0, 2, 0, 2, 1, 1, 0, 1, 0, 2, 1, 1, 2, 1, 0, 2, 2, 0, 2, 2, 0, 1, 1, 2, 2, 2, 1, 1, 2, 0, 2, 2, 0, 1, 1, 2, 0, 1, 1, 1, 2, 1, 2, 1, 2, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 2, 1, 0, 1, 1, 0, 2, 1, 0, 1, 0, 0, 0, 0, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s4/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s4/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-s4/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f736c093935bbbf5b37ddb73629a6703b586de9b --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 5, "n": 700, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s4/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s4/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-nppc-3col-l3-s2/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s2/environment/instance.json b/tasks/construct-nppc-3col-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbda91a51e4ab795b4c4a9e5346c391876dd400b --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 1], [0, 2], [0, 5], [0, 11], [0, 22], [2, 3], [2, 14], [2, 20], [2, 27], [3, 19], [3, 20], [3, 24], [3, 27], [4, 9], [4, 10], [4, 15], [4, 23], [4, 25], [4, 28], [5, 6], [5, 13], [5, 14], [6, 10], [6, 22], [7, 16], [8, 20], [8, 22], [8, 27], [8, 29], [9, 18], [9, 23], [11, 13], [11, 16], [11, 18], [11, 20], [12, 19], [12, 20], [12, 23], [12, 27], [13, 16], [13, 19], [14, 16], [15, 21], [15, 24], [15, 29], [16, 19], [16, 25], [17, 22], [17, 23], [18, 21], [19, 20], [19, 27], [20, 21], [21, 24], [21, 28], [22, 23], [22, 25], [22, 28], [23, 24], [25, 27]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s2/solution/solve.sh b/tasks/construct-nppc-3col-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f8434650545b713c42d75304df47366d6264c33d --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [2, 1, 0, 1, 2, 0, 2, 0, 0, 1, 1, 0, 1, 1, 1, 0, 2, 2, 2, 0, 2, 1, 1, 0, 2, 0, 2, 2, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s2/tests/check.py b/tasks/construct-nppc-3col-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s2/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-s2/tests/instance.json b/tasks/construct-nppc-3col-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbda91a51e4ab795b4c4a9e5346c391876dd400b --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 1], [0, 2], [0, 5], [0, 11], [0, 22], [2, 3], [2, 14], [2, 20], [2, 27], [3, 19], [3, 20], [3, 24], [3, 27], [4, 9], [4, 10], [4, 15], [4, 23], [4, 25], [4, 28], [5, 6], [5, 13], [5, 14], [6, 10], [6, 22], [7, 16], [8, 20], [8, 22], [8, 27], [8, 29], [9, 18], [9, 23], [11, 13], [11, 16], [11, 18], [11, 20], [12, 19], [12, 20], [12, 23], [12, 27], [13, 16], [13, 19], [14, 16], [15, 21], [15, 24], [15, 29], [16, 19], [16, 25], [17, 22], [17, 23], [18, 21], [19, 20], [19, 27], [20, 21], [21, 24], [21, 28], [22, 23], [22, 25], [22, 28], [23, 24], [25, 27]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s2/tests/run.py b/tasks/construct-nppc-3col-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s2/tests/test.sh b/tasks/construct-nppc-3col-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s5/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s5/environment/instance.json b/tasks/construct-nppc-3col-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4031d93a9c5fcdc5cca65d74facebcca8916cfeb --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 4], [0, 8], [0, 21], [1, 20], [1, 24], [2, 4], [2, 8], [2, 14], [2, 20], [2, 28], [3, 6], [3, 8], [3, 14], [3, 15], [3, 16], [4, 9], [4, 11], [4, 16], [5, 12], [5, 29], [6, 13], [6, 17], [7, 8], [7, 9], [8, 15], [9, 17], [9, 22], [9, 24], [10, 11], [10, 16], [10, 18], [11, 14], [11, 20], [11, 22], [11, 25], [11, 29], [12, 18], [12, 21], [12, 29], [13, 16], [13, 22], [14, 15], [15, 20], [15, 22], [16, 18], [16, 27], [18, 27], [19, 20], [19, 25], [19, 28], [20, 25], [20, 29], [21, 23], [22, 24], [24, 28], [25, 26], [25, 28], [26, 29], [27, 28], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s5/solution/solve.sh b/tasks/construct-nppc-3col-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0b048bd7d84561c0d80b144b377f7c216ff26e71 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [1, 0, 1, 2, 2, 2, 1, 2, 0, 0, 0, 1, 1, 0, 0, 1, 1, 2, 2, 1, 2, 2, 2, 0, 1, 0, 1, 0, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s5/tests/check.py b/tasks/construct-nppc-3col-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s5/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-s5/tests/instance.json b/tasks/construct-nppc-3col-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4031d93a9c5fcdc5cca65d74facebcca8916cfeb --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 4], [0, 8], [0, 21], [1, 20], [1, 24], [2, 4], [2, 8], [2, 14], [2, 20], [2, 28], [3, 6], [3, 8], [3, 14], [3, 15], [3, 16], [4, 9], [4, 11], [4, 16], [5, 12], [5, 29], [6, 13], [6, 17], [7, 8], [7, 9], [8, 15], [9, 17], [9, 22], [9, 24], [10, 11], [10, 16], [10, 18], [11, 14], [11, 20], [11, 22], [11, 25], [11, 29], [12, 18], [12, 21], [12, 29], [13, 16], [13, 22], [14, 15], [15, 20], [15, 22], [16, 18], [16, 27], [18, 27], [19, 20], [19, 25], [19, 28], [20, 25], [20, 29], [21, 23], [22, 24], [24, 28], [25, 26], [25, 28], [26, 29], [27, 28], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s5/tests/run.py b/tasks/construct-nppc-3col-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s5/tests/test.sh b/tasks/construct-nppc-3col-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-bandwidth-l1-s9/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s9/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65cda936b9f336739dcbc0d0e1df886e4eb5c87d --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 4]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s9/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..28840004f9b11d86adfedadfc802a00fd33260c2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [0, 2, 3, 4, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s9/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s9/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-s9/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65cda936b9f336739dcbc0d0e1df886e4eb5c87d --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 4]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s9/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s9/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s0/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l5-s0/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c619a70fcf861402eb4d9824a94bb79293436a5 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 15], [0, 28], [0, 30], [0, 33], [0, 34], [0, 38], [1, 2], [1, 8], [1, 10], [1, 11], [2, 3], [2, 8], [2, 10], [2, 18], [2, 22], [3, 9], [3, 16], [4, 5], [4, 7], [4, 20], [4, 26], [4, 32], [5, 7], [5, 17], [5, 25], [5, 26], [5, 32], [6, 8], [6, 10], [6, 15], [6, 22], [7, 25], [7, 26], [7, 32], [8, 10], [8, 18], [8, 28], [8, 38], [9, 11], [9, 27], [9, 29], [9, 35], [10, 15], [10, 16], [10, 18], [11, 16], [11, 27], [11, 35], [12, 13], [12, 14], [12, 19], [12, 23], [13, 14], [13, 19], [13, 26], [13, 39], [14, 17], [14, 19], [14, 39], [15, 18], [15, 28], [15, 38], [16, 22], [17, 19], [17, 32], [18, 28], [18, 38], [19, 20], [19, 26], [19, 39], [20, 26], [20, 32], [21, 23], [21, 24], [21, 39], [23, 24], [23, 35], [23, 39], [24, 27], [24, 35], [24, 36], [24, 39], [25, 31], [25, 32], [26, 32], [27, 29], [27, 35], [28, 30], [28, 33], [29, 35], [29, 36], [30, 33], [30, 34], [30, 37], [31, 32], [33, 34], [34, 37], [34, 38], [35, 36], [36, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s0/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..635bb7769776b7054dc83e6411c3882e8a1a8bd9 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [3, 13, 12, 16, 34, 36, 10, 37, 9, 18, 11, 17, 27, 29, 28, 7, 15, 32, 8, 30, 31, 25, 14, 24, 23, 38, 33, 20, 5, 19, 4, 39, 35, 1, 2, 21, 22, 0, 6, 26]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s0/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-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-l5-s0/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c619a70fcf861402eb4d9824a94bb79293436a5 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 15], [0, 28], [0, 30], [0, 33], [0, 34], [0, 38], [1, 2], [1, 8], [1, 10], [1, 11], [2, 3], [2, 8], [2, 10], [2, 18], [2, 22], [3, 9], [3, 16], [4, 5], [4, 7], [4, 20], [4, 26], [4, 32], [5, 7], [5, 17], [5, 25], [5, 26], [5, 32], [6, 8], [6, 10], [6, 15], [6, 22], [7, 25], [7, 26], [7, 32], [8, 10], [8, 18], [8, 28], [8, 38], [9, 11], [9, 27], [9, 29], [9, 35], [10, 15], [10, 16], [10, 18], [11, 16], [11, 27], [11, 35], [12, 13], [12, 14], [12, 19], [12, 23], [13, 14], [13, 19], [13, 26], [13, 39], [14, 17], [14, 19], [14, 39], [15, 18], [15, 28], [15, 38], [16, 22], [17, 19], [17, 32], [18, 28], [18, 38], [19, 20], [19, 26], [19, 39], [20, 26], [20, 32], [21, 23], [21, 24], [21, 39], [23, 24], [23, 35], [23, 39], [24, 27], [24, 35], [24, 36], [24, 39], [25, 31], [25, 32], [26, 32], [27, 29], [27, 35], [28, 30], [28, 33], [29, 35], [29, 36], [30, 33], [30, 34], [30, 37], [31, 32], [33, 34], [34, 37], [34, 38], [35, 36], [36, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s0/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l5-s0/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l5-s1/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s1/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c26bb007e804d21264ff47bffd72b4e1abe0e62b --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 1], [0, 20], [0, 32], [0, 39], [1, 4], [2, 8], [2, 11], [2, 30], [2, 33], [3, 9], [3, 13], [3, 19], [3, 21], [3, 31], [3, 35], [4, 10], [4, 20], [4, 39], [5, 8], [5, 12], [5, 17], [5, 22], [6, 12], [6, 26], [6, 27], [6, 28], [6, 34], [7, 11], [7, 15], [7, 21], [7, 25], [7, 37], [8, 14], [8, 17], [8, 23], [9, 19], [9, 31], [9, 39], [10, 20], [10, 32], [10, 39], [11, 14], [11, 25], [11, 38], [12, 16], [12, 28], [12, 29], [12, 34], [13, 15], [13, 19], [13, 31], [13, 35], [14, 23], [14, 25], [14, 30], [14, 38], [15, 21], [15, 24], [15, 25], [15, 38], [16, 18], [16, 27], [16, 28], [16, 34], [17, 18], [17, 22], [17, 23], [17, 29], [17, 30], [18, 22], [18, 27], [18, 28], [19, 20], [19, 31], [19, 32], [19, 36], [20, 32], [20, 39], [21, 24], [21, 37], [22, 23], [22, 30], [23, 30], [24, 25], [24, 38], [25, 33], [25, 38], [26, 27], [26, 34], [27, 28], [27, 34], [28, 29], [30, 33], [31, 32], [31, 35], [31, 37], [32, 36], [32, 39], [33, 38], [35, 36], [35, 37]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s1/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ea6e31b1771933a8556b5a24460b871cde5c8bb0 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [4, 0, 24, 11, 1, 30, 37, 17, 27, 7, 2, 21, 34, 13, 23, 16, 35, 28, 32, 9, 5, 15, 29, 25, 18, 19, 39, 36, 33, 31, 26, 10, 6, 22, 38, 12, 8, 14, 20, 3]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s1/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s1/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-s1/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c26bb007e804d21264ff47bffd72b4e1abe0e62b --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 1], [0, 20], [0, 32], [0, 39], [1, 4], [2, 8], [2, 11], [2, 30], [2, 33], [3, 9], [3, 13], [3, 19], [3, 21], [3, 31], [3, 35], [4, 10], [4, 20], [4, 39], [5, 8], [5, 12], [5, 17], [5, 22], [6, 12], [6, 26], [6, 27], [6, 28], [6, 34], [7, 11], [7, 15], [7, 21], [7, 25], [7, 37], [8, 14], [8, 17], [8, 23], [9, 19], [9, 31], [9, 39], [10, 20], [10, 32], [10, 39], [11, 14], [11, 25], [11, 38], [12, 16], [12, 28], [12, 29], [12, 34], [13, 15], [13, 19], [13, 31], [13, 35], [14, 23], [14, 25], [14, 30], [14, 38], [15, 21], [15, 24], [15, 25], [15, 38], [16, 18], [16, 27], [16, 28], [16, 34], [17, 18], [17, 22], [17, 23], [17, 29], [17, 30], [18, 22], [18, 27], [18, 28], [19, 20], [19, 31], [19, 32], [19, 36], [20, 32], [20, 39], [21, 24], [21, 37], [22, 23], [22, 30], [23, 30], [24, 25], [24, 38], [25, 33], [25, 38], [26, 27], [26, 34], [27, 28], [27, 34], [28, 29], [30, 33], [31, 32], [31, 35], [31, 37], [32, 36], [32, 39], [33, 38], [35, 36], [35, 37]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s1/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s1/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-dominating-set-l4-s0/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l4-s0/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a460aae13e79b919dd97ddc5b1084b5c76bef889 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 6], [0, 11], [0, 13], [0, 15], [0, 21], [0, 24], [0, 29], [0, 30], [0, 32], [0, 38], [0, 42], [0, 46], [0, 48], [0, 52], [0, 53], [0, 54], [0, 56], [0, 58], [0, 59], [0, 62], [0, 63], [0, 65], [0, 66], [0, 69], [0, 73], [0, 74], [0, 77], [0, 80], [0, 86], [0, 87], [0, 88], [0, 90], [0, 93], [0, 99], [1, 7], [1, 9], [1, 12], [1, 14], [1, 18], [1, 21], [1, 22], [1, 23], [1, 24], [1, 27], [1, 29], [1, 33], [1, 34], [1, 36], [1, 40], [1, 47], [1, 48], [1, 50], [1, 52], [1, 54], [1, 55], [1, 57], [1, 59], [1, 61], [1, 63], [1, 64], [1, 68], [1, 71], [1, 72], [1, 74], [1, 83], [1, 87], [1, 88], [1, 90], [1, 95], [1, 99], [2, 4], [2, 5], [2, 17], [2, 21], [2, 24], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 35], [2, 36], [2, 42], [2, 43], [2, 46], [2, 47], [2, 49], [2, 54], [2, 55], [2, 58], [2, 59], [2, 60], [2, 66], [2, 70], [2, 74], [2, 75], [2, 79], [2, 82], [2, 85], [2, 90], [2, 93], [2, 95], [2, 97], [3, 4], [3, 9], [3, 10], [3, 15], [3, 19], [3, 22], [3, 23], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 33], [3, 40], [3, 41], [3, 44], [3, 50], [3, 56], [3, 59], [3, 60], [3, 63], [3, 66], [3, 67], [3, 73], [3, 79], [3, 86], [3, 87], [3, 90], [3, 91], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 18], [4, 19], [4, 20], [4, 27], [4, 29], [4, 31], [4, 32], [4, 35], [4, 37], [4, 39], [4, 42], [4, 44], [4, 46], [4, 47], [4, 52], [4, 53], [4, 54], [4, 57], [4, 60], [4, 75], [4, 83], [4, 86], [4, 88], [4, 89], [4, 90], [4, 92], [4, 93], [4, 96], [4, 97], [5, 8], [5, 14], [5, 15], [5, 23], [5, 29], [5, 31], [5, 32], [5, 41], [5, 43], [5, 53], [5, 61], [5, 65], [5, 71], [5, 77], [5, 81], [5, 85], [5, 88], [5, 89], [5, 92], [5, 93], [5, 95], [6, 8], [6, 13], [6, 15], [6, 19], [6, 20], [6, 22], [6, 24], [6, 25], [6, 38], [6, 41], [6, 45], [6, 46], [6, 48], [6, 51], [6, 58], [6, 61], [6, 63], [6, 66], [6, 68], [6, 69], [6, 70], [6, 76], [6, 78], [6, 83], [6, 85], [6, 89], [6, 91], [6, 94], [6, 97], [7, 9], [7, 13], [7, 16], [7, 20], [7, 21], [7, 22], [7, 39], [7, 45], [7, 47], [7, 50], [7, 51], [7, 53], [7, 57], [7, 61], [7, 63], [7, 76], [7, 77], [7, 79], [7, 81], [7, 84], [7, 88], [7, 90], [7, 92], [7, 94], [7, 99], [8, 11], [8, 16], [8, 17], [8, 22], [8, 28], [8, 31], [8, 32], [8, 37], [8, 38], [8, 40], [8, 41], [8, 42], [8, 47], [8, 52], [8, 53], [8, 55], [8, 61], [8, 62], [8, 64], [8, 69], [8, 70], [8, 71], [8, 74], [8, 75], [8, 82], [8, 85], [8, 87], [8, 90], [8, 93], [8, 94], [8, 97], [9, 12], [9, 18], [9, 20], [9, 22], [9, 34], [9, 35], [9, 38], [9, 41], [9, 42], [9, 44], [9, 45], [9, 47], [9, 48], [9, 51], [9, 53], [9, 59], [9, 61], [9, 72], [9, 73], [9, 76], [9, 78], [9, 88], [9, 89], [9, 91], [9, 92], [9, 94], [9, 97], [10, 11], [10, 12], [10, 17], [10, 18], [10, 30], [10, 34], [10, 38], [10, 39], [10, 40], [10, 46], [10, 47], [10, 49], [10, 54], [10, 55], [10, 57], [10, 58], [10, 60], [10, 61], [10, 67], [10, 70], [10, 72], [10, 76], [10, 77], [10, 83], [10, 84], [10, 89], [10, 96], [10, 97], [10, 98], [10, 99], [11, 12], [11, 17], [11, 20], [11, 22], [11, 28], [11, 29], [11, 30], [11, 36], [11, 40], [11, 48], [11, 50], [11, 51], [11, 52], [11, 54], [11, 61], [11, 71], [11, 72], [11, 80], [11, 83], [11, 90], [11, 92], [11, 98], [11, 99], [12, 20], [12, 22], [12, 23], [12, 24], [12, 26], [12, 27], [12, 31], [12, 33], [12, 35], [12, 36], [12, 37], [12, 43], [12, 45], [12, 55], [12, 56], [12, 59], [12, 63], [12, 66], [12, 68], [12, 69], [12, 77], [12, 78], [12, 83], [12, 88], [12, 92], [12, 95], [12, 97], [13, 16], [13, 21], [13, 23], [13, 28], [13, 30], [13, 34], [13, 39], [13, 40], [13, 44], [13, 48], [13, 52], [13, 56], [13, 60], [13, 62], [13, 63], [13, 69], [13, 73], [13, 74], [13, 80], [13, 82], [13, 84], [13, 86], [13, 91], [13, 93], [13, 96], [13, 97], [14, 19], [14, 21], [14, 23], [14, 24], [14, 28], [14, 31], [14, 34], [14, 35], [14, 36], [14, 37], [14, 42], [14, 44], [14, 49], [14, 51], [14, 63], [14, 69], [14, 72], [14, 76], [14, 77], [14, 81], [14, 82], [14, 84], [14, 88], [14, 89], [14, 93], [14, 94], [14, 98], [14, 99], [15, 17], [15, 19], [15, 22], [15, 23], [15, 27], [15, 37], [15, 43], [15, 44], [15, 45], [15, 46], [15, 48], [15, 52], [15, 56], [15, 60], [15, 61], [15, 63], [15, 66], [15, 67], [15, 70], [15, 75], [15, 77], [15, 78], [15, 84], [15, 86], [15, 90], [15, 91], [15, 93], [15, 95], [15, 97], [15, 99], [16, 18], [16, 20], [16, 27], [16, 29], [16, 32], [16, 35], [16, 36], [16, 38], [16, 42], [16, 53], [16, 56], [16, 58], [16, 60], [16, 64], [16, 67], [16, 70], [16, 71], [16, 73], [16, 74], [16, 78], [16, 79], [16, 85], [16, 86], [16, 89], [16, 90], [16, 91], [16, 93], [16, 97], [17, 18], [17, 21], [17, 23], [17, 24], [17, 25], [17, 29], [17, 36], [17, 38], [17, 39], [17, 41], [17, 48], [17, 56], [17, 57], [17, 59], [17, 72], [17, 82], [17, 83], [17, 85], [17, 86], [17, 89], [17, 90], [17, 95], [17, 96], [17, 97], [17, 98], [17, 99], [18, 21], [18, 22], [18, 23], [18, 24], [18, 26], [18, 27], [18, 28], [18, 35], [18, 36], [18, 38], [18, 41], [18, 42], [18, 52], [18, 53], [18, 63], [18, 71], [18, 72], [18, 74], [18, 75], [18, 81], [18, 83], [18, 86], [18, 88], [18, 90], [18, 92], [18, 94], [18, 99], [19, 20], [19, 29], [19, 31], [19, 32], [19, 37], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 53], [19, 58], [19, 59], [19, 61], [19, 64], [19, 67], [19, 69], [19, 76], [19, 79], [19, 82], [19, 84], [19, 87], [19, 88], [19, 90], [19, 93], [19, 98], [19, 99], [20, 24], [20, 25], [20, 26], [20, 29], [20, 31], [20, 32], [20, 37], [20, 46], [20, 47], [20, 51], [20, 52], [20, 57], [20, 58], [20, 63], [20, 64], [20, 66], [20, 71], [20, 72], [20, 73], [20, 76], [20, 80], [20, 81], [20, 83], [20, 84], [20, 86], [20, 88], [20, 91], [21, 26], [21, 27], [21, 29], [21, 36], [21, 37], [21, 40], [21, 41], [21, 43], [21, 44], [21, 45], [21, 47], [21, 48], [21, 49], [21, 52], [21, 53], [21, 55], [21, 57], [21, 63], [21, 65], [21, 68], [21, 69], [21, 83], [21, 84], [21, 90], [21, 96], [21, 98], [22, 23], [22, 24], [22, 25], [22, 27], [22, 31], [22, 32], [22, 35], [22, 36], [22, 41], [22, 43], [22, 45], [22, 47], [22, 49], [22, 51], [22, 54], [22, 55], [22, 56], [22, 61], [22, 63], [22, 68], [22, 76], [22, 77], [22, 81], [22, 82], [22, 89], [22, 93], [22, 94], [22, 99], [23, 29], [23, 30], [23, 35], [23, 39], [23, 42], [23, 44], [23, 53], [23, 55], [23, 56], [23, 64], [23, 65], [23, 67], [23, 68], [23, 77], [23, 78], [23, 79], [23, 81], [23, 83], [23, 86], [23, 87], [23, 89], [23, 92], [23, 93], [23, 94], [23, 98], [24, 25], [24, 26], [24, 28], [24, 34], [24, 43], [24, 46], [24, 47], [24, 49], [24, 63], [24, 65], [24, 70], [24, 73], [24, 84], [24, 90], [24, 91], [24, 94], [24, 95], [24, 98], [25, 28], [25, 34], [25, 35], [25, 36], [25, 38], [25, 39], [25, 42], [25, 52], [25, 53], [25, 54], [25, 56], [25, 59], [25, 62], [25, 63], [25, 64], [25, 66], [25, 69], [25, 74], [25, 75], [25, 87], [25, 89], [25, 90], [25, 93], [25, 96], [25, 99], [26, 32], [26, 33], [26, 37], [26, 38], [26, 46], [26, 48], [26, 53], [26, 56], [26, 57], [26, 61], [26, 67], [26, 74], [26, 76], [26, 80], [26, 81], [26, 82], [26, 89], [26, 91], [26, 92], [26, 93], [26, 98], [27, 32], [27, 36], [27, 41], [27, 43], [27, 49], [27, 56], [27, 63], [27, 71], [27, 75], [27, 77], [27, 79], [27, 85], [27, 89], [27, 90], [27, 91], [27, 94], [27, 95], [27, 97], [27, 99], [28, 30], [28, 35], [28, 40], [28, 41], [28, 44], [28, 46], [28, 47], [28, 52], [28, 53], [28, 54], [28, 57], [28, 60], [28, 62], [28, 65], [28, 66], [28, 73], [28, 76], [28, 79], [28, 83], [28, 87], [28, 90], [29, 31], [29, 35], [29, 37], [29, 40], [29, 41], [29, 42], [29, 43], [29, 49], [29, 57], [29, 58], [29, 59], [29, 65], [29, 66], [29, 68], [29, 73], [29, 75], [29, 81], [29, 84], [29, 85], [29, 86], [29, 87], [29, 88], [29, 93], [29, 97], [30, 34], [30, 41], [30, 42], [30, 47], [30, 49], [30, 51], [30, 54], [30, 58], [30, 59], [30, 61], [30, 64], [30, 66], [30, 68], [30, 69], [30, 70], [30, 73], [30, 76], [30, 77], [30, 83], [30, 85], [30, 88], [30, 90], [30, 94], [31, 32], [31, 33], [31, 42], [31, 52], [31, 54], [31, 55], [31, 60], [31, 62], [31, 63], [31, 72], [31, 75], [31, 79], [31, 81], [31, 82], [31, 83], [31, 84], [31, 86], [31, 87], [31, 88], [31, 89], [31, 94], [31, 95], [31, 99], [32, 36], [32, 39], [32, 40], [32, 43], [32, 48], [32, 53], [32, 55], [32, 57], [32, 66], [32, 69], [32, 72], [32, 74], [32, 75], [32, 78], [32, 79], [32, 83], [32, 84], [32, 89], [32, 91], [32, 96], [33, 35], [33, 36], [33, 40], [33, 41], [33, 43], [33, 45], [33, 47], [33, 48], [33, 50], [33, 60], [33, 61], [33, 64], [33, 66], [33, 70], [33, 73], [33, 78], [33, 81], [33, 82], [33, 91], [33, 94], [33, 96], [33, 97], [33, 99], [34, 35], [34, 38], [34, 39], [34, 41], [34, 47], [34, 51], [34, 52], [34, 57], [34, 60], [34, 63], [34, 64], [34, 65], [34, 67], [34, 68], [34, 69], [34, 83], [34, 85], [34, 91], [34, 97], [35, 36], [35, 37], [35, 39], [35, 41], [35, 43], [35, 44], [35, 46], [35, 47], [35, 49], [35, 50], [35, 52], [35, 54], [35, 66], [35, 67], [35, 70], [35, 72], [35, 77], [35, 79], [35, 82], [35, 90], [36, 39], [36, 44], [36, 47], [36, 52], [36, 55], [36, 56], [36, 59], [36, 60], [36, 62], [36, 63], [36, 64], [36, 65], [36, 67], [36, 69], [36, 73], [36, 77], [36, 78], [36, 85], [36, 86], [36, 90], [36, 93], [36, 96], [37, 41], [37, 42], [37, 44], [37, 45], [37, 56], [37, 68], [37, 70], [37, 71], [37, 73], [37, 75], [37, 76], [37, 78], [37, 81], [37, 83], [37, 92], [37, 99], [38, 39], [38, 43], [38, 53], [38, 57], [38, 59], [38, 63], [38, 68], [38, 69], [38, 71], [38, 78], [38, 80], [38, 81], [38, 85], [38, 86], [38, 89], [38, 94], [38, 98], [38, 99], [39, 42], [39, 43], [39, 45], [39, 46], [39, 47], [39, 60], [39, 62], [39, 63], [39, 64], [39, 65], [39, 68], [39, 69], [39, 71], [39, 73], [39, 77], [39, 81], [39, 88], [39, 94], [39, 95], [39, 97], [39, 98], [40, 46], [40, 52], [40, 57], [40, 61], [40, 62], [40, 64], [40, 67], [40, 74], [40, 81], [40, 83], [40, 86], [40, 87], [40, 89], [40, 91], [40, 97], [40, 98], [40, 99], [41, 44], [41, 52], [41, 59], [41, 60], [41, 62], [41, 64], [41, 66], [41, 70], [41, 72], [41, 73], [41, 76], [41, 78], [41, 84], [41, 88], [41, 89], [41, 96], [41, 99], [42, 47], [42, 49], [42, 57], [42, 59], [42, 65], [42, 66], [42, 74], [42, 80], [42, 84], [42, 85], [42, 89], [42, 91], [42, 98], [42, 99], [43, 51], [43, 52], [43, 57], [43, 58], [43, 61], [43, 64], [43, 76], [43, 77], [43, 81], [43, 85], [43, 88], [43, 94], [43, 97], [43, 98], [44, 45], [44, 46], [44, 48], [44, 50], [44, 54], [44, 56], [44, 58], [44, 60], [44, 61], [44, 62], [44, 63], [44, 65], [44, 76], [44, 77], [44, 80], [44, 85], [44, 90], [44, 93], [44, 94], [44, 98], [45, 47], [45, 49], [45, 53], [45, 56], [45, 64], [45, 66], [45, 69], [45, 73], [45, 74], [45, 76], [45, 83], [45, 84], [45, 85], [45, 89], [45, 90], [45, 91], [45, 92], [45, 99], [46, 48], [46, 51], [46, 52], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 69], [46, 71], [46, 76], [46, 79], [46, 94], [47, 51], [47, 53], [47, 56], [47, 58], [47, 60], [47, 62], [47, 69], [47, 73], [47, 85], [47, 87], [47, 89], [47, 90], [47, 93], [47, 95], [47, 98], [48, 49], [48, 59], [48, 62], [48, 65], [48, 67], [48, 70], [48, 78], [48, 79], [48, 81], [48, 85], [48, 87], [48, 89], [48, 92], [48, 95], [48, 96], [48, 97], [49, 50], [49, 52], [49, 55], [49, 57], [49, 61], [49, 62], [49, 65], [49, 71], [49, 80], [49, 82], [49, 85], [49, 87], [49, 91], [49, 93], [49, 98], [50, 51], [50, 52], [50, 59], [50, 60], [50, 61], [50, 63], [50, 65], [50, 66], [50, 68], [50, 73], [50, 74], [50, 77], [50, 78], [50, 79], [50, 86], [50, 91], [50, 98], [51, 52], [51, 53], [51, 57], [51, 64], [51, 67], [51, 68], [51, 72], [51, 74], [51, 75], [51, 78], [51, 85], [51, 88], [51, 90], [51, 91], [51, 97], [52, 55], [52, 59], [52, 60], [52, 76], [52, 79], [52, 80], [52, 85], [52, 86], [52, 87], [52, 90], [52, 92], [52, 99], [53, 55], [53, 56], [53, 57], [53, 58], [53, 59], [53, 65], [53, 66], [53, 68], [53, 70], [53, 74], [53, 78], [53, 79], [53, 82], [53, 83], [53, 84], [53, 87], [53, 88], [53, 90], [53, 96], [53, 99], [54, 62], [54, 64], [54, 68], [54, 69], [54, 74], [54, 76], [54, 77], [54, 79], [54, 93], [54, 99], [55, 58], [55, 60], [55, 61], [55, 73], [55, 77], [55, 78], [55, 81], [55, 83], [55, 84], [55, 87], [55, 90], [55, 92], [55, 93], [56, 57], [56, 59], [56, 63], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 75], [56, 79], [56, 80], [56, 81], [56, 82], [56, 85], [56, 86], [56, 89], [56, 91], [56, 92], [56, 93], [56, 96], [56, 97], [57, 59], [57, 63], [57, 65], [57, 74], [57, 75], [57, 77], [57, 78], [57, 82], [57, 83], [57, 87], [57, 88], [57, 91], [57, 96], [57, 99], [58, 64], [58, 65], [58, 70], [58, 75], [58, 78], [58, 79], [58, 81], [58, 84], [58, 88], [58, 91], [59, 61], [59, 63], [59, 66], [59, 69], [59, 72], [59, 77], [59, 80], [59, 85], [59, 91], [59, 98], [59, 99], [60, 62], [60, 64], [60, 65], [60, 71], [60, 81], [60, 82], [60, 85], [60, 88], [60, 89], [60, 92], [60, 98], [61, 66], [61, 70], [61, 72], [61, 73], [61, 75], [61, 82], [61, 88], [61, 91], [61, 93], [61, 96], [62, 63], [62, 64], [62, 67], [62, 76], [62, 82], [62, 85], [62, 93], [62, 96], [62, 97], [63, 69], [63, 75], [63, 77], [63, 81], [63, 87], [63, 88], [63, 89], [63, 90], [63, 91], [63, 92], [63, 94], [63, 96], [63, 97], [63, 98], [63, 99], [64, 65], [64, 66], [64, 68], [64, 70], [64, 74], [64, 76], [64, 79], [64, 80], [64, 82], [64, 83], [64, 85], [64, 86], [64, 89], [64, 90], [64, 98], [65, 73], [65, 77], [65, 79], [65, 82], [65, 84], [65, 87], [65, 95], [65, 97], [66, 76], [66, 77], [66, 80], [66, 84], [66, 88], [66, 89], [66, 90], [66, 92], [67, 68], [67, 71], [67, 74], [67, 79], [67, 80], [67, 88], [67, 90], [67, 91], [67, 96], [67, 99], [68, 70], [68, 72], [68, 75], [68, 77], [68, 78], [68, 79], [68, 81], [68, 82], [68, 83], [68, 85], [68, 89], [68, 90], [68, 91], [68, 93], [68, 94], [68, 95], [68, 97], [69, 82], [69, 85], [69, 87], [69, 89], [69, 92], [69, 93], [69, 96], [69, 98], [69, 99], [70, 71], [70, 76], [70, 78], [70, 82], [70, 88], [70, 89], [70, 95], [70, 97], [71, 75], [71, 78], [71, 94], [71, 96], [71, 97], [71, 98], [72, 76], [72, 78], [72, 83], [72, 89], [73, 76], [73, 79], [73, 83], [73, 88], [73, 89], [73, 92], [73, 94], [74, 75], [74, 76], [74, 78], [74, 81], [74, 84], [74, 90], [74, 92], [74, 98], [75, 82], [75, 84], [75, 88], [75, 90], [75, 92], [75, 96], [75, 97], [75, 98], [76, 78], [76, 79], [76, 80], [76, 81], [76, 83], [76, 89], [76, 93], [76, 97], [76, 98], [77, 78], [77, 84], [77, 87], [77, 95], [77, 99], [78, 81], [78, 83], [78, 84], [78, 88], [78, 91], [78, 92], [78, 93], [78, 98], [79, 80], [79, 81], [79, 86], [79, 90], [79, 96], [79, 98], [79, 99], [80, 82], [80, 83], [80, 84], [80, 90], [80, 93], [80, 96], [80, 97], [81, 84], [81, 94], [82, 83], [82, 86], [82, 87], [82, 89], [82, 93], [82, 97], [82, 98], [83, 86], [83, 89], [83, 94], [83, 95], [83, 99], [84, 85], [84, 88], [84, 90], [84, 92], [84, 94], [84, 95], [84, 98], [85, 93], [85, 94], [85, 98], [86, 93], [86, 94], [87, 90], [87, 92], [88, 95], [88, 97], [88, 98], [88, 99], [89, 90], [89, 96], [89, 97], [89, 99], [90, 96], [90, 98], [91, 94], [91, 96], [91, 98], [92, 93], [92, 97], [93, 95], [93, 96], [93, 98], [94, 99], [95, 96], [95, 97]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s0/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d214e03b3603529ebb8d866a9ba1bcff435122b1 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [1, 4, 6, 9, 10, 28, 31, 40, 43, 56, 59, 65, 68, 76, 78, 80, 82, 90, 93, 95]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s0/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s0/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-s0/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a460aae13e79b919dd97ddc5b1084b5c76bef889 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 6], [0, 11], [0, 13], [0, 15], [0, 21], [0, 24], [0, 29], [0, 30], [0, 32], [0, 38], [0, 42], [0, 46], [0, 48], [0, 52], [0, 53], [0, 54], [0, 56], [0, 58], [0, 59], [0, 62], [0, 63], [0, 65], [0, 66], [0, 69], [0, 73], [0, 74], [0, 77], [0, 80], [0, 86], [0, 87], [0, 88], [0, 90], [0, 93], [0, 99], [1, 7], [1, 9], [1, 12], [1, 14], [1, 18], [1, 21], [1, 22], [1, 23], [1, 24], [1, 27], [1, 29], [1, 33], [1, 34], [1, 36], [1, 40], [1, 47], [1, 48], [1, 50], [1, 52], [1, 54], [1, 55], [1, 57], [1, 59], [1, 61], [1, 63], [1, 64], [1, 68], [1, 71], [1, 72], [1, 74], [1, 83], [1, 87], [1, 88], [1, 90], [1, 95], [1, 99], [2, 4], [2, 5], [2, 17], [2, 21], [2, 24], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 35], [2, 36], [2, 42], [2, 43], [2, 46], [2, 47], [2, 49], [2, 54], [2, 55], [2, 58], [2, 59], [2, 60], [2, 66], [2, 70], [2, 74], [2, 75], [2, 79], [2, 82], [2, 85], [2, 90], [2, 93], [2, 95], [2, 97], [3, 4], [3, 9], [3, 10], [3, 15], [3, 19], [3, 22], [3, 23], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 33], [3, 40], [3, 41], [3, 44], [3, 50], [3, 56], [3, 59], [3, 60], [3, 63], [3, 66], [3, 67], [3, 73], [3, 79], [3, 86], [3, 87], [3, 90], [3, 91], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 18], [4, 19], [4, 20], [4, 27], [4, 29], [4, 31], [4, 32], [4, 35], [4, 37], [4, 39], [4, 42], [4, 44], [4, 46], [4, 47], [4, 52], [4, 53], [4, 54], [4, 57], [4, 60], [4, 75], [4, 83], [4, 86], [4, 88], [4, 89], [4, 90], [4, 92], [4, 93], [4, 96], [4, 97], [5, 8], [5, 14], [5, 15], [5, 23], [5, 29], [5, 31], [5, 32], [5, 41], [5, 43], [5, 53], [5, 61], [5, 65], [5, 71], [5, 77], [5, 81], [5, 85], [5, 88], [5, 89], [5, 92], [5, 93], [5, 95], [6, 8], [6, 13], [6, 15], [6, 19], [6, 20], [6, 22], [6, 24], [6, 25], [6, 38], [6, 41], [6, 45], [6, 46], [6, 48], [6, 51], [6, 58], [6, 61], [6, 63], [6, 66], [6, 68], [6, 69], [6, 70], [6, 76], [6, 78], [6, 83], [6, 85], [6, 89], [6, 91], [6, 94], [6, 97], [7, 9], [7, 13], [7, 16], [7, 20], [7, 21], [7, 22], [7, 39], [7, 45], [7, 47], [7, 50], [7, 51], [7, 53], [7, 57], [7, 61], [7, 63], [7, 76], [7, 77], [7, 79], [7, 81], [7, 84], [7, 88], [7, 90], [7, 92], [7, 94], [7, 99], [8, 11], [8, 16], [8, 17], [8, 22], [8, 28], [8, 31], [8, 32], [8, 37], [8, 38], [8, 40], [8, 41], [8, 42], [8, 47], [8, 52], [8, 53], [8, 55], [8, 61], [8, 62], [8, 64], [8, 69], [8, 70], [8, 71], [8, 74], [8, 75], [8, 82], [8, 85], [8, 87], [8, 90], [8, 93], [8, 94], [8, 97], [9, 12], [9, 18], [9, 20], [9, 22], [9, 34], [9, 35], [9, 38], [9, 41], [9, 42], [9, 44], [9, 45], [9, 47], [9, 48], [9, 51], [9, 53], [9, 59], [9, 61], [9, 72], [9, 73], [9, 76], [9, 78], [9, 88], [9, 89], [9, 91], [9, 92], [9, 94], [9, 97], [10, 11], [10, 12], [10, 17], [10, 18], [10, 30], [10, 34], [10, 38], [10, 39], [10, 40], [10, 46], [10, 47], [10, 49], [10, 54], [10, 55], [10, 57], [10, 58], [10, 60], [10, 61], [10, 67], [10, 70], [10, 72], [10, 76], [10, 77], [10, 83], [10, 84], [10, 89], [10, 96], [10, 97], [10, 98], [10, 99], [11, 12], [11, 17], [11, 20], [11, 22], [11, 28], [11, 29], [11, 30], [11, 36], [11, 40], [11, 48], [11, 50], [11, 51], [11, 52], [11, 54], [11, 61], [11, 71], [11, 72], [11, 80], [11, 83], [11, 90], [11, 92], [11, 98], [11, 99], [12, 20], [12, 22], [12, 23], [12, 24], [12, 26], [12, 27], [12, 31], [12, 33], [12, 35], [12, 36], [12, 37], [12, 43], [12, 45], [12, 55], [12, 56], [12, 59], [12, 63], [12, 66], [12, 68], [12, 69], [12, 77], [12, 78], [12, 83], [12, 88], [12, 92], [12, 95], [12, 97], [13, 16], [13, 21], [13, 23], [13, 28], [13, 30], [13, 34], [13, 39], [13, 40], [13, 44], [13, 48], [13, 52], [13, 56], [13, 60], [13, 62], [13, 63], [13, 69], [13, 73], [13, 74], [13, 80], [13, 82], [13, 84], [13, 86], [13, 91], [13, 93], [13, 96], [13, 97], [14, 19], [14, 21], [14, 23], [14, 24], [14, 28], [14, 31], [14, 34], [14, 35], [14, 36], [14, 37], [14, 42], [14, 44], [14, 49], [14, 51], [14, 63], [14, 69], [14, 72], [14, 76], [14, 77], [14, 81], [14, 82], [14, 84], [14, 88], [14, 89], [14, 93], [14, 94], [14, 98], [14, 99], [15, 17], [15, 19], [15, 22], [15, 23], [15, 27], [15, 37], [15, 43], [15, 44], [15, 45], [15, 46], [15, 48], [15, 52], [15, 56], [15, 60], [15, 61], [15, 63], [15, 66], [15, 67], [15, 70], [15, 75], [15, 77], [15, 78], [15, 84], [15, 86], [15, 90], [15, 91], [15, 93], [15, 95], [15, 97], [15, 99], [16, 18], [16, 20], [16, 27], [16, 29], [16, 32], [16, 35], [16, 36], [16, 38], [16, 42], [16, 53], [16, 56], [16, 58], [16, 60], [16, 64], [16, 67], [16, 70], [16, 71], [16, 73], [16, 74], [16, 78], [16, 79], [16, 85], [16, 86], [16, 89], [16, 90], [16, 91], [16, 93], [16, 97], [17, 18], [17, 21], [17, 23], [17, 24], [17, 25], [17, 29], [17, 36], [17, 38], [17, 39], [17, 41], [17, 48], [17, 56], [17, 57], [17, 59], [17, 72], [17, 82], [17, 83], [17, 85], [17, 86], [17, 89], [17, 90], [17, 95], [17, 96], [17, 97], [17, 98], [17, 99], [18, 21], [18, 22], [18, 23], [18, 24], [18, 26], [18, 27], [18, 28], [18, 35], [18, 36], [18, 38], [18, 41], [18, 42], [18, 52], [18, 53], [18, 63], [18, 71], [18, 72], [18, 74], [18, 75], [18, 81], [18, 83], [18, 86], [18, 88], [18, 90], [18, 92], [18, 94], [18, 99], [19, 20], [19, 29], [19, 31], [19, 32], [19, 37], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 53], [19, 58], [19, 59], [19, 61], [19, 64], [19, 67], [19, 69], [19, 76], [19, 79], [19, 82], [19, 84], [19, 87], [19, 88], [19, 90], [19, 93], [19, 98], [19, 99], [20, 24], [20, 25], [20, 26], [20, 29], [20, 31], [20, 32], [20, 37], [20, 46], [20, 47], [20, 51], [20, 52], [20, 57], [20, 58], [20, 63], [20, 64], [20, 66], [20, 71], [20, 72], [20, 73], [20, 76], [20, 80], [20, 81], [20, 83], [20, 84], [20, 86], [20, 88], [20, 91], [21, 26], [21, 27], [21, 29], [21, 36], [21, 37], [21, 40], [21, 41], [21, 43], [21, 44], [21, 45], [21, 47], [21, 48], [21, 49], [21, 52], [21, 53], [21, 55], [21, 57], [21, 63], [21, 65], [21, 68], [21, 69], [21, 83], [21, 84], [21, 90], [21, 96], [21, 98], [22, 23], [22, 24], [22, 25], [22, 27], [22, 31], [22, 32], [22, 35], [22, 36], [22, 41], [22, 43], [22, 45], [22, 47], [22, 49], [22, 51], [22, 54], [22, 55], [22, 56], [22, 61], [22, 63], [22, 68], [22, 76], [22, 77], [22, 81], [22, 82], [22, 89], [22, 93], [22, 94], [22, 99], [23, 29], [23, 30], [23, 35], [23, 39], [23, 42], [23, 44], [23, 53], [23, 55], [23, 56], [23, 64], [23, 65], [23, 67], [23, 68], [23, 77], [23, 78], [23, 79], [23, 81], [23, 83], [23, 86], [23, 87], [23, 89], [23, 92], [23, 93], [23, 94], [23, 98], [24, 25], [24, 26], [24, 28], [24, 34], [24, 43], [24, 46], [24, 47], [24, 49], [24, 63], [24, 65], [24, 70], [24, 73], [24, 84], [24, 90], [24, 91], [24, 94], [24, 95], [24, 98], [25, 28], [25, 34], [25, 35], [25, 36], [25, 38], [25, 39], [25, 42], [25, 52], [25, 53], [25, 54], [25, 56], [25, 59], [25, 62], [25, 63], [25, 64], [25, 66], [25, 69], [25, 74], [25, 75], [25, 87], [25, 89], [25, 90], [25, 93], [25, 96], [25, 99], [26, 32], [26, 33], [26, 37], [26, 38], [26, 46], [26, 48], [26, 53], [26, 56], [26, 57], [26, 61], [26, 67], [26, 74], [26, 76], [26, 80], [26, 81], [26, 82], [26, 89], [26, 91], [26, 92], [26, 93], [26, 98], [27, 32], [27, 36], [27, 41], [27, 43], [27, 49], [27, 56], [27, 63], [27, 71], [27, 75], [27, 77], [27, 79], [27, 85], [27, 89], [27, 90], [27, 91], [27, 94], [27, 95], [27, 97], [27, 99], [28, 30], [28, 35], [28, 40], [28, 41], [28, 44], [28, 46], [28, 47], [28, 52], [28, 53], [28, 54], [28, 57], [28, 60], [28, 62], [28, 65], [28, 66], [28, 73], [28, 76], [28, 79], [28, 83], [28, 87], [28, 90], [29, 31], [29, 35], [29, 37], [29, 40], [29, 41], [29, 42], [29, 43], [29, 49], [29, 57], [29, 58], [29, 59], [29, 65], [29, 66], [29, 68], [29, 73], [29, 75], [29, 81], [29, 84], [29, 85], [29, 86], [29, 87], [29, 88], [29, 93], [29, 97], [30, 34], [30, 41], [30, 42], [30, 47], [30, 49], [30, 51], [30, 54], [30, 58], [30, 59], [30, 61], [30, 64], [30, 66], [30, 68], [30, 69], [30, 70], [30, 73], [30, 76], [30, 77], [30, 83], [30, 85], [30, 88], [30, 90], [30, 94], [31, 32], [31, 33], [31, 42], [31, 52], [31, 54], [31, 55], [31, 60], [31, 62], [31, 63], [31, 72], [31, 75], [31, 79], [31, 81], [31, 82], [31, 83], [31, 84], [31, 86], [31, 87], [31, 88], [31, 89], [31, 94], [31, 95], [31, 99], [32, 36], [32, 39], [32, 40], [32, 43], [32, 48], [32, 53], [32, 55], [32, 57], [32, 66], [32, 69], [32, 72], [32, 74], [32, 75], [32, 78], [32, 79], [32, 83], [32, 84], [32, 89], [32, 91], [32, 96], [33, 35], [33, 36], [33, 40], [33, 41], [33, 43], [33, 45], [33, 47], [33, 48], [33, 50], [33, 60], [33, 61], [33, 64], [33, 66], [33, 70], [33, 73], [33, 78], [33, 81], [33, 82], [33, 91], [33, 94], [33, 96], [33, 97], [33, 99], [34, 35], [34, 38], [34, 39], [34, 41], [34, 47], [34, 51], [34, 52], [34, 57], [34, 60], [34, 63], [34, 64], [34, 65], [34, 67], [34, 68], [34, 69], [34, 83], [34, 85], [34, 91], [34, 97], [35, 36], [35, 37], [35, 39], [35, 41], [35, 43], [35, 44], [35, 46], [35, 47], [35, 49], [35, 50], [35, 52], [35, 54], [35, 66], [35, 67], [35, 70], [35, 72], [35, 77], [35, 79], [35, 82], [35, 90], [36, 39], [36, 44], [36, 47], [36, 52], [36, 55], [36, 56], [36, 59], [36, 60], [36, 62], [36, 63], [36, 64], [36, 65], [36, 67], [36, 69], [36, 73], [36, 77], [36, 78], [36, 85], [36, 86], [36, 90], [36, 93], [36, 96], [37, 41], [37, 42], [37, 44], [37, 45], [37, 56], [37, 68], [37, 70], [37, 71], [37, 73], [37, 75], [37, 76], [37, 78], [37, 81], [37, 83], [37, 92], [37, 99], [38, 39], [38, 43], [38, 53], [38, 57], [38, 59], [38, 63], [38, 68], [38, 69], [38, 71], [38, 78], [38, 80], [38, 81], [38, 85], [38, 86], [38, 89], [38, 94], [38, 98], [38, 99], [39, 42], [39, 43], [39, 45], [39, 46], [39, 47], [39, 60], [39, 62], [39, 63], [39, 64], [39, 65], [39, 68], [39, 69], [39, 71], [39, 73], [39, 77], [39, 81], [39, 88], [39, 94], [39, 95], [39, 97], [39, 98], [40, 46], [40, 52], [40, 57], [40, 61], [40, 62], [40, 64], [40, 67], [40, 74], [40, 81], [40, 83], [40, 86], [40, 87], [40, 89], [40, 91], [40, 97], [40, 98], [40, 99], [41, 44], [41, 52], [41, 59], [41, 60], [41, 62], [41, 64], [41, 66], [41, 70], [41, 72], [41, 73], [41, 76], [41, 78], [41, 84], [41, 88], [41, 89], [41, 96], [41, 99], [42, 47], [42, 49], [42, 57], [42, 59], [42, 65], [42, 66], [42, 74], [42, 80], [42, 84], [42, 85], [42, 89], [42, 91], [42, 98], [42, 99], [43, 51], [43, 52], [43, 57], [43, 58], [43, 61], [43, 64], [43, 76], [43, 77], [43, 81], [43, 85], [43, 88], [43, 94], [43, 97], [43, 98], [44, 45], [44, 46], [44, 48], [44, 50], [44, 54], [44, 56], [44, 58], [44, 60], [44, 61], [44, 62], [44, 63], [44, 65], [44, 76], [44, 77], [44, 80], [44, 85], [44, 90], [44, 93], [44, 94], [44, 98], [45, 47], [45, 49], [45, 53], [45, 56], [45, 64], [45, 66], [45, 69], [45, 73], [45, 74], [45, 76], [45, 83], [45, 84], [45, 85], [45, 89], [45, 90], [45, 91], [45, 92], [45, 99], [46, 48], [46, 51], [46, 52], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 69], [46, 71], [46, 76], [46, 79], [46, 94], [47, 51], [47, 53], [47, 56], [47, 58], [47, 60], [47, 62], [47, 69], [47, 73], [47, 85], [47, 87], [47, 89], [47, 90], [47, 93], [47, 95], [47, 98], [48, 49], [48, 59], [48, 62], [48, 65], [48, 67], [48, 70], [48, 78], [48, 79], [48, 81], [48, 85], [48, 87], [48, 89], [48, 92], [48, 95], [48, 96], [48, 97], [49, 50], [49, 52], [49, 55], [49, 57], [49, 61], [49, 62], [49, 65], [49, 71], [49, 80], [49, 82], [49, 85], [49, 87], [49, 91], [49, 93], [49, 98], [50, 51], [50, 52], [50, 59], [50, 60], [50, 61], [50, 63], [50, 65], [50, 66], [50, 68], [50, 73], [50, 74], [50, 77], [50, 78], [50, 79], [50, 86], [50, 91], [50, 98], [51, 52], [51, 53], [51, 57], [51, 64], [51, 67], [51, 68], [51, 72], [51, 74], [51, 75], [51, 78], [51, 85], [51, 88], [51, 90], [51, 91], [51, 97], [52, 55], [52, 59], [52, 60], [52, 76], [52, 79], [52, 80], [52, 85], [52, 86], [52, 87], [52, 90], [52, 92], [52, 99], [53, 55], [53, 56], [53, 57], [53, 58], [53, 59], [53, 65], [53, 66], [53, 68], [53, 70], [53, 74], [53, 78], [53, 79], [53, 82], [53, 83], [53, 84], [53, 87], [53, 88], [53, 90], [53, 96], [53, 99], [54, 62], [54, 64], [54, 68], [54, 69], [54, 74], [54, 76], [54, 77], [54, 79], [54, 93], [54, 99], [55, 58], [55, 60], [55, 61], [55, 73], [55, 77], [55, 78], [55, 81], [55, 83], [55, 84], [55, 87], [55, 90], [55, 92], [55, 93], [56, 57], [56, 59], [56, 63], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 75], [56, 79], [56, 80], [56, 81], [56, 82], [56, 85], [56, 86], [56, 89], [56, 91], [56, 92], [56, 93], [56, 96], [56, 97], [57, 59], [57, 63], [57, 65], [57, 74], [57, 75], [57, 77], [57, 78], [57, 82], [57, 83], [57, 87], [57, 88], [57, 91], [57, 96], [57, 99], [58, 64], [58, 65], [58, 70], [58, 75], [58, 78], [58, 79], [58, 81], [58, 84], [58, 88], [58, 91], [59, 61], [59, 63], [59, 66], [59, 69], [59, 72], [59, 77], [59, 80], [59, 85], [59, 91], [59, 98], [59, 99], [60, 62], [60, 64], [60, 65], [60, 71], [60, 81], [60, 82], [60, 85], [60, 88], [60, 89], [60, 92], [60, 98], [61, 66], [61, 70], [61, 72], [61, 73], [61, 75], [61, 82], [61, 88], [61, 91], [61, 93], [61, 96], [62, 63], [62, 64], [62, 67], [62, 76], [62, 82], [62, 85], [62, 93], [62, 96], [62, 97], [63, 69], [63, 75], [63, 77], [63, 81], [63, 87], [63, 88], [63, 89], [63, 90], [63, 91], [63, 92], [63, 94], [63, 96], [63, 97], [63, 98], [63, 99], [64, 65], [64, 66], [64, 68], [64, 70], [64, 74], [64, 76], [64, 79], [64, 80], [64, 82], [64, 83], [64, 85], [64, 86], [64, 89], [64, 90], [64, 98], [65, 73], [65, 77], [65, 79], [65, 82], [65, 84], [65, 87], [65, 95], [65, 97], [66, 76], [66, 77], [66, 80], [66, 84], [66, 88], [66, 89], [66, 90], [66, 92], [67, 68], [67, 71], [67, 74], [67, 79], [67, 80], [67, 88], [67, 90], [67, 91], [67, 96], [67, 99], [68, 70], [68, 72], [68, 75], [68, 77], [68, 78], [68, 79], [68, 81], [68, 82], [68, 83], [68, 85], [68, 89], [68, 90], [68, 91], [68, 93], [68, 94], [68, 95], [68, 97], [69, 82], [69, 85], [69, 87], [69, 89], [69, 92], [69, 93], [69, 96], [69, 98], [69, 99], [70, 71], [70, 76], [70, 78], [70, 82], [70, 88], [70, 89], [70, 95], [70, 97], [71, 75], [71, 78], [71, 94], [71, 96], [71, 97], [71, 98], [72, 76], [72, 78], [72, 83], [72, 89], [73, 76], [73, 79], [73, 83], [73, 88], [73, 89], [73, 92], [73, 94], [74, 75], [74, 76], [74, 78], [74, 81], [74, 84], [74, 90], [74, 92], [74, 98], [75, 82], [75, 84], [75, 88], [75, 90], [75, 92], [75, 96], [75, 97], [75, 98], [76, 78], [76, 79], [76, 80], [76, 81], [76, 83], [76, 89], [76, 93], [76, 97], [76, 98], [77, 78], [77, 84], [77, 87], [77, 95], [77, 99], [78, 81], [78, 83], [78, 84], [78, 88], [78, 91], [78, 92], [78, 93], [78, 98], [79, 80], [79, 81], [79, 86], [79, 90], [79, 96], [79, 98], [79, 99], [80, 82], [80, 83], [80, 84], [80, 90], [80, 93], [80, 96], [80, 97], [81, 84], [81, 94], [82, 83], [82, 86], [82, 87], [82, 89], [82, 93], [82, 97], [82, 98], [83, 86], [83, 89], [83, 94], [83, 95], [83, 99], [84, 85], [84, 88], [84, 90], [84, 92], [84, 94], [84, 95], [84, 98], [85, 93], [85, 94], [85, 98], [86, 93], [86, 94], [87, 90], [87, 92], [88, 95], [88, 97], [88, 98], [88, 99], [89, 90], [89, 96], [89, 97], [89, 99], [90, 96], [90, 98], [91, 94], [91, 96], [91, 98], [92, 93], [92, 97], [93, 95], [93, 96], [93, 98], [94, 99], [95, 96], [95, 97]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s0/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l4-s0/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l4-s7/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l4-s7/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..269e547fbc04760231b56c0ce33268d39e6b643a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 2], [0, 6], [0, 7], [0, 8], [0, 23], [0, 29], [0, 32], [0, 34], [0, 40], [0, 46], [0, 48], [0, 54], [0, 57], [0, 62], [0, 64], [0, 65], [0, 66], [0, 69], [0, 71], [0, 73], [0, 83], [0, 91], [0, 92], [0, 95], [1, 5], [1, 13], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 26], [1, 30], [1, 31], [1, 36], [1, 38], [1, 46], [1, 47], [1, 52], [1, 53], [1, 54], [1, 55], [1, 65], [1, 66], [1, 67], [1, 69], [1, 71], [1, 76], [1, 79], [1, 81], [1, 82], [1, 84], [1, 93], [1, 96], [1, 98], [1, 99], [2, 4], [2, 5], [2, 8], [2, 10], [2, 11], [2, 15], [2, 16], [2, 17], [2, 21], [2, 22], [2, 23], [2, 24], [2, 26], [2, 27], [2, 35], [2, 36], [2, 38], [2, 54], [2, 57], [2, 58], [2, 62], [2, 68], [2, 70], [2, 72], [2, 77], [2, 81], [2, 82], [2, 86], [2, 92], [2, 93], [3, 7], [3, 14], [3, 23], [3, 25], [3, 26], [3, 28], [3, 33], [3, 35], [3, 40], [3, 47], [3, 50], [3, 52], [3, 59], [3, 61], [3, 62], [3, 66], [3, 75], [3, 76], [3, 79], [3, 84], [3, 89], [3, 92], [3, 98], [4, 5], [4, 10], [4, 16], [4, 24], [4, 28], [4, 29], [4, 30], [4, 33], [4, 34], [4, 45], [4, 48], [4, 49], [4, 50], [4, 53], [4, 55], [4, 60], [4, 65], [4, 68], [4, 73], [4, 74], [4, 76], [4, 79], [4, 88], [4, 91], [4, 92], [4, 99], [5, 8], [5, 10], [5, 11], [5, 20], [5, 21], [5, 30], [5, 33], [5, 39], [5, 41], [5, 42], [5, 46], [5, 59], [5, 63], [5, 65], [5, 67], [5, 69], [5, 70], [5, 72], [5, 75], [5, 81], [5, 82], [5, 86], [5, 87], [5, 88], [5, 89], [5, 91], [5, 93], [5, 95], [5, 97], [5, 98], [6, 10], [6, 11], [6, 12], [6, 13], [6, 17], [6, 25], [6, 27], [6, 31], [6, 32], [6, 33], [6, 37], [6, 40], [6, 42], [6, 43], [6, 52], [6, 57], [6, 59], [6, 61], [6, 62], [6, 63], [6, 66], [6, 69], [6, 71], [6, 73], [6, 74], [6, 75], [6, 78], [6, 80], [6, 81], [6, 83], [6, 85], [6, 86], [6, 87], [6, 92], [6, 97], [6, 99], [7, 9], [7, 10], [7, 12], [7, 16], [7, 26], [7, 34], [7, 35], [7, 38], [7, 45], [7, 47], [7, 49], [7, 50], [7, 53], [7, 54], [7, 56], [7, 59], [7, 61], [7, 62], [7, 64], [7, 66], [7, 67], [7, 68], [7, 72], [7, 74], [7, 76], [7, 83], [7, 85], [7, 86], [7, 88], [7, 94], [7, 96], [7, 98], [8, 16], [8, 17], [8, 18], [8, 22], [8, 24], [8, 27], [8, 29], [8, 30], [8, 40], [8, 41], [8, 43], [8, 49], [8, 50], [8, 51], [8, 53], [8, 54], [8, 61], [8, 64], [8, 65], [8, 74], [8, 78], [8, 79], [8, 81], [8, 86], [9, 15], [9, 20], [9, 23], [9, 35], [9, 36], [9, 44], [9, 45], [9, 46], [9, 52], [9, 57], [9, 59], [9, 63], [9, 69], [9, 71], [9, 74], [9, 77], [9, 79], [9, 82], [9, 85], [9, 91], [9, 95], [9, 97], [10, 12], [10, 18], [10, 21], [10, 22], [10, 25], [10, 42], [10, 43], [10, 44], [10, 49], [10, 51], [10, 53], [10, 57], [10, 64], [10, 67], [10, 78], [10, 80], [10, 83], [10, 86], [10, 91], [10, 93], [10, 98], [11, 17], [11, 18], [11, 19], [11, 20], [11, 27], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 40], [11, 44], [11, 47], [11, 51], [11, 52], [11, 54], [11, 56], [11, 58], [11, 61], [11, 63], [11, 64], [11, 67], [11, 68], [11, 70], [11, 71], [11, 73], [11, 82], [11, 87], [11, 90], [11, 92], [11, 93], [11, 97], [12, 19], [12, 22], [12, 25], [12, 26], [12, 27], [12, 29], [12, 32], [12, 47], [12, 48], [12, 52], [12, 54], [12, 56], [12, 58], [12, 62], [12, 69], [12, 70], [12, 71], [12, 74], [12, 76], [12, 78], [12, 83], [12, 84], [12, 86], [12, 89], [12, 90], [12, 94], [12, 95], [12, 97], [12, 98], [13, 16], [13, 19], [13, 20], [13, 36], [13, 38], [13, 39], [13, 41], [13, 42], [13, 43], [13, 45], [13, 47], [13, 48], [13, 49], [13, 53], [13, 54], [13, 55], [13, 56], [13, 59], [13, 61], [13, 63], [13, 65], [13, 67], [13, 68], [13, 71], [13, 75], [13, 81], [13, 85], [13, 86], [13, 89], [13, 95], [13, 96], [13, 97], [14, 25], [14, 31], [14, 35], [14, 37], [14, 38], [14, 40], [14, 41], [14, 44], [14, 45], [14, 53], [14, 57], [14, 60], [14, 62], [14, 66], [14, 71], [14, 72], [14, 75], [14, 79], [14, 83], [14, 88], [14, 91], [14, 92], [14, 93], [14, 95], [14, 96], [14, 97], [14, 98], [14, 99], [15, 16], [15, 24], [15, 30], [15, 34], [15, 35], [15, 36], [15, 46], [15, 50], [15, 51], [15, 53], [15, 55], [15, 57], [15, 58], [15, 63], [15, 64], [15, 65], [15, 70], [15, 72], [15, 75], [15, 76], [15, 81], [15, 82], [15, 84], [15, 86], [15, 91], [15, 99], [16, 20], [16, 21], [16, 23], [16, 26], [16, 32], [16, 37], [16, 41], [16, 43], [16, 46], [16, 47], [16, 48], [16, 49], [16, 52], [16, 54], [16, 58], [16, 67], [16, 69], [16, 71], [16, 74], [16, 79], [16, 88], [16, 89], [16, 96], [16, 97], [16, 98], [16, 99], [17, 23], [17, 25], [17, 30], [17, 32], [17, 39], [17, 47], [17, 56], [17, 57], [17, 58], [17, 61], [17, 64], [17, 70], [17, 77], [17, 84], [17, 85], [17, 87], [17, 88], [17, 96], [17, 99], [18, 21], [18, 22], [18, 24], [18, 27], [18, 37], [18, 39], [18, 42], [18, 46], [18, 47], [18, 49], [18, 50], [18, 55], [18, 57], [18, 63], [18, 66], [18, 70], [18, 71], [18, 72], [18, 74], [18, 76], [18, 77], [18, 78], [18, 79], [18, 81], [18, 82], [18, 84], [18, 86], [18, 88], [18, 92], [18, 94], [18, 98], [19, 25], [19, 28], [19, 32], [19, 33], [19, 37], [19, 40], [19, 43], [19, 46], [19, 52], [19, 53], [19, 57], [19, 60], [19, 61], [19, 62], [19, 66], [19, 70], [19, 71], [19, 75], [19, 78], [19, 80], [19, 86], [19, 88], [19, 92], [19, 93], [19, 95], [19, 96], [19, 99], [20, 21], [20, 22], [20, 27], [20, 29], [20, 32], [20, 33], [20, 34], [20, 42], [20, 43], [20, 45], [20, 46], [20, 49], [20, 51], [20, 52], [20, 53], [20, 54], [20, 55], [20, 71], [20, 76], [20, 77], [20, 80], [20, 82], [20, 83], [20, 84], [20, 92], [20, 97], [21, 25], [21, 32], [21, 35], [21, 36], [21, 38], [21, 43], [21, 59], [21, 64], [21, 65], [21, 66], [21, 67], [21, 71], [21, 73], [21, 74], [21, 76], [21, 80], [21, 82], [21, 85], [21, 88], [21, 98], [22, 23], [22, 26], [22, 29], [22, 38], [22, 39], [22, 46], [22, 48], [22, 53], [22, 58], [22, 59], [22, 61], [22, 64], [22, 66], [22, 70], [22, 72], [22, 85], [22, 88], [23, 24], [23, 25], [23, 34], [23, 35], [23, 39], [23, 44], [23, 46], [23, 47], [23, 51], [23, 54], [23, 57], [23, 71], [23, 75], [23, 78], [23, 79], [23, 81], [23, 82], [23, 86], [23, 87], [23, 97], [24, 25], [24, 28], [24, 34], [24, 36], [24, 38], [24, 40], [24, 48], [24, 51], [24, 52], [24, 63], [24, 66], [24, 67], [24, 68], [24, 77], [24, 79], [24, 84], [24, 86], [24, 89], [24, 91], [24, 95], [25, 27], [25, 31], [25, 37], [25, 38], [25, 40], [25, 41], [25, 44], [25, 46], [25, 47], [25, 48], [25, 52], [25, 54], [25, 56], [25, 58], [25, 60], [25, 61], [25, 64], [25, 67], [25, 74], [25, 77], [25, 79], [25, 84], [25, 89], [25, 91], [25, 93], [25, 96], [25, 97], [26, 27], [26, 31], [26, 34], [26, 40], [26, 44], [26, 45], [26, 47], [26, 49], [26, 50], [26, 51], [26, 53], [26, 54], [26, 65], [26, 73], [26, 76], [26, 77], [26, 83], [26, 84], [26, 89], [26, 91], [26, 94], [26, 95], [27, 29], [27, 30], [27, 36], [27, 39], [27, 41], [27, 45], [27, 51], [27, 52], [27, 53], [27, 54], [27, 56], [27, 58], [27, 60], [27, 74], [27, 82], [27, 86], [27, 88], [27, 96], [27, 99], [28, 30], [28, 32], [28, 37], [28, 38], [28, 39], [28, 42], [28, 47], [28, 51], [28, 53], [28, 54], [28, 57], [28, 59], [28, 60], [28, 63], [28, 65], [28, 66], [28, 69], [28, 72], [28, 73], [28, 74], [28, 77], [28, 79], [28, 85], [28, 87], [28, 90], [28, 92], [28, 94], [28, 99], [29, 32], [29, 33], [29, 36], [29, 38], [29, 42], [29, 43], [29, 45], [29, 48], [29, 49], [29, 52], [29, 54], [29, 55], [29, 59], [29, 67], [29, 72], [29, 75], [29, 79], [29, 80], [29, 88], [30, 34], [30, 43], [30, 45], [30, 51], [30, 52], [30, 53], [30, 54], [30, 62], [30, 65], [30, 66], [30, 79], [30, 81], [30, 84], [30, 85], [30, 89], [30, 90], [30, 93], [31, 39], [31, 41], [31, 49], [31, 51], [31, 56], [31, 57], [31, 60], [31, 66], [31, 72], [31, 79], [31, 81], [31, 87], [31, 88], [31, 92], [31, 94], [31, 98], [31, 99], [32, 33], [32, 36], [32, 49], [32, 62], [32, 65], [32, 70], [32, 71], [32, 75], [32, 77], [32, 80], [32, 88], [32, 89], [32, 94], [32, 95], [33, 34], [33, 36], [33, 39], [33, 42], [33, 49], [33, 50], [33, 52], [33, 55], [33, 56], [33, 57], [33, 61], [33, 62], [33, 63], [33, 73], [33, 74], [33, 77], [33, 81], [33, 82], [33, 83], [33, 87], [33, 92], [33, 97], [34, 39], [34, 40], [34, 41], [34, 46], [34, 51], [34, 63], [34, 65], [34, 68], [34, 73], [34, 75], [34, 79], [34, 81], [34, 82], [34, 83], [34, 86], [34, 87], [34, 88], [34, 89], [34, 90], [34, 92], [34, 95], [34, 96], [35, 39], [35, 50], [35, 54], [35, 62], [35, 64], [35, 67], [35, 68], [35, 69], [35, 72], [35, 76], [35, 77], [35, 82], [35, 83], [35, 89], [36, 38], [36, 40], [36, 44], [36, 45], [36, 48], [36, 49], [36, 51], [36, 52], [36, 55], [36, 57], [36, 58], [36, 63], [36, 66], [36, 67], [36, 68], [36, 73], [36, 74], [36, 78], [36, 82], [36, 88], [36, 89], [36, 92], [36, 94], [36, 95], [36, 97], [36, 98], [36, 99], [37, 44], [37, 48], [37, 54], [37, 55], [37, 56], [37, 57], [37, 59], [37, 60], [37, 62], [37, 65], [37, 68], [37, 73], [37, 80], [37, 90], [37, 95], [38, 44], [38, 47], [38, 53], [38, 58], [38, 59], [38, 61], [38, 63], [38, 73], [38, 75], [38, 76], [38, 78], [38, 80], [38, 81], [38, 84], [38, 92], [39, 40], [39, 43], [39, 44], [39, 45], [39, 47], [39, 54], [39, 62], [39, 65], [39, 68], [39, 70], [39, 75], [39, 78], [39, 85], [39, 88], [39, 90], [39, 93], [39, 96], [40, 43], [40, 49], [40, 54], [40, 55], [40, 56], [40, 59], [40, 61], [40, 70], [40, 72], [40, 90], [40, 98], [41, 42], [41, 45], [41, 46], [41, 56], [41, 61], [41, 62], [41, 63], [41, 64], [41, 72], [41, 80], [41, 85], [41, 87], [41, 88], [41, 91], [41, 94], [41, 96], [41, 99], [42, 46], [42, 49], [42, 53], [42, 56], [42, 57], [42, 64], [42, 66], [42, 79], [42, 81], [42, 84], [42, 85], [42, 87], [42, 90], [42, 91], [42, 93], [42, 95], [42, 97], [42, 98], [42, 99], [43, 46], [43, 50], [43, 52], [43, 54], [43, 61], [43, 72], [43, 73], [43, 75], [43, 76], [43, 80], [43, 93], [43, 96], [43, 99], [44, 46], [44, 50], [44, 57], [44, 59], [44, 61], [44, 63], [44, 64], [44, 68], [44, 72], [44, 80], [44, 91], [44, 92], [44, 93], [44, 96], [44, 97], [44, 99], [45, 48], [45, 51], [45, 58], [45, 59], [45, 60], [45, 62], [45, 64], [45, 65], [45, 71], [45, 78], [45, 79], [45, 80], [45, 91], [45, 92], [45, 98], [46, 49], [46, 52], [46, 55], [46, 59], [46, 63], [46, 67], [46, 72], [46, 73], [46, 75], [46, 77], [46, 78], [46, 81], [46, 83], [46, 86], [46, 87], [46, 89], [46, 94], [46, 95], [47, 48], [47, 50], [47, 53], [47, 57], [47, 60], [47, 61], [47, 63], [47, 66], [47, 79], [47, 80], [47, 87], [47, 90], [47, 91], [47, 92], [47, 95], [47, 97], [48, 49], [48, 51], [48, 53], [48, 58], [48, 61], [48, 67], [48, 69], [48, 70], [48, 76], [48, 79], [48, 81], [48, 90], [48, 95], [48, 96], [49, 51], [49, 52], [49, 53], [49, 56], [49, 57], [49, 62], [49, 73], [49, 74], [49, 86], [49, 89], [49, 99], [50, 51], [50, 54], [50, 58], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 72], [50, 73], [50, 80], [50, 82], [50, 83], [50, 87], [50, 88], [50, 89], [50, 94], [51, 54], [51, 62], [51, 64], [51, 69], [51, 72], [51, 74], [51, 76], [51, 77], [51, 78], [51, 79], [51, 82], [51, 84], [51, 93], [52, 54], [52, 55], [52, 56], [52, 60], [52, 62], [52, 64], [52, 66], [52, 68], [52, 71], [52, 74], [52, 77], [52, 78], [52, 90], [52, 91], [52, 97], [52, 99], [53, 55], [53, 62], [53, 63], [53, 69], [53, 75], [53, 76], [53, 79], [53, 80], [53, 81], [53, 84], [53, 89], [53, 90], [53, 92], [53, 96], [53, 98], [54, 56], [54, 60], [54, 64], [54, 67], [54, 69], [54, 75], [54, 76], [54, 81], [54, 86], [54, 87], [54, 91], [54, 92], [55, 58], [55, 63], [55, 68], [55, 70], [55, 72], [55, 73], [55, 84], [55, 86], [55, 88], [55, 93], [55, 94], [55, 95], [55, 97], [55, 99], [56, 61], [56, 63], [56, 68], [56, 74], [56, 75], [56, 80], [56, 84], [56, 86], [56, 87], [56, 89], [56, 91], [56, 95], [57, 59], [57, 62], [57, 64], [57, 68], [57, 69], [57, 70], [57, 71], [57, 77], [57, 80], [57, 82], [57, 86], [57, 87], [57, 92], [57, 93], [57, 95], [57, 98], [58, 61], [58, 62], [58, 66], [58, 68], [58, 72], [58, 73], [58, 74], [58, 79], [58, 80], [58, 82], [58, 84], [58, 86], [58, 87], [58, 88], [58, 89], [58, 92], [58, 93], [58, 97], [58, 99], [59, 64], [59, 69], [59, 71], [59, 72], [59, 74], [59, 76], [59, 82], [59, 85], [59, 87], [59, 90], [59, 94], [59, 98], [60, 63], [60, 68], [60, 71], [60, 72], [60, 74], [60, 76], [60, 82], [60, 87], [60, 93], [60, 95], [60, 96], [60, 97], [60, 98], [61, 63], [61, 64], [61, 66], [61, 67], [61, 70], [61, 73], [61, 74], [61, 80], [61, 83], [61, 84], [61, 87], [62, 67], [62, 69], [62, 70], [62, 71], [62, 72], [62, 77], [62, 83], [62, 86], [62, 89], [62, 92], [62, 97], [62, 99], [63, 65], [63, 82], [63, 83], [63, 87], [63, 91], [63, 92], [63, 95], [63, 97], [64, 68], [64, 71], [64, 72], [64, 77], [64, 78], [64, 85], [64, 86], [64, 87], [64, 93], [65, 67], [65, 68], [65, 75], [65, 77], [65, 87], [65, 89], [65, 90], [65, 91], [65, 92], [65, 96], [66, 70], [66, 80], [66, 81], [66, 83], [66, 84], [66, 87], [66, 88], [66, 95], [66, 97], [66, 98], [67, 69], [67, 70], [67, 77], [67, 78], [67, 81], [67, 82], [67, 87], [67, 91], [67, 93], [67, 96], [67, 99], [68, 74], [68, 76], [68, 78], [68, 79], [68, 81], [68, 85], [68, 86], [68, 87], [68, 91], [68, 94], [68, 95], [68, 97], [69, 70], [69, 72], [69, 73], [69, 74], [69, 79], [69, 82], [69, 90], [69, 91], [69, 99], [70, 76], [70, 78], [70, 86], [70, 87], [70, 88], [70, 91], [70, 92], [70, 95], [70, 98], [71, 76], [71, 82], [71, 83], [71, 84], [71, 92], [72, 74], [72, 79], [72, 89], [72, 91], [72, 92], [72, 94], [72, 98], [73, 78], [73, 81], [73, 82], [73, 83], [73, 88], [73, 89], [73, 93], [73, 95], [73, 96], [73, 98], [74, 75], [74, 76], [74, 80], [74, 87], [74, 88], [74, 93], [74, 94], [74, 95], [74, 96], [74, 98], [74, 99], [75, 76], [75, 79], [75, 80], [75, 85], [75, 90], [75, 91], [75, 98], [75, 99], [76, 82], [76, 84], [76, 85], [76, 87], [76, 88], [76, 90], [76, 91], [76, 92], [76, 95], [77, 89], [77, 94], [77, 95], [78, 80], [78, 94], [78, 96], [79, 83], [79, 85], [79, 87], [79, 91], [79, 92], [79, 95], [79, 98], [80, 81], [80, 85], [80, 88], [80, 90], [80, 93], [80, 94], [80, 96], [80, 99], [81, 82], [81, 86], [82, 83], [82, 84], [82, 88], [83, 84], [83, 89], [83, 93], [83, 94], [83, 99], [84, 86], [84, 87], [84, 88], [84, 93], [84, 95], [84, 96], [84, 98], [84, 99], [85, 89], [85, 90], [85, 94], [85, 97], [86, 89], [86, 90], [86, 95], [86, 96], [86, 97], [86, 98], [87, 89], [87, 93], [87, 94], [87, 95], [87, 99], [88, 90], [88, 92], [88, 93], [88, 94], [88, 98], [88, 99], [89, 91], [89, 94], [89, 95], [89, 98], [89, 99], [90, 92], [90, 94], [91, 92], [91, 93], [91, 96], [92, 95], [93, 98], [93, 99], [94, 98], [95, 96]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s7/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5d737c5e0a7f4ea3529d92f17b30473406039069 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [0, 11, 19, 21, 25, 36, 46, 47, 51, 54, 59, 65, 69, 74, 80, 84, 85, 86, 89, 98]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s7/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s7/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-s7/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..269e547fbc04760231b56c0ce33268d39e6b643a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 2], [0, 6], [0, 7], [0, 8], [0, 23], [0, 29], [0, 32], [0, 34], [0, 40], [0, 46], [0, 48], [0, 54], [0, 57], [0, 62], [0, 64], [0, 65], [0, 66], [0, 69], [0, 71], [0, 73], [0, 83], [0, 91], [0, 92], [0, 95], [1, 5], [1, 13], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 26], [1, 30], [1, 31], [1, 36], [1, 38], [1, 46], [1, 47], [1, 52], [1, 53], [1, 54], [1, 55], [1, 65], [1, 66], [1, 67], [1, 69], [1, 71], [1, 76], [1, 79], [1, 81], [1, 82], [1, 84], [1, 93], [1, 96], [1, 98], [1, 99], [2, 4], [2, 5], [2, 8], [2, 10], [2, 11], [2, 15], [2, 16], [2, 17], [2, 21], [2, 22], [2, 23], [2, 24], [2, 26], [2, 27], [2, 35], [2, 36], [2, 38], [2, 54], [2, 57], [2, 58], [2, 62], [2, 68], [2, 70], [2, 72], [2, 77], [2, 81], [2, 82], [2, 86], [2, 92], [2, 93], [3, 7], [3, 14], [3, 23], [3, 25], [3, 26], [3, 28], [3, 33], [3, 35], [3, 40], [3, 47], [3, 50], [3, 52], [3, 59], [3, 61], [3, 62], [3, 66], [3, 75], [3, 76], [3, 79], [3, 84], [3, 89], [3, 92], [3, 98], [4, 5], [4, 10], [4, 16], [4, 24], [4, 28], [4, 29], [4, 30], [4, 33], [4, 34], [4, 45], [4, 48], [4, 49], [4, 50], [4, 53], [4, 55], [4, 60], [4, 65], [4, 68], [4, 73], [4, 74], [4, 76], [4, 79], [4, 88], [4, 91], [4, 92], [4, 99], [5, 8], [5, 10], [5, 11], [5, 20], [5, 21], [5, 30], [5, 33], [5, 39], [5, 41], [5, 42], [5, 46], [5, 59], [5, 63], [5, 65], [5, 67], [5, 69], [5, 70], [5, 72], [5, 75], [5, 81], [5, 82], [5, 86], [5, 87], [5, 88], [5, 89], [5, 91], [5, 93], [5, 95], [5, 97], [5, 98], [6, 10], [6, 11], [6, 12], [6, 13], [6, 17], [6, 25], [6, 27], [6, 31], [6, 32], [6, 33], [6, 37], [6, 40], [6, 42], [6, 43], [6, 52], [6, 57], [6, 59], [6, 61], [6, 62], [6, 63], [6, 66], [6, 69], [6, 71], [6, 73], [6, 74], [6, 75], [6, 78], [6, 80], [6, 81], [6, 83], [6, 85], [6, 86], [6, 87], [6, 92], [6, 97], [6, 99], [7, 9], [7, 10], [7, 12], [7, 16], [7, 26], [7, 34], [7, 35], [7, 38], [7, 45], [7, 47], [7, 49], [7, 50], [7, 53], [7, 54], [7, 56], [7, 59], [7, 61], [7, 62], [7, 64], [7, 66], [7, 67], [7, 68], [7, 72], [7, 74], [7, 76], [7, 83], [7, 85], [7, 86], [7, 88], [7, 94], [7, 96], [7, 98], [8, 16], [8, 17], [8, 18], [8, 22], [8, 24], [8, 27], [8, 29], [8, 30], [8, 40], [8, 41], [8, 43], [8, 49], [8, 50], [8, 51], [8, 53], [8, 54], [8, 61], [8, 64], [8, 65], [8, 74], [8, 78], [8, 79], [8, 81], [8, 86], [9, 15], [9, 20], [9, 23], [9, 35], [9, 36], [9, 44], [9, 45], [9, 46], [9, 52], [9, 57], [9, 59], [9, 63], [9, 69], [9, 71], [9, 74], [9, 77], [9, 79], [9, 82], [9, 85], [9, 91], [9, 95], [9, 97], [10, 12], [10, 18], [10, 21], [10, 22], [10, 25], [10, 42], [10, 43], [10, 44], [10, 49], [10, 51], [10, 53], [10, 57], [10, 64], [10, 67], [10, 78], [10, 80], [10, 83], [10, 86], [10, 91], [10, 93], [10, 98], [11, 17], [11, 18], [11, 19], [11, 20], [11, 27], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 40], [11, 44], [11, 47], [11, 51], [11, 52], [11, 54], [11, 56], [11, 58], [11, 61], [11, 63], [11, 64], [11, 67], [11, 68], [11, 70], [11, 71], [11, 73], [11, 82], [11, 87], [11, 90], [11, 92], [11, 93], [11, 97], [12, 19], [12, 22], [12, 25], [12, 26], [12, 27], [12, 29], [12, 32], [12, 47], [12, 48], [12, 52], [12, 54], [12, 56], [12, 58], [12, 62], [12, 69], [12, 70], [12, 71], [12, 74], [12, 76], [12, 78], [12, 83], [12, 84], [12, 86], [12, 89], [12, 90], [12, 94], [12, 95], [12, 97], [12, 98], [13, 16], [13, 19], [13, 20], [13, 36], [13, 38], [13, 39], [13, 41], [13, 42], [13, 43], [13, 45], [13, 47], [13, 48], [13, 49], [13, 53], [13, 54], [13, 55], [13, 56], [13, 59], [13, 61], [13, 63], [13, 65], [13, 67], [13, 68], [13, 71], [13, 75], [13, 81], [13, 85], [13, 86], [13, 89], [13, 95], [13, 96], [13, 97], [14, 25], [14, 31], [14, 35], [14, 37], [14, 38], [14, 40], [14, 41], [14, 44], [14, 45], [14, 53], [14, 57], [14, 60], [14, 62], [14, 66], [14, 71], [14, 72], [14, 75], [14, 79], [14, 83], [14, 88], [14, 91], [14, 92], [14, 93], [14, 95], [14, 96], [14, 97], [14, 98], [14, 99], [15, 16], [15, 24], [15, 30], [15, 34], [15, 35], [15, 36], [15, 46], [15, 50], [15, 51], [15, 53], [15, 55], [15, 57], [15, 58], [15, 63], [15, 64], [15, 65], [15, 70], [15, 72], [15, 75], [15, 76], [15, 81], [15, 82], [15, 84], [15, 86], [15, 91], [15, 99], [16, 20], [16, 21], [16, 23], [16, 26], [16, 32], [16, 37], [16, 41], [16, 43], [16, 46], [16, 47], [16, 48], [16, 49], [16, 52], [16, 54], [16, 58], [16, 67], [16, 69], [16, 71], [16, 74], [16, 79], [16, 88], [16, 89], [16, 96], [16, 97], [16, 98], [16, 99], [17, 23], [17, 25], [17, 30], [17, 32], [17, 39], [17, 47], [17, 56], [17, 57], [17, 58], [17, 61], [17, 64], [17, 70], [17, 77], [17, 84], [17, 85], [17, 87], [17, 88], [17, 96], [17, 99], [18, 21], [18, 22], [18, 24], [18, 27], [18, 37], [18, 39], [18, 42], [18, 46], [18, 47], [18, 49], [18, 50], [18, 55], [18, 57], [18, 63], [18, 66], [18, 70], [18, 71], [18, 72], [18, 74], [18, 76], [18, 77], [18, 78], [18, 79], [18, 81], [18, 82], [18, 84], [18, 86], [18, 88], [18, 92], [18, 94], [18, 98], [19, 25], [19, 28], [19, 32], [19, 33], [19, 37], [19, 40], [19, 43], [19, 46], [19, 52], [19, 53], [19, 57], [19, 60], [19, 61], [19, 62], [19, 66], [19, 70], [19, 71], [19, 75], [19, 78], [19, 80], [19, 86], [19, 88], [19, 92], [19, 93], [19, 95], [19, 96], [19, 99], [20, 21], [20, 22], [20, 27], [20, 29], [20, 32], [20, 33], [20, 34], [20, 42], [20, 43], [20, 45], [20, 46], [20, 49], [20, 51], [20, 52], [20, 53], [20, 54], [20, 55], [20, 71], [20, 76], [20, 77], [20, 80], [20, 82], [20, 83], [20, 84], [20, 92], [20, 97], [21, 25], [21, 32], [21, 35], [21, 36], [21, 38], [21, 43], [21, 59], [21, 64], [21, 65], [21, 66], [21, 67], [21, 71], [21, 73], [21, 74], [21, 76], [21, 80], [21, 82], [21, 85], [21, 88], [21, 98], [22, 23], [22, 26], [22, 29], [22, 38], [22, 39], [22, 46], [22, 48], [22, 53], [22, 58], [22, 59], [22, 61], [22, 64], [22, 66], [22, 70], [22, 72], [22, 85], [22, 88], [23, 24], [23, 25], [23, 34], [23, 35], [23, 39], [23, 44], [23, 46], [23, 47], [23, 51], [23, 54], [23, 57], [23, 71], [23, 75], [23, 78], [23, 79], [23, 81], [23, 82], [23, 86], [23, 87], [23, 97], [24, 25], [24, 28], [24, 34], [24, 36], [24, 38], [24, 40], [24, 48], [24, 51], [24, 52], [24, 63], [24, 66], [24, 67], [24, 68], [24, 77], [24, 79], [24, 84], [24, 86], [24, 89], [24, 91], [24, 95], [25, 27], [25, 31], [25, 37], [25, 38], [25, 40], [25, 41], [25, 44], [25, 46], [25, 47], [25, 48], [25, 52], [25, 54], [25, 56], [25, 58], [25, 60], [25, 61], [25, 64], [25, 67], [25, 74], [25, 77], [25, 79], [25, 84], [25, 89], [25, 91], [25, 93], [25, 96], [25, 97], [26, 27], [26, 31], [26, 34], [26, 40], [26, 44], [26, 45], [26, 47], [26, 49], [26, 50], [26, 51], [26, 53], [26, 54], [26, 65], [26, 73], [26, 76], [26, 77], [26, 83], [26, 84], [26, 89], [26, 91], [26, 94], [26, 95], [27, 29], [27, 30], [27, 36], [27, 39], [27, 41], [27, 45], [27, 51], [27, 52], [27, 53], [27, 54], [27, 56], [27, 58], [27, 60], [27, 74], [27, 82], [27, 86], [27, 88], [27, 96], [27, 99], [28, 30], [28, 32], [28, 37], [28, 38], [28, 39], [28, 42], [28, 47], [28, 51], [28, 53], [28, 54], [28, 57], [28, 59], [28, 60], [28, 63], [28, 65], [28, 66], [28, 69], [28, 72], [28, 73], [28, 74], [28, 77], [28, 79], [28, 85], [28, 87], [28, 90], [28, 92], [28, 94], [28, 99], [29, 32], [29, 33], [29, 36], [29, 38], [29, 42], [29, 43], [29, 45], [29, 48], [29, 49], [29, 52], [29, 54], [29, 55], [29, 59], [29, 67], [29, 72], [29, 75], [29, 79], [29, 80], [29, 88], [30, 34], [30, 43], [30, 45], [30, 51], [30, 52], [30, 53], [30, 54], [30, 62], [30, 65], [30, 66], [30, 79], [30, 81], [30, 84], [30, 85], [30, 89], [30, 90], [30, 93], [31, 39], [31, 41], [31, 49], [31, 51], [31, 56], [31, 57], [31, 60], [31, 66], [31, 72], [31, 79], [31, 81], [31, 87], [31, 88], [31, 92], [31, 94], [31, 98], [31, 99], [32, 33], [32, 36], [32, 49], [32, 62], [32, 65], [32, 70], [32, 71], [32, 75], [32, 77], [32, 80], [32, 88], [32, 89], [32, 94], [32, 95], [33, 34], [33, 36], [33, 39], [33, 42], [33, 49], [33, 50], [33, 52], [33, 55], [33, 56], [33, 57], [33, 61], [33, 62], [33, 63], [33, 73], [33, 74], [33, 77], [33, 81], [33, 82], [33, 83], [33, 87], [33, 92], [33, 97], [34, 39], [34, 40], [34, 41], [34, 46], [34, 51], [34, 63], [34, 65], [34, 68], [34, 73], [34, 75], [34, 79], [34, 81], [34, 82], [34, 83], [34, 86], [34, 87], [34, 88], [34, 89], [34, 90], [34, 92], [34, 95], [34, 96], [35, 39], [35, 50], [35, 54], [35, 62], [35, 64], [35, 67], [35, 68], [35, 69], [35, 72], [35, 76], [35, 77], [35, 82], [35, 83], [35, 89], [36, 38], [36, 40], [36, 44], [36, 45], [36, 48], [36, 49], [36, 51], [36, 52], [36, 55], [36, 57], [36, 58], [36, 63], [36, 66], [36, 67], [36, 68], [36, 73], [36, 74], [36, 78], [36, 82], [36, 88], [36, 89], [36, 92], [36, 94], [36, 95], [36, 97], [36, 98], [36, 99], [37, 44], [37, 48], [37, 54], [37, 55], [37, 56], [37, 57], [37, 59], [37, 60], [37, 62], [37, 65], [37, 68], [37, 73], [37, 80], [37, 90], [37, 95], [38, 44], [38, 47], [38, 53], [38, 58], [38, 59], [38, 61], [38, 63], [38, 73], [38, 75], [38, 76], [38, 78], [38, 80], [38, 81], [38, 84], [38, 92], [39, 40], [39, 43], [39, 44], [39, 45], [39, 47], [39, 54], [39, 62], [39, 65], [39, 68], [39, 70], [39, 75], [39, 78], [39, 85], [39, 88], [39, 90], [39, 93], [39, 96], [40, 43], [40, 49], [40, 54], [40, 55], [40, 56], [40, 59], [40, 61], [40, 70], [40, 72], [40, 90], [40, 98], [41, 42], [41, 45], [41, 46], [41, 56], [41, 61], [41, 62], [41, 63], [41, 64], [41, 72], [41, 80], [41, 85], [41, 87], [41, 88], [41, 91], [41, 94], [41, 96], [41, 99], [42, 46], [42, 49], [42, 53], [42, 56], [42, 57], [42, 64], [42, 66], [42, 79], [42, 81], [42, 84], [42, 85], [42, 87], [42, 90], [42, 91], [42, 93], [42, 95], [42, 97], [42, 98], [42, 99], [43, 46], [43, 50], [43, 52], [43, 54], [43, 61], [43, 72], [43, 73], [43, 75], [43, 76], [43, 80], [43, 93], [43, 96], [43, 99], [44, 46], [44, 50], [44, 57], [44, 59], [44, 61], [44, 63], [44, 64], [44, 68], [44, 72], [44, 80], [44, 91], [44, 92], [44, 93], [44, 96], [44, 97], [44, 99], [45, 48], [45, 51], [45, 58], [45, 59], [45, 60], [45, 62], [45, 64], [45, 65], [45, 71], [45, 78], [45, 79], [45, 80], [45, 91], [45, 92], [45, 98], [46, 49], [46, 52], [46, 55], [46, 59], [46, 63], [46, 67], [46, 72], [46, 73], [46, 75], [46, 77], [46, 78], [46, 81], [46, 83], [46, 86], [46, 87], [46, 89], [46, 94], [46, 95], [47, 48], [47, 50], [47, 53], [47, 57], [47, 60], [47, 61], [47, 63], [47, 66], [47, 79], [47, 80], [47, 87], [47, 90], [47, 91], [47, 92], [47, 95], [47, 97], [48, 49], [48, 51], [48, 53], [48, 58], [48, 61], [48, 67], [48, 69], [48, 70], [48, 76], [48, 79], [48, 81], [48, 90], [48, 95], [48, 96], [49, 51], [49, 52], [49, 53], [49, 56], [49, 57], [49, 62], [49, 73], [49, 74], [49, 86], [49, 89], [49, 99], [50, 51], [50, 54], [50, 58], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 72], [50, 73], [50, 80], [50, 82], [50, 83], [50, 87], [50, 88], [50, 89], [50, 94], [51, 54], [51, 62], [51, 64], [51, 69], [51, 72], [51, 74], [51, 76], [51, 77], [51, 78], [51, 79], [51, 82], [51, 84], [51, 93], [52, 54], [52, 55], [52, 56], [52, 60], [52, 62], [52, 64], [52, 66], [52, 68], [52, 71], [52, 74], [52, 77], [52, 78], [52, 90], [52, 91], [52, 97], [52, 99], [53, 55], [53, 62], [53, 63], [53, 69], [53, 75], [53, 76], [53, 79], [53, 80], [53, 81], [53, 84], [53, 89], [53, 90], [53, 92], [53, 96], [53, 98], [54, 56], [54, 60], [54, 64], [54, 67], [54, 69], [54, 75], [54, 76], [54, 81], [54, 86], [54, 87], [54, 91], [54, 92], [55, 58], [55, 63], [55, 68], [55, 70], [55, 72], [55, 73], [55, 84], [55, 86], [55, 88], [55, 93], [55, 94], [55, 95], [55, 97], [55, 99], [56, 61], [56, 63], [56, 68], [56, 74], [56, 75], [56, 80], [56, 84], [56, 86], [56, 87], [56, 89], [56, 91], [56, 95], [57, 59], [57, 62], [57, 64], [57, 68], [57, 69], [57, 70], [57, 71], [57, 77], [57, 80], [57, 82], [57, 86], [57, 87], [57, 92], [57, 93], [57, 95], [57, 98], [58, 61], [58, 62], [58, 66], [58, 68], [58, 72], [58, 73], [58, 74], [58, 79], [58, 80], [58, 82], [58, 84], [58, 86], [58, 87], [58, 88], [58, 89], [58, 92], [58, 93], [58, 97], [58, 99], [59, 64], [59, 69], [59, 71], [59, 72], [59, 74], [59, 76], [59, 82], [59, 85], [59, 87], [59, 90], [59, 94], [59, 98], [60, 63], [60, 68], [60, 71], [60, 72], [60, 74], [60, 76], [60, 82], [60, 87], [60, 93], [60, 95], [60, 96], [60, 97], [60, 98], [61, 63], [61, 64], [61, 66], [61, 67], [61, 70], [61, 73], [61, 74], [61, 80], [61, 83], [61, 84], [61, 87], [62, 67], [62, 69], [62, 70], [62, 71], [62, 72], [62, 77], [62, 83], [62, 86], [62, 89], [62, 92], [62, 97], [62, 99], [63, 65], [63, 82], [63, 83], [63, 87], [63, 91], [63, 92], [63, 95], [63, 97], [64, 68], [64, 71], [64, 72], [64, 77], [64, 78], [64, 85], [64, 86], [64, 87], [64, 93], [65, 67], [65, 68], [65, 75], [65, 77], [65, 87], [65, 89], [65, 90], [65, 91], [65, 92], [65, 96], [66, 70], [66, 80], [66, 81], [66, 83], [66, 84], [66, 87], [66, 88], [66, 95], [66, 97], [66, 98], [67, 69], [67, 70], [67, 77], [67, 78], [67, 81], [67, 82], [67, 87], [67, 91], [67, 93], [67, 96], [67, 99], [68, 74], [68, 76], [68, 78], [68, 79], [68, 81], [68, 85], [68, 86], [68, 87], [68, 91], [68, 94], [68, 95], [68, 97], [69, 70], [69, 72], [69, 73], [69, 74], [69, 79], [69, 82], [69, 90], [69, 91], [69, 99], [70, 76], [70, 78], [70, 86], [70, 87], [70, 88], [70, 91], [70, 92], [70, 95], [70, 98], [71, 76], [71, 82], [71, 83], [71, 84], [71, 92], [72, 74], [72, 79], [72, 89], [72, 91], [72, 92], [72, 94], [72, 98], [73, 78], [73, 81], [73, 82], [73, 83], [73, 88], [73, 89], [73, 93], [73, 95], [73, 96], [73, 98], [74, 75], [74, 76], [74, 80], [74, 87], [74, 88], [74, 93], [74, 94], [74, 95], [74, 96], [74, 98], [74, 99], [75, 76], [75, 79], [75, 80], [75, 85], [75, 90], [75, 91], [75, 98], [75, 99], [76, 82], [76, 84], [76, 85], [76, 87], [76, 88], [76, 90], [76, 91], [76, 92], [76, 95], [77, 89], [77, 94], [77, 95], [78, 80], [78, 94], [78, 96], [79, 83], [79, 85], [79, 87], [79, 91], [79, 92], [79, 95], [79, 98], [80, 81], [80, 85], [80, 88], [80, 90], [80, 93], [80, 94], [80, 96], [80, 99], [81, 82], [81, 86], [82, 83], [82, 84], [82, 88], [83, 84], [83, 89], [83, 93], [83, 94], [83, 99], [84, 86], [84, 87], [84, 88], [84, 93], [84, 95], [84, 96], [84, 98], [84, 99], [85, 89], [85, 90], [85, 94], [85, 97], [86, 89], [86, 90], [86, 95], [86, 96], [86, 97], [86, 98], [87, 89], [87, 93], [87, 94], [87, 95], [87, 99], [88, 90], [88, 92], [88, 93], [88, 94], [88, 98], [88, 99], [89, 91], [89, 94], [89, 95], [89, 98], [89, 99], [90, 92], [90, 94], [91, 92], [91, 93], [91, 96], [92, 95], [93, 98], [93, 99], [94, 98], [95, 96]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s7/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l4-s7/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l4-s9/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l4-s9/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5708866902161b15c5267287bc720a0eeb0efd7e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 1], [0, 7], [0, 9], [0, 17], [0, 18], [0, 21], [0, 22], [0, 25], [0, 35], [0, 36], [0, 39], [0, 51], [0, 52], [0, 54], [0, 58], [0, 59], [0, 63], [0, 64], [0, 66], [0, 72], [0, 73], [0, 75], [0, 76], [0, 79], [0, 86], [0, 90], [0, 92], [0, 99], [1, 7], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 18], [1, 20], [1, 41], [1, 45], [1, 51], [1, 54], [1, 57], [1, 62], [1, 64], [1, 70], [1, 76], [1, 78], [1, 79], [1, 86], [1, 87], [1, 91], [1, 95], [1, 97], [1, 99], [2, 10], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 21], [2, 30], [2, 32], [2, 33], [2, 41], [2, 47], [2, 48], [2, 51], [2, 53], [2, 56], [2, 58], [2, 61], [2, 62], [2, 63], [2, 66], [2, 69], [2, 70], [2, 72], [2, 75], [2, 79], [2, 88], [2, 94], [3, 4], [3, 8], [3, 10], [3, 11], [3, 15], [3, 23], [3, 25], [3, 26], [3, 29], [3, 36], [3, 40], [3, 42], [3, 44], [3, 45], [3, 47], [3, 53], [3, 54], [3, 55], [3, 60], [3, 62], [3, 63], [3, 64], [3, 66], [3, 67], [3, 71], [3, 74], [3, 80], [3, 82], [3, 83], [3, 87], [3, 92], [3, 93], [3, 94], [4, 6], [4, 7], [4, 12], [4, 13], [4, 16], [4, 21], [4, 24], [4, 26], [4, 27], [4, 29], [4, 32], [4, 36], [4, 38], [4, 43], [4, 47], [4, 51], [4, 61], [4, 62], [4, 67], [4, 73], [4, 77], [4, 80], [4, 82], [4, 84], [4, 86], [4, 96], [4, 98], [5, 6], [5, 7], [5, 10], [5, 13], [5, 17], [5, 19], [5, 20], [5, 23], [5, 25], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 39], [5, 46], [5, 47], [5, 52], [5, 56], [5, 58], [5, 59], [5, 60], [5, 65], [5, 68], [5, 69], [5, 76], [5, 79], [5, 82], [5, 83], [5, 90], [5, 93], [5, 94], [5, 96], [6, 9], [6, 11], [6, 12], [6, 22], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 31], [6, 34], [6, 38], [6, 42], [6, 43], [6, 47], [6, 49], [6, 51], [6, 52], [6, 54], [6, 56], [6, 57], [6, 62], [6, 63], [6, 65], [6, 68], [6, 70], [6, 71], [6, 72], [6, 78], [6, 86], [6, 88], [6, 90], [6, 94], [6, 96], [6, 97], [7, 8], [7, 12], [7, 14], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 32], [7, 33], [7, 36], [7, 37], [7, 42], [7, 48], [7, 50], [7, 53], [7, 54], [7, 56], [7, 57], [7, 63], [7, 65], [7, 75], [7, 76], [7, 79], [7, 81], [7, 82], [7, 87], [7, 89], [7, 97], [7, 98], [7, 99], [8, 9], [8, 11], [8, 16], [8, 23], [8, 28], [8, 29], [8, 39], [8, 41], [8, 45], [8, 51], [8, 54], [8, 55], [8, 56], [8, 58], [8, 70], [8, 73], [8, 74], [8, 75], [8, 77], [8, 87], [8, 89], [8, 90], [8, 93], [8, 95], [8, 98], [9, 10], [9, 11], [9, 14], [9, 16], [9, 18], [9, 21], [9, 22], [9, 29], [9, 30], [9, 33], [9, 35], [9, 36], [9, 38], [9, 39], [9, 42], [9, 43], [9, 44], [9, 48], [9, 50], [9, 51], [9, 54], [9, 57], [9, 59], [9, 61], [9, 62], [9, 65], [9, 66], [9, 67], [9, 69], [9, 74], [9, 76], [9, 77], [9, 81], [9, 83], [9, 85], [9, 86], [9, 91], [9, 94], [9, 99], [10, 13], [10, 14], [10, 16], [10, 25], [10, 31], [10, 32], [10, 35], [10, 39], [10, 42], [10, 44], [10, 45], [10, 48], [10, 51], [10, 53], [10, 55], [10, 56], [10, 58], [10, 60], [10, 63], [10, 66], [10, 69], [10, 81], [10, 83], [10, 85], [10, 86], [10, 88], [10, 97], [11, 25], [11, 33], [11, 35], [11, 38], [11, 39], [11, 41], [11, 43], [11, 45], [11, 48], [11, 50], [11, 53], [11, 55], [11, 64], [11, 66], [11, 67], [11, 68], [11, 69], [11, 70], [11, 73], [11, 77], [11, 83], [11, 85], [11, 87], [11, 89], [11, 96], [11, 99], [12, 13], [12, 17], [12, 18], [12, 24], [12, 28], [12, 31], [12, 36], [12, 44], [12, 46], [12, 49], [12, 53], [12, 54], [12, 73], [12, 74], [12, 83], [12, 90], [12, 92], [12, 94], [12, 97], [12, 98], [12, 99], [13, 15], [13, 20], [13, 38], [13, 40], [13, 41], [13, 47], [13, 49], [13, 50], [13, 52], [13, 53], [13, 57], [13, 61], [13, 69], [13, 72], [13, 73], [13, 77], [13, 78], [13, 83], [13, 84], [13, 90], [13, 95], [14, 15], [14, 17], [14, 20], [14, 22], [14, 23], [14, 25], [14, 27], [14, 30], [14, 41], [14, 45], [14, 51], [14, 52], [14, 54], [14, 61], [14, 62], [14, 63], [14, 64], [14, 70], [14, 72], [14, 73], [14, 76], [14, 77], [14, 81], [14, 84], [14, 87], [14, 88], [14, 93], [14, 96], [14, 98], [14, 99], [15, 22], [15, 24], [15, 25], [15, 27], [15, 31], [15, 34], [15, 38], [15, 48], [15, 58], [15, 59], [15, 60], [15, 61], [15, 71], [15, 76], [15, 82], [15, 83], [15, 88], [15, 89], [15, 96], [15, 97], [15, 99], [16, 19], [16, 20], [16, 21], [16, 24], [16, 25], [16, 26], [16, 29], [16, 31], [16, 33], [16, 49], [16, 57], [16, 58], [16, 62], [16, 64], [16, 67], [16, 70], [16, 75], [16, 80], [16, 84], [16, 87], [16, 92], [16, 95], [16, 96], [16, 97], [17, 20], [17, 32], [17, 35], [17, 36], [17, 37], [17, 39], [17, 40], [17, 43], [17, 46], [17, 47], [17, 49], [17, 50], [17, 52], [17, 57], [17, 61], [17, 62], [17, 65], [17, 67], [17, 68], [17, 69], [17, 72], [17, 73], [17, 74], [17, 76], [17, 79], [17, 80], [17, 81], [17, 82], [17, 91], [17, 92], [17, 93], [17, 95], [17, 97], [17, 98], [18, 19], [18, 22], [18, 25], [18, 26], [18, 32], [18, 33], [18, 35], [18, 36], [18, 37], [18, 42], [18, 56], [18, 58], [18, 60], [18, 64], [18, 67], [18, 71], [18, 72], [18, 77], [18, 82], [18, 83], [18, 85], [18, 88], [18, 89], [18, 93], [18, 94], [18, 99], [19, 24], [19, 27], [19, 29], [19, 31], [19, 32], [19, 35], [19, 38], [19, 39], [19, 41], [19, 45], [19, 46], [19, 47], [19, 53], [19, 54], [19, 56], [19, 60], [19, 64], [19, 66], [19, 68], [19, 70], [19, 74], [19, 76], [19, 80], [19, 82], [19, 84], [19, 85], [19, 86], [19, 89], [19, 93], [20, 25], [20, 26], [20, 28], [20, 32], [20, 37], [20, 38], [20, 39], [20, 44], [20, 46], [20, 47], [20, 50], [20, 56], [20, 58], [20, 64], [20, 68], [20, 69], [20, 71], [20, 72], [20, 74], [20, 77], [20, 81], [20, 86], [20, 88], [20, 89], [20, 92], [20, 93], [20, 95], [20, 98], [20, 99], [21, 34], [21, 35], [21, 37], [21, 50], [21, 53], [21, 55], [21, 56], [21, 57], [21, 60], [21, 64], [21, 67], [21, 68], [21, 70], [21, 76], [21, 77], [21, 78], [21, 79], [21, 81], [21, 86], [21, 87], [21, 89], [21, 94], [21, 96], [22, 27], [22, 29], [22, 33], [22, 36], [22, 37], [22, 41], [22, 44], [22, 48], [22, 49], [22, 53], [22, 65], [22, 67], [22, 70], [22, 72], [22, 76], [22, 85], [22, 89], [22, 96], [23, 26], [23, 31], [23, 34], [23, 37], [23, 38], [23, 41], [23, 42], [23, 45], [23, 46], [23, 47], [23, 49], [23, 51], [23, 52], [23, 58], [23, 61], [23, 62], [23, 68], [23, 71], [23, 80], [23, 82], [23, 83], [23, 84], [23, 89], [23, 93], [23, 95], [23, 96], [23, 97], [24, 25], [24, 29], [24, 30], [24, 36], [24, 37], [24, 38], [24, 48], [24, 49], [24, 55], [24, 57], [24, 59], [24, 60], [24, 61], [24, 65], [24, 74], [24, 75], [24, 77], [24, 81], [24, 82], [24, 92], [24, 93], [24, 97], [24, 98], [25, 28], [25, 29], [25, 30], [25, 32], [25, 36], [25, 41], [25, 43], [25, 47], [25, 48], [25, 51], [25, 52], [25, 55], [25, 59], [25, 60], [25, 64], [25, 65], [25, 69], [25, 71], [25, 78], [25, 79], [25, 80], [25, 82], [25, 84], [25, 86], [25, 87], [25, 91], [25, 93], [25, 95], [25, 96], [25, 99], [26, 27], [26, 28], [26, 33], [26, 37], [26, 41], [26, 43], [26, 44], [26, 48], [26, 51], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 61], [26, 63], [26, 65], [26, 66], [26, 68], [26, 69], [26, 72], [26, 84], [26, 87], [26, 88], [26, 95], [26, 98], [26, 99], [27, 29], [27, 31], [27, 40], [27, 51], [27, 52], [27, 56], [27, 59], [27, 60], [27, 61], [27, 67], [27, 82], [27, 84], [27, 85], [27, 89], [27, 90], [27, 91], [27, 94], [27, 95], [27, 98], [27, 99], [28, 36], [28, 38], [28, 42], [28, 47], [28, 48], [28, 50], [28, 53], [28, 54], [28, 55], [28, 56], [28, 58], [28, 61], [28, 69], [28, 84], [28, 86], [28, 91], [28, 93], [28, 95], [28, 99], [29, 30], [29, 32], [29, 34], [29, 37], [29, 39], [29, 40], [29, 44], [29, 48], [29, 49], [29, 50], [29, 61], [29, 62], [29, 64], [29, 69], [29, 70], [29, 71], [29, 72], [29, 73], [29, 80], [29, 87], [29, 91], [29, 95], [29, 99], [30, 33], [30, 35], [30, 38], [30, 40], [30, 41], [30, 44], [30, 50], [30, 55], [30, 58], [30, 67], [30, 71], [30, 73], [30, 77], [30, 79], [30, 82], [30, 84], [30, 85], [30, 86], [30, 92], [30, 98], [31, 34], [31, 37], [31, 39], [31, 47], [31, 53], [31, 54], [31, 58], [31, 64], [31, 68], [31, 74], [31, 75], [31, 76], [31, 78], [31, 79], [31, 80], [31, 86], [31, 87], [31, 88], [31, 91], [31, 95], [32, 39], [32, 41], [32, 42], [32, 43], [32, 46], [32, 48], [32, 50], [32, 52], [32, 53], [32, 63], [32, 65], [32, 66], [32, 67], [32, 69], [32, 70], [32, 83], [32, 85], [32, 86], [32, 87], [32, 92], [32, 99], [33, 35], [33, 40], [33, 46], [33, 47], [33, 56], [33, 61], [33, 66], [33, 70], [33, 71], [33, 72], [33, 75], [33, 77], [33, 78], [33, 79], [33, 87], [33, 90], [33, 93], [33, 97], [34, 37], [34, 38], [34, 40], [34, 41], [34, 44], [34, 50], [34, 51], [34, 53], [34, 55], [34, 57], [34, 68], [34, 69], [34, 72], [34, 73], [34, 77], [34, 83], [34, 84], [34, 85], [34, 92], [34, 94], [34, 95], [34, 98], [35, 39], [35, 43], [35, 51], [35, 52], [35, 54], [35, 55], [35, 56], [35, 58], [35, 60], [35, 63], [35, 67], [35, 71], [35, 72], [35, 74], [35, 75], [35, 76], [35, 77], [35, 78], [35, 79], [35, 96], [36, 38], [36, 46], [36, 50], [36, 54], [36, 57], [36, 58], [36, 60], [36, 64], [36, 69], [36, 77], [36, 78], [36, 79], [36, 82], [36, 83], [36, 86], [36, 87], [36, 90], [36, 92], [36, 94], [36, 95], [36, 96], [37, 42], [37, 45], [37, 55], [37, 56], [37, 59], [37, 62], [37, 72], [37, 73], [37, 75], [37, 77], [37, 80], [37, 81], [37, 83], [37, 84], [37, 95], [38, 39], [38, 40], [38, 44], [38, 46], [38, 48], [38, 50], [38, 53], [38, 55], [38, 56], [38, 59], [38, 65], [38, 71], [38, 87], [38, 88], [38, 94], [38, 95], [39, 50], [39, 55], [39, 57], [39, 62], [39, 70], [39, 71], [39, 73], [39, 75], [39, 81], [39, 82], [39, 84], [39, 85], [39, 87], [39, 88], [39, 90], [39, 94], [40, 43], [40, 47], [40, 49], [40, 50], [40, 56], [40, 58], [40, 64], [40, 65], [40, 68], [40, 73], [40, 78], [40, 81], [40, 83], [40, 84], [40, 86], [40, 89], [40, 91], [40, 97], [40, 98], [41, 43], [41, 44], [41, 45], [41, 47], [41, 49], [41, 51], [41, 53], [41, 60], [41, 61], [41, 62], [41, 64], [41, 66], [41, 67], [41, 68], [41, 69], [41, 73], [41, 74], [41, 75], [41, 80], [41, 81], [41, 85], [41, 86], [41, 87], [41, 88], [41, 89], [41, 90], [41, 94], [41, 96], [42, 48], [42, 52], [42, 53], [42, 58], [42, 61], [42, 65], [42, 70], [42, 75], [42, 76], [42, 78], [42, 84], [42, 85], [42, 86], [42, 88], [42, 90], [42, 95], [42, 96], [42, 98], [42, 99], [43, 44], [43, 49], [43, 50], [43, 53], [43, 59], [43, 60], [43, 61], [43, 64], [43, 65], [43, 66], [43, 68], [43, 69], [43, 75], [43, 78], [43, 79], [43, 83], [43, 97], [43, 98], [43, 99], [44, 47], [44, 51], [44, 54], [44, 57], [44, 59], [44, 61], [44, 64], [44, 71], [44, 73], [44, 75], [44, 77], [44, 80], [44, 83], [44, 98], [45, 46], [45, 47], [45, 48], [45, 50], [45, 53], [45, 55], [45, 58], [45, 60], [45, 62], [45, 67], [45, 69], [45, 72], [45, 75], [45, 77], [45, 82], [45, 83], [45, 87], [45, 89], [45, 91], [45, 93], [45, 94], [45, 97], [46, 49], [46, 51], [46, 54], [46, 56], [46, 58], [46, 59], [46, 62], [46, 67], [46, 68], [46, 71], [46, 85], [46, 88], [46, 91], [46, 92], [46, 95], [46, 97], [46, 98], [47, 49], [47, 65], [47, 67], [47, 68], [47, 74], [47, 76], [47, 81], [47, 83], [47, 85], [47, 86], [47, 93], [47, 97], [47, 98], [47, 99], [48, 49], [48, 51], [48, 55], [48, 57], [48, 64], [48, 73], [48, 76], [48, 78], [48, 79], [48, 83], [48, 84], [48, 88], [48, 89], [48, 93], [48, 94], [48, 95], [49, 50], [49, 51], [49, 56], [49, 57], [49, 58], [49, 63], [49, 67], [49, 69], [49, 71], [49, 75], [49, 79], [49, 86], [49, 88], [49, 91], [49, 94], [49, 97], [50, 52], [50, 53], [50, 68], [50, 70], [50, 76], [50, 77], [51, 59], [51, 60], [51, 61], [51, 65], [51, 71], [51, 74], [51, 75], [51, 83], [51, 85], [51, 86], [51, 89], [51, 90], [51, 91], [51, 96], [51, 97], [51, 99], [52, 58], [52, 59], [52, 60], [52, 62], [52, 65], [52, 67], [52, 69], [52, 72], [52, 73], [52, 74], [52, 75], [52, 83], [52, 84], [52, 85], [52, 87], [52, 95], [53, 54], [53, 56], [53, 58], [53, 59], [53, 61], [53, 63], [53, 68], [53, 75], [53, 76], [53, 84], [53, 88], [53, 95], [53, 98], [54, 57], [54, 58], [54, 62], [54, 65], [54, 67], [54, 68], [54, 70], [54, 72], [54, 73], [54, 80], [54, 84], [54, 87], [54, 89], [54, 90], [55, 60], [55, 63], [55, 64], [55, 65], [55, 68], [55, 69], [55, 71], [55, 73], [55, 75], [55, 76], [55, 80], [55, 82], [55, 85], [55, 92], [55, 95], [55, 97], [56, 57], [56, 67], [56, 70], [56, 72], [56, 74], [56, 75], [56, 82], [56, 84], [56, 87], [56, 92], [56, 94], [56, 98], [56, 99], [57, 62], [57, 65], [57, 71], [57, 73], [57, 75], [57, 80], [57, 88], [57, 89], [57, 90], [57, 97], [57, 98], [58, 63], [58, 71], [58, 76], [58, 82], [58, 85], [58, 88], [58, 95], [58, 96], [59, 65], [59, 69], [59, 71], [59, 76], [59, 80], [59, 81], [59, 84], [59, 87], [59, 97], [59, 98], [59, 99], [60, 70], [60, 72], [60, 73], [60, 75], [60, 80], [60, 81], [60, 97], [60, 99], [61, 62], [61, 65], [61, 66], [61, 67], [61, 73], [61, 75], [61, 79], [61, 81], [61, 94], [61, 95], [62, 65], [62, 67], [62, 68], [62, 70], [62, 71], [62, 72], [62, 73], [62, 78], [62, 81], [62, 86], [62, 87], [62, 90], [62, 92], [62, 93], [62, 96], [62, 97], [62, 98], [63, 68], [63, 69], [63, 72], [63, 75], [63, 76], [63, 77], [63, 79], [63, 83], [63, 85], [63, 88], [63, 89], [63, 90], [63, 92], [63, 93], [63, 99], [64, 67], [64, 68], [64, 70], [64, 73], [64, 75], [64, 76], [64, 77], [64, 80], [64, 84], [64, 85], [64, 86], [64, 93], [64, 94], [64, 95], [64, 96], [64, 98], [65, 67], [65, 69], [65, 75], [65, 76], [65, 79], [65, 82], [65, 84], [65, 87], [65, 91], [65, 92], [65, 94], [65, 95], [66, 67], [66, 71], [66, 80], [66, 82], [66, 85], [66, 87], [66, 90], [66, 93], [66, 94], [66, 97], [66, 98], [67, 68], [67, 71], [67, 78], [67, 79], [67, 81], [67, 84], [67, 87], [67, 89], [67, 93], [68, 79], [68, 83], [68, 86], [68, 93], [69, 70], [69, 71], [69, 76], [69, 77], [69, 78], [69, 79], [69, 82], [69, 84], [69, 89], [69, 93], [69, 95], [70, 73], [70, 83], [70, 86], [70, 88], [70, 90], [70, 97], [71, 74], [71, 75], [71, 79], [71, 86], [71, 93], [71, 94], [71, 96], [72, 74], [72, 75], [72, 76], [72, 79], [72, 81], [72, 83], [72, 93], [73, 76], [73, 82], [73, 83], [73, 84], [73, 91], [73, 96], [73, 99], [74, 76], [74, 77], [74, 80], [74, 93], [74, 94], [74, 98], [74, 99], [75, 76], [75, 78], [75, 85], [75, 87], [75, 88], [75, 91], [75, 99], [76, 80], [76, 81], [76, 92], [76, 93], [76, 94], [76, 98], [77, 83], [77, 86], [77, 95], [77, 96], [77, 97], [77, 99], [78, 79], [78, 82], [78, 83], [78, 86], [78, 89], [78, 91], [78, 92], [79, 80], [79, 82], [79, 83], [79, 93], [79, 95], [79, 96], [80, 81], [80, 85], [80, 91], [80, 97], [80, 99], [81, 88], [81, 93], [81, 96], [81, 97], [81, 98], [82, 84], [82, 85], [82, 87], [82, 91], [82, 92], [82, 94], [82, 95], [83, 86], [83, 91], [83, 93], [83, 94], [83, 95], [83, 96], [83, 98], [83, 99], [84, 85], [84, 87], [84, 90], [84, 96], [85, 86], [85, 89], [86, 90], [86, 93], [86, 97], [86, 99], [88, 92], [89, 91], [89, 96], [89, 97], [89, 98], [89, 99], [90, 91], [90, 92], [90, 96], [91, 99], [92, 95], [92, 99], [94, 95], [94, 96], [94, 98], [95, 97], [95, 98], [96, 97], [97, 98]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s9/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8a6dd1f15b611f51638abfbad768a16658cacf68 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [11, 20, 21, 25, 26, 29, 38, 41, 54, 57, 60, 64, 67, 75, 76, 82, 90, 94, 96, 97]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s9/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s9/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-s9/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5708866902161b15c5267287bc720a0eeb0efd7e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 1], [0, 7], [0, 9], [0, 17], [0, 18], [0, 21], [0, 22], [0, 25], [0, 35], [0, 36], [0, 39], [0, 51], [0, 52], [0, 54], [0, 58], [0, 59], [0, 63], [0, 64], [0, 66], [0, 72], [0, 73], [0, 75], [0, 76], [0, 79], [0, 86], [0, 90], [0, 92], [0, 99], [1, 7], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 18], [1, 20], [1, 41], [1, 45], [1, 51], [1, 54], [1, 57], [1, 62], [1, 64], [1, 70], [1, 76], [1, 78], [1, 79], [1, 86], [1, 87], [1, 91], [1, 95], [1, 97], [1, 99], [2, 10], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 21], [2, 30], [2, 32], [2, 33], [2, 41], [2, 47], [2, 48], [2, 51], [2, 53], [2, 56], [2, 58], [2, 61], [2, 62], [2, 63], [2, 66], [2, 69], [2, 70], [2, 72], [2, 75], [2, 79], [2, 88], [2, 94], [3, 4], [3, 8], [3, 10], [3, 11], [3, 15], [3, 23], [3, 25], [3, 26], [3, 29], [3, 36], [3, 40], [3, 42], [3, 44], [3, 45], [3, 47], [3, 53], [3, 54], [3, 55], [3, 60], [3, 62], [3, 63], [3, 64], [3, 66], [3, 67], [3, 71], [3, 74], [3, 80], [3, 82], [3, 83], [3, 87], [3, 92], [3, 93], [3, 94], [4, 6], [4, 7], [4, 12], [4, 13], [4, 16], [4, 21], [4, 24], [4, 26], [4, 27], [4, 29], [4, 32], [4, 36], [4, 38], [4, 43], [4, 47], [4, 51], [4, 61], [4, 62], [4, 67], [4, 73], [4, 77], [4, 80], [4, 82], [4, 84], [4, 86], [4, 96], [4, 98], [5, 6], [5, 7], [5, 10], [5, 13], [5, 17], [5, 19], [5, 20], [5, 23], [5, 25], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 39], [5, 46], [5, 47], [5, 52], [5, 56], [5, 58], [5, 59], [5, 60], [5, 65], [5, 68], [5, 69], [5, 76], [5, 79], [5, 82], [5, 83], [5, 90], [5, 93], [5, 94], [5, 96], [6, 9], [6, 11], [6, 12], [6, 22], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 31], [6, 34], [6, 38], [6, 42], [6, 43], [6, 47], [6, 49], [6, 51], [6, 52], [6, 54], [6, 56], [6, 57], [6, 62], [6, 63], [6, 65], [6, 68], [6, 70], [6, 71], [6, 72], [6, 78], [6, 86], [6, 88], [6, 90], [6, 94], [6, 96], [6, 97], [7, 8], [7, 12], [7, 14], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 32], [7, 33], [7, 36], [7, 37], [7, 42], [7, 48], [7, 50], [7, 53], [7, 54], [7, 56], [7, 57], [7, 63], [7, 65], [7, 75], [7, 76], [7, 79], [7, 81], [7, 82], [7, 87], [7, 89], [7, 97], [7, 98], [7, 99], [8, 9], [8, 11], [8, 16], [8, 23], [8, 28], [8, 29], [8, 39], [8, 41], [8, 45], [8, 51], [8, 54], [8, 55], [8, 56], [8, 58], [8, 70], [8, 73], [8, 74], [8, 75], [8, 77], [8, 87], [8, 89], [8, 90], [8, 93], [8, 95], [8, 98], [9, 10], [9, 11], [9, 14], [9, 16], [9, 18], [9, 21], [9, 22], [9, 29], [9, 30], [9, 33], [9, 35], [9, 36], [9, 38], [9, 39], [9, 42], [9, 43], [9, 44], [9, 48], [9, 50], [9, 51], [9, 54], [9, 57], [9, 59], [9, 61], [9, 62], [9, 65], [9, 66], [9, 67], [9, 69], [9, 74], [9, 76], [9, 77], [9, 81], [9, 83], [9, 85], [9, 86], [9, 91], [9, 94], [9, 99], [10, 13], [10, 14], [10, 16], [10, 25], [10, 31], [10, 32], [10, 35], [10, 39], [10, 42], [10, 44], [10, 45], [10, 48], [10, 51], [10, 53], [10, 55], [10, 56], [10, 58], [10, 60], [10, 63], [10, 66], [10, 69], [10, 81], [10, 83], [10, 85], [10, 86], [10, 88], [10, 97], [11, 25], [11, 33], [11, 35], [11, 38], [11, 39], [11, 41], [11, 43], [11, 45], [11, 48], [11, 50], [11, 53], [11, 55], [11, 64], [11, 66], [11, 67], [11, 68], [11, 69], [11, 70], [11, 73], [11, 77], [11, 83], [11, 85], [11, 87], [11, 89], [11, 96], [11, 99], [12, 13], [12, 17], [12, 18], [12, 24], [12, 28], [12, 31], [12, 36], [12, 44], [12, 46], [12, 49], [12, 53], [12, 54], [12, 73], [12, 74], [12, 83], [12, 90], [12, 92], [12, 94], [12, 97], [12, 98], [12, 99], [13, 15], [13, 20], [13, 38], [13, 40], [13, 41], [13, 47], [13, 49], [13, 50], [13, 52], [13, 53], [13, 57], [13, 61], [13, 69], [13, 72], [13, 73], [13, 77], [13, 78], [13, 83], [13, 84], [13, 90], [13, 95], [14, 15], [14, 17], [14, 20], [14, 22], [14, 23], [14, 25], [14, 27], [14, 30], [14, 41], [14, 45], [14, 51], [14, 52], [14, 54], [14, 61], [14, 62], [14, 63], [14, 64], [14, 70], [14, 72], [14, 73], [14, 76], [14, 77], [14, 81], [14, 84], [14, 87], [14, 88], [14, 93], [14, 96], [14, 98], [14, 99], [15, 22], [15, 24], [15, 25], [15, 27], [15, 31], [15, 34], [15, 38], [15, 48], [15, 58], [15, 59], [15, 60], [15, 61], [15, 71], [15, 76], [15, 82], [15, 83], [15, 88], [15, 89], [15, 96], [15, 97], [15, 99], [16, 19], [16, 20], [16, 21], [16, 24], [16, 25], [16, 26], [16, 29], [16, 31], [16, 33], [16, 49], [16, 57], [16, 58], [16, 62], [16, 64], [16, 67], [16, 70], [16, 75], [16, 80], [16, 84], [16, 87], [16, 92], [16, 95], [16, 96], [16, 97], [17, 20], [17, 32], [17, 35], [17, 36], [17, 37], [17, 39], [17, 40], [17, 43], [17, 46], [17, 47], [17, 49], [17, 50], [17, 52], [17, 57], [17, 61], [17, 62], [17, 65], [17, 67], [17, 68], [17, 69], [17, 72], [17, 73], [17, 74], [17, 76], [17, 79], [17, 80], [17, 81], [17, 82], [17, 91], [17, 92], [17, 93], [17, 95], [17, 97], [17, 98], [18, 19], [18, 22], [18, 25], [18, 26], [18, 32], [18, 33], [18, 35], [18, 36], [18, 37], [18, 42], [18, 56], [18, 58], [18, 60], [18, 64], [18, 67], [18, 71], [18, 72], [18, 77], [18, 82], [18, 83], [18, 85], [18, 88], [18, 89], [18, 93], [18, 94], [18, 99], [19, 24], [19, 27], [19, 29], [19, 31], [19, 32], [19, 35], [19, 38], [19, 39], [19, 41], [19, 45], [19, 46], [19, 47], [19, 53], [19, 54], [19, 56], [19, 60], [19, 64], [19, 66], [19, 68], [19, 70], [19, 74], [19, 76], [19, 80], [19, 82], [19, 84], [19, 85], [19, 86], [19, 89], [19, 93], [20, 25], [20, 26], [20, 28], [20, 32], [20, 37], [20, 38], [20, 39], [20, 44], [20, 46], [20, 47], [20, 50], [20, 56], [20, 58], [20, 64], [20, 68], [20, 69], [20, 71], [20, 72], [20, 74], [20, 77], [20, 81], [20, 86], [20, 88], [20, 89], [20, 92], [20, 93], [20, 95], [20, 98], [20, 99], [21, 34], [21, 35], [21, 37], [21, 50], [21, 53], [21, 55], [21, 56], [21, 57], [21, 60], [21, 64], [21, 67], [21, 68], [21, 70], [21, 76], [21, 77], [21, 78], [21, 79], [21, 81], [21, 86], [21, 87], [21, 89], [21, 94], [21, 96], [22, 27], [22, 29], [22, 33], [22, 36], [22, 37], [22, 41], [22, 44], [22, 48], [22, 49], [22, 53], [22, 65], [22, 67], [22, 70], [22, 72], [22, 76], [22, 85], [22, 89], [22, 96], [23, 26], [23, 31], [23, 34], [23, 37], [23, 38], [23, 41], [23, 42], [23, 45], [23, 46], [23, 47], [23, 49], [23, 51], [23, 52], [23, 58], [23, 61], [23, 62], [23, 68], [23, 71], [23, 80], [23, 82], [23, 83], [23, 84], [23, 89], [23, 93], [23, 95], [23, 96], [23, 97], [24, 25], [24, 29], [24, 30], [24, 36], [24, 37], [24, 38], [24, 48], [24, 49], [24, 55], [24, 57], [24, 59], [24, 60], [24, 61], [24, 65], [24, 74], [24, 75], [24, 77], [24, 81], [24, 82], [24, 92], [24, 93], [24, 97], [24, 98], [25, 28], [25, 29], [25, 30], [25, 32], [25, 36], [25, 41], [25, 43], [25, 47], [25, 48], [25, 51], [25, 52], [25, 55], [25, 59], [25, 60], [25, 64], [25, 65], [25, 69], [25, 71], [25, 78], [25, 79], [25, 80], [25, 82], [25, 84], [25, 86], [25, 87], [25, 91], [25, 93], [25, 95], [25, 96], [25, 99], [26, 27], [26, 28], [26, 33], [26, 37], [26, 41], [26, 43], [26, 44], [26, 48], [26, 51], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 61], [26, 63], [26, 65], [26, 66], [26, 68], [26, 69], [26, 72], [26, 84], [26, 87], [26, 88], [26, 95], [26, 98], [26, 99], [27, 29], [27, 31], [27, 40], [27, 51], [27, 52], [27, 56], [27, 59], [27, 60], [27, 61], [27, 67], [27, 82], [27, 84], [27, 85], [27, 89], [27, 90], [27, 91], [27, 94], [27, 95], [27, 98], [27, 99], [28, 36], [28, 38], [28, 42], [28, 47], [28, 48], [28, 50], [28, 53], [28, 54], [28, 55], [28, 56], [28, 58], [28, 61], [28, 69], [28, 84], [28, 86], [28, 91], [28, 93], [28, 95], [28, 99], [29, 30], [29, 32], [29, 34], [29, 37], [29, 39], [29, 40], [29, 44], [29, 48], [29, 49], [29, 50], [29, 61], [29, 62], [29, 64], [29, 69], [29, 70], [29, 71], [29, 72], [29, 73], [29, 80], [29, 87], [29, 91], [29, 95], [29, 99], [30, 33], [30, 35], [30, 38], [30, 40], [30, 41], [30, 44], [30, 50], [30, 55], [30, 58], [30, 67], [30, 71], [30, 73], [30, 77], [30, 79], [30, 82], [30, 84], [30, 85], [30, 86], [30, 92], [30, 98], [31, 34], [31, 37], [31, 39], [31, 47], [31, 53], [31, 54], [31, 58], [31, 64], [31, 68], [31, 74], [31, 75], [31, 76], [31, 78], [31, 79], [31, 80], [31, 86], [31, 87], [31, 88], [31, 91], [31, 95], [32, 39], [32, 41], [32, 42], [32, 43], [32, 46], [32, 48], [32, 50], [32, 52], [32, 53], [32, 63], [32, 65], [32, 66], [32, 67], [32, 69], [32, 70], [32, 83], [32, 85], [32, 86], [32, 87], [32, 92], [32, 99], [33, 35], [33, 40], [33, 46], [33, 47], [33, 56], [33, 61], [33, 66], [33, 70], [33, 71], [33, 72], [33, 75], [33, 77], [33, 78], [33, 79], [33, 87], [33, 90], [33, 93], [33, 97], [34, 37], [34, 38], [34, 40], [34, 41], [34, 44], [34, 50], [34, 51], [34, 53], [34, 55], [34, 57], [34, 68], [34, 69], [34, 72], [34, 73], [34, 77], [34, 83], [34, 84], [34, 85], [34, 92], [34, 94], [34, 95], [34, 98], [35, 39], [35, 43], [35, 51], [35, 52], [35, 54], [35, 55], [35, 56], [35, 58], [35, 60], [35, 63], [35, 67], [35, 71], [35, 72], [35, 74], [35, 75], [35, 76], [35, 77], [35, 78], [35, 79], [35, 96], [36, 38], [36, 46], [36, 50], [36, 54], [36, 57], [36, 58], [36, 60], [36, 64], [36, 69], [36, 77], [36, 78], [36, 79], [36, 82], [36, 83], [36, 86], [36, 87], [36, 90], [36, 92], [36, 94], [36, 95], [36, 96], [37, 42], [37, 45], [37, 55], [37, 56], [37, 59], [37, 62], [37, 72], [37, 73], [37, 75], [37, 77], [37, 80], [37, 81], [37, 83], [37, 84], [37, 95], [38, 39], [38, 40], [38, 44], [38, 46], [38, 48], [38, 50], [38, 53], [38, 55], [38, 56], [38, 59], [38, 65], [38, 71], [38, 87], [38, 88], [38, 94], [38, 95], [39, 50], [39, 55], [39, 57], [39, 62], [39, 70], [39, 71], [39, 73], [39, 75], [39, 81], [39, 82], [39, 84], [39, 85], [39, 87], [39, 88], [39, 90], [39, 94], [40, 43], [40, 47], [40, 49], [40, 50], [40, 56], [40, 58], [40, 64], [40, 65], [40, 68], [40, 73], [40, 78], [40, 81], [40, 83], [40, 84], [40, 86], [40, 89], [40, 91], [40, 97], [40, 98], [41, 43], [41, 44], [41, 45], [41, 47], [41, 49], [41, 51], [41, 53], [41, 60], [41, 61], [41, 62], [41, 64], [41, 66], [41, 67], [41, 68], [41, 69], [41, 73], [41, 74], [41, 75], [41, 80], [41, 81], [41, 85], [41, 86], [41, 87], [41, 88], [41, 89], [41, 90], [41, 94], [41, 96], [42, 48], [42, 52], [42, 53], [42, 58], [42, 61], [42, 65], [42, 70], [42, 75], [42, 76], [42, 78], [42, 84], [42, 85], [42, 86], [42, 88], [42, 90], [42, 95], [42, 96], [42, 98], [42, 99], [43, 44], [43, 49], [43, 50], [43, 53], [43, 59], [43, 60], [43, 61], [43, 64], [43, 65], [43, 66], [43, 68], [43, 69], [43, 75], [43, 78], [43, 79], [43, 83], [43, 97], [43, 98], [43, 99], [44, 47], [44, 51], [44, 54], [44, 57], [44, 59], [44, 61], [44, 64], [44, 71], [44, 73], [44, 75], [44, 77], [44, 80], [44, 83], [44, 98], [45, 46], [45, 47], [45, 48], [45, 50], [45, 53], [45, 55], [45, 58], [45, 60], [45, 62], [45, 67], [45, 69], [45, 72], [45, 75], [45, 77], [45, 82], [45, 83], [45, 87], [45, 89], [45, 91], [45, 93], [45, 94], [45, 97], [46, 49], [46, 51], [46, 54], [46, 56], [46, 58], [46, 59], [46, 62], [46, 67], [46, 68], [46, 71], [46, 85], [46, 88], [46, 91], [46, 92], [46, 95], [46, 97], [46, 98], [47, 49], [47, 65], [47, 67], [47, 68], [47, 74], [47, 76], [47, 81], [47, 83], [47, 85], [47, 86], [47, 93], [47, 97], [47, 98], [47, 99], [48, 49], [48, 51], [48, 55], [48, 57], [48, 64], [48, 73], [48, 76], [48, 78], [48, 79], [48, 83], [48, 84], [48, 88], [48, 89], [48, 93], [48, 94], [48, 95], [49, 50], [49, 51], [49, 56], [49, 57], [49, 58], [49, 63], [49, 67], [49, 69], [49, 71], [49, 75], [49, 79], [49, 86], [49, 88], [49, 91], [49, 94], [49, 97], [50, 52], [50, 53], [50, 68], [50, 70], [50, 76], [50, 77], [51, 59], [51, 60], [51, 61], [51, 65], [51, 71], [51, 74], [51, 75], [51, 83], [51, 85], [51, 86], [51, 89], [51, 90], [51, 91], [51, 96], [51, 97], [51, 99], [52, 58], [52, 59], [52, 60], [52, 62], [52, 65], [52, 67], [52, 69], [52, 72], [52, 73], [52, 74], [52, 75], [52, 83], [52, 84], [52, 85], [52, 87], [52, 95], [53, 54], [53, 56], [53, 58], [53, 59], [53, 61], [53, 63], [53, 68], [53, 75], [53, 76], [53, 84], [53, 88], [53, 95], [53, 98], [54, 57], [54, 58], [54, 62], [54, 65], [54, 67], [54, 68], [54, 70], [54, 72], [54, 73], [54, 80], [54, 84], [54, 87], [54, 89], [54, 90], [55, 60], [55, 63], [55, 64], [55, 65], [55, 68], [55, 69], [55, 71], [55, 73], [55, 75], [55, 76], [55, 80], [55, 82], [55, 85], [55, 92], [55, 95], [55, 97], [56, 57], [56, 67], [56, 70], [56, 72], [56, 74], [56, 75], [56, 82], [56, 84], [56, 87], [56, 92], [56, 94], [56, 98], [56, 99], [57, 62], [57, 65], [57, 71], [57, 73], [57, 75], [57, 80], [57, 88], [57, 89], [57, 90], [57, 97], [57, 98], [58, 63], [58, 71], [58, 76], [58, 82], [58, 85], [58, 88], [58, 95], [58, 96], [59, 65], [59, 69], [59, 71], [59, 76], [59, 80], [59, 81], [59, 84], [59, 87], [59, 97], [59, 98], [59, 99], [60, 70], [60, 72], [60, 73], [60, 75], [60, 80], [60, 81], [60, 97], [60, 99], [61, 62], [61, 65], [61, 66], [61, 67], [61, 73], [61, 75], [61, 79], [61, 81], [61, 94], [61, 95], [62, 65], [62, 67], [62, 68], [62, 70], [62, 71], [62, 72], [62, 73], [62, 78], [62, 81], [62, 86], [62, 87], [62, 90], [62, 92], [62, 93], [62, 96], [62, 97], [62, 98], [63, 68], [63, 69], [63, 72], [63, 75], [63, 76], [63, 77], [63, 79], [63, 83], [63, 85], [63, 88], [63, 89], [63, 90], [63, 92], [63, 93], [63, 99], [64, 67], [64, 68], [64, 70], [64, 73], [64, 75], [64, 76], [64, 77], [64, 80], [64, 84], [64, 85], [64, 86], [64, 93], [64, 94], [64, 95], [64, 96], [64, 98], [65, 67], [65, 69], [65, 75], [65, 76], [65, 79], [65, 82], [65, 84], [65, 87], [65, 91], [65, 92], [65, 94], [65, 95], [66, 67], [66, 71], [66, 80], [66, 82], [66, 85], [66, 87], [66, 90], [66, 93], [66, 94], [66, 97], [66, 98], [67, 68], [67, 71], [67, 78], [67, 79], [67, 81], [67, 84], [67, 87], [67, 89], [67, 93], [68, 79], [68, 83], [68, 86], [68, 93], [69, 70], [69, 71], [69, 76], [69, 77], [69, 78], [69, 79], [69, 82], [69, 84], [69, 89], [69, 93], [69, 95], [70, 73], [70, 83], [70, 86], [70, 88], [70, 90], [70, 97], [71, 74], [71, 75], [71, 79], [71, 86], [71, 93], [71, 94], [71, 96], [72, 74], [72, 75], [72, 76], [72, 79], [72, 81], [72, 83], [72, 93], [73, 76], [73, 82], [73, 83], [73, 84], [73, 91], [73, 96], [73, 99], [74, 76], [74, 77], [74, 80], [74, 93], [74, 94], [74, 98], [74, 99], [75, 76], [75, 78], [75, 85], [75, 87], [75, 88], [75, 91], [75, 99], [76, 80], [76, 81], [76, 92], [76, 93], [76, 94], [76, 98], [77, 83], [77, 86], [77, 95], [77, 96], [77, 97], [77, 99], [78, 79], [78, 82], [78, 83], [78, 86], [78, 89], [78, 91], [78, 92], [79, 80], [79, 82], [79, 83], [79, 93], [79, 95], [79, 96], [80, 81], [80, 85], [80, 91], [80, 97], [80, 99], [81, 88], [81, 93], [81, 96], [81, 97], [81, 98], [82, 84], [82, 85], [82, 87], [82, 91], [82, 92], [82, 94], [82, 95], [83, 86], [83, 91], [83, 93], [83, 94], [83, 95], [83, 96], [83, 98], [83, 99], [84, 85], [84, 87], [84, 90], [84, 96], [85, 86], [85, 89], [86, 90], [86, 93], [86, 97], [86, 99], [88, 92], [89, 91], [89, 96], [89, 97], [89, 98], [89, 99], [90, 91], [90, 92], [90, 96], [91, 99], [92, 95], [92, 99], [94, 95], [94, 96], [94, 98], [95, 97], [95, 98], [96, 97], [97, 98]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s9/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l4-s9/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-independent-set-l1-s6/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l1-s6/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c7ee620177fe9eb34a8e6aaa198e3472cce82cad --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 2], [0, 3], [0, 4], [1, 2], [2, 3], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 6], [4, 7], [5, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s6/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7bd3154a06b175b84f15d23d392fede83f5d716 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [0, 1, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s6/tests/check.py b/tasks/construct-nppc-independent-set-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-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-l1-s6/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c7ee620177fe9eb34a8e6aaa198e3472cce82cad --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 2], [0, 3], [0, 4], [1, 2], [2, 3], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7], [4, 6], [4, 7], [5, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s6/tests/run.py b/tasks/construct-nppc-independent-set-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l1-s6/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-quad-diophantine-l4-s9/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l4-s9/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..45e8b76060ef41ceb24be9790180a13e3a7ff4f7 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"a": 130169, "b": 175976, "c": 1830899032512, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s9/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9437ecca61546c64d0de7a2aeeba37683b8b18eb --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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' +{"x": 3740, "y": 57662} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s9/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s9/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-s9/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..45e8b76060ef41ceb24be9790180a13e3a7ff4f7 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"a": 130169, "b": 175976, "c": 1830899032512, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s9/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l4-s9/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quadratic-congruence-l4-s8/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s8/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ffdf6952e833d713da5c7d074403fc5abc06106 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"a": 22300, "b": 45397, "c": 552952, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s8/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f224b21c1acf4a1ff8953d2b7a592887db18d9e --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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' +{"x": 267987} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s8/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-s8/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ffdf6952e833d713da5c7d074403fc5abc06106 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"a": 22300, "b": 45397, "c": 552952, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s8/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s9/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l4-s9/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f9a77a766053c1ecd18e39f0d8bf53d214ee95a4 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"a": 216112, "b": 552092, "c": 2798116, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s9/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5c464d8f6d9554fd933ca6f80b7523ebca3ff60f --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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' +{"x": 2672004} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s9/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-s9/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f9a77a766053c1ecd18e39f0d8bf53d214ee95a4 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"a": 216112, "b": 552092, "c": 2798116, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l4-s9/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-vertex-cover-l6-s2/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l6-s2/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06c938c83fdd58b90c93c2c69234eb0f00661d24 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 108], [0, 125], [0, 127], [0, 137], [0, 147], [0, 158], [1, 20], [1, 71], [1, 96], [1, 124], [1, 128], [1, 136], [1, 137], [1, 153], [2, 6], [2, 7], [2, 15], [2, 18], [2, 24], [2, 27], [2, 32], [2, 45], [2, 49], [2, 57], [2, 63], [2, 64], [2, 66], [2, 68], [2, 73], [2, 74], [2, 88], [2, 91], [2, 95], [2, 96], [2, 103], [2, 104], [2, 118], [2, 127], [2, 128], [2, 136], [2, 139], [2, 145], [2, 148], [2, 152], [2, 153], [3, 19], [3, 20], [3, 23], [3, 38], [3, 41], [3, 46], [3, 49], [3, 53], [3, 77], [3, 85], [3, 88], [3, 102], [3, 120], [3, 124], [4, 21], [4, 40], [4, 53], [4, 68], [4, 74], [4, 103], [4, 106], [4, 108], [4, 145], [5, 6], [5, 7], [5, 40], [5, 71], [5, 102], [5, 103], [5, 128], [5, 132], [5, 141], [5, 158], [6, 13], [6, 25], [6, 28], [6, 44], [6, 45], [6, 46], [6, 47], [6, 50], [6, 52], [6, 53], [6, 55], [6, 57], [6, 58], [6, 60], [6, 65], [6, 81], [6, 87], [6, 98], [6, 100], [6, 102], [6, 103], [6, 105], [6, 108], [6, 114], [6, 120], [6, 127], [6, 131], [6, 132], [6, 135], [6, 137], [6, 141], [6, 148], [6, 151], [6, 153], [7, 19], [7, 23], [7, 36], [7, 38], [7, 41], [7, 42], [7, 53], [7, 59], [7, 60], [7, 65], [7, 70], [7, 81], [7, 83], [7, 87], [7, 88], [7, 91], [7, 98], [7, 104], [7, 110], [7, 113], [7, 114], [7, 122], [7, 123], [7, 125], [7, 129], [7, 132], [7, 136], [7, 138], [7, 140], [7, 143], [7, 145], [7, 148], [7, 153], [8, 68], [8, 77], [8, 99], [8, 103], [8, 113], [8, 148], [8, 153], [8, 158], [9, 12], [9, 14], [9, 22], [9, 29], [9, 40], [9, 43], [9, 45], [9, 67], [9, 71], [9, 79], [9, 85], [9, 88], [9, 94], [9, 95], [9, 96], [9, 97], [9, 104], [9, 108], [9, 113], [9, 115], [9, 131], [9, 132], [9, 133], [9, 135], [9, 137], [9, 140], [9, 151], [9, 152], [9, 156], [9, 157], [9, 158], [10, 19], [10, 28], [10, 49], [10, 67], [10, 95], [10, 103], [10, 120], [10, 138], [10, 148], [10, 150], [11, 20], [11, 36], [11, 52], [11, 66], [11, 101], [11, 103], [11, 104], [11, 106], [11, 108], [11, 136], [11, 137], [11, 158], [12, 21], [12, 36], [12, 46], [12, 48], [12, 50], [12, 53], [12, 57], [12, 61], [12, 63], [12, 68], [12, 70], [12, 77], [12, 80], [12, 81], [12, 85], [12, 92], [12, 98], [12, 103], [12, 106], [12, 118], [12, 121], [12, 126], [12, 129], [12, 137], [12, 145], [12, 149], [12, 154], [12, 159], [13, 21], [13, 52], [13, 66], [13, 85], [13, 88], [13, 96], [13, 120], [13, 136], [13, 159], [14, 19], [14, 39], [14, 68], [14, 69], [14, 71], [14, 77], [14, 88], [14, 102], [14, 125], [14, 127], [14, 145], [14, 158], [14, 159], [15, 23], [15, 24], [15, 26], [15, 36], [15, 40], [15, 57], [15, 78], [15, 80], [15, 85], [15, 89], [15, 90], [15, 98], [15, 103], [15, 107], [15, 108], [15, 113], [15, 117], [15, 130], [15, 132], [15, 133], [15, 137], [15, 138], [15, 140], [15, 143], [15, 144], [15, 146], [15, 147], [15, 152], [15, 154], [16, 20], [16, 23], [16, 94], [16, 98], [16, 99], [16, 138], [16, 141], [16, 150], [16, 153], [17, 19], [17, 46], [17, 69], [17, 77], [18, 69], [18, 91], [18, 99], [18, 113], [18, 120], [18, 127], [18, 135], [18, 158], [19, 20], [19, 33], [19, 35], [19, 36], [19, 37], [19, 40], [19, 42], [19, 45], [19, 51], [19, 55], [19, 57], [19, 58], [19, 64], [19, 65], [19, 73], [19, 82], [19, 86], [19, 89], [19, 91], [19, 101], [19, 104], [19, 108], [19, 112], [19, 113], [19, 115], [19, 128], [19, 131], [19, 136], [19, 145], [19, 147], [19, 148], [19, 154], [19, 158], [20, 26], [20, 33], [20, 39], [20, 43], [20, 54], [20, 56], [20, 57], [20, 70], [20, 71], [20, 76], [20, 80], [20, 83], [20, 84], [20, 87], [20, 93], [20, 95], [20, 115], [20, 117], [20, 118], [20, 119], [20, 125], [20, 136], [20, 138], [20, 145], [20, 146], [20, 147], [20, 151], [20, 154], [20, 158], [21, 26], [21, 37], [21, 43], [21, 54], [21, 61], [21, 64], [21, 66], [21, 69], [21, 73], [21, 76], [21, 96], [21, 101], [21, 102], [21, 103], [21, 105], [21, 111], [21, 112], [21, 125], [21, 130], [21, 131], [21, 135], [21, 136], [21, 141], [21, 142], [21, 149], [21, 150], [21, 151], [21, 153], [22, 40], [22, 104], [22, 113], [22, 135], [22, 136], [22, 150], [23, 30], [23, 34], [23, 35], [23, 42], [23, 43], [23, 57], [23, 69], [23, 79], [23, 87], [23, 88], [23, 95], [23, 103], [23, 104], [23, 106], [23, 113], [23, 121], [23, 131], [23, 135], [23, 137], [23, 140], [23, 145], [23, 148], [23, 159], [24, 41], [24, 52], [24, 53], [24, 67], [24, 69], [24, 91], [24, 95], [24, 137], [24, 147], [25, 91], [25, 103], [25, 120], [25, 145], [25, 148], [26, 27], [26, 38], [26, 52], [26, 91], [26, 94], [26, 98], [26, 120], [26, 132], [26, 148], [26, 152], [27, 29], [27, 33], [27, 40], [27, 42], [27, 45], [27, 47], [27, 52], [27, 57], [27, 58], [27, 61], [27, 71], [27, 74], [27, 85], [27, 89], [27, 102], [27, 103], [27, 108], [27, 109], [27, 113], [27, 114], [27, 115], [27, 117], [27, 120], [27, 124], [27, 128], [27, 131], [27, 132], [27, 133], [27, 135], [27, 138], [27, 145], [27, 148], [27, 151], [27, 152], [27, 157], [28, 31], [28, 33], [28, 46], [28, 58], [28, 62], [28, 66], [28, 68], [28, 69], [28, 71], [28, 72], [28, 74], [28, 87], [28, 88], [28, 90], [28, 93], [28, 96], [28, 128], [28, 133], [28, 136], [28, 137], [28, 141], [28, 144], [28, 147], [29, 53], [29, 68], [29, 85], [29, 102], [29, 103], [29, 141], [30, 36], [30, 39], [30, 77], [30, 88], [30, 96], [30, 141], [30, 147], [31, 53], [31, 66], [31, 96], [31, 99], [31, 101], [31, 103], [31, 120], [31, 124], [31, 141], [31, 145], [32, 85], [32, 103], [32, 148], [32, 152], [33, 49], [33, 53], [33, 77], [33, 80], [33, 85], [33, 88], [33, 91], [33, 103], [33, 120], [33, 128], [33, 138], [33, 147], [33, 158], [34, 68], [34, 113], [34, 137], [34, 141], [34, 148], [35, 38], [35, 69], [35, 141], [35, 152], [36, 38], [36, 40], [36, 52], [36, 56], [36, 57], [36, 59], [36, 62], [36, 65], [36, 76], [36, 77], [36, 80], [36, 82], [36, 85], [36, 87], [36, 88], [36, 93], [36, 94], [36, 96], [36, 98], [36, 100], [36, 114], [36, 120], [36, 126], [36, 128], [36, 132], [36, 146], [36, 153], [36, 154], [36, 157], [36, 159], [37, 46], [37, 66], [37, 69], [37, 74], [37, 88], [37, 94], [37, 99], [37, 101], [38, 45], [38, 46], [38, 47], [38, 53], [38, 70], [38, 73], [38, 83], [38, 100], [38, 101], [38, 104], [38, 109], [38, 113], [38, 116], [38, 124], [38, 132], [38, 136], [38, 137], [38, 153], [39, 40], [39, 42], [39, 45], [39, 49], [39, 52], [39, 53], [39, 66], [39, 67], [39, 69], [39, 71], [39, 80], [39, 96], [39, 97], [39, 99], [39, 102], [39, 108], [39, 111], [39, 112], [39, 113], [39, 120], [39, 122], [39, 130], [39, 133], [39, 142], [39, 145], [39, 147], [39, 150], [39, 152], [39, 154], [39, 156], [39, 158], [40, 41], [40, 48], [40, 53], [40, 60], [40, 65], [40, 71], [40, 74], [40, 77], [40, 80], [40, 84], [40, 85], [40, 86], [40, 88], [40, 95], [40, 96], [40, 97], [40, 101], [40, 115], [40, 120], [40, 140], [40, 141], [40, 144], [40, 147], [40, 157], [41, 44], [41, 57], [41, 61], [41, 66], [41, 67], [41, 69], [41, 81], [41, 85], [41, 89], [41, 93], [41, 94], [41, 95], [41, 96], [41, 101], [41, 102], [41, 103], [41, 109], [41, 111], [41, 123], [41, 127], [41, 131], [41, 133], [41, 142], [41, 150], [41, 151], [41, 158], [41, 159], [42, 69], [42, 91], [42, 101], [42, 104], [42, 128], [42, 136], [42, 150], [43, 46], [43, 88], [43, 99], [43, 127], [43, 130], [43, 136], [43, 150], [44, 52], [44, 80], [44, 94], [44, 101], [44, 106], [44, 113], [44, 120], [45, 68], [45, 77], [45, 85], [45, 91], [45, 102], [45, 103], [45, 141], [45, 147], [45, 152], [46, 53], [46, 59], [46, 64], [46, 69], [46, 74], [46, 78], [46, 82], [46, 90], [46, 95], [46, 98], [46, 106], [46, 108], [46, 112], [46, 129], [46, 130], [46, 140], [46, 144], [46, 145], [46, 148], [46, 157], [47, 52], [47, 95], [47, 108], [47, 124], [47, 128], [47, 136], [47, 141], [47, 150], [48, 49], [48, 74], [48, 85], [48, 98], [48, 102], [48, 138], [48, 152], [48, 153], [49, 50], [49, 53], [49, 55], [49, 64], [49, 67], [49, 68], [49, 71], [49, 73], [49, 77], [49, 81], [49, 82], [49, 84], [49, 85], [49, 90], [49, 96], [49, 97], [49, 98], [49, 105], [49, 120], [49, 136], [49, 137], [49, 138], [49, 142], [49, 146], [49, 153], [49, 154], [49, 155], [49, 158], [50, 53], [50, 69], [50, 101], [50, 102], [50, 128], [50, 141], [51, 67], [51, 69], [51, 77], [51, 96], [51, 104], [51, 127], [51, 136], [51, 148], [51, 153], [52, 54], [52, 56], [52, 59], [52, 63], [52, 64], [52, 66], [52, 71], [52, 78], [52, 80], [52, 82], [52, 88], [52, 89], [52, 93], [52, 99], [52, 101], [52, 103], [52, 113], [52, 114], [52, 117], [52, 118], [52, 122], [52, 126], [52, 130], [52, 137], [52, 138], [52, 141], [52, 146], [52, 148], [52, 150], [52, 152], [52, 155], [53, 59], [53, 61], [53, 63], [53, 66], [53, 74], [53, 78], [53, 80], [53, 84], [53, 85], [53, 91], [53, 96], [53, 102], [53, 106], [53, 109], [53, 116], [53, 135], [53, 136], [53, 141], [53, 145], [53, 147], [53, 148], [53, 152], [54, 98], [54, 124], [54, 128], [54, 141], [54, 158], [55, 74], [55, 91], [55, 94], [55, 95], [55, 108], [55, 135], [55, 138], [55, 152], [56, 108], [56, 153], [56, 158], [56, 159], [57, 71], [57, 128], [57, 159], [58, 66], [58, 68], [58, 94], [58, 113], [58, 125], [58, 141], [59, 69], [59, 71], [59, 77], [59, 96], [59, 113], [59, 141], [59, 147], [59, 150], [60, 74], [60, 77], [60, 98], [60, 120], [60, 137], [60, 138], [60, 141], [61, 94], [61, 96], [61, 106], [61, 137], [61, 148], [62, 99], [62, 101], [62, 130], [62, 136], [62, 137], [62, 148], [63, 71], [63, 77], [63, 108], [63, 120], [63, 125], [63, 141], [63, 145], [63, 148], [64, 67], [64, 69], [64, 99], [64, 137], [64, 150], [64, 158], [65, 68], [65, 88], [65, 135], [65, 136], [65, 138], [65, 148], [65, 152], [66, 69], [66, 74], [66, 75], [66, 76], [66, 98], [66, 103], [66, 104], [66, 106], [66, 108], [66, 120], [66, 132], [66, 136], [66, 137], [66, 145], [66, 147], [66, 148], [67, 68], [67, 69], [67, 72], [67, 74], [67, 75], [67, 78], [67, 80], [67, 86], [67, 88], [67, 90], [67, 91], [67, 96], [67, 100], [67, 114], [67, 115], [67, 122], [67, 123], [67, 130], [67, 137], [67, 146], [67, 154], [67, 156], [67, 158], [68, 69], [68, 71], [68, 72], [68, 77], [68, 89], [68, 91], [68, 94], [68, 98], [68, 99], [68, 100], [68, 108], [68, 109], [68, 111], [68, 113], [68, 114], [68, 120], [68, 121], [68, 123], [68, 125], [68, 126], [68, 136], [68, 139], [68, 145], [68, 147], [68, 151], [68, 152], [68, 158], [69, 71], [69, 72], [69, 74], [69, 77], [69, 83], [69, 90], [69, 95], [69, 99], [69, 101], [69, 102], [69, 123], [69, 131], [69, 135], [69, 140], [69, 142], [69, 143], [69, 150], [69, 157], [69, 159], [70, 96], [70, 102], [70, 120], [70, 125], [70, 128], [70, 159], [71, 74], [71, 90], [71, 104], [71, 106], [71, 113], [71, 114], [71, 121], [71, 127], [71, 131], [71, 150], [72, 80], [72, 88], [72, 96], [72, 106], [72, 120], [72, 125], [72, 132], [73, 96], [73, 128], [73, 132], [73, 147], [73, 159], [74, 76], [74, 79], [74, 84], [74, 87], [74, 92], [74, 95], [74, 96], [74, 104], [74, 108], [74, 116], [74, 118], [74, 120], [74, 124], [74, 126], [74, 143], [74, 145], [74, 148], [74, 152], [74, 153], [74, 159], [75, 80], [75, 85], [75, 98], [75, 145], [76, 91], [76, 95], [76, 98], [76, 108], [76, 130], [76, 141], [77, 80], [77, 83], [77, 102], [77, 108], [77, 109], [77, 115], [77, 120], [77, 123], [77, 132], [77, 134], [77, 135], [77, 139], [77, 140], [77, 145], [77, 149], [77, 159], [78, 85], [78, 124], [78, 128], [78, 150], [78, 153], [79, 99], [79, 104], [79, 113], [79, 127], [79, 147], [79, 153], [79, 158], [80, 91], [80, 97], [80, 99], [80, 102], [80, 103], [80, 111], [80, 117], [80, 121], [80, 122], [80, 128], [80, 130], [80, 132], [80, 146], [80, 147], [80, 148], [80, 156], [81, 96], [81, 128], [81, 145], [81, 159], [82, 102], [82, 103], [82, 138], [82, 158], [83, 98], [83, 104], [83, 124], [83, 127], [83, 138], [83, 159], [84, 102], [84, 106], [84, 125], [84, 138], [84, 147], [84, 148], [84, 153], [84, 158], [85, 103], [85, 117], [85, 124], [85, 125], [85, 130], [85, 131], [85, 135], [85, 137], [85, 144], [85, 153], [85, 157], [85, 158], [85, 159], [86, 96], [86, 106], [86, 132], [86, 135], [86, 141], [87, 95], [87, 98], [87, 99], [87, 130], [87, 152], [88, 94], [88, 98], [88, 104], [88, 105], [88, 106], [88, 107], [88, 112], [88, 127], [88, 135], [88, 137], [88, 139], [88, 146], [88, 148], [88, 151], [88, 154], [89, 108], [89, 124], [89, 127], [89, 128], [89, 136], [89, 147], [89, 150], [89, 153], [89, 159], [90, 95], [90, 108], [90, 128], [90, 150], [91, 92], [91, 95], [91, 103], [91, 109], [91, 114], [91, 124], [91, 128], [91, 130], [91, 131], [91, 133], [91, 136], [91, 138], [91, 145], [91, 149], [91, 153], [91, 159], [92, 99], [92, 132], [92, 137], [92, 150], [92, 152], [92, 159], [93, 95], [93, 103], [93, 130], [93, 145], [93, 148], [93, 159], [94, 95], [94, 98], [94, 102], [94, 103], [94, 104], [94, 106], [94, 107], [94, 113], [94, 121], [94, 125], [94, 126], [94, 127], [94, 128], [94, 133], [94, 139], [94, 141], [94, 143], [94, 149], [94, 150], [94, 152], [94, 153], [94, 156], [95, 101], [95, 106], [95, 108], [95, 110], [95, 112], [95, 116], [95, 124], [95, 135], [95, 146], [95, 152], [96, 99], [96, 101], [96, 108], [96, 110], [96, 116], [96, 118], [96, 120], [96, 123], [96, 125], [96, 128], [96, 130], [96, 148], [96, 150], [96, 153], [96, 156], [97, 101], [97, 108], [97, 120], [97, 138], [97, 150], [98, 103], [98, 116], [98, 126], [98, 133], [98, 134], [98, 147], [98, 149], [98, 152], [98, 158], [99, 104], [99, 120], [99, 125], [99, 132], [99, 134], [99, 138], [99, 143], [99, 157], [100, 103], [100, 128], [101, 103], [101, 104], [101, 107], [101, 108], [101, 113], [101, 115], [101, 118], [101, 124], [101, 128], [101, 129], [101, 136], [101, 143], [101, 152], [101, 157], [102, 106], [102, 110], [102, 111], [102, 122], [102, 127], [102, 133], [102, 134], [102, 136], [102, 141], [102, 148], [102, 150], [102, 152], [103, 108], [103, 124], [103, 140], [103, 156], [104, 106], [104, 112], [104, 120], [104, 121], [104, 124], [104, 125], [104, 127], [104, 128], [104, 132], [104, 134], [104, 138], [104, 140], [104, 141], [104, 144], [104, 148], [104, 152], [105, 106], [105, 128], [105, 135], [105, 152], [105, 159], [106, 107], [106, 108], [106, 117], [106, 122], [106, 135], [106, 144], [106, 146], [106, 156], [107, 138], [107, 141], [107, 145], [108, 109], [108, 112], [108, 122], [108, 127], [108, 128], [108, 132], [108, 134], [108, 136], [108, 137], [108, 145], [108, 155], [109, 125], [109, 130], [109, 132], [109, 135], [109, 148], [109, 159], [110, 127], [110, 147], [111, 120], [111, 125], [111, 132], [111, 147], [111, 153], [111, 159], [112, 127], [112, 136], [112, 159], [113, 117], [113, 126], [113, 127], [113, 128], [113, 130], [113, 147], [113, 150], [113, 158], [114, 120], [114, 125], [114, 136], [114, 145], [114, 148], [116, 135], [116, 147], [116, 150], [117, 120], [117, 130], [117, 135], [117, 145], [117, 159], [118, 130], [118, 132], [118, 141], [118, 145], [118, 152], [118, 159], [120, 126], [120, 129], [120, 130], [120, 136], [120, 138], [120, 139], [120, 141], [120, 145], [120, 147], [120, 152], [121, 147], [121, 148], [121, 158], [122, 125], [122, 137], [122, 148], [123, 158], [124, 125], [124, 130], [124, 135], [124, 136], [124, 147], [124, 150], [124, 159], [125, 127], [125, 134], [125, 135], [125, 138], [125, 144], [125, 152], [125, 153], [125, 158], [126, 132], [126, 158], [126, 159], [127, 143], [127, 150], [127, 155], [128, 138], [128, 139], [128, 143], [128, 148], [128, 151], [128, 152], [128, 153], [128, 155], [128, 159], [129, 138], [129, 148], [129, 159], [130, 131], [130, 132], [130, 135], [130, 139], [130, 146], [130, 147], [130, 151], [130, 159], [131, 137], [131, 152], [132, 134], [132, 147], [132, 150], [132, 159], [133, 137], [133, 158], [134, 137], [134, 138], [134, 158], [135, 137], [135, 139], [135, 145], [135, 146], [135, 147], [135, 151], [136, 137], [136, 138], [136, 148], [136, 150], [136, 157], [137, 145], [137, 146], [137, 147], [137, 150], [137, 152], [137, 153], [138, 145], [138, 147], [138, 149], [138, 150], [138, 159], [139, 158], [141, 152], [141, 154], [141, 157], [142, 153], [142, 158], [145, 150], [146, 147], [146, 158], [147, 148], [147, 150], [147, 159], [148, 154], [148, 157], [149, 152], [149, 158], [150, 152], [150, 159], [158, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s2/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a735598f608ca871198680ddab760f4f68125a8e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [2, 6, 7, 9, 12, 15, 19, 20, 21, 23, 27, 28, 36, 38, 39, 40, 41, 46, 49, 52, 53, 66, 67, 68, 69, 71, 74, 77, 80, 85, 88, 91, 94, 95, 96, 98, 99, 101, 102, 103, 104, 106, 108, 113, 120, 124, 125, 127, 128, 130, 132, 135, 136, 137, 138, 141, 145, 147, 148, 150, 152, 153, 158, 159]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s2/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s2/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-s2/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06c938c83fdd58b90c93c2c69234eb0f00661d24 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 108], [0, 125], [0, 127], [0, 137], [0, 147], [0, 158], [1, 20], [1, 71], [1, 96], [1, 124], [1, 128], [1, 136], [1, 137], [1, 153], [2, 6], [2, 7], [2, 15], [2, 18], [2, 24], [2, 27], [2, 32], [2, 45], [2, 49], [2, 57], [2, 63], [2, 64], [2, 66], [2, 68], [2, 73], [2, 74], [2, 88], [2, 91], [2, 95], [2, 96], [2, 103], [2, 104], [2, 118], [2, 127], [2, 128], [2, 136], [2, 139], [2, 145], [2, 148], [2, 152], [2, 153], [3, 19], [3, 20], [3, 23], [3, 38], [3, 41], [3, 46], [3, 49], [3, 53], [3, 77], [3, 85], [3, 88], [3, 102], [3, 120], [3, 124], [4, 21], [4, 40], [4, 53], [4, 68], [4, 74], [4, 103], [4, 106], [4, 108], [4, 145], [5, 6], [5, 7], [5, 40], [5, 71], [5, 102], [5, 103], [5, 128], [5, 132], [5, 141], [5, 158], [6, 13], [6, 25], [6, 28], [6, 44], [6, 45], [6, 46], [6, 47], [6, 50], [6, 52], [6, 53], [6, 55], [6, 57], [6, 58], [6, 60], [6, 65], [6, 81], [6, 87], [6, 98], [6, 100], [6, 102], [6, 103], [6, 105], [6, 108], [6, 114], [6, 120], [6, 127], [6, 131], [6, 132], [6, 135], [6, 137], [6, 141], [6, 148], [6, 151], [6, 153], [7, 19], [7, 23], [7, 36], [7, 38], [7, 41], [7, 42], [7, 53], [7, 59], [7, 60], [7, 65], [7, 70], [7, 81], [7, 83], [7, 87], [7, 88], [7, 91], [7, 98], [7, 104], [7, 110], [7, 113], [7, 114], [7, 122], [7, 123], [7, 125], [7, 129], [7, 132], [7, 136], [7, 138], [7, 140], [7, 143], [7, 145], [7, 148], [7, 153], [8, 68], [8, 77], [8, 99], [8, 103], [8, 113], [8, 148], [8, 153], [8, 158], [9, 12], [9, 14], [9, 22], [9, 29], [9, 40], [9, 43], [9, 45], [9, 67], [9, 71], [9, 79], [9, 85], [9, 88], [9, 94], [9, 95], [9, 96], [9, 97], [9, 104], [9, 108], [9, 113], [9, 115], [9, 131], [9, 132], [9, 133], [9, 135], [9, 137], [9, 140], [9, 151], [9, 152], [9, 156], [9, 157], [9, 158], [10, 19], [10, 28], [10, 49], [10, 67], [10, 95], [10, 103], [10, 120], [10, 138], [10, 148], [10, 150], [11, 20], [11, 36], [11, 52], [11, 66], [11, 101], [11, 103], [11, 104], [11, 106], [11, 108], [11, 136], [11, 137], [11, 158], [12, 21], [12, 36], [12, 46], [12, 48], [12, 50], [12, 53], [12, 57], [12, 61], [12, 63], [12, 68], [12, 70], [12, 77], [12, 80], [12, 81], [12, 85], [12, 92], [12, 98], [12, 103], [12, 106], [12, 118], [12, 121], [12, 126], [12, 129], [12, 137], [12, 145], [12, 149], [12, 154], [12, 159], [13, 21], [13, 52], [13, 66], [13, 85], [13, 88], [13, 96], [13, 120], [13, 136], [13, 159], [14, 19], [14, 39], [14, 68], [14, 69], [14, 71], [14, 77], [14, 88], [14, 102], [14, 125], [14, 127], [14, 145], [14, 158], [14, 159], [15, 23], [15, 24], [15, 26], [15, 36], [15, 40], [15, 57], [15, 78], [15, 80], [15, 85], [15, 89], [15, 90], [15, 98], [15, 103], [15, 107], [15, 108], [15, 113], [15, 117], [15, 130], [15, 132], [15, 133], [15, 137], [15, 138], [15, 140], [15, 143], [15, 144], [15, 146], [15, 147], [15, 152], [15, 154], [16, 20], [16, 23], [16, 94], [16, 98], [16, 99], [16, 138], [16, 141], [16, 150], [16, 153], [17, 19], [17, 46], [17, 69], [17, 77], [18, 69], [18, 91], [18, 99], [18, 113], [18, 120], [18, 127], [18, 135], [18, 158], [19, 20], [19, 33], [19, 35], [19, 36], [19, 37], [19, 40], [19, 42], [19, 45], [19, 51], [19, 55], [19, 57], [19, 58], [19, 64], [19, 65], [19, 73], [19, 82], [19, 86], [19, 89], [19, 91], [19, 101], [19, 104], [19, 108], [19, 112], [19, 113], [19, 115], [19, 128], [19, 131], [19, 136], [19, 145], [19, 147], [19, 148], [19, 154], [19, 158], [20, 26], [20, 33], [20, 39], [20, 43], [20, 54], [20, 56], [20, 57], [20, 70], [20, 71], [20, 76], [20, 80], [20, 83], [20, 84], [20, 87], [20, 93], [20, 95], [20, 115], [20, 117], [20, 118], [20, 119], [20, 125], [20, 136], [20, 138], [20, 145], [20, 146], [20, 147], [20, 151], [20, 154], [20, 158], [21, 26], [21, 37], [21, 43], [21, 54], [21, 61], [21, 64], [21, 66], [21, 69], [21, 73], [21, 76], [21, 96], [21, 101], [21, 102], [21, 103], [21, 105], [21, 111], [21, 112], [21, 125], [21, 130], [21, 131], [21, 135], [21, 136], [21, 141], [21, 142], [21, 149], [21, 150], [21, 151], [21, 153], [22, 40], [22, 104], [22, 113], [22, 135], [22, 136], [22, 150], [23, 30], [23, 34], [23, 35], [23, 42], [23, 43], [23, 57], [23, 69], [23, 79], [23, 87], [23, 88], [23, 95], [23, 103], [23, 104], [23, 106], [23, 113], [23, 121], [23, 131], [23, 135], [23, 137], [23, 140], [23, 145], [23, 148], [23, 159], [24, 41], [24, 52], [24, 53], [24, 67], [24, 69], [24, 91], [24, 95], [24, 137], [24, 147], [25, 91], [25, 103], [25, 120], [25, 145], [25, 148], [26, 27], [26, 38], [26, 52], [26, 91], [26, 94], [26, 98], [26, 120], [26, 132], [26, 148], [26, 152], [27, 29], [27, 33], [27, 40], [27, 42], [27, 45], [27, 47], [27, 52], [27, 57], [27, 58], [27, 61], [27, 71], [27, 74], [27, 85], [27, 89], [27, 102], [27, 103], [27, 108], [27, 109], [27, 113], [27, 114], [27, 115], [27, 117], [27, 120], [27, 124], [27, 128], [27, 131], [27, 132], [27, 133], [27, 135], [27, 138], [27, 145], [27, 148], [27, 151], [27, 152], [27, 157], [28, 31], [28, 33], [28, 46], [28, 58], [28, 62], [28, 66], [28, 68], [28, 69], [28, 71], [28, 72], [28, 74], [28, 87], [28, 88], [28, 90], [28, 93], [28, 96], [28, 128], [28, 133], [28, 136], [28, 137], [28, 141], [28, 144], [28, 147], [29, 53], [29, 68], [29, 85], [29, 102], [29, 103], [29, 141], [30, 36], [30, 39], [30, 77], [30, 88], [30, 96], [30, 141], [30, 147], [31, 53], [31, 66], [31, 96], [31, 99], [31, 101], [31, 103], [31, 120], [31, 124], [31, 141], [31, 145], [32, 85], [32, 103], [32, 148], [32, 152], [33, 49], [33, 53], [33, 77], [33, 80], [33, 85], [33, 88], [33, 91], [33, 103], [33, 120], [33, 128], [33, 138], [33, 147], [33, 158], [34, 68], [34, 113], [34, 137], [34, 141], [34, 148], [35, 38], [35, 69], [35, 141], [35, 152], [36, 38], [36, 40], [36, 52], [36, 56], [36, 57], [36, 59], [36, 62], [36, 65], [36, 76], [36, 77], [36, 80], [36, 82], [36, 85], [36, 87], [36, 88], [36, 93], [36, 94], [36, 96], [36, 98], [36, 100], [36, 114], [36, 120], [36, 126], [36, 128], [36, 132], [36, 146], [36, 153], [36, 154], [36, 157], [36, 159], [37, 46], [37, 66], [37, 69], [37, 74], [37, 88], [37, 94], [37, 99], [37, 101], [38, 45], [38, 46], [38, 47], [38, 53], [38, 70], [38, 73], [38, 83], [38, 100], [38, 101], [38, 104], [38, 109], [38, 113], [38, 116], [38, 124], [38, 132], [38, 136], [38, 137], [38, 153], [39, 40], [39, 42], [39, 45], [39, 49], [39, 52], [39, 53], [39, 66], [39, 67], [39, 69], [39, 71], [39, 80], [39, 96], [39, 97], [39, 99], [39, 102], [39, 108], [39, 111], [39, 112], [39, 113], [39, 120], [39, 122], [39, 130], [39, 133], [39, 142], [39, 145], [39, 147], [39, 150], [39, 152], [39, 154], [39, 156], [39, 158], [40, 41], [40, 48], [40, 53], [40, 60], [40, 65], [40, 71], [40, 74], [40, 77], [40, 80], [40, 84], [40, 85], [40, 86], [40, 88], [40, 95], [40, 96], [40, 97], [40, 101], [40, 115], [40, 120], [40, 140], [40, 141], [40, 144], [40, 147], [40, 157], [41, 44], [41, 57], [41, 61], [41, 66], [41, 67], [41, 69], [41, 81], [41, 85], [41, 89], [41, 93], [41, 94], [41, 95], [41, 96], [41, 101], [41, 102], [41, 103], [41, 109], [41, 111], [41, 123], [41, 127], [41, 131], [41, 133], [41, 142], [41, 150], [41, 151], [41, 158], [41, 159], [42, 69], [42, 91], [42, 101], [42, 104], [42, 128], [42, 136], [42, 150], [43, 46], [43, 88], [43, 99], [43, 127], [43, 130], [43, 136], [43, 150], [44, 52], [44, 80], [44, 94], [44, 101], [44, 106], [44, 113], [44, 120], [45, 68], [45, 77], [45, 85], [45, 91], [45, 102], [45, 103], [45, 141], [45, 147], [45, 152], [46, 53], [46, 59], [46, 64], [46, 69], [46, 74], [46, 78], [46, 82], [46, 90], [46, 95], [46, 98], [46, 106], [46, 108], [46, 112], [46, 129], [46, 130], [46, 140], [46, 144], [46, 145], [46, 148], [46, 157], [47, 52], [47, 95], [47, 108], [47, 124], [47, 128], [47, 136], [47, 141], [47, 150], [48, 49], [48, 74], [48, 85], [48, 98], [48, 102], [48, 138], [48, 152], [48, 153], [49, 50], [49, 53], [49, 55], [49, 64], [49, 67], [49, 68], [49, 71], [49, 73], [49, 77], [49, 81], [49, 82], [49, 84], [49, 85], [49, 90], [49, 96], [49, 97], [49, 98], [49, 105], [49, 120], [49, 136], [49, 137], [49, 138], [49, 142], [49, 146], [49, 153], [49, 154], [49, 155], [49, 158], [50, 53], [50, 69], [50, 101], [50, 102], [50, 128], [50, 141], [51, 67], [51, 69], [51, 77], [51, 96], [51, 104], [51, 127], [51, 136], [51, 148], [51, 153], [52, 54], [52, 56], [52, 59], [52, 63], [52, 64], [52, 66], [52, 71], [52, 78], [52, 80], [52, 82], [52, 88], [52, 89], [52, 93], [52, 99], [52, 101], [52, 103], [52, 113], [52, 114], [52, 117], [52, 118], [52, 122], [52, 126], [52, 130], [52, 137], [52, 138], [52, 141], [52, 146], [52, 148], [52, 150], [52, 152], [52, 155], [53, 59], [53, 61], [53, 63], [53, 66], [53, 74], [53, 78], [53, 80], [53, 84], [53, 85], [53, 91], [53, 96], [53, 102], [53, 106], [53, 109], [53, 116], [53, 135], [53, 136], [53, 141], [53, 145], [53, 147], [53, 148], [53, 152], [54, 98], [54, 124], [54, 128], [54, 141], [54, 158], [55, 74], [55, 91], [55, 94], [55, 95], [55, 108], [55, 135], [55, 138], [55, 152], [56, 108], [56, 153], [56, 158], [56, 159], [57, 71], [57, 128], [57, 159], [58, 66], [58, 68], [58, 94], [58, 113], [58, 125], [58, 141], [59, 69], [59, 71], [59, 77], [59, 96], [59, 113], [59, 141], [59, 147], [59, 150], [60, 74], [60, 77], [60, 98], [60, 120], [60, 137], [60, 138], [60, 141], [61, 94], [61, 96], [61, 106], [61, 137], [61, 148], [62, 99], [62, 101], [62, 130], [62, 136], [62, 137], [62, 148], [63, 71], [63, 77], [63, 108], [63, 120], [63, 125], [63, 141], [63, 145], [63, 148], [64, 67], [64, 69], [64, 99], [64, 137], [64, 150], [64, 158], [65, 68], [65, 88], [65, 135], [65, 136], [65, 138], [65, 148], [65, 152], [66, 69], [66, 74], [66, 75], [66, 76], [66, 98], [66, 103], [66, 104], [66, 106], [66, 108], [66, 120], [66, 132], [66, 136], [66, 137], [66, 145], [66, 147], [66, 148], [67, 68], [67, 69], [67, 72], [67, 74], [67, 75], [67, 78], [67, 80], [67, 86], [67, 88], [67, 90], [67, 91], [67, 96], [67, 100], [67, 114], [67, 115], [67, 122], [67, 123], [67, 130], [67, 137], [67, 146], [67, 154], [67, 156], [67, 158], [68, 69], [68, 71], [68, 72], [68, 77], [68, 89], [68, 91], [68, 94], [68, 98], [68, 99], [68, 100], [68, 108], [68, 109], [68, 111], [68, 113], [68, 114], [68, 120], [68, 121], [68, 123], [68, 125], [68, 126], [68, 136], [68, 139], [68, 145], [68, 147], [68, 151], [68, 152], [68, 158], [69, 71], [69, 72], [69, 74], [69, 77], [69, 83], [69, 90], [69, 95], [69, 99], [69, 101], [69, 102], [69, 123], [69, 131], [69, 135], [69, 140], [69, 142], [69, 143], [69, 150], [69, 157], [69, 159], [70, 96], [70, 102], [70, 120], [70, 125], [70, 128], [70, 159], [71, 74], [71, 90], [71, 104], [71, 106], [71, 113], [71, 114], [71, 121], [71, 127], [71, 131], [71, 150], [72, 80], [72, 88], [72, 96], [72, 106], [72, 120], [72, 125], [72, 132], [73, 96], [73, 128], [73, 132], [73, 147], [73, 159], [74, 76], [74, 79], [74, 84], [74, 87], [74, 92], [74, 95], [74, 96], [74, 104], [74, 108], [74, 116], [74, 118], [74, 120], [74, 124], [74, 126], [74, 143], [74, 145], [74, 148], [74, 152], [74, 153], [74, 159], [75, 80], [75, 85], [75, 98], [75, 145], [76, 91], [76, 95], [76, 98], [76, 108], [76, 130], [76, 141], [77, 80], [77, 83], [77, 102], [77, 108], [77, 109], [77, 115], [77, 120], [77, 123], [77, 132], [77, 134], [77, 135], [77, 139], [77, 140], [77, 145], [77, 149], [77, 159], [78, 85], [78, 124], [78, 128], [78, 150], [78, 153], [79, 99], [79, 104], [79, 113], [79, 127], [79, 147], [79, 153], [79, 158], [80, 91], [80, 97], [80, 99], [80, 102], [80, 103], [80, 111], [80, 117], [80, 121], [80, 122], [80, 128], [80, 130], [80, 132], [80, 146], [80, 147], [80, 148], [80, 156], [81, 96], [81, 128], [81, 145], [81, 159], [82, 102], [82, 103], [82, 138], [82, 158], [83, 98], [83, 104], [83, 124], [83, 127], [83, 138], [83, 159], [84, 102], [84, 106], [84, 125], [84, 138], [84, 147], [84, 148], [84, 153], [84, 158], [85, 103], [85, 117], [85, 124], [85, 125], [85, 130], [85, 131], [85, 135], [85, 137], [85, 144], [85, 153], [85, 157], [85, 158], [85, 159], [86, 96], [86, 106], [86, 132], [86, 135], [86, 141], [87, 95], [87, 98], [87, 99], [87, 130], [87, 152], [88, 94], [88, 98], [88, 104], [88, 105], [88, 106], [88, 107], [88, 112], [88, 127], [88, 135], [88, 137], [88, 139], [88, 146], [88, 148], [88, 151], [88, 154], [89, 108], [89, 124], [89, 127], [89, 128], [89, 136], [89, 147], [89, 150], [89, 153], [89, 159], [90, 95], [90, 108], [90, 128], [90, 150], [91, 92], [91, 95], [91, 103], [91, 109], [91, 114], [91, 124], [91, 128], [91, 130], [91, 131], [91, 133], [91, 136], [91, 138], [91, 145], [91, 149], [91, 153], [91, 159], [92, 99], [92, 132], [92, 137], [92, 150], [92, 152], [92, 159], [93, 95], [93, 103], [93, 130], [93, 145], [93, 148], [93, 159], [94, 95], [94, 98], [94, 102], [94, 103], [94, 104], [94, 106], [94, 107], [94, 113], [94, 121], [94, 125], [94, 126], [94, 127], [94, 128], [94, 133], [94, 139], [94, 141], [94, 143], [94, 149], [94, 150], [94, 152], [94, 153], [94, 156], [95, 101], [95, 106], [95, 108], [95, 110], [95, 112], [95, 116], [95, 124], [95, 135], [95, 146], [95, 152], [96, 99], [96, 101], [96, 108], [96, 110], [96, 116], [96, 118], [96, 120], [96, 123], [96, 125], [96, 128], [96, 130], [96, 148], [96, 150], [96, 153], [96, 156], [97, 101], [97, 108], [97, 120], [97, 138], [97, 150], [98, 103], [98, 116], [98, 126], [98, 133], [98, 134], [98, 147], [98, 149], [98, 152], [98, 158], [99, 104], [99, 120], [99, 125], [99, 132], [99, 134], [99, 138], [99, 143], [99, 157], [100, 103], [100, 128], [101, 103], [101, 104], [101, 107], [101, 108], [101, 113], [101, 115], [101, 118], [101, 124], [101, 128], [101, 129], [101, 136], [101, 143], [101, 152], [101, 157], [102, 106], [102, 110], [102, 111], [102, 122], [102, 127], [102, 133], [102, 134], [102, 136], [102, 141], [102, 148], [102, 150], [102, 152], [103, 108], [103, 124], [103, 140], [103, 156], [104, 106], [104, 112], [104, 120], [104, 121], [104, 124], [104, 125], [104, 127], [104, 128], [104, 132], [104, 134], [104, 138], [104, 140], [104, 141], [104, 144], [104, 148], [104, 152], [105, 106], [105, 128], [105, 135], [105, 152], [105, 159], [106, 107], [106, 108], [106, 117], [106, 122], [106, 135], [106, 144], [106, 146], [106, 156], [107, 138], [107, 141], [107, 145], [108, 109], [108, 112], [108, 122], [108, 127], [108, 128], [108, 132], [108, 134], [108, 136], [108, 137], [108, 145], [108, 155], [109, 125], [109, 130], [109, 132], [109, 135], [109, 148], [109, 159], [110, 127], [110, 147], [111, 120], [111, 125], [111, 132], [111, 147], [111, 153], [111, 159], [112, 127], [112, 136], [112, 159], [113, 117], [113, 126], [113, 127], [113, 128], [113, 130], [113, 147], [113, 150], [113, 158], [114, 120], [114, 125], [114, 136], [114, 145], [114, 148], [116, 135], [116, 147], [116, 150], [117, 120], [117, 130], [117, 135], [117, 145], [117, 159], [118, 130], [118, 132], [118, 141], [118, 145], [118, 152], [118, 159], [120, 126], [120, 129], [120, 130], [120, 136], [120, 138], [120, 139], [120, 141], [120, 145], [120, 147], [120, 152], [121, 147], [121, 148], [121, 158], [122, 125], [122, 137], [122, 148], [123, 158], [124, 125], [124, 130], [124, 135], [124, 136], [124, 147], [124, 150], [124, 159], [125, 127], [125, 134], [125, 135], [125, 138], [125, 144], [125, 152], [125, 153], [125, 158], [126, 132], [126, 158], [126, 159], [127, 143], [127, 150], [127, 155], [128, 138], [128, 139], [128, 143], [128, 148], [128, 151], [128, 152], [128, 153], [128, 155], [128, 159], [129, 138], [129, 148], [129, 159], [130, 131], [130, 132], [130, 135], [130, 139], [130, 146], [130, 147], [130, 151], [130, 159], [131, 137], [131, 152], [132, 134], [132, 147], [132, 150], [132, 159], [133, 137], [133, 158], [134, 137], [134, 138], [134, 158], [135, 137], [135, 139], [135, 145], [135, 146], [135, 147], [135, 151], [136, 137], [136, 138], [136, 148], [136, 150], [136, 157], [137, 145], [137, 146], [137, 147], [137, 150], [137, 152], [137, 153], [138, 145], [138, 147], [138, 149], [138, 150], [138, 159], [139, 158], [141, 152], [141, 154], [141, 157], [142, 153], [142, 158], [145, 150], [146, 147], [146, 158], [147, 148], [147, 150], [147, 159], [148, 154], [148, 157], [149, 152], [149, 158], [150, 152], [150, 159], [158, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s2/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l6-s2/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l6-s3/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l6-s3/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4be7a84d58467da841bd3aa7c188845f0dabb6f --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 7], [0, 13], [0, 46], [0, 50], [0, 59], [0, 61], [0, 73], [0, 84], [0, 87], [0, 99], [0, 104], [0, 107], [0, 120], [0, 127], [0, 150], [1, 6], [1, 13], [1, 14], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 29], [1, 33], [1, 35], [1, 37], [1, 38], [1, 46], [1, 47], [1, 49], [1, 51], [1, 61], [1, 65], [1, 66], [1, 71], [1, 73], [1, 80], [1, 84], [1, 97], [1, 102], [1, 103], [1, 114], [1, 115], [1, 118], [1, 120], [1, 121], [1, 141], [1, 144], [1, 150], [1, 155], [1, 159], [2, 6], [2, 102], [2, 110], [2, 130], [2, 146], [3, 7], [3, 10], [3, 13], [3, 28], [3, 29], [3, 45], [3, 46], [3, 63], [3, 64], [3, 68], [3, 75], [3, 84], [3, 88], [3, 89], [3, 90], [3, 93], [3, 97], [3, 98], [3, 99], [3, 101], [3, 111], [3, 129], [3, 131], [3, 139], [3, 141], [3, 142], [3, 145], [3, 146], [3, 149], [3, 150], [3, 152], [3, 156], [3, 157], [4, 6], [4, 44], [4, 46], [4, 51], [4, 59], [4, 107], [4, 137], [4, 139], [5, 30], [5, 33], [5, 73], [5, 102], [5, 133], [5, 147], [6, 17], [6, 20], [6, 21], [6, 24], [6, 28], [6, 30], [6, 31], [6, 36], [6, 38], [6, 43], [6, 48], [6, 50], [6, 61], [6, 62], [6, 65], [6, 75], [6, 77], [6, 93], [6, 94], [6, 100], [6, 101], [6, 102], [6, 105], [6, 110], [6, 114], [6, 121], [6, 129], [6, 130], [6, 134], [6, 136], [6, 145], [6, 150], [6, 153], [7, 10], [7, 22], [7, 30], [7, 32], [7, 34], [7, 38], [7, 43], [7, 44], [7, 55], [7, 59], [7, 61], [7, 62], [7, 67], [7, 75], [7, 84], [7, 86], [7, 89], [7, 98], [7, 99], [7, 107], [7, 108], [7, 110], [7, 118], [7, 121], [7, 135], [7, 137], [7, 142], [7, 144], [7, 152], [7, 153], [7, 157], [7, 158], [7, 159], [8, 13], [8, 18], [8, 19], [8, 27], [8, 34], [8, 45], [8, 56], [8, 57], [8, 59], [8, 63], [8, 65], [8, 66], [8, 77], [8, 78], [8, 80], [8, 81], [8, 84], [8, 86], [8, 96], [8, 115], [8, 116], [8, 118], [8, 121], [8, 125], [8, 130], [8, 132], [8, 135], [8, 137], [8, 138], [8, 141], [8, 146], [8, 155], [9, 13], [9, 33], [9, 88], [9, 100], [9, 118], [9, 120], [9, 137], [9, 138], [10, 24], [10, 28], [10, 55], [10, 71], [10, 84], [10, 86], [10, 99], [10, 127], [10, 133], [10, 150], [11, 20], [11, 21], [11, 23], [11, 27], [11, 29], [11, 35], [11, 38], [11, 40], [11, 47], [11, 51], [11, 52], [11, 53], [11, 54], [11, 55], [11, 59], [11, 61], [11, 65], [11, 67], [11, 68], [11, 74], [11, 80], [11, 83], [11, 85], [11, 86], [11, 100], [11, 107], [11, 111], [11, 112], [11, 113], [11, 118], [11, 122], [11, 124], [11, 127], [11, 129], [11, 131], [11, 141], [11, 144], [11, 145], [11, 147], [11, 152], [11, 155], [11, 157], [11, 158], [12, 59], [12, 65], [12, 73], [12, 84], [12, 88], [12, 118], [12, 121], [12, 141], [12, 143], [12, 150], [13, 14], [13, 18], [13, 30], [13, 33], [13, 35], [13, 45], [13, 57], [13, 66], [13, 75], [13, 79], [13, 80], [13, 85], [13, 89], [13, 95], [13, 102], [13, 103], [13, 105], [13, 113], [13, 118], [13, 120], [13, 121], [13, 134], [13, 142], [13, 154], [14, 44], [14, 71], [14, 80], [14, 102], [14, 146], [14, 147], [15, 23], [15, 59], [15, 75], [15, 88], [15, 110], [15, 120], [15, 133], [15, 137], [16, 21], [16, 44], [16, 45], [16, 89], [16, 99], [16, 110], [16, 141], [17, 23], [17, 44], [17, 50], [17, 51], [17, 55], [17, 65], [17, 67], [17, 75], [17, 87], [17, 99], [17, 100], [17, 107], [17, 120], [17, 130], [17, 133], [17, 150], [18, 24], [18, 32], [18, 33], [18, 46], [18, 50], [18, 51], [18, 102], [18, 108], [18, 127], [18, 130], [18, 143], [18, 147], [19, 28], [19, 33], [19, 79], [19, 80], [19, 114], [19, 129], [19, 137], [19, 146], [19, 150], [20, 28], [20, 32], [20, 61], [20, 107], [20, 108], [20, 115], [20, 118], [21, 22], [21, 23], [21, 24], [21, 30], [21, 32], [21, 47], [21, 50], [21, 63], [21, 72], [21, 73], [21, 79], [21, 82], [21, 87], [21, 89], [21, 99], [21, 104], [21, 110], [21, 115], [21, 118], [21, 121], [21, 127], [21, 128], [21, 130], [21, 146], [21, 147], [21, 151], [21, 153], [21, 156], [22, 28], [22, 40], [22, 44], [22, 65], [22, 84], [22, 107], [22, 108], [22, 114], [22, 121], [22, 133], [22, 138], [22, 144], [23, 25], [23, 29], [23, 33], [23, 37], [23, 41], [23, 46], [23, 66], [23, 67], [23, 69], [23, 76], [23, 88], [23, 110], [23, 115], [23, 118], [23, 120], [23, 121], [23, 122], [23, 124], [23, 141], [23, 158], [24, 35], [24, 42], [24, 44], [24, 50], [24, 71], [24, 78], [24, 83], [24, 85], [24, 87], [24, 89], [24, 92], [24, 97], [24, 100], [24, 102], [24, 103], [24, 105], [24, 106], [24, 108], [24, 110], [24, 111], [24, 125], [24, 127], [24, 129], [24, 130], [24, 131], [24, 133], [24, 138], [24, 143], [24, 145], [24, 156], [24, 159], [25, 33], [25, 71], [25, 78], [25, 84], [25, 104], [25, 127], [25, 138], [25, 156], [26, 44], [26, 45], [26, 55], [26, 75], [26, 100], [26, 115], [26, 118], [26, 120], [26, 127], [26, 130], [26, 137], [26, 147], [26, 156], [27, 50], [27, 55], [27, 80], [27, 89], [27, 102], [27, 127], [27, 139], [27, 143], [27, 146], [28, 31], [28, 33], [28, 34], [28, 38], [28, 40], [28, 45], [28, 54], [28, 58], [28, 59], [28, 61], [28, 62], [28, 67], [28, 69], [28, 72], [28, 74], [28, 78], [28, 79], [28, 83], [28, 88], [28, 91], [28, 93], [28, 97], [28, 100], [28, 102], [28, 107], [28, 112], [28, 116], [28, 121], [28, 127], [28, 139], [28, 141], [28, 149], [28, 150], [28, 151], [28, 158], [29, 33], [29, 40], [29, 46], [29, 78], [29, 80], [29, 95], [29, 99], [29, 100], [29, 129], [29, 137], [29, 150], [30, 35], [30, 40], [30, 54], [30, 70], [30, 81], [30, 86], [30, 87], [30, 88], [30, 89], [30, 94], [30, 95], [30, 103], [30, 110], [30, 131], [30, 136], [30, 137], [30, 141], [30, 144], [30, 148], [30, 157], [31, 55], [31, 61], [31, 65], [31, 71], [31, 100], [31, 137], [31, 138], [31, 141], [31, 144], [31, 156], [32, 44], [32, 46], [32, 47], [32, 59], [32, 60], [32, 63], [32, 73], [32, 76], [32, 83], [32, 84], [32, 86], [32, 101], [32, 102], [32, 110], [32, 130], [32, 133], [32, 134], [32, 143], [32, 153], [33, 37], [33, 41], [33, 46], [33, 47], [33, 48], [33, 52], [33, 57], [33, 62], [33, 65], [33, 66], [33, 67], [33, 71], [33, 77], [33, 78], [33, 84], [33, 87], [33, 94], [33, 96], [33, 102], [33, 110], [33, 133], [33, 137], [33, 139], [33, 140], [33, 142], [33, 144], [33, 146], [33, 159], [34, 40], [34, 73], [34, 107], [34, 127], [34, 143], [34, 146], [35, 51], [35, 65], [35, 78], [35, 84], [35, 86], [35, 87], [35, 89], [35, 127], [35, 133], [36, 45], [36, 51], [36, 65], [36, 75], [36, 87], [36, 120], [36, 133], [36, 139], [36, 143], [36, 144], [36, 146], [37, 59], [37, 61], [37, 65], [37, 80], [37, 100], [37, 104], [37, 110], [37, 127], [37, 137], [37, 138], [38, 44], [38, 46], [38, 78], [38, 84], [38, 127], [38, 129], [38, 139], [38, 143], [38, 147], [38, 150], [38, 156], [39, 61], [39, 73], [39, 110], [39, 114], [39, 115], [39, 120], [39, 127], [39, 129], [39, 141], [40, 44], [40, 45], [40, 51], [40, 52], [40, 55], [40, 58], [40, 65], [40, 74], [40, 76], [40, 79], [40, 81], [40, 82], [40, 88], [40, 89], [40, 95], [40, 97], [40, 114], [40, 119], [40, 121], [40, 125], [40, 127], [40, 139], [40, 142], [40, 144], [40, 146], [40, 148], [40, 152], [40, 156], [40, 158], [41, 55], [41, 71], [41, 75], [41, 110], [41, 146], [42, 45], [42, 46], [42, 51], [42, 61], [42, 67], [42, 73], [42, 86], [42, 138], [43, 55], [43, 61], [43, 71], [43, 78], [43, 84], [43, 100], [43, 120], [43, 138], [43, 139], [43, 144], [44, 46], [44, 50], [44, 52], [44, 56], [44, 59], [44, 66], [44, 71], [44, 73], [44, 76], [44, 79], [44, 80], [44, 81], [44, 83], [44, 84], [44, 85], [44, 88], [44, 95], [44, 100], [44, 104], [44, 107], [44, 118], [44, 126], [44, 129], [44, 132], [44, 134], [44, 138], [44, 144], [44, 146], [44, 148], [44, 153], [44, 157], [45, 67], [45, 68], [45, 69], [45, 71], [45, 75], [45, 79], [45, 80], [45, 81], [45, 87], [45, 88], [45, 89], [45, 97], [45, 103], [45, 104], [45, 105], [45, 107], [45, 108], [45, 109], [45, 120], [45, 125], [45, 130], [45, 151], [45, 154], [45, 155], [46, 50], [46, 51], [46, 52], [46, 55], [46, 61], [46, 63], [46, 67], [46, 70], [46, 71], [46, 75], [46, 78], [46, 81], [46, 84], [46, 91], [46, 93], [46, 94], [46, 121], [46, 124], [46, 133], [46, 147], [46, 156], [47, 65], [47, 71], [47, 78], [47, 100], [47, 121], [47, 141], [47, 147], [48, 108], [48, 114], [49, 55], [49, 65], [49, 71], [49, 121], [49, 133], [49, 147], [50, 55], [50, 59], [50, 65], [50, 73], [50, 84], [50, 85], [50, 86], [50, 89], [50, 94], [50, 97], [50, 105], [50, 109], [50, 111], [50, 114], [50, 137], [50, 138], [50, 146], [50, 151], [50, 155], [50, 156], [51, 52], [51, 53], [51, 56], [51, 73], [51, 74], [51, 79], [51, 94], [51, 103], [51, 112], [51, 113], [51, 115], [51, 119], [51, 120], [51, 133], [51, 139], [51, 143], [51, 145], [51, 147], [51, 152], [52, 65], [52, 79], [52, 99], [52, 100], [52, 110], [52, 139], [52, 141], [52, 147], [52, 156], [53, 88], [53, 95], [53, 111], [53, 127], [53, 143], [54, 55], [54, 61], [54, 87], [54, 99], [54, 110], [54, 138], [54, 139], [54, 147], [55, 62], [55, 67], [55, 71], [55, 78], [55, 102], [55, 103], [55, 104], [55, 105], [55, 108], [55, 111], [55, 112], [55, 115], [55, 117], [55, 121], [55, 125], [55, 136], [55, 137], [55, 141], [55, 142], [55, 145], [55, 152], [55, 159], [56, 59], [56, 75], [56, 84], [56, 88], [56, 95], [56, 99], [56, 121], [56, 129], [56, 139], [56, 150], [57, 61], [57, 65], [57, 67], [57, 87], [57, 100], [57, 107], [57, 111], [57, 141], [57, 156], [58, 65], [58, 71], [58, 73], [58, 75], [58, 87], [58, 129], [58, 133], [58, 139], [59, 60], [59, 62], [59, 74], [59, 76], [59, 78], [59, 79], [59, 91], [59, 94], [59, 97], [59, 104], [59, 112], [59, 115], [59, 125], [59, 128], [59, 138], [59, 153], [60, 65], [60, 87], [60, 95], [60, 99], [60, 133], [61, 66], [61, 67], [61, 73], [61, 83], [61, 90], [61, 100], [61, 103], [61, 108], [61, 109], [61, 110], [61, 117], [61, 118], [61, 120], [61, 124], [61, 128], [61, 129], [61, 130], [61, 133], [61, 135], [61, 136], [61, 141], [61, 143], [61, 147], [61, 153], [62, 78], [62, 108], [62, 130], [62, 141], [63, 79], [63, 104], [63, 111], [63, 114], [63, 120], [63, 129], [63, 137], [63, 146], [64, 65], [64, 71], [64, 75], [64, 86], [64, 88], [64, 100], [64, 104], [64, 115], [64, 133], [64, 146], [65, 74], [65, 76], [65, 82], [65, 84], [65, 86], [65, 98], [65, 108], [65, 112], [65, 117], [65, 134], [65, 139], [65, 158], [66, 75], [66, 144], [67, 76], [67, 81], [67, 83], [67, 85], [67, 89], [67, 91], [67, 92], [67, 96], [67, 115], [67, 116], [67, 117], [67, 119], [67, 120], [67, 123], [67, 139], [67, 146], [67, 147], [67, 149], [67, 155], [68, 80], [68, 95], [68, 102], [68, 108], [68, 114], [68, 127], [68, 133], [68, 146], [69, 95], [69, 108], [69, 114], [69, 129], [69, 144], [70, 87], [70, 89], [70, 95], [70, 111], [70, 114], [70, 138], [71, 73], [71, 93], [71, 104], [71, 105], [71, 114], [71, 115], [71, 116], [71, 118], [71, 129], [71, 139], [71, 142], [71, 147], [72, 75], [72, 99], [72, 104], [72, 114], [72, 120], [72, 129], [72, 143], [72, 146], [72, 156], [73, 80], [73, 81], [73, 86], [73, 87], [73, 89], [73, 98], [73, 100], [73, 101], [73, 104], [73, 111], [73, 117], [73, 123], [73, 127], [73, 131], [73, 133], [73, 140], [73, 148], [73, 151], [73, 154], [74, 79], [74, 104], [74, 121], [74, 130], [74, 139], [75, 77], [75, 79], [75, 88], [75, 95], [75, 102], [75, 103], [75, 105], [75, 119], [75, 124], [75, 128], [75, 133], [75, 138], [75, 140], [75, 141], [75, 142], [75, 146], [75, 147], [75, 149], [75, 150], [75, 156], [75, 157], [76, 78], [76, 111], [76, 120], [76, 121], [76, 137], [76, 139], [76, 146], [77, 80], [77, 84], [77, 88], [77, 102], [77, 130], [77, 141], [77, 150], [78, 79], [78, 80], [78, 88], [78, 89], [78, 94], [78, 97], [78, 99], [78, 102], [78, 108], [78, 112], [78, 116], [78, 129], [78, 134], [78, 139], [78, 144], [78, 146], [78, 152], [78, 155], [79, 84], [79, 88], [79, 99], [79, 105], [79, 107], [79, 108], [79, 115], [79, 122], [79, 136], [79, 137], [79, 146], [79, 148], [79, 158], [80, 86], [80, 87], [80, 89], [80, 91], [80, 96], [80, 99], [80, 100], [80, 101], [80, 102], [80, 104], [80, 106], [80, 107], [80, 110], [80, 111], [80, 119], [80, 120], [80, 122], [80, 125], [80, 126], [80, 128], [80, 129], [80, 152], [80, 156], [80, 157], [81, 88], [81, 102], [81, 118], [81, 127], [81, 129], [81, 138], [82, 86], [82, 100], [82, 108], [82, 118], [82, 130], [82, 133], [82, 141], [82, 146], [83, 86], [83, 89], [83, 95], [83, 129], [83, 143], [84, 89], [84, 91], [84, 94], [84, 95], [84, 97], [84, 99], [84, 111], [84, 113], [84, 120], [84, 127], [84, 133], [84, 139], [84, 147], [84, 149], [84, 150], [84, 151], [84, 152], [84, 156], [85, 115], [85, 127], [85, 139], [86, 90], [86, 94], [86, 95], [86, 100], [86, 103], [86, 105], [86, 107], [86, 110], [86, 118], [86, 120], [86, 128], [86, 139], [86, 140], [86, 156], [86, 158], [87, 89], [87, 118], [87, 120], [87, 128], [87, 132], [87, 136], [87, 139], [87, 159], [88, 89], [88, 98], [88, 99], [88, 100], [88, 107], [88, 110], [88, 114], [88, 126], [88, 129], [88, 133], [88, 135], [88, 138], [88, 142], [88, 146], [88, 149], [88, 150], [88, 154], [88, 158], [88, 159], [89, 95], [89, 96], [89, 100], [89, 102], [89, 105], [89, 110], [89, 114], [89, 119], [89, 121], [89, 129], [89, 133], [89, 134], [89, 137], [89, 139], [89, 143], [89, 144], [89, 148], [89, 157], [89, 159], [90, 108], [90, 115], [90, 144], [91, 99], [91, 104], [91, 118], [91, 127], [91, 144], [92, 121], [92, 133], [92, 146], [93, 110], [93, 129], [93, 138], [93, 147], [93, 156], [94, 108], [94, 111], [94, 118], [94, 120], [95, 99], [95, 102], [95, 105], [95, 108], [95, 110], [95, 115], [95, 124], [95, 143], [95, 156], [96, 100], [96, 108], [96, 118], [96, 133], [96, 147], [96, 156], [97, 99], [97, 100], [97, 108], [97, 115], [97, 121], [98, 108], [98, 138], [99, 104], [99, 115], [99, 117], [99, 118], [99, 120], [99, 126], [99, 128], [99, 130], [99, 131], [99, 133], [99, 137], [99, 145], [99, 146], [99, 147], [99, 150], [99, 151], [100, 107], [100, 111], [100, 115], [100, 121], [100, 137], [100, 142], [100, 152], [100, 153], [101, 114], [101, 120], [101, 139], [102, 107], [102, 111], [102, 118], [102, 122], [102, 129], [102, 133], [102, 144], [102, 145], [102, 147], [102, 153], [102, 154], [103, 111], [103, 120], [103, 130], [103, 133], [103, 141], [103, 143], [104, 107], [104, 111], [104, 119], [104, 127], [104, 139], [104, 146], [104, 155], [105, 111], [105, 127], [105, 139], [105, 144], [106, 127], [106, 143], [106, 144], [107, 109], [107, 114], [107, 116], [107, 118], [107, 121], [107, 126], [107, 136], [107, 137], [107, 143], [107, 145], [107, 147], [107, 157], [108, 109], [108, 113], [108, 121], [108, 123], [108, 125], [108, 130], [108, 131], [108, 132], [108, 136], [108, 139], [108, 142], [108, 145], [108, 156], [108, 157], [109, 118], [110, 111], [110, 112], [110, 118], [110, 120], [110, 122], [110, 123], [110, 128], [110, 131], [110, 136], [110, 139], [110, 143], [111, 114], [111, 115], [111, 116], [111, 118], [111, 124], [111, 127], [111, 129], [111, 133], [111, 142], [111, 156], [111, 158], [112, 121], [112, 127], [112, 129], [112, 143], [112, 144], [113, 115], [113, 133], [113, 137], [113, 138], [113, 147], [113, 150], [114, 120], [114, 121], [114, 123], [114, 124], [114, 127], [114, 128], [114, 132], [114, 136], [114, 144], [114, 145], [114, 147], [114, 151], [114, 158], [115, 117], [115, 121], [115, 122], [115, 125], [115, 132], [115, 133], [115, 137], [115, 141], [115, 142], [115, 146], [115, 148], [115, 156], [115, 158], [116, 138], [116, 146], [117, 120], [117, 133], [117, 143], [118, 128], [118, 129], [118, 130], [118, 138], [118, 139], [118, 144], [118, 147], [118, 154], [118, 158], [119, 120], [119, 130], [119, 137], [120, 122], [120, 132], [120, 137], [120, 139], [120, 141], [120, 143], [120, 149], [121, 127], [121, 129], [121, 131], [121, 141], [121, 144], [122, 156], [123, 138], [123, 141], [123, 144], [124, 137], [124, 139], [124, 143], [124, 147], [125, 129], [125, 133], [125, 146], [125, 147], [126, 133], [127, 137], [127, 138], [127, 141], [127, 142], [127, 152], [127, 155], [127, 158], [128, 130], [128, 139], [128, 141], [129, 138], [129, 143], [129, 147], [129, 148], [129, 155], [130, 132], [130, 133], [130, 135], [130, 145], [130, 149], [130, 151], [130, 154], [131, 147], [132, 141], [132, 146], [133, 136], [133, 137], [133, 148], [134, 138], [134, 144], [135, 143], [136, 143], [136, 146], [137, 139], [137, 141], [137, 144], [137, 150], [137, 154], [137, 157], [138, 140], [138, 141], [138, 143], [138, 149], [138, 150], [138, 151], [138, 156], [138, 157], [138, 158], [139, 143], [139, 146], [139, 147], [139, 149], [139, 153], [139, 159], [141, 144], [141, 150], [141, 159], [143, 144], [143, 149], [143, 155], [143, 156], [143, 157], [143, 159], [144, 147], [144, 152], [146, 147], [146, 150], [146, 153], [146, 154], [146, 156], [149, 150], [150, 156], [156, 158], [156, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s3/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb99240f282879c9e3ee2415601d55b8ae79b53b --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [1, 3, 6, 7, 8, 11, 13, 21, 23, 24, 28, 30, 32, 33, 40, 44, 45, 46, 50, 51, 55, 59, 61, 65, 67, 71, 73, 75, 78, 79, 80, 84, 86, 87, 88, 89, 95, 99, 100, 102, 104, 107, 108, 110, 111, 114, 115, 118, 120, 121, 127, 129, 130, 133, 137, 138, 139, 141, 143, 144, 146, 147, 150, 156]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s3/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-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-l6-s3/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4be7a84d58467da841bd3aa7c188845f0dabb6f --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 7], [0, 13], [0, 46], [0, 50], [0, 59], [0, 61], [0, 73], [0, 84], [0, 87], [0, 99], [0, 104], [0, 107], [0, 120], [0, 127], [0, 150], [1, 6], [1, 13], [1, 14], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 29], [1, 33], [1, 35], [1, 37], [1, 38], [1, 46], [1, 47], [1, 49], [1, 51], [1, 61], [1, 65], [1, 66], [1, 71], [1, 73], [1, 80], [1, 84], [1, 97], [1, 102], [1, 103], [1, 114], [1, 115], [1, 118], [1, 120], [1, 121], [1, 141], [1, 144], [1, 150], [1, 155], [1, 159], [2, 6], [2, 102], [2, 110], [2, 130], [2, 146], [3, 7], [3, 10], [3, 13], [3, 28], [3, 29], [3, 45], [3, 46], [3, 63], [3, 64], [3, 68], [3, 75], [3, 84], [3, 88], [3, 89], [3, 90], [3, 93], [3, 97], [3, 98], [3, 99], [3, 101], [3, 111], [3, 129], [3, 131], [3, 139], [3, 141], [3, 142], [3, 145], [3, 146], [3, 149], [3, 150], [3, 152], [3, 156], [3, 157], [4, 6], [4, 44], [4, 46], [4, 51], [4, 59], [4, 107], [4, 137], [4, 139], [5, 30], [5, 33], [5, 73], [5, 102], [5, 133], [5, 147], [6, 17], [6, 20], [6, 21], [6, 24], [6, 28], [6, 30], [6, 31], [6, 36], [6, 38], [6, 43], [6, 48], [6, 50], [6, 61], [6, 62], [6, 65], [6, 75], [6, 77], [6, 93], [6, 94], [6, 100], [6, 101], [6, 102], [6, 105], [6, 110], [6, 114], [6, 121], [6, 129], [6, 130], [6, 134], [6, 136], [6, 145], [6, 150], [6, 153], [7, 10], [7, 22], [7, 30], [7, 32], [7, 34], [7, 38], [7, 43], [7, 44], [7, 55], [7, 59], [7, 61], [7, 62], [7, 67], [7, 75], [7, 84], [7, 86], [7, 89], [7, 98], [7, 99], [7, 107], [7, 108], [7, 110], [7, 118], [7, 121], [7, 135], [7, 137], [7, 142], [7, 144], [7, 152], [7, 153], [7, 157], [7, 158], [7, 159], [8, 13], [8, 18], [8, 19], [8, 27], [8, 34], [8, 45], [8, 56], [8, 57], [8, 59], [8, 63], [8, 65], [8, 66], [8, 77], [8, 78], [8, 80], [8, 81], [8, 84], [8, 86], [8, 96], [8, 115], [8, 116], [8, 118], [8, 121], [8, 125], [8, 130], [8, 132], [8, 135], [8, 137], [8, 138], [8, 141], [8, 146], [8, 155], [9, 13], [9, 33], [9, 88], [9, 100], [9, 118], [9, 120], [9, 137], [9, 138], [10, 24], [10, 28], [10, 55], [10, 71], [10, 84], [10, 86], [10, 99], [10, 127], [10, 133], [10, 150], [11, 20], [11, 21], [11, 23], [11, 27], [11, 29], [11, 35], [11, 38], [11, 40], [11, 47], [11, 51], [11, 52], [11, 53], [11, 54], [11, 55], [11, 59], [11, 61], [11, 65], [11, 67], [11, 68], [11, 74], [11, 80], [11, 83], [11, 85], [11, 86], [11, 100], [11, 107], [11, 111], [11, 112], [11, 113], [11, 118], [11, 122], [11, 124], [11, 127], [11, 129], [11, 131], [11, 141], [11, 144], [11, 145], [11, 147], [11, 152], [11, 155], [11, 157], [11, 158], [12, 59], [12, 65], [12, 73], [12, 84], [12, 88], [12, 118], [12, 121], [12, 141], [12, 143], [12, 150], [13, 14], [13, 18], [13, 30], [13, 33], [13, 35], [13, 45], [13, 57], [13, 66], [13, 75], [13, 79], [13, 80], [13, 85], [13, 89], [13, 95], [13, 102], [13, 103], [13, 105], [13, 113], [13, 118], [13, 120], [13, 121], [13, 134], [13, 142], [13, 154], [14, 44], [14, 71], [14, 80], [14, 102], [14, 146], [14, 147], [15, 23], [15, 59], [15, 75], [15, 88], [15, 110], [15, 120], [15, 133], [15, 137], [16, 21], [16, 44], [16, 45], [16, 89], [16, 99], [16, 110], [16, 141], [17, 23], [17, 44], [17, 50], [17, 51], [17, 55], [17, 65], [17, 67], [17, 75], [17, 87], [17, 99], [17, 100], [17, 107], [17, 120], [17, 130], [17, 133], [17, 150], [18, 24], [18, 32], [18, 33], [18, 46], [18, 50], [18, 51], [18, 102], [18, 108], [18, 127], [18, 130], [18, 143], [18, 147], [19, 28], [19, 33], [19, 79], [19, 80], [19, 114], [19, 129], [19, 137], [19, 146], [19, 150], [20, 28], [20, 32], [20, 61], [20, 107], [20, 108], [20, 115], [20, 118], [21, 22], [21, 23], [21, 24], [21, 30], [21, 32], [21, 47], [21, 50], [21, 63], [21, 72], [21, 73], [21, 79], [21, 82], [21, 87], [21, 89], [21, 99], [21, 104], [21, 110], [21, 115], [21, 118], [21, 121], [21, 127], [21, 128], [21, 130], [21, 146], [21, 147], [21, 151], [21, 153], [21, 156], [22, 28], [22, 40], [22, 44], [22, 65], [22, 84], [22, 107], [22, 108], [22, 114], [22, 121], [22, 133], [22, 138], [22, 144], [23, 25], [23, 29], [23, 33], [23, 37], [23, 41], [23, 46], [23, 66], [23, 67], [23, 69], [23, 76], [23, 88], [23, 110], [23, 115], [23, 118], [23, 120], [23, 121], [23, 122], [23, 124], [23, 141], [23, 158], [24, 35], [24, 42], [24, 44], [24, 50], [24, 71], [24, 78], [24, 83], [24, 85], [24, 87], [24, 89], [24, 92], [24, 97], [24, 100], [24, 102], [24, 103], [24, 105], [24, 106], [24, 108], [24, 110], [24, 111], [24, 125], [24, 127], [24, 129], [24, 130], [24, 131], [24, 133], [24, 138], [24, 143], [24, 145], [24, 156], [24, 159], [25, 33], [25, 71], [25, 78], [25, 84], [25, 104], [25, 127], [25, 138], [25, 156], [26, 44], [26, 45], [26, 55], [26, 75], [26, 100], [26, 115], [26, 118], [26, 120], [26, 127], [26, 130], [26, 137], [26, 147], [26, 156], [27, 50], [27, 55], [27, 80], [27, 89], [27, 102], [27, 127], [27, 139], [27, 143], [27, 146], [28, 31], [28, 33], [28, 34], [28, 38], [28, 40], [28, 45], [28, 54], [28, 58], [28, 59], [28, 61], [28, 62], [28, 67], [28, 69], [28, 72], [28, 74], [28, 78], [28, 79], [28, 83], [28, 88], [28, 91], [28, 93], [28, 97], [28, 100], [28, 102], [28, 107], [28, 112], [28, 116], [28, 121], [28, 127], [28, 139], [28, 141], [28, 149], [28, 150], [28, 151], [28, 158], [29, 33], [29, 40], [29, 46], [29, 78], [29, 80], [29, 95], [29, 99], [29, 100], [29, 129], [29, 137], [29, 150], [30, 35], [30, 40], [30, 54], [30, 70], [30, 81], [30, 86], [30, 87], [30, 88], [30, 89], [30, 94], [30, 95], [30, 103], [30, 110], [30, 131], [30, 136], [30, 137], [30, 141], [30, 144], [30, 148], [30, 157], [31, 55], [31, 61], [31, 65], [31, 71], [31, 100], [31, 137], [31, 138], [31, 141], [31, 144], [31, 156], [32, 44], [32, 46], [32, 47], [32, 59], [32, 60], [32, 63], [32, 73], [32, 76], [32, 83], [32, 84], [32, 86], [32, 101], [32, 102], [32, 110], [32, 130], [32, 133], [32, 134], [32, 143], [32, 153], [33, 37], [33, 41], [33, 46], [33, 47], [33, 48], [33, 52], [33, 57], [33, 62], [33, 65], [33, 66], [33, 67], [33, 71], [33, 77], [33, 78], [33, 84], [33, 87], [33, 94], [33, 96], [33, 102], [33, 110], [33, 133], [33, 137], [33, 139], [33, 140], [33, 142], [33, 144], [33, 146], [33, 159], [34, 40], [34, 73], [34, 107], [34, 127], [34, 143], [34, 146], [35, 51], [35, 65], [35, 78], [35, 84], [35, 86], [35, 87], [35, 89], [35, 127], [35, 133], [36, 45], [36, 51], [36, 65], [36, 75], [36, 87], [36, 120], [36, 133], [36, 139], [36, 143], [36, 144], [36, 146], [37, 59], [37, 61], [37, 65], [37, 80], [37, 100], [37, 104], [37, 110], [37, 127], [37, 137], [37, 138], [38, 44], [38, 46], [38, 78], [38, 84], [38, 127], [38, 129], [38, 139], [38, 143], [38, 147], [38, 150], [38, 156], [39, 61], [39, 73], [39, 110], [39, 114], [39, 115], [39, 120], [39, 127], [39, 129], [39, 141], [40, 44], [40, 45], [40, 51], [40, 52], [40, 55], [40, 58], [40, 65], [40, 74], [40, 76], [40, 79], [40, 81], [40, 82], [40, 88], [40, 89], [40, 95], [40, 97], [40, 114], [40, 119], [40, 121], [40, 125], [40, 127], [40, 139], [40, 142], [40, 144], [40, 146], [40, 148], [40, 152], [40, 156], [40, 158], [41, 55], [41, 71], [41, 75], [41, 110], [41, 146], [42, 45], [42, 46], [42, 51], [42, 61], [42, 67], [42, 73], [42, 86], [42, 138], [43, 55], [43, 61], [43, 71], [43, 78], [43, 84], [43, 100], [43, 120], [43, 138], [43, 139], [43, 144], [44, 46], [44, 50], [44, 52], [44, 56], [44, 59], [44, 66], [44, 71], [44, 73], [44, 76], [44, 79], [44, 80], [44, 81], [44, 83], [44, 84], [44, 85], [44, 88], [44, 95], [44, 100], [44, 104], [44, 107], [44, 118], [44, 126], [44, 129], [44, 132], [44, 134], [44, 138], [44, 144], [44, 146], [44, 148], [44, 153], [44, 157], [45, 67], [45, 68], [45, 69], [45, 71], [45, 75], [45, 79], [45, 80], [45, 81], [45, 87], [45, 88], [45, 89], [45, 97], [45, 103], [45, 104], [45, 105], [45, 107], [45, 108], [45, 109], [45, 120], [45, 125], [45, 130], [45, 151], [45, 154], [45, 155], [46, 50], [46, 51], [46, 52], [46, 55], [46, 61], [46, 63], [46, 67], [46, 70], [46, 71], [46, 75], [46, 78], [46, 81], [46, 84], [46, 91], [46, 93], [46, 94], [46, 121], [46, 124], [46, 133], [46, 147], [46, 156], [47, 65], [47, 71], [47, 78], [47, 100], [47, 121], [47, 141], [47, 147], [48, 108], [48, 114], [49, 55], [49, 65], [49, 71], [49, 121], [49, 133], [49, 147], [50, 55], [50, 59], [50, 65], [50, 73], [50, 84], [50, 85], [50, 86], [50, 89], [50, 94], [50, 97], [50, 105], [50, 109], [50, 111], [50, 114], [50, 137], [50, 138], [50, 146], [50, 151], [50, 155], [50, 156], [51, 52], [51, 53], [51, 56], [51, 73], [51, 74], [51, 79], [51, 94], [51, 103], [51, 112], [51, 113], [51, 115], [51, 119], [51, 120], [51, 133], [51, 139], [51, 143], [51, 145], [51, 147], [51, 152], [52, 65], [52, 79], [52, 99], [52, 100], [52, 110], [52, 139], [52, 141], [52, 147], [52, 156], [53, 88], [53, 95], [53, 111], [53, 127], [53, 143], [54, 55], [54, 61], [54, 87], [54, 99], [54, 110], [54, 138], [54, 139], [54, 147], [55, 62], [55, 67], [55, 71], [55, 78], [55, 102], [55, 103], [55, 104], [55, 105], [55, 108], [55, 111], [55, 112], [55, 115], [55, 117], [55, 121], [55, 125], [55, 136], [55, 137], [55, 141], [55, 142], [55, 145], [55, 152], [55, 159], [56, 59], [56, 75], [56, 84], [56, 88], [56, 95], [56, 99], [56, 121], [56, 129], [56, 139], [56, 150], [57, 61], [57, 65], [57, 67], [57, 87], [57, 100], [57, 107], [57, 111], [57, 141], [57, 156], [58, 65], [58, 71], [58, 73], [58, 75], [58, 87], [58, 129], [58, 133], [58, 139], [59, 60], [59, 62], [59, 74], [59, 76], [59, 78], [59, 79], [59, 91], [59, 94], [59, 97], [59, 104], [59, 112], [59, 115], [59, 125], [59, 128], [59, 138], [59, 153], [60, 65], [60, 87], [60, 95], [60, 99], [60, 133], [61, 66], [61, 67], [61, 73], [61, 83], [61, 90], [61, 100], [61, 103], [61, 108], [61, 109], [61, 110], [61, 117], [61, 118], [61, 120], [61, 124], [61, 128], [61, 129], [61, 130], [61, 133], [61, 135], [61, 136], [61, 141], [61, 143], [61, 147], [61, 153], [62, 78], [62, 108], [62, 130], [62, 141], [63, 79], [63, 104], [63, 111], [63, 114], [63, 120], [63, 129], [63, 137], [63, 146], [64, 65], [64, 71], [64, 75], [64, 86], [64, 88], [64, 100], [64, 104], [64, 115], [64, 133], [64, 146], [65, 74], [65, 76], [65, 82], [65, 84], [65, 86], [65, 98], [65, 108], [65, 112], [65, 117], [65, 134], [65, 139], [65, 158], [66, 75], [66, 144], [67, 76], [67, 81], [67, 83], [67, 85], [67, 89], [67, 91], [67, 92], [67, 96], [67, 115], [67, 116], [67, 117], [67, 119], [67, 120], [67, 123], [67, 139], [67, 146], [67, 147], [67, 149], [67, 155], [68, 80], [68, 95], [68, 102], [68, 108], [68, 114], [68, 127], [68, 133], [68, 146], [69, 95], [69, 108], [69, 114], [69, 129], [69, 144], [70, 87], [70, 89], [70, 95], [70, 111], [70, 114], [70, 138], [71, 73], [71, 93], [71, 104], [71, 105], [71, 114], [71, 115], [71, 116], [71, 118], [71, 129], [71, 139], [71, 142], [71, 147], [72, 75], [72, 99], [72, 104], [72, 114], [72, 120], [72, 129], [72, 143], [72, 146], [72, 156], [73, 80], [73, 81], [73, 86], [73, 87], [73, 89], [73, 98], [73, 100], [73, 101], [73, 104], [73, 111], [73, 117], [73, 123], [73, 127], [73, 131], [73, 133], [73, 140], [73, 148], [73, 151], [73, 154], [74, 79], [74, 104], [74, 121], [74, 130], [74, 139], [75, 77], [75, 79], [75, 88], [75, 95], [75, 102], [75, 103], [75, 105], [75, 119], [75, 124], [75, 128], [75, 133], [75, 138], [75, 140], [75, 141], [75, 142], [75, 146], [75, 147], [75, 149], [75, 150], [75, 156], [75, 157], [76, 78], [76, 111], [76, 120], [76, 121], [76, 137], [76, 139], [76, 146], [77, 80], [77, 84], [77, 88], [77, 102], [77, 130], [77, 141], [77, 150], [78, 79], [78, 80], [78, 88], [78, 89], [78, 94], [78, 97], [78, 99], [78, 102], [78, 108], [78, 112], [78, 116], [78, 129], [78, 134], [78, 139], [78, 144], [78, 146], [78, 152], [78, 155], [79, 84], [79, 88], [79, 99], [79, 105], [79, 107], [79, 108], [79, 115], [79, 122], [79, 136], [79, 137], [79, 146], [79, 148], [79, 158], [80, 86], [80, 87], [80, 89], [80, 91], [80, 96], [80, 99], [80, 100], [80, 101], [80, 102], [80, 104], [80, 106], [80, 107], [80, 110], [80, 111], [80, 119], [80, 120], [80, 122], [80, 125], [80, 126], [80, 128], [80, 129], [80, 152], [80, 156], [80, 157], [81, 88], [81, 102], [81, 118], [81, 127], [81, 129], [81, 138], [82, 86], [82, 100], [82, 108], [82, 118], [82, 130], [82, 133], [82, 141], [82, 146], [83, 86], [83, 89], [83, 95], [83, 129], [83, 143], [84, 89], [84, 91], [84, 94], [84, 95], [84, 97], [84, 99], [84, 111], [84, 113], [84, 120], [84, 127], [84, 133], [84, 139], [84, 147], [84, 149], [84, 150], [84, 151], [84, 152], [84, 156], [85, 115], [85, 127], [85, 139], [86, 90], [86, 94], [86, 95], [86, 100], [86, 103], [86, 105], [86, 107], [86, 110], [86, 118], [86, 120], [86, 128], [86, 139], [86, 140], [86, 156], [86, 158], [87, 89], [87, 118], [87, 120], [87, 128], [87, 132], [87, 136], [87, 139], [87, 159], [88, 89], [88, 98], [88, 99], [88, 100], [88, 107], [88, 110], [88, 114], [88, 126], [88, 129], [88, 133], [88, 135], [88, 138], [88, 142], [88, 146], [88, 149], [88, 150], [88, 154], [88, 158], [88, 159], [89, 95], [89, 96], [89, 100], [89, 102], [89, 105], [89, 110], [89, 114], [89, 119], [89, 121], [89, 129], [89, 133], [89, 134], [89, 137], [89, 139], [89, 143], [89, 144], [89, 148], [89, 157], [89, 159], [90, 108], [90, 115], [90, 144], [91, 99], [91, 104], [91, 118], [91, 127], [91, 144], [92, 121], [92, 133], [92, 146], [93, 110], [93, 129], [93, 138], [93, 147], [93, 156], [94, 108], [94, 111], [94, 118], [94, 120], [95, 99], [95, 102], [95, 105], [95, 108], [95, 110], [95, 115], [95, 124], [95, 143], [95, 156], [96, 100], [96, 108], [96, 118], [96, 133], [96, 147], [96, 156], [97, 99], [97, 100], [97, 108], [97, 115], [97, 121], [98, 108], [98, 138], [99, 104], [99, 115], [99, 117], [99, 118], [99, 120], [99, 126], [99, 128], [99, 130], [99, 131], [99, 133], [99, 137], [99, 145], [99, 146], [99, 147], [99, 150], [99, 151], [100, 107], [100, 111], [100, 115], [100, 121], [100, 137], [100, 142], [100, 152], [100, 153], [101, 114], [101, 120], [101, 139], [102, 107], [102, 111], [102, 118], [102, 122], [102, 129], [102, 133], [102, 144], [102, 145], [102, 147], [102, 153], [102, 154], [103, 111], [103, 120], [103, 130], [103, 133], [103, 141], [103, 143], [104, 107], [104, 111], [104, 119], [104, 127], [104, 139], [104, 146], [104, 155], [105, 111], [105, 127], [105, 139], [105, 144], [106, 127], [106, 143], [106, 144], [107, 109], [107, 114], [107, 116], [107, 118], [107, 121], [107, 126], [107, 136], [107, 137], [107, 143], [107, 145], [107, 147], [107, 157], [108, 109], [108, 113], [108, 121], [108, 123], [108, 125], [108, 130], [108, 131], [108, 132], [108, 136], [108, 139], [108, 142], [108, 145], [108, 156], [108, 157], [109, 118], [110, 111], [110, 112], [110, 118], [110, 120], [110, 122], [110, 123], [110, 128], [110, 131], [110, 136], [110, 139], [110, 143], [111, 114], [111, 115], [111, 116], [111, 118], [111, 124], [111, 127], [111, 129], [111, 133], [111, 142], [111, 156], [111, 158], [112, 121], [112, 127], [112, 129], [112, 143], [112, 144], [113, 115], [113, 133], [113, 137], [113, 138], [113, 147], [113, 150], [114, 120], [114, 121], [114, 123], [114, 124], [114, 127], [114, 128], [114, 132], [114, 136], [114, 144], [114, 145], [114, 147], [114, 151], [114, 158], [115, 117], [115, 121], [115, 122], [115, 125], [115, 132], [115, 133], [115, 137], [115, 141], [115, 142], [115, 146], [115, 148], [115, 156], [115, 158], [116, 138], [116, 146], [117, 120], [117, 133], [117, 143], [118, 128], [118, 129], [118, 130], [118, 138], [118, 139], [118, 144], [118, 147], [118, 154], [118, 158], [119, 120], [119, 130], [119, 137], [120, 122], [120, 132], [120, 137], [120, 139], [120, 141], [120, 143], [120, 149], [121, 127], [121, 129], [121, 131], [121, 141], [121, 144], [122, 156], [123, 138], [123, 141], [123, 144], [124, 137], [124, 139], [124, 143], [124, 147], [125, 129], [125, 133], [125, 146], [125, 147], [126, 133], [127, 137], [127, 138], [127, 141], [127, 142], [127, 152], [127, 155], [127, 158], [128, 130], [128, 139], [128, 141], [129, 138], [129, 143], [129, 147], [129, 148], [129, 155], [130, 132], [130, 133], [130, 135], [130, 145], [130, 149], [130, 151], [130, 154], [131, 147], [132, 141], [132, 146], [133, 136], [133, 137], [133, 148], [134, 138], [134, 144], [135, 143], [136, 143], [136, 146], [137, 139], [137, 141], [137, 144], [137, 150], [137, 154], [137, 157], [138, 140], [138, 141], [138, 143], [138, 149], [138, 150], [138, 151], [138, 156], [138, 157], [138, 158], [139, 143], [139, 146], [139, 147], [139, 149], [139, 153], [139, 159], [141, 144], [141, 150], [141, 159], [143, 144], [143, 149], [143, 155], [143, 156], [143, 157], [143, 159], [144, 147], [144, 152], [146, 147], [146, 150], [146, 153], [146, 154], [146, 156], [149, 150], [150, 156], [156, 158], [156, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s3/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l6-s3/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-rg-graph-color-l1-s0/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s0/environment/instance.json b/tasks/construct-rg-graph-color-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a62f98d70bcd40a3b4edfd0f0696f626adec43a --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 4], [1, 2], [1, 4], [2, 3], [4, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s0/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8bfa2ae9e2e3179c2daa216e29dd7b3893c22c04 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 2, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s0/tests/check.py b/tasks/construct-rg-graph-color-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s0/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-s0/tests/instance.json b/tasks/construct-rg-graph-color-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a62f98d70bcd40a3b4edfd0f0696f626adec43a --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 4], [1, 2], [1, 4], [2, 3], [4, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s0/tests/run.py b/tasks/construct-rg-graph-color-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s0/tests/test.sh b/tasks/construct-rg-graph-color-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s7/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s7/environment/instance.json b/tasks/construct-rg-graph-color-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c98eedabc356134291f7941bb0d23fefc84ada66 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 3], [0, 4], [1, 3], [3, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s7/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..44957564b84175d4fb187da9370114fbd23c69d6 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 1, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s7/tests/check.py b/tasks/construct-rg-graph-color-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-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-l1-s7/tests/instance.json b/tasks/construct-rg-graph-color-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c98eedabc356134291f7941bb0d23fefc84ada66 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 3], [0, 4], [1, 3], [3, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s7/tests/run.py b/tasks/construct-rg-graph-color-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s7/tests/test.sh b/tasks/construct-rg-graph-color-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s9/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s9/environment/instance.json b/tasks/construct-rg-graph-color-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a0f67505d777595cb5dc248cd158c8fd818e6bf4 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 4], [1, 3], [2, 4], [4, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s9/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..44957564b84175d4fb187da9370114fbd23c69d6 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 1, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s9/tests/check.py b/tasks/construct-rg-graph-color-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-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-l1-s9/tests/instance.json b/tasks/construct-rg-graph-color-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a0f67505d777595cb5dc248cd158c8fd818e6bf4 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 4], [1, 3], [2, 4], [4, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s9/tests/run.py b/tasks/construct-rg-graph-color-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s9/tests/test.sh b/tasks/construct-rg-graph-color-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l5-s1/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s1/environment/instance.json b/tasks/construct-rg-graph-color-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecd0c90431fb97eebc137f644f7f763eb25466b4 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 15], [0, 17], [0, 19], [0, 23], [1, 6], [2, 8], [2, 11], [2, 16], [2, 19], [2, 20], [2, 24], [3, 22], [3, 23], [3, 24], [4, 5], [4, 6], [4, 21], [5, 9], [5, 14], [5, 19], [6, 10], [6, 16], [6, 20], [7, 10], [7, 11], [7, 18], [7, 22], [8, 19], [9, 10], [10, 14], [10, 17], [11, 13], [12, 22], [13, 16], [14, 16], [14, 19], [14, 22], [17, 18], [17, 20], [17, 24], [20, 22]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s1/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..794b5c8231a19564d801087a97b8f6076ecdc2b9 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 3, 2, 1, 1, 1, 2, 3, 2, 3, 3, 3, 2, 2, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s1/tests/check.py b/tasks/construct-rg-graph-color-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s1/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-s1/tests/instance.json b/tasks/construct-rg-graph-color-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecd0c90431fb97eebc137f644f7f763eb25466b4 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 15], [0, 17], [0, 19], [0, 23], [1, 6], [2, 8], [2, 11], [2, 16], [2, 19], [2, 20], [2, 24], [3, 22], [3, 23], [3, 24], [4, 5], [4, 6], [4, 21], [5, 9], [5, 14], [5, 19], [6, 10], [6, 16], [6, 20], [7, 10], [7, 11], [7, 18], [7, 22], [8, 19], [9, 10], [10, 14], [10, 17], [11, 13], [12, 22], [13, 16], [14, 16], [14, 19], [14, 22], [17, 18], [17, 20], [17, 24], [20, 22]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s1/tests/run.py b/tasks/construct-rg-graph-color-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s1/tests/test.sh b/tasks/construct-rg-graph-color-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s6/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s6/environment/instance.json b/tasks/construct-rg-graph-color-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b187bcf2618c638e351a208917da23ea70690134 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 1], [0, 7], [0, 10], [0, 15], [1, 5], [1, 13], [1, 14], [1, 15], [1, 19], [1, 20], [2, 5], [2, 6], [2, 11], [3, 9], [3, 11], [4, 5], [4, 16], [4, 18], [5, 23], [5, 24], [6, 22], [7, 13], [7, 17], [7, 21], [7, 24], [8, 13], [8, 16], [10, 12], [10, 13], [11, 19], [12, 19], [13, 21], [14, 15], [14, 20], [14, 22], [16, 20], [16, 21], [19, 21], [19, 23], [19, 24], [20, 24], [21, 22], [22, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s6/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0581657c8beb8c1d1ad98d19793acc5ee2a0c64b --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 2, 1, 1, 1, 3, 2, 2, 1, 2, 2, 2, 1, 3, 1, 3, 2, 1, 2, 3, 3, 1, 3, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s6/tests/check.py b/tasks/construct-rg-graph-color-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-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-l5-s6/tests/instance.json b/tasks/construct-rg-graph-color-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b187bcf2618c638e351a208917da23ea70690134 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 1], [0, 7], [0, 10], [0, 15], [1, 5], [1, 13], [1, 14], [1, 15], [1, 19], [1, 20], [2, 5], [2, 6], [2, 11], [3, 9], [3, 11], [4, 5], [4, 16], [4, 18], [5, 23], [5, 24], [6, 22], [7, 13], [7, 17], [7, 21], [7, 24], [8, 13], [8, 16], [10, 12], [10, 13], [11, 19], [12, 19], [13, 21], [14, 15], [14, 20], [14, 22], [16, 20], [16, 21], [19, 21], [19, 23], [19, 24], [20, 24], [21, 22], [22, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s6/tests/run.py b/tasks/construct-rg-graph-color-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s6/tests/test.sh b/tasks/construct-rg-graph-color-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l5-s8/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l5-s8/environment/instance.json b/tasks/construct-rg-graph-color-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6c72244123ffc9236d397d325d5a1fbcc0bf8cf --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 2], [0, 10], [1, 6], [1, 11], [1, 12], [1, 20], [2, 3], [2, 5], [2, 21], [2, 24], [3, 14], [3, 17], [3, 19], [3, 21], [3, 22], [4, 11], [4, 13], [4, 16], [5, 10], [5, 15], [6, 13], [6, 22], [7, 9], [8, 10], [8, 19], [9, 10], [9, 19], [10, 14], [10, 15], [10, 23], [11, 17], [11, 21], [12, 17], [12, 21], [13, 16], [13, 23], [13, 24], [14, 18], [15, 21], [16, 17], [16, 19], [16, 23], [17, 23], [19, 20], [20, 23], [21, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s8/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bbf5fdf525a8efcea30172ea6bc69645ae06d8f --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 3, 2, 2, 3, 2, 2, 2, 3, 1, 3, 2, 3, 3, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s8/tests/check.py b/tasks/construct-rg-graph-color-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-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-l5-s8/tests/instance.json b/tasks/construct-rg-graph-color-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6c72244123ffc9236d397d325d5a1fbcc0bf8cf --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 2], [0, 10], [1, 6], [1, 11], [1, 12], [1, 20], [2, 3], [2, 5], [2, 21], [2, 24], [3, 14], [3, 17], [3, 19], [3, 21], [3, 22], [4, 11], [4, 13], [4, 16], [5, 10], [5, 15], [6, 13], [6, 22], [7, 9], [8, 10], [8, 19], [9, 10], [9, 19], [10, 14], [10, 15], [10, 23], [11, 17], [11, 21], [12, 17], [12, 21], [13, 16], [13, 23], [13, 24], [14, 18], [15, 21], [16, 17], [16, 19], [16, 23], [17, 23], [19, 20], [20, 23], [21, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s8/tests/run.py b/tasks/construct-rg-graph-color-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l5-s8/tests/test.sh b/tasks/construct-rg-graph-color-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-simple-integration-l1-s1/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s1/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98d36805f0121f22ee535c1cc83d3f940e4c1e9f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "92*x**3/5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s1/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9abebe0105c00469b64797df1fe5b3234efb9144 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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": "23*x**4/5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s1/tests/check.py b/tasks/construct-rg-simple-integration-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s1/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98d36805f0121f22ee535c1cc83d3f940e4c1e9f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "92*x**3/5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s1/tests/run.py b/tasks/construct-rg-simple-integration-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s1/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s6/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l1-s6/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc7dab12e504d5b540c08cd64c2a302b78d3a02f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-16*X**3 - 6*X", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s6/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a53f1be9b6924f02f3b059957a13e08658090343 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-4*X**4 - 3*X**2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s6/tests/check.py b/tasks/construct-rg-simple-integration-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s6/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc7dab12e504d5b540c08cd64c2a302b78d3a02f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-16*X**3 - 6*X", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s6/tests/run.py b/tasks/construct-rg-simple-integration-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l1-s6/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l1-s8/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l1-s8/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5ada38c3f0d9b3f06780f99c5e31448ebe40e34 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "14*X**3/3 + 14*X", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s8/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..47953a00d9d8a7e596e703dec88d174221412c95 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "7*X**4/6 + 7*X**2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s8/tests/check.py b/tasks/construct-rg-simple-integration-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s8/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-s8/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5ada38c3f0d9b3f06780f99c5e31448ebe40e34 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "14*X**3/3 + 14*X", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s8/tests/run.py b/tasks/construct-rg-simple-integration-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l1-s8/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s0/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s0/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b308dd2cc83973974522d55c04f5e1c848e4474d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "63*x**8 - 12*x**5 - 10/x**2 + 27/(8*x**4) - 20/(3*x**5)", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s0/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9bb684b6e15aa439d47e1768b1e0f8e5a29b76a5 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "7*x**9 - 2*x**6 + 3/4 + 10/x - 9/(8*x**3) + 5/(3*x**4) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s0/tests/check.py b/tasks/construct-rg-simple-integration-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-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-l5-s0/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b308dd2cc83973974522d55c04f5e1c848e4474d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "63*x**8 - 12*x**5 - 10/x**2 + 27/(8*x**4) - 20/(3*x**5)", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s0/tests/run.py b/tasks/construct-rg-simple-integration-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s0/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s7/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s7/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c52490ab7f39e564a1cad1c1579e2eab52917b46 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "14*X**6 - 30*X**4 + 36*X**3 - 3/X**2 - 20/X**3 - 35/X**6", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s7/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..35911409cb3e8404650bb11ee9f950a06952b083 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "2*X**7 - 6*X**5 + 9*X**4 + 3/X + 10/X**2 + 7/X**5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s7/tests/check.py b/tasks/construct-rg-simple-integration-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s7/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-s7/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c52490ab7f39e564a1cad1c1579e2eab52917b46 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "14*X**6 - 30*X**4 + 36*X**3 - 3/X**2 - 20/X**3 - 35/X**6", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s7/tests/run.py b/tasks/construct-rg-simple-integration-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s7/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s9/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s9/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8e0458559c80532df03260ba40bbeddb17f4142 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "185*x**9/6 - 6*x**5 + 5*x/2 - 32/x**5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s9/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..868ec9af67302287ab3e7c239d94f777f89394e9 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "37*x**10/12 - x**6 + 5*x**2/4 + 8/x**4 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s9/tests/check.py b/tasks/construct-rg-simple-integration-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s9/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-s9/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8e0458559c80532df03260ba40bbeddb17f4142 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "185*x**9/6 - 6*x**5 + 5*x/2 - 32/x**5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s9/tests/run.py b/tasks/construct-rg-simple-integration-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s9/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rlve-antiderivative-l4-s0/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s0/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7325e3d4541e2f916322dc9863af1149179906c7 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-(-16*x + 16*sin(x))**x*(x*(16*cos(x) - 16)/(-16*x + 16*sin(x)) + log(-16*x + 16*sin(x)))*sin((-16*x + 16*sin(x))**x)", "max_ops": 44, "max_len": 940, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s0/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3c4c3092f8125cde5bcf20b01a60663f7e672f80 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "cos((-16*x + 16*sin(x))**x)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s0/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s0/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-s0/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7325e3d4541e2f916322dc9863af1149179906c7 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-(-16*x + 16*sin(x))**x*(x*(16*cos(x) - 16)/(-16*x + 16*sin(x)) + log(-16*x + 16*sin(x)))*sin((-16*x + 16*sin(x))**x)", "max_ops": 44, "max_len": 940, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s0/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s0/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s7/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s7/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42cbead47083d55c1eabef5dec81293413cc7fdc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "2*x*log(x)*cos(x**2/3)/3 + (sin(x**2/3) + 2)/x", "max_ops": 44, "max_len": 880, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s7/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8aa8dc4da06fe056c6aa588e100aa6e6bac2940e --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "(sin(x**2/3) + 2)*log(x)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s7/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s7/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-s7/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42cbead47083d55c1eabef5dec81293413cc7fdc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "2*x*log(x)*cos(x**2/3)/3 + (sin(x**2/3) + 2)/x", "max_ops": 44, "max_len": 880, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s7/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s7/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s9/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s9/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72ba2f3fa0aff9e5af9bcead0db44b7ead5bccbe --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-(-sin(x + 1) - 3)*sin(sin(-3*x + cos(x + 1) + 2))*cos(-3*x + cos(x + 1) + 2)", "max_ops": 48, "max_len": 1020, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s9/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2c76e2952373848d973c78259927e96797035f60 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "cos(sin(-3*x + cos(x + 1) + 2))"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s9/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s9/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-s9/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72ba2f3fa0aff9e5af9bcead0db44b7ead5bccbe --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-(-sin(x + 1) - 3)*sin(sin(-3*x + cos(x + 1) + 2))*cos(-3*x + cos(x + 1) + 2)", "max_ops": 48, "max_len": 1020, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s9/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s9/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-bezout-identity-l1-s2/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s2/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..231633490a11206c8e4e6961b21b4825e7f398f9 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [26, 13], "target": 13, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s2/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53e6e3b84866036b2097d25dc9ec4119c0348d4a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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' +{"X": [0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s2/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-l1-s2/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..231633490a11206c8e4e6961b21b4825e7f398f9 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [26, 13], "target": 13, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s2/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s2/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s5/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-bezout-identity-l1-s5/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0dadbb0f092f22337ae61b5f6042e71e4ee91f86 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": [10, 10], "target": 10, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s5/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53e6e3b84866036b2097d25dc9ec4119c0348d4a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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": [0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s5/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0dadbb0f092f22337ae61b5f6042e71e4ee91f86 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": [10, 10], "target": 10, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s5/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-bezout-identity-l1-s5/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-bezout-identity-l5-s3/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s3/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b64b1e97b884ae8f6fc3ee62ff74764db1b3b344 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": [-7175, -2795, 2450, -3900, 1330, -1425, 1729, 2375, -3990, -7020], "target": 1, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s3/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..483e8dd82ecf0e0647df11f56d168a58811af2e4 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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' +{"X": [-56744, 145666, 0, 0, 0, 0, -1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s3/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s3/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-s3/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b64b1e97b884ae8f6fc3ee62ff74764db1b3b344 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": [-7175, -2795, 2450, -3900, 1330, -1425, 1729, 2375, -3990, -7020], "target": 1, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s3/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s3/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s4/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-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-bezout-identity-l5-s4/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40f3929557238cfc1d13747d21c6633c53b94f72 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": [1368, -1347, -7869, -1767, -1335, -4563, -4488, 5508, 7803, 3348], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s4/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4c1527216716107278abeec35c814278eeb57b67 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-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": [-64, -65, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s4/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s4/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-s4/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40f3929557238cfc1d13747d21c6633c53b94f72 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": [1368, -1347, -7869, -1767, -1335, -4563, -4488, 5508, 7803, 3348], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s4/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-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-bezout-identity-l5-s4/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-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-construct-hack-interval-l3-s7/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s7/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8bcfb7c8c0054e130b7715d23adfe2d1982bc014 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"mod": 614217, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s7/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7a24a3111365dcff8471802db6639973c4602f4b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 3, "R": 32619} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s7/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-s7/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8bcfb7c8c0054e130b7715d23adfe2d1982bc014 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"mod": 614217, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s7/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-crt-l2-s0/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-rlve-crt-l2-s0/environment/instance.json b/tasks/construct-rlve-crt-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b4f0575945e84f8f259063ca1cad608b8be76de --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [30, 29, 18], "residues": [15, 16, 9], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s0/solution/solve.sh b/tasks/construct-rlve-crt-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c569e4e66f83f660351164f5ac9f1f08436fdc8c --- /dev/null +++ b/tasks/construct-rlve-crt-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' +{"x": 45} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s0/tests/check.py b/tasks/construct-rlve-crt-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s0/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-s0/tests/instance.json b/tasks/construct-rlve-crt-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b4f0575945e84f8f259063ca1cad608b8be76de --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [30, 29, 18], "residues": [15, 16, 9], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s0/tests/run.py b/tasks/construct-rlve-crt-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-rlve-crt-l2-s0/tests/test.sh b/tasks/construct-rlve-crt-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-rlve-crt-l2-s7/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s7/environment/instance.json b/tasks/construct-rlve-crt-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ac8ac975f42ea4c92d60e996213389a8b764c855 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [34, 32, 6], "residues": [30, 6, 4], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s7/solution/solve.sh b/tasks/construct-rlve-crt-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8032c1135c85537a9adff1f0ded968feb85464cf --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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": 166} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s7/tests/check.py b/tasks/construct-rlve-crt-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-crt-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ac8ac975f42ea4c92d60e996213389a8b764c855 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [34, 32, 6], "residues": [30, 6, 4], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s7/tests/run.py b/tasks/construct-rlve-crt-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s7/tests/test.sh b/tasks/construct-rlve-crt-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s9/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s9/environment/instance.json b/tasks/construct-rlve-crt-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..635c1ac97e8ba076f1a0722dc36143cd017d4f55 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [24, 3, 4], "residues": [13, 1, 1], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s9/solution/solve.sh b/tasks/construct-rlve-crt-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..71e19c099c5eb3c6b10d187d8e7a5b046365a4af --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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": 37} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s9/tests/check.py b/tasks/construct-rlve-crt-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s9/tests/instance.json b/tasks/construct-rlve-crt-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..635c1ac97e8ba076f1a0722dc36143cd017d4f55 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [24, 3, 4], "residues": [13, 1, 1], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s9/tests/run.py b/tasks/construct-rlve-crt-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s9/tests/test.sh b/tasks/construct-rlve-crt-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l6-s1/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-crt-l6-s1/environment/instance.json b/tasks/construct-rlve-crt-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eaa446a640962998038407056ba409138a17cf48 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [627016053749209, 506011066320784, 453572871577179, 165380699340067, 110850560097054, 71869848300373, 19631030300707, 776488109295258], "residues": [215275172312746, 336280159741171, 388718354484776, 15387729361620, 66337305382577, 51722894757852, 17787953432261, 65803116766697], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s1/solution/solve.sh b/tasks/construct-rlve-crt-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d383e0dd4f9023bdc6fc2b92304e2f068c75fafd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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": 842291226061955} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s1/tests/check.py b/tasks/construct-rlve-crt-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s1/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-s1/tests/instance.json b/tasks/construct-rlve-crt-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eaa446a640962998038407056ba409138a17cf48 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [627016053749209, 506011066320784, 453572871577179, 165380699340067, 110850560097054, 71869848300373, 19631030300707, 776488109295258], "residues": [215275172312746, 336280159741171, 388718354484776, 15387729361620, 66337305382577, 51722894757852, 17787953432261, 65803116766697], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s1/tests/run.py b/tasks/construct-rlve-crt-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-crt-l6-s1/tests/test.sh b/tasks/construct-rlve-crt-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-crt-l6-s6/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s6/environment/instance.json b/tasks/construct-rlve-crt-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..686b8c615d8d012e9a9751e9a310e933f6e66fb7 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [184200192271908, 764595874852306, 708781502056833, 800226229520191, 488490670468920, 36428706766183, 414309450448446, 483001008778372], "residues": [9988691296789, 166393777804023, 222208150599496, 130763423136138, 442498982187409, 20271983501754, 102370751759437, 447988643877957], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s6/solution/solve.sh b/tasks/construct-rlve-crt-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b3ce125ad3abcfc2b250e7da19a186acdf8bb0a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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": 930989652656329} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s6/tests/check.py b/tasks/construct-rlve-crt-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s6/tests/instance.json b/tasks/construct-rlve-crt-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..686b8c615d8d012e9a9751e9a310e933f6e66fb7 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [184200192271908, 764595874852306, 708781502056833, 800226229520191, 488490670468920, 36428706766183, 414309450448446, 483001008778372], "residues": [9988691296789, 166393777804023, 222208150599496, 130763423136138, 442498982187409, 20271983501754, 102370751759437, 447988643877957], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s6/tests/run.py b/tasks/construct-rlve-crt-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s6/tests/test.sh b/tasks/construct-rlve-crt-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s8/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-crt-l6-s8/environment/instance.json b/tasks/construct-rlve-crt-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7578141edd81f608cc87837a6b7d942677045b2 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [758273739531656, 639246385013878, 633520272940345, 385932036200077, 815619138566358, 564562920330518, 206550933374662, 516073171203366], "residues": [64005538255882, 183032892773660, 188759004847193, 50415205387384, 6660139221180, 257716357457020, 202626477663552, 306206106584172], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s8/solution/solve.sh b/tasks/construct-rlve-crt-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dec2b8f10061168f1ff12c8dfed509979ef07dc6 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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": 822279277787538} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s8/tests/check.py b/tasks/construct-rlve-crt-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s8/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-s8/tests/instance.json b/tasks/construct-rlve-crt-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7578141edd81f608cc87837a6b7d942677045b2 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [758273739531656, 639246385013878, 633520272940345, 385932036200077, 815619138566358, 564562920330518, 206550933374662, 516073171203366], "residues": [64005538255882, 183032892773660, 188759004847193, 50415205387384, 6660139221180, 257716357457020, 202626477663552, 306206106584172], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s8/tests/run.py b/tasks/construct-rlve-crt-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-crt-l6-s8/tests/test.sh b/tasks/construct-rlve-crt-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-distinct-subset-sum-permutation-l3-s0/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s0/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5449ba595260b669484538bab8622ae8abd4443f --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": [6, 14, 1, 0, 12, 10, 5, 11, 7, 4], "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-s0/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6ed236b53f8c704428713225beb966e2781a716a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [7, 0, 4, 1, 14, 11, 6, 12, 10, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/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-s0/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5449ba595260b669484538bab8622ae8abd4443f --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": [6, 14, 1, 0, 12, 10, 5, 11, 7, 4], "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-s0/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s0/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s7/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s7/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91d8d94b0bd2c27eeec50b0593a75e25292db11e --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": [1, 10, 9, 11, 4, 18, 2, 15, 7, 0], "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-s7/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..613efadfedf7a51f51768945ee10f5c8ca1ac798 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [2, 11, 10, 15, 7, 0, 4, 18, 9, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/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-s7/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91d8d94b0bd2c27eeec50b0593a75e25292db11e --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": [1, 10, 9, 11, 4, 18, 2, 15, 7, 0], "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-s7/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s7/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s9/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s9/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ef4d9d6a8dee5d95f911054ed06697df3a77b9d --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [4, 6, 9, 0, 2, 10, 8, 17, 13, 12], "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-s9/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e6e3f5d39de4c2bf4c6ecad10bd395b5187e8dfc --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [6, 8, 10, 2, 4, 12, 9, 0, 17, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/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-s9/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ef4d9d6a8dee5d95f911054ed06697df3a77b9d --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [4, 6, 9, 0, 2, 10, 8, 17, 13, 12], "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-s9/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s9/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-even-degree-partition-l2-s0/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-rlve-even-degree-partition-l2-s0/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cff091c472faa95c330c87c6cfde4441885074e7 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 6], [1, 4], [1, 7], [2, 3], [2, 6], [2, 7], [4, 5], [5, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s0/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b752c9b96adb68f48e4e3e6e211e011cb6de57b1 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s0/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-l2-s0/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cff091c472faa95c330c87c6cfde4441885074e7 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 6], [1, 4], [1, 7], [2, 3], [2, 6], [2, 7], [4, 5], [5, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s0/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-rlve-even-degree-partition-l2-s0/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-rlve-even-degree-partition-l2-s7/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-l2-s7/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..59b4484038a6da9f68cfe4aacc0915b28ad5d634 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [1, 4], [1, 5], [1, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [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-s7/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0419f203f071de7fbbe59c2d55e74f91423395d1 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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": [1, 1, 1, 1, 1, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s7/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..59b4484038a6da9f68cfe4aacc0915b28ad5d634 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [1, 4], [1, 5], [1, 6], [1, 7], [2, 7], [3, 7], [4, 7], [5, 7], [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-s7/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-l2-s7/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-even-degree-partition-l2-s9/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-even-degree-partition-l2-s9/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4597336d44081c225b84e6b42ad9b68d7e360ba6 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 2], [0, 4], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 5], [2, 4], [2, 6], [3, 6], [4, 6], [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-s9/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3c39b8fc2709603760adaf8b80dfc39bb2c01130 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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' +{"groups": [2, 2, 2, 2, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s9/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s9/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-s9/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4597336d44081c225b84e6b42ad9b68d7e360ba6 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 2], [0, 4], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 5], [2, 4], [2, 6], [3, 6], [4, 6], [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-s9/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-even-degree-partition-l2-s9/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-even-degree-partition-l6-s1/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-l6-s1/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..143aa853a6a8dfe299f98d96a0c3f0a2f667b78b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 14], [0, 15], [0, 16], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 36], [0, 38], [0, 39], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 23], [3, 29], [3, 31], [3, 32], [3, 34], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 37], [4, 38], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 38], [5, 39], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [7, 8], [7, 12], [7, 13], [7, 15], [7, 17], [7, 18], [7, 19], [7, 20], [7, 27], [7, 31], [7, 33], [7, 36], [7, 37], [7, 39], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 19], [8, 20], [8, 21], [8, 23], [8, 24], [8, 25], [8, 28], [8, 31], [8, 32], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [9, 29], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 38], [10, 39], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 21], [11, 27], [11, 29], [11, 33], [11, 34], [11, 35], [11, 36], [11, 39], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 25], [12, 26], [12, 27], [12, 31], [12, 33], [12, 36], [12, 38], [12, 39], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 32], [13, 33], [13, 34], [13, 36], [13, 38], [13, 39], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 33], [14, 34], [14, 35], [14, 36], [14, 39], [15, 16], [15, 17], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 37], [15, 38], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [16, 33], [16, 34], [16, 35], [16, 36], [16, 38], [16, 39], [17, 18], [17, 19], [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, 39], [18, 19], [18, 23], [18, 24], [18, 26], [18, 27], [18, 29], [18, 31], [18, 33], [18, 36], [18, 39], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [20, 23], [20, 24], [20, 25], [20, 27], [20, 31], [20, 34], [20, 36], [20, 39], [21, 22], [21, 23], [21, 26], [21, 27], [21, 29], [21, 33], [21, 34], [21, 36], [21, 39], [22, 23], [22, 24], [22, 26], [22, 27], [22, 30], [22, 31], [22, 32], [22, 33], [22, 35], [22, 36], [22, 38], [22, 39], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 36], [23, 38], [23, 39], [24, 25], [24, 26], [24, 27], [24, 28], [24, 30], [24, 31], [24, 34], [24, 35], [24, 36], [24, 38], [24, 39], [25, 26], [25, 27], [25, 30], [25, 31], [25, 33], [25, 35], [25, 36], [25, 38], [25, 39], [26, 27], [26, 28], [26, 30], [26, 31], [26, 33], [26, 34], [26, 35], [26, 36], [26, 39], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 39], [28, 29], [28, 30], [28, 32], [28, 34], [28, 36], [28, 39], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 39], [30, 35], [30, 36], [30, 39], [31, 33], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 34], [33, 35], [33, 36], [33, 39], [34, 35], [34, 36], [34, 38], [34, 39], [35, 36], [35, 39], [36, 38], [37, 39], [38, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s1/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3b8e530f387abb510c1aaf3b0bbc78bb472e43ad --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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": [2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s1/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-l6-s1/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..143aa853a6a8dfe299f98d96a0c3f0a2f667b78b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 14], [0, 15], [0, 16], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 36], [0, 38], [0, 39], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 23], [3, 29], [3, 31], [3, 32], [3, 34], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 37], [4, 38], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 38], [5, 39], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [7, 8], [7, 12], [7, 13], [7, 15], [7, 17], [7, 18], [7, 19], [7, 20], [7, 27], [7, 31], [7, 33], [7, 36], [7, 37], [7, 39], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 19], [8, 20], [8, 21], [8, 23], [8, 24], [8, 25], [8, 28], [8, 31], [8, 32], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [9, 29], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 25], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 38], [10, 39], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 21], [11, 27], [11, 29], [11, 33], [11, 34], [11, 35], [11, 36], [11, 39], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 25], [12, 26], [12, 27], [12, 31], [12, 33], [12, 36], [12, 38], [12, 39], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 32], [13, 33], [13, 34], [13, 36], [13, 38], [13, 39], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 33], [14, 34], [14, 35], [14, 36], [14, 39], [15, 16], [15, 17], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 37], [15, 38], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 31], [16, 33], [16, 34], [16, 35], [16, 36], [16, 38], [16, 39], [17, 18], [17, 19], [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, 39], [18, 19], [18, 23], [18, 24], [18, 26], [18, 27], [18, 29], [18, 31], [18, 33], [18, 36], [18, 39], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [20, 23], [20, 24], [20, 25], [20, 27], [20, 31], [20, 34], [20, 36], [20, 39], [21, 22], [21, 23], [21, 26], [21, 27], [21, 29], [21, 33], [21, 34], [21, 36], [21, 39], [22, 23], [22, 24], [22, 26], [22, 27], [22, 30], [22, 31], [22, 32], [22, 33], [22, 35], [22, 36], [22, 38], [22, 39], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 36], [23, 38], [23, 39], [24, 25], [24, 26], [24, 27], [24, 28], [24, 30], [24, 31], [24, 34], [24, 35], [24, 36], [24, 38], [24, 39], [25, 26], [25, 27], [25, 30], [25, 31], [25, 33], [25, 35], [25, 36], [25, 38], [25, 39], [26, 27], [26, 28], [26, 30], [26, 31], [26, 33], [26, 34], [26, 35], [26, 36], [26, 39], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 39], [28, 29], [28, 30], [28, 32], [28, 34], [28, 36], [28, 39], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 39], [30, 35], [30, 36], [30, 39], [31, 33], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 34], [33, 35], [33, 36], [33, 39], [34, 35], [34, 36], [34, 38], [34, 39], [35, 36], [35, 39], [36, 38], [37, 39], [38, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s1/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-l6-s1/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-s6/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-even-degree-partition-l6-s6/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56c2218f492b253185793813d5f4ba28c57b07b2 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 30], [0, 35], [0, 36], [0, 38], [0, 39], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 26], [1, 27], [1, 28], [1, 29], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [2, 3], [2, 4], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 18], [2, 20], [2, 21], [2, 22], [2, 23], [2, 27], [2, 28], [2, 29], [2, 30], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 39], [4, 5], [4, 7], [4, 8], [4, 9], [4, 11], [4, 14], [4, 15], [4, 16], [4, 18], [4, 20], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 29], [4, 30], [4, 36], [4, 37], [4, 38], [4, 39], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 38], [6, 8], [6, 9], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 33], [6, 35], [6, 37], [6, 38], [6, 39], [7, 8], [7, 9], [7, 15], [7, 16], [7, 20], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 30], [7, 36], [7, 37], [7, 38], [7, 39], [8, 9], [8, 11], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 30], [8, 31], [8, 32], [8, 35], [8, 37], [8, 38], [8, 39], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [10, 15], [10, 16], [10, 20], [10, 21], [10, 23], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 37], [10, 39], [11, 15], [11, 16], [11, 18], [11, 20], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 36], [11, 37], [11, 38], [11, 39], [12, 15], [12, 16], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 30], [12, 37], [12, 38], [12, 39], [13, 15], [13, 16], [13, 23], [13, 24], [13, 26], [13, 27], [13, 30], [13, 37], [13, 38], [13, 39], [14, 15], [14, 16], [14, 20], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [14, 32], [14, 37], [14, 38], [14, 39], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 26], [16, 28], [16, 29], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [17, 18], [17, 20], [17, 21], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 36], [17, 37], [17, 38], [17, 39], [18, 19], [18, 20], [18, 21], [18, 23], [18, 24], [18, 26], [18, 27], [18, 30], [18, 32], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 30], [19, 33], [19, 36], [19, 37], [19, 38], [19, 39], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 30], [21, 31], [21, 32], [21, 37], [21, 38], [21, 39], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 29], [22, 30], [22, 31], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [24, 26], [24, 28], [24, 29], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [25, 28], [25, 29], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 36], [26, 37], [26, 39], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [29, 30], [29, 31], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 39], [31, 36], [31, 37], [31, 38], [31, 39], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 35], [33, 37], [33, 38], [33, 39], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s6/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c140de3e189166cac7c830532b7cf49302fde6fd --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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' +{"groups": [1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s6/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s6/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-s6/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56c2218f492b253185793813d5f4ba28c57b07b2 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 30], [0, 35], [0, 36], [0, 38], [0, 39], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 26], [1, 27], [1, 28], [1, 29], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [2, 3], [2, 4], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 18], [2, 20], [2, 21], [2, 22], [2, 23], [2, 27], [2, 28], [2, 29], [2, 30], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 37], [3, 38], [3, 39], [4, 5], [4, 7], [4, 8], [4, 9], [4, 11], [4, 14], [4, 15], [4, 16], [4, 18], [4, 20], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 29], [4, 30], [4, 36], [4, 37], [4, 38], [4, 39], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 38], [6, 8], [6, 9], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 33], [6, 35], [6, 37], [6, 38], [6, 39], [7, 8], [7, 9], [7, 15], [7, 16], [7, 20], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 30], [7, 36], [7, 37], [7, 38], [7, 39], [8, 9], [8, 11], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 30], [8, 31], [8, 32], [8, 35], [8, 37], [8, 38], [8, 39], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [10, 15], [10, 16], [10, 20], [10, 21], [10, 23], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 37], [10, 39], [11, 15], [11, 16], [11, 18], [11, 20], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 36], [11, 37], [11, 38], [11, 39], [12, 15], [12, 16], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 30], [12, 37], [12, 38], [12, 39], [13, 15], [13, 16], [13, 23], [13, 24], [13, 26], [13, 27], [13, 30], [13, 37], [13, 38], [13, 39], [14, 15], [14, 16], [14, 20], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [14, 32], [14, 37], [14, 38], [14, 39], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 26], [16, 28], [16, 29], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [17, 18], [17, 20], [17, 21], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 36], [17, 37], [17, 38], [17, 39], [18, 19], [18, 20], [18, 21], [18, 23], [18, 24], [18, 26], [18, 27], [18, 30], [18, 32], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 30], [19, 33], [19, 36], [19, 37], [19, 38], [19, 39], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 30], [21, 31], [21, 32], [21, 37], [21, 38], [21, 39], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 29], [22, 30], [22, 31], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [24, 26], [24, 28], [24, 29], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [25, 28], [25, 29], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 36], [26, 37], [26, 39], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [29, 30], [29, 31], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 39], [31, 36], [31, 37], [31, 38], [31, 39], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 35], [33, 37], [33, 38], [33, 39], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s6/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-even-degree-partition-l6-s6/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-l6-s8/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-even-degree-partition-l6-s8/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..11a15ed67f2aaede7f0ed9a2d86ac5e07fe43553 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 3], [0, 7], [0, 9], [0, 16], [0, 17], [0, 21], [0, 24], [0, 25], [0, 33], [0, 34], [0, 35], [0, 37], [1, 4], [1, 5], [1, 6], [1, 7], [1, 14], [1, 19], [1, 39], [2, 4], [2, 7], [2, 11], [2, 12], [2, 19], [3, 7], [3, 8], [3, 12], [3, 16], [3, 17], [3, 20], [3, 21], [3, 24], [3, 28], [3, 31], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [4, 5], [4, 6], [4, 8], [4, 10], [4, 18], [4, 22], [4, 23], [4, 26], [4, 29], [4, 31], [4, 33], [4, 37], [4, 39], [5, 12], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 24], [5, 30], [5, 31], [5, 35], [5, 37], [5, 38], [6, 15], [6, 18], [6, 19], [6, 22], [6, 26], [6, 29], [6, 31], [6, 38], [7, 21], [7, 24], [7, 27], [7, 28], [7, 32], [7, 35], [8, 13], [8, 21], [8, 24], [8, 25], [8, 28], [8, 32], [8, 35], [9, 17], [9, 24], [9, 25], [9, 32], [9, 34], [9, 35], [9, 36], [10, 12], [10, 18], [10, 19], [10, 28], [10, 29], [10, 31], [11, 14], [11, 15], [11, 18], [11, 19], [11, 20], [11, 23], [11, 28], [11, 29], [11, 31], [11, 37], [12, 13], [12, 16], [12, 18], [12, 19], [12, 22], [12, 23], [12, 26], [12, 29], [12, 30], [12, 31], [12, 36], [12, 39], [13, 15], [13, 24], [13, 30], [13, 32], [13, 35], [14, 27], [14, 29], [14, 36], [14, 37], [15, 19], [15, 22], [15, 23], [15, 33], [16, 17], [16, 21], [16, 26], [16, 28], [16, 32], [16, 33], [16, 35], [17, 21], [17, 24], [17, 28], [17, 29], [17, 32], [17, 35], [17, 36], [17, 38], [18, 26], [18, 29], [18, 31], [18, 39], [19, 22], [19, 23], [19, 26], [19, 29], [19, 30], [19, 31], [19, 34], [19, 38], [19, 39], [20, 21], [20, 24], [20, 28], [20, 30], [20, 32], [20, 33], [20, 38], [21, 24], [21, 28], [21, 33], [21, 34], [21, 35], [22, 23], [23, 24], [23, 25], [23, 31], [23, 36], [23, 38], [24, 25], [24, 28], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [25, 28], [25, 32], [26, 30], [26, 31], [26, 38], [27, 34], [28, 34], [28, 35], [28, 37], [29, 31], [29, 39], [30, 32], [30, 38], [30, 39], [31, 37], [31, 38], [32, 35], [32, 36], [32, 37], [33, 35], [33, 37], [33, 39], [34, 35], [35, 36], [35, 37], [38, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s8/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6cc14a74fc58a260272c7cfc7c72ef732644210a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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' +{"groups": [2, 1, 1, 2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s8/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s8/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-s8/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..11a15ed67f2aaede7f0ed9a2d86ac5e07fe43553 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 3], [0, 7], [0, 9], [0, 16], [0, 17], [0, 21], [0, 24], [0, 25], [0, 33], [0, 34], [0, 35], [0, 37], [1, 4], [1, 5], [1, 6], [1, 7], [1, 14], [1, 19], [1, 39], [2, 4], [2, 7], [2, 11], [2, 12], [2, 19], [3, 7], [3, 8], [3, 12], [3, 16], [3, 17], [3, 20], [3, 21], [3, 24], [3, 28], [3, 31], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [4, 5], [4, 6], [4, 8], [4, 10], [4, 18], [4, 22], [4, 23], [4, 26], [4, 29], [4, 31], [4, 33], [4, 37], [4, 39], [5, 12], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 24], [5, 30], [5, 31], [5, 35], [5, 37], [5, 38], [6, 15], [6, 18], [6, 19], [6, 22], [6, 26], [6, 29], [6, 31], [6, 38], [7, 21], [7, 24], [7, 27], [7, 28], [7, 32], [7, 35], [8, 13], [8, 21], [8, 24], [8, 25], [8, 28], [8, 32], [8, 35], [9, 17], [9, 24], [9, 25], [9, 32], [9, 34], [9, 35], [9, 36], [10, 12], [10, 18], [10, 19], [10, 28], [10, 29], [10, 31], [11, 14], [11, 15], [11, 18], [11, 19], [11, 20], [11, 23], [11, 28], [11, 29], [11, 31], [11, 37], [12, 13], [12, 16], [12, 18], [12, 19], [12, 22], [12, 23], [12, 26], [12, 29], [12, 30], [12, 31], [12, 36], [12, 39], [13, 15], [13, 24], [13, 30], [13, 32], [13, 35], [14, 27], [14, 29], [14, 36], [14, 37], [15, 19], [15, 22], [15, 23], [15, 33], [16, 17], [16, 21], [16, 26], [16, 28], [16, 32], [16, 33], [16, 35], [17, 21], [17, 24], [17, 28], [17, 29], [17, 32], [17, 35], [17, 36], [17, 38], [18, 26], [18, 29], [18, 31], [18, 39], [19, 22], [19, 23], [19, 26], [19, 29], [19, 30], [19, 31], [19, 34], [19, 38], [19, 39], [20, 21], [20, 24], [20, 28], [20, 30], [20, 32], [20, 33], [20, 38], [21, 24], [21, 28], [21, 33], [21, 34], [21, 35], [22, 23], [23, 24], [23, 25], [23, 31], [23, 36], [23, 38], [24, 25], [24, 28], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [25, 28], [25, 32], [26, 30], [26, 31], [26, 38], [27, 34], [28, 34], [28, 35], [28, 37], [29, 31], [29, 39], [30, 32], [30, 38], [30, 39], [31, 37], [31, 38], [32, 35], [32, 36], [32, 37], [33, 35], [33, 37], [33, 39], [34, 35], [35, 36], [35, 37], [38, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s8/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-even-degree-partition-l6-s8/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-graph-isomorphism-l4-s3/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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-graph-isomorphism-l4-s3/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e050e292f0d21b43b45bd6630b52bc967d5470f --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[16, 17], [8, 16], [3, 9], [10, 16], [3, 11], [5, 16], [1, 10], [4, 16], [12, 17], [2, 12], [1, 4], [9, 16], [11, 17], [5, 10], [6, 15], [0, 6], [7, 15], [6, 16], [8, 11], [0, 16], [8, 9], [1, 6], [8, 12], [0, 15], [5, 9], [3, 8], [3, 15], [2, 10], [0, 4], [7, 13], [12, 14], [6, 7], [1, 11], [5, 11], [9, 15], [0, 10], [5, 17], [3, 16], [3, 14], [0, 12], [3, 7], [7, 16], [10, 13], [0, 14], [5, 13], [10, 11], [1, 16], [3, 12], [2, 4], [8, 15], [4, 8], [0, 13], [14, 16], [1, 12], [10, 17], [0, 8], [1, 17], [2, 9], [7, 8], [4, 12], [14, 17], [14, 15], [0, 2], [8, 10], [4, 6], [2, 7], [4, 7], [11, 13]], "edges2": [[1, 13], [0, 17], [11, 16], [1, 5], [8, 11], [5, 13], [5, 14], [3, 4], [2, 5], [1, 6], [6, 11], [4, 7], [0, 16], [5, 7], [7, 14], [6, 12], [6, 15], [9, 14], [3, 5], [1, 7], [8, 17], [8, 9], [4, 15], [1, 16], [10, 14], [0, 15], [9, 11], [3, 14], [0, 13], [4, 16], [15, 17], [7, 16], [6, 14], [13, 14], [8, 16], [10, 11], [2, 16], [13, 17], [1, 12], [9, 16], [1, 10], [0, 2], [2, 17], [8, 12], [10, 13], [0, 12], [3, 6], [3, 7], [2, 15], [2, 13], [0, 14], [7, 12], [4, 11], [4, 9], [1, 9], [4, 12], [14, 17], [4, 14], [8, 14], [14, 16], [0, 5], [6, 10], [3, 11], [2, 9], [6, 16], [6, 7], [9, 10], [0, 6]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s3/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b42c63708a12190248de5b6cdeb1479d01ea8c1 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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' +{"p": [6, 5, 12, 9, 7, 17, 3, 4, 16, 8, 0, 2, 1, 15, 10, 11, 14, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s3/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-s3/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e050e292f0d21b43b45bd6630b52bc967d5470f --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[16, 17], [8, 16], [3, 9], [10, 16], [3, 11], [5, 16], [1, 10], [4, 16], [12, 17], [2, 12], [1, 4], [9, 16], [11, 17], [5, 10], [6, 15], [0, 6], [7, 15], [6, 16], [8, 11], [0, 16], [8, 9], [1, 6], [8, 12], [0, 15], [5, 9], [3, 8], [3, 15], [2, 10], [0, 4], [7, 13], [12, 14], [6, 7], [1, 11], [5, 11], [9, 15], [0, 10], [5, 17], [3, 16], [3, 14], [0, 12], [3, 7], [7, 16], [10, 13], [0, 14], [5, 13], [10, 11], [1, 16], [3, 12], [2, 4], [8, 15], [4, 8], [0, 13], [14, 16], [1, 12], [10, 17], [0, 8], [1, 17], [2, 9], [7, 8], [4, 12], [14, 17], [14, 15], [0, 2], [8, 10], [4, 6], [2, 7], [4, 7], [11, 13]], "edges2": [[1, 13], [0, 17], [11, 16], [1, 5], [8, 11], [5, 13], [5, 14], [3, 4], [2, 5], [1, 6], [6, 11], [4, 7], [0, 16], [5, 7], [7, 14], [6, 12], [6, 15], [9, 14], [3, 5], [1, 7], [8, 17], [8, 9], [4, 15], [1, 16], [10, 14], [0, 15], [9, 11], [3, 14], [0, 13], [4, 16], [15, 17], [7, 16], [6, 14], [13, 14], [8, 16], [10, 11], [2, 16], [13, 17], [1, 12], [9, 16], [1, 10], [0, 2], [2, 17], [8, 12], [10, 13], [0, 12], [3, 6], [3, 7], [2, 15], [2, 13], [0, 14], [7, 12], [4, 11], [4, 9], [1, 9], [4, 12], [14, 17], [4, 14], [8, 14], [14, 16], [0, 5], [6, 10], [3, 11], [2, 9], [6, 16], [6, 7], [9, 10], [0, 6]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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-graph-isomorphism-l4-s3/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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-graph-isomorphism-l4-s4/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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-graph-isomorphism-l4-s4/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc17a98a86ad27b3ff94fadc8e719fb902be8b78 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[0, 14], [7, 9], [12, 13], [2, 8], [10, 12], [6, 12], [5, 14], [3, 13], [7, 16], [10, 14], [0, 17], [11, 13], [1, 7], [2, 17], [2, 5], [3, 15], [3, 17], [4, 12], [15, 17], [10, 15], [6, 14], [2, 10], [7, 13], [12, 14], [4, 6], [8, 12], [3, 8], [5, 13], [3, 11], [8, 10], [5, 17], [1, 8], [11, 17], [4, 8], [0, 12], [11, 14], [6, 10], [7, 17], [3, 14], [1, 5], [1, 10], [3, 7], [16, 17], [1, 17], [1, 12], [11, 12], [12, 15], [3, 4], [7, 8], [6, 16], [2, 7], [1, 11], [1, 3], [10, 17], [5, 15], [8, 17], [1, 14], [9, 13], [6, 9], [0, 6], [1, 16], [14, 16], [13, 16], [4, 11], [3, 9], [10, 11], [4, 14], [15, 16], [0, 2], [4, 17], [12, 17], [7, 15], [5, 16], [7, 10], [14, 17], [3, 10], [14, 15], [8, 14], [7, 12], [5, 9], [1, 15], [10, 13], [0, 7], [6, 7], [2, 14], [8, 15], [1, 2], [0, 1], [4, 16], [12, 16], [4, 13], [0, 16], [2, 11], [6, 11], [0, 15], [2, 4], [9, 11], [4, 7], [2, 13], [13, 14], [2, 12], [0, 4], [3, 6], [5, 7], [4, 9], [5, 11], [6, 8], [9, 14], [1, 9], [5, 6], [9, 16], [0, 13], [0, 9], [2, 9]], "edges2": [[2, 3], [9, 11], [3, 8], [1, 7], [0, 14], [12, 13], [4, 5], [2, 6], [6, 14], [0, 10], [2, 4], [2, 14], [4, 9], [9, 15], [10, 16], [14, 16], [7, 13], [4, 17], [8, 17], [5, 10], [11, 17], [13, 17], [3, 12], [10, 17], [2, 9], [9, 16], [2, 5], [15, 17], [10, 12], [0, 6], [0, 9], [5, 7], [15, 16], [3, 5], [5, 8], [1, 11], [4, 10], [0, 7], [7, 11], [9, 17], [3, 16], [1, 16], [1, 6], [1, 2], [16, 17], [1, 15], [8, 16], [10, 11], [1, 13], [0, 4], [0, 13], [14, 17], [3, 17], [3, 6], [6, 17], [5, 15], [1, 9], [3, 11], [2, 7], [4, 7], [9, 14], [14, 15], [7, 14], [1, 12], [3, 9], [5, 11], [6, 7], [8, 15], [6, 13], [5, 6], [0, 15], [3, 7], [6, 10], [4, 15], [5, 14], [1, 3], [12, 17], [11, 14], [0, 1], [7, 16], [2, 11], [1, 4], [8, 14], [7, 12], [11, 15], [10, 15], [13, 16], [1, 8], [8, 12], [3, 15], [0, 17], [7, 9], [4, 6], [5, 17], [8, 13], [9, 12], [3, 13], [4, 14], [11, 16], [4, 8], [0, 3], [5, 12], [12, 16], [1, 17], [7, 10], [7, 8], [2, 13], [11, 13], [2, 10], [5, 9], [2, 17], [6, 11], [8, 10], [11, 12]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s4/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f189fe282df94866e020d2a70d67f701aa5c9b4f --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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' +{"p": [2, 1, 9, 8, 5, 0, 10, 7, 12, 4, 16, 15, 11, 14, 17, 13, 6, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s4/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-s4/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc17a98a86ad27b3ff94fadc8e719fb902be8b78 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[0, 14], [7, 9], [12, 13], [2, 8], [10, 12], [6, 12], [5, 14], [3, 13], [7, 16], [10, 14], [0, 17], [11, 13], [1, 7], [2, 17], [2, 5], [3, 15], [3, 17], [4, 12], [15, 17], [10, 15], [6, 14], [2, 10], [7, 13], [12, 14], [4, 6], [8, 12], [3, 8], [5, 13], [3, 11], [8, 10], [5, 17], [1, 8], [11, 17], [4, 8], [0, 12], [11, 14], [6, 10], [7, 17], [3, 14], [1, 5], [1, 10], [3, 7], [16, 17], [1, 17], [1, 12], [11, 12], [12, 15], [3, 4], [7, 8], [6, 16], [2, 7], [1, 11], [1, 3], [10, 17], [5, 15], [8, 17], [1, 14], [9, 13], [6, 9], [0, 6], [1, 16], [14, 16], [13, 16], [4, 11], [3, 9], [10, 11], [4, 14], [15, 16], [0, 2], [4, 17], [12, 17], [7, 15], [5, 16], [7, 10], [14, 17], [3, 10], [14, 15], [8, 14], [7, 12], [5, 9], [1, 15], [10, 13], [0, 7], [6, 7], [2, 14], [8, 15], [1, 2], [0, 1], [4, 16], [12, 16], [4, 13], [0, 16], [2, 11], [6, 11], [0, 15], [2, 4], [9, 11], [4, 7], [2, 13], [13, 14], [2, 12], [0, 4], [3, 6], [5, 7], [4, 9], [5, 11], [6, 8], [9, 14], [1, 9], [5, 6], [9, 16], [0, 13], [0, 9], [2, 9]], "edges2": [[2, 3], [9, 11], [3, 8], [1, 7], [0, 14], [12, 13], [4, 5], [2, 6], [6, 14], [0, 10], [2, 4], [2, 14], [4, 9], [9, 15], [10, 16], [14, 16], [7, 13], [4, 17], [8, 17], [5, 10], [11, 17], [13, 17], [3, 12], [10, 17], [2, 9], [9, 16], [2, 5], [15, 17], [10, 12], [0, 6], [0, 9], [5, 7], [15, 16], [3, 5], [5, 8], [1, 11], [4, 10], [0, 7], [7, 11], [9, 17], [3, 16], [1, 16], [1, 6], [1, 2], [16, 17], [1, 15], [8, 16], [10, 11], [1, 13], [0, 4], [0, 13], [14, 17], [3, 17], [3, 6], [6, 17], [5, 15], [1, 9], [3, 11], [2, 7], [4, 7], [9, 14], [14, 15], [7, 14], [1, 12], [3, 9], [5, 11], [6, 7], [8, 15], [6, 13], [5, 6], [0, 15], [3, 7], [6, 10], [4, 15], [5, 14], [1, 3], [12, 17], [11, 14], [0, 1], [7, 16], [2, 11], [1, 4], [8, 14], [7, 12], [11, 15], [10, 15], [13, 16], [1, 8], [8, 12], [3, 15], [0, 17], [7, 9], [4, 6], [5, 17], [8, 13], [9, 12], [3, 13], [4, 14], [11, 16], [4, 8], [0, 3], [5, 12], [12, 16], [1, 17], [7, 10], [7, 8], [2, 13], [11, 13], [2, 10], [5, 9], [2, 17], [6, 11], [8, 10], [11, 12]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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-graph-isomorphism-l4-s4/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-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-grid-parity-construction-l4-s3/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-grid-parity-construction-l4-s3/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..946ca27c4cbbe72137f79622bbb9b07b584f6aa4 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["00", "10", "00", "11", "00", "01", "11", "01", "00", "00", "00", "11"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s3/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..70e177cf1efcb57747a0891d45d30191e35720f2 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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' +{"grid": ["10", "11", "00", "11", "11", "11", "10", "11", "11", "11", "11", "11"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s3/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-s3/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..946ca27c4cbbe72137f79622bbb9b07b584f6aa4 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["00", "10", "00", "11", "00", "01", "11", "01", "00", "00", "00", "11"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-grid-parity-construction-l4-s3/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-grid-parity-construction-l4-s4/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-grid-parity-construction-l4-s4/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2f03f99d2613e44a243d5a4083c72e9455c4d88 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["100011000", "001101111", "001111001", "110000011", "010011111"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s4/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b513cde8b7e9c806d36b3edaa676e84d65a4dea4 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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' +{"grid": ["101110111", "000111010", "101001011", "100111011", "100011000"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s4/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-s4/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2f03f99d2613e44a243d5a4083c72e9455c4d88 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["100011000", "001101111", "001111001", "110000011", "010011111"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-grid-parity-construction-l4-s4/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-imp-party-l2-s2/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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-imp-party-l2-s2/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7dac6b0b1a2b8746330190463708a7cd30a736bf --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 8], [0, 13], [1, 10], [1, 11], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 5], [3, 13], [3, 14], [4, 5], [4, 7], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [13, 14]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s2/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ea432614966d724fbea951bbb9895a8be5d8a436 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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": [2, 5, 7, 11, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s2/tests/check.py b/tasks/construct-rlve-imp-party-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s2/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-s2/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7dac6b0b1a2b8746330190463708a7cd30a736bf --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 8], [0, 13], [1, 10], [1, 11], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 5], [3, 13], [3, 14], [4, 5], [4, 7], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [12, 14], [13, 14]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s2/tests/run.py b/tasks/construct-rlve-imp-party-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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-imp-party-l2-s2/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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-integer-linear-system-l5-s3/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l5-s3/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..650dda089ef683246389e2d4739bd9eb7822f850 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[3, 0, 1, 2, 0, 0, 2, 2, 0, 0, 1, 3, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 2, 1, 0, 0, 0, 0, 3, 0, 1, 0, 1, 0, 2, 1], [3, 0, 0, 0, 0, 3, 2, 0, 3, 1, 1, 3, 2, 0, 0, 0, 3, 0], [3, 3, 2, 0, 0, 2, 0, 3, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0], [0, 0, 3, 3, 1, 2, 2, 0, 1, 0, 3, 0, 0, 0, 2, 0, 1, 0], [0, 2, 2, 0, 0, 0, 0, 2, 0, 0, 2, 0, 1, 0, 1, 3, 0, 2], [0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 2, 2, 2, 0, 0, 2, 0, 1, 0, 0, 0, 0, 2, 1], [2, 2, 1, 0, 1, 2, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0], [0, 0, 0, 3, 2, 0, 1, 0, 0, 3, 0, 0, 0, 0, 1, 0, 0, 0], [2, 0, 0, 0, 3, 0, 0, 2, 2, 0, 1, 1, 0, 3, 0, 3, 0, 3], [2, 0, 0, 0, 0, 3, 0, 1, 2, 3, 0, 3, 0, 0, 0, 1, 0, 3], [0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0], [3, 0, 0, 3, 0, 3, 3, 0, 0, 2, 1, 0, 0, 0, 0, 0, 0, 0], [3, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 1], [0, 0, 1, 3, 0, 0, 3, 0, 0, 3, 2, 0, 3, 0, 2, 0, 0, 3], [0, 0, 2, 1, 2, 2, 1, 0, 2, 0, 0, 0, 0, 2, 0, 1, 0, 1], [0, 3, 3, 0, 0, 0, 3, 1, 0, 2, 3, 3, 2, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 3, 0, 0, 3, 2, 0, 0, 0, 1, 0, 3, 0, 2], [1, 0, 3, 3, 1, 0, 3, 3, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2], [0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 3, 0, 3, 0, 3, 1, 0], [1, 3, 1, 1, 0, 1, 2, 0, 1, 2, 2, 0, 0, 3, 0, 0, 0, 0], [0, 0, 0, 0, 2, 3, 3, 0, 0, 2, 0, 1, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 3, 0, 1, 3, 0, 0, 2, 0, 0, 2, 3, 0, 0, 2], [0, 1, 0, 0, 0, 0, 0, 0, 3, 2, 1, 0, 0, 2, 0, 1, 2, 3], [0, 3, 0, 1, 0, 0, 1, 0, 0, 3, 0, 2, 0, 2, 0, 1, 0, 1], [1, 0, 3, 2, 0, 0, 2, 0, 0, 0, 3, 3, 1, 0, 0, 0, 3, 1], [2, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 3, 0, 0, 2, 3, 1, 3], [0, 0, 3, 2, 0, 3, 3, 1, 3, 2, 0, 0, 0, 3, 1, 0, 1, 2], [0, 0, 1, 2, 1, 2, 1, 1, 0, 0, 3, 0, 0, 0, 0, 0, 2, 1], [3, 2, 0, 0, 0, 1, 3, 0, 2, 1, 1, 0, 0, 3, 1, 2, 3, 0], [2, 3, 0, 1, 0, 3, 3, 2, 2, 2, 0, 2, 1, 2, 2, 0, 0, 0], [3, 0, 0, 1, 0, 1, 3, 2, 0, 0, 0, 0, 0, 3, 3, 3, 1, 0], [0, 2, 0, 0, 0, 3, 2, 0, 0, 2, 2, 0, 0, 2, 0, 1, 1, 2], [1, 3, 3, 0, 1, 3, 0, 0, 1, 0, 0, 3, 1, 1, 1, 0, 0, 0], [0, 0, 1, 0, 0, 0, 3, 3, 0, 0, 0, 2, 0, 0, 0, 3, 0, 2], [0, 3, 2, 0, 2, 2, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 2, 1], [3, 1, 1, 0, 2, 1, 2, 2, 1, 0, 0, 0, 1, 2, 0, 0, 2, 3], [0, 0, 1, 0, 0, 1, 1, 2, 1, 3, 0, 2, 0, 2, 3, 3, 0, 2], [3, 0, 0, 0, 2, 1, 2, 0, 2, 0, 0, 3, 0, 3, 3, 0, 0, 3], [1, 2, 0, 0, 0, 1, 2, 0, 3, 3, 3, 3, 0, 1, 0, 1, 0, 0], [0, 0, 0, 0, 1, 0, 2, 3, 3, 1, 0, 3, 1, 1, 0, 0, 0, 2], [1, 1, 0, 2, 2, 3, 3, 1, 0, 0, 1, 0, 0, 3, 1, 2, 1, 3], [3, 0, 1, 0, 1, 0, 2, 3, 0, 0, 0, 0, 2, 1, 2, 2, 0, 0], [1, 2, 3, 2, 0, 0, 0, 0, 2, 2, 0, 0, 2, 0, 3, 0, 3, 0], [1, 3, 1, 1, 2, 0, 0, 3, 0, 3, 0, 0, 0, 0, 2, 2, 1, 3], [0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 2, 2, 3, 0, 3], [0, 1, 1, 0, 0, 2, 2, 0, 3, 0, 0, 3, 1, 1, 1, 1, 0, 1], [0, 1, 1, 3, 2, 0, 1, 2, 0, 2, 3, 3, 2, 2, 3, 2, 0, 1], [0, 0, 3, 1, 0, 2, 0, 3, 3, 0, 2, 2, 1, 3, 0, 3, 2, 1]], "rhs": [142, 99, 217, 153, 197, 152, 49, 128, 123, 119, 190, 184, 123, 163, 93, 226, 162, 162, 202, 196, 124, 151, 112, 163, 170, 124, 171, 221, 280, 141, 224, 255, 200, 161, 171, 142, 167, 224, 208, 209, 171, 173, 253, 171, 248, 245, 148, 183, 251, 257], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s5/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-rlve-integer-linear-system-l5-s5/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b14e9113bfc1ede50b153ef30a0f96ec2721aa92 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 0, 2, 1, 2, 0, 2, 1, 1, 0, 2, 1, 0, 0, 3, 0, 3, 2], [1, 0, 2, 3, 0, 0, 1, 0, 3, 0, 0, 2, 0, 2, 0, 1, 1, 0], [3, 2, 3, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 0, 3, 0, 3, 0], [0, 2, 0, 0, 0, 2, 0, 2, 1, 1, 0, 2, 0, 0, 0, 0, 3, 1], [1, 0, 0, 3, 0, 2, 0, 3, 0, 0, 0, 0, 3, 3, 0, 2, 2, 3], [2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 2, 0, 0, 1], [2, 0, 0, 0, 0, 3, 1, 2, 3, 2, 1, 3, 0, 1, 0, 0, 1, 1], [3, 2, 0, 0, 2, 2, 0, 0, 3, 3, 0, 0, 0, 0, 1, 0, 2, 1], [0, 1, 0, 0, 3, 2, 0, 3, 0, 0, 3, 0, 1, 2, 0, 1, 3, 3], [0, 1, 1, 0, 0, 0, 0, 2, 1, 0, 0, 2, 3, 1, 0, 1, 0, 3], [0, 0, 2, 1, 1, 3, 0, 1, 1, 3, 1, 0, 0, 0, 0, 1, 0, 0], [3, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 2, 2, 1, 2, 1, 3], [0, 0, 0, 3, 1, 3, 3, 0, 2, 0, 3, 2, 3, 0, 0, 0, 0, 0], [3, 0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 3], [2, 0, 0, 0, 2, 3, 0, 3, 0, 0, 1, 3, 0, 1, 3, 2, 2, 3], [2, 1, 3, 1, 1, 3, 0, 0, 2, 0, 0, 1, 2, 0, 3, 3, 2, 0], [0, 0, 2, 2, 0, 0, 0, 0, 3, 0, 3, 2, 3, 2, 2, 3, 3, 1], [3, 2, 2, 1, 3, 0, 2, 3, 0, 0, 0, 0, 0, 2, 3, 2, 3, 2], [0, 0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 3, 2, 0, 0, 1, 3, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0], [0, 0, 2, 0, 2, 0, 2, 0, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1, 0, 0, 1, 2, 3], [1, 2, 2, 1, 0, 0, 0, 0, 2, 0, 0, 2, 0, 1, 0, 2, 3, 2], [3, 1, 3, 1, 3, 1, 2, 2, 2, 1, 0, 3, 0, 3, 0, 2, 3, 2], [1, 1, 2, 1, 0, 0, 0, 0, 3, 0, 2, 1, 0, 0, 0, 1, 1, 1], [2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 1, 2, 3, 0, 2, 0, 0, 3], [3, 0, 3, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 3, 2, 1, 3, 0], [2, 0, 0, 0, 3, 1, 1, 3, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0], [3, 2, 1, 1, 0, 2, 0, 0, 1, 2, 1, 0, 1, 1, 2, 2, 0, 0], [3, 3, 0, 0, 3, 3, 3, 3, 0, 0, 3, 0, 0, 1, 1, 0, 2, 1], [0, 0, 0, 0, 3, 0, 3, 0, 3, 1, 0, 3, 0, 2, 0, 2, 3, 0], [3, 2, 1, 0, 0, 1, 1, 2, 0, 0, 0, 1, 0, 0, 2, 3, 0, 0], [1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 3, 1, 3, 0, 2, 1, 3, 0, 2, 0, 0, 1, 1, 3, 0, 0], [1, 0, 2, 3, 3, 2, 2, 2, 1, 3, 1, 0, 0, 0, 1, 0, 1, 2], [1, 0, 0, 0, 3, 0, 2, 3, 0, 2, 0, 0, 0, 1, 2, 0, 1, 0], [0, 0, 2, 2, 0, 0, 0, 1, 0, 3, 3, 3, 1, 3, 2, 0, 0, 0], [0, 0, 0, 2, 2, 0, 1, 0, 0, 1, 3, 0, 0, 0, 0, 3, 0, 0], [2, 1, 0, 3, 1, 2, 2, 0, 1, 0, 3, 3, 1, 0, 0, 2, 3, 0], [3, 1, 0, 2, 1, 0, 3, 2, 1, 0, 0, 0, 0, 2, 2, 0, 0, 1], [0, 2, 0, 2, 2, 0, 0, 1, 1, 0, 0, 0, 1, 0, 2, 0, 2, 1], [0, 3, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 3, 1, 0, 0, 3], [0, 0, 0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 3, 0, 0, 3, 0, 3, 1], [3, 0, 0, 2, 0, 2, 3, 1, 2, 2, 1, 2, 1, 0, 3, 1, 1, 0], [1, 1, 3, 0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 3, 3, 0, 2, 0], [0, 3, 3, 0, 2, 1, 0, 2, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0], [2, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 3, 0, 3, 0, 1, 0], [1, 3, 1, 0, 1, 0, 0, 0, 2, 0, 3, 3, 0, 2, 1, 0, 0, 2], [3, 2, 2, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 1, 2, 2, 0, 0], [3, 3, 0, 0, 0, 1, 2, 1, 3, 2, 1, 2, 0, 3, 0, 0, 0, 1], [3, 2, 3, 0, 3, 2, 2, 3, 0, 0, 2, 0, 1, 1, 0, 0, 3, 0], [0, 1, 0, 2, 0, 0, 1, 0, 2, 3, 0, 0, 0, 1, 2, 3, 1, 0], [2, 0, 0, 0, 1, 3, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]], "rhs": [208, 157, 197, 103, 191, 114, 138, 178, 175, 137, 101, 239, 168, 203, 189, 216, 225, 284, 40, 142, 124, 116, 172, 286, 140, 170, 161, 117, 157, 223, 165, 136, 55, 209, 240, 139, 138, 98, 194, 193, 161, 115, 81, 114, 210, 164, 127, 124, 158, 157, 179, 228, 143, 60], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s5/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4e73258f658f3e248e3109e7a482e99970512a3a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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' +{"x": [11, 11, 13, 15, 12, 1, 12, 8, 13, 5, 4, 2, 10, 3, 11, 5, 9, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s5/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s5/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-s5/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b14e9113bfc1ede50b153ef30a0f96ec2721aa92 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 0, 2, 1, 2, 0, 2, 1, 1, 0, 2, 1, 0, 0, 3, 0, 3, 2], [1, 0, 2, 3, 0, 0, 1, 0, 3, 0, 0, 2, 0, 2, 0, 1, 1, 0], [3, 2, 3, 0, 1, 0, 0, 2, 0, 1, 0, 0, 1, 0, 3, 0, 3, 0], [0, 2, 0, 0, 0, 2, 0, 2, 1, 1, 0, 2, 0, 0, 0, 0, 3, 1], [1, 0, 0, 3, 0, 2, 0, 3, 0, 0, 0, 0, 3, 3, 0, 2, 2, 3], [2, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, 0, 2, 2, 0, 0, 1], [2, 0, 0, 0, 0, 3, 1, 2, 3, 2, 1, 3, 0, 1, 0, 0, 1, 1], [3, 2, 0, 0, 2, 2, 0, 0, 3, 3, 0, 0, 0, 0, 1, 0, 2, 1], [0, 1, 0, 0, 3, 2, 0, 3, 0, 0, 3, 0, 1, 2, 0, 1, 3, 3], [0, 1, 1, 0, 0, 0, 0, 2, 1, 0, 0, 2, 3, 1, 0, 1, 0, 3], [0, 0, 2, 1, 1, 3, 0, 1, 1, 3, 1, 0, 0, 0, 0, 1, 0, 0], [3, 3, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 2, 2, 1, 2, 1, 3], [0, 0, 0, 3, 1, 3, 3, 0, 2, 0, 3, 2, 3, 0, 0, 0, 0, 0], [3, 0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 3, 0, 3, 3], [2, 0, 0, 0, 2, 3, 0, 3, 0, 0, 1, 3, 0, 1, 3, 2, 2, 3], [2, 1, 3, 1, 1, 3, 0, 0, 2, 0, 0, 1, 2, 0, 3, 3, 2, 0], [0, 0, 2, 2, 0, 0, 0, 0, 3, 0, 3, 2, 3, 2, 2, 3, 3, 1], [3, 2, 2, 1, 3, 0, 2, 3, 0, 0, 0, 0, 0, 2, 3, 2, 3, 2], [0, 0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 3, 2, 0, 0, 1, 3, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0], [0, 0, 2, 0, 2, 0, 2, 0, 1, 0, 0, 1, 1, 1, 2, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 1, 0, 1, 0, 3, 1, 0, 0, 1, 2, 3], [1, 2, 2, 1, 0, 0, 0, 0, 2, 0, 0, 2, 0, 1, 0, 2, 3, 2], [3, 1, 3, 1, 3, 1, 2, 2, 2, 1, 0, 3, 0, 3, 0, 2, 3, 2], [1, 1, 2, 1, 0, 0, 0, 0, 3, 0, 2, 1, 0, 0, 0, 1, 1, 1], [2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 1, 2, 3, 0, 2, 0, 0, 3], [3, 0, 3, 0, 0, 0, 0, 0, 1, 1, 2, 0, 0, 3, 2, 1, 3, 0], [2, 0, 0, 0, 3, 1, 1, 3, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0], [3, 2, 1, 1, 0, 2, 0, 0, 1, 2, 1, 0, 1, 1, 2, 2, 0, 0], [3, 3, 0, 0, 3, 3, 3, 3, 0, 0, 3, 0, 0, 1, 1, 0, 2, 1], [0, 0, 0, 0, 3, 0, 3, 0, 3, 1, 0, 3, 0, 2, 0, 2, 3, 0], [3, 2, 1, 0, 0, 1, 1, 2, 0, 0, 0, 1, 0, 0, 2, 3, 0, 0], [1, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 3, 1, 3, 0, 2, 1, 3, 0, 2, 0, 0, 1, 1, 3, 0, 0], [1, 0, 2, 3, 3, 2, 2, 2, 1, 3, 1, 0, 0, 0, 1, 0, 1, 2], [1, 0, 0, 0, 3, 0, 2, 3, 0, 2, 0, 0, 0, 1, 2, 0, 1, 0], [0, 0, 2, 2, 0, 0, 0, 1, 0, 3, 3, 3, 1, 3, 2, 0, 0, 0], [0, 0, 0, 2, 2, 0, 1, 0, 0, 1, 3, 0, 0, 0, 0, 3, 0, 0], [2, 1, 0, 3, 1, 2, 2, 0, 1, 0, 3, 3, 1, 0, 0, 2, 3, 0], [3, 1, 0, 2, 1, 0, 3, 2, 1, 0, 0, 0, 0, 2, 2, 0, 0, 1], [0, 2, 0, 2, 2, 0, 0, 1, 1, 0, 0, 0, 1, 0, 2, 0, 2, 1], [0, 3, 0, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 3, 1, 0, 0, 3], [0, 0, 0, 0, 3, 0, 1, 1, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 3, 0, 0, 3, 0, 3, 1], [3, 0, 0, 2, 0, 2, 3, 1, 2, 2, 1, 2, 1, 0, 3, 1, 1, 0], [1, 1, 3, 0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 3, 3, 0, 2, 0], [0, 3, 3, 0, 2, 1, 0, 2, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0], [2, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 3, 0, 3, 0, 1, 0], [1, 3, 1, 0, 1, 0, 0, 0, 2, 0, 3, 3, 0, 2, 1, 0, 0, 2], [3, 2, 2, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 1, 2, 2, 0, 0], [3, 3, 0, 0, 0, 1, 2, 1, 3, 2, 1, 2, 0, 3, 0, 0, 0, 1], [3, 2, 3, 0, 3, 2, 2, 3, 0, 0, 2, 0, 1, 1, 0, 0, 3, 0], [0, 1, 0, 2, 0, 0, 1, 0, 2, 3, 0, 0, 0, 1, 2, 3, 1, 0], [2, 0, 0, 0, 1, 3, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0]], "rhs": [208, 157, 197, 103, 191, 114, 138, 178, 175, 137, 101, 239, 168, 203, 189, 216, 225, 284, 40, 142, 124, 116, 172, 286, 140, 170, 161, 117, 157, 223, 165, 136, 55, 209, 240, 139, 138, 98, 194, 193, 161, 115, 81, 114, 210, 164, 127, 124, 158, 157, 179, 228, 143, 60], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s5/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-rlve-integer-linear-system-l5-s5/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-rlve-largest-convex-polygon-l2-s2/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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-largest-convex-polygon-l2-s2/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..afd3039a814e46fda93cab9d7bf78af90ca070e4 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 3], [0, 0], [5, 8], [4, 6], [5, 0], [9, 8], [3, 2], [6, 3], [9, 7]], "k": 6, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s2/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5b30db85ad96729edb1ea7d749ec107a6e477fa1 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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' +{"indices": [0, 3, 5, 8, 7, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s2/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-l2-s2/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..afd3039a814e46fda93cab9d7bf78af90ca070e4 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 3], [0, 0], [5, 8], [4, 6], [5, 0], [9, 8], [3, 2], [6, 3], [9, 7]], "k": 6, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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-largest-convex-polygon-l2-s2/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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-l2-s5/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s5/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a8a0f379227cfaba8d7ad690d05404284f66b31 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [2, 7], [3, 1], [9, 2], [0, 6], [6, 7], [9, 5], [1, 6], [2, 8]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s5/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e5c292beeb25cf29fc1909ce01e3d823fa8e7729 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [0, 7, 1, 5, 6, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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-l2-s5/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a8a0f379227cfaba8d7ad690d05404284f66b31 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [2, 7], [3, 1], [9, 2], [0, 6], [6, 7], [9, 5], [1, 6], [2, 8]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s5/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s3/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s3/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ec358ab19540133ee2bfd9e5299a1342b1cc190 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[6, 18], [25, 29], [25, 23], [32, 34], [16, 32], [12, 19], [30, 3], [28, 18], [5, 22], [10, 15], [30, 27], [7, 7], [29, 1], [6, 11], [11, 29], [2, 26], [22, 4], [33, 32], [34, 3], [34, 12], [19, 11], [33, 1], [17, 23], [2, 4], [8, 17], [14, 33], [35, 16], [15, 19], [15, 28], [11, 0], [32, 13], [5, 26], [19, 28], [16, 8], [7, 5]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s3/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..afcaae102f6907b74f2834ceb2d5f137ed104b7c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [34, 11, 9, 5, 22, 1, 3, 17, 26, 19, 6, 12, 29]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s3/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-s3/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ec358ab19540133ee2bfd9e5299a1342b1cc190 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[6, 18], [25, 29], [25, 23], [32, 34], [16, 32], [12, 19], [30, 3], [28, 18], [5, 22], [10, 15], [30, 27], [7, 7], [29, 1], [6, 11], [11, 29], [2, 26], [22, 4], [33, 32], [34, 3], [34, 12], [19, 11], [33, 1], [17, 23], [2, 4], [8, 17], [14, 33], [35, 16], [15, 19], [15, 28], [11, 0], [32, 13], [5, 26], [19, 28], [16, 8], [7, 5]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s3/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s4/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s4/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6f347fe7cfe130bf09f31a06e845d5726897d19 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"points": [[6, 24], [14, 7], [22, 20], [3, 34], [10, 21], [26, 11], [9, 29], [29, 4], [19, 30], [32, 27], [12, 0], [16, 28], [22, 16], [17, 5], [34, 15], [6, 29], [3, 12], [19, 5], [34, 30], [30, 11], [5, 15], [0, 4], [8, 17], [33, 13], [29, 6], [11, 28], [35, 19], [20, 0], [1, 32], [21, 35], [23, 35], [10, 16], [9, 27], [20, 2], [7, 8]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s4/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bc012c4b586f6ef34d6076a876b942490a2bc19a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [0, 32, 25, 11, 9, 26, 14, 23, 19, 17, 13, 1, 22]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s4/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-s4/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6f347fe7cfe130bf09f31a06e845d5726897d19 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"points": [[6, 24], [14, 7], [22, 20], [3, 34], [10, 21], [26, 11], [9, 29], [29, 4], [19, 30], [32, 27], [12, 0], [16, 28], [22, 16], [17, 5], [34, 15], [6, 29], [3, 12], [19, 5], [34, 30], [30, 11], [5, 15], [0, 4], [8, 17], [33, 13], [29, 6], [11, 28], [35, 19], [20, 0], [1, 32], [21, 35], [23, 35], [10, 16], [9, 27], [20, 2], [7, 8]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s4/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-rectangle-l4-s3/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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-largest-rectangle-l4-s3/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2448c2f65af2d2dfb5aa471fc200657ec1fda468 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-1, -1], [-22, -9], [-10, 24], [22, 12], [2, 12], [21, -16], [7, 4], [-7, 25], [12, -7], [-19, 21], [15, 8], [-12, 23], [8, 1], [-17, 15], [4, -6], [9, 5], [20, 7], [-20, 3], [-15, -14], [-6, 7], [-8, 23], [18, -20], [21, 16], [14, 25], [10, -11]], "area": 89, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s3/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a4e14a9fbc5913a65d6c1a9aeaee92492a335cd1 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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": [0, 6, 4, 19]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s3/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s3/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-s3/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2448c2f65af2d2dfb5aa471fc200657ec1fda468 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-1, -1], [-22, -9], [-10, 24], [22, 12], [2, 12], [21, -16], [7, 4], [-7, 25], [12, -7], [-19, 21], [15, 8], [-12, 23], [8, 1], [-17, 15], [4, -6], [9, 5], [20, 7], [-20, 3], [-15, -14], [-6, 7], [-8, 23], [18, -20], [21, 16], [14, 25], [10, -11]], "area": 89, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s3/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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-largest-rectangle-l4-s3/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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-largest-rectangle-l4-s4/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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-largest-rectangle-l4-s4/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1dc5608db82dc822d7c8dc987d7dcd9ff2862a34 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-11, -23], [-20, -10], [20, 11], [-6, -15], [-14, -10], [1, 4], [-6, 11], [-11, -25], [-9, -2], [9, 14], [-1, -7], [-23, 13], [20, -11], [0, 25], [16, -20], [23, -15], [24, 23], [-5, 18], [-17, -17], [-25, -12], [21, 3], [3, -2], [-9, -9], [-15, -18], [7, 2]], "area": 89, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s4/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..951d4ab20f235249d151dc1810c986241c693925 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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": [3, 4, 8, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s4/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s4/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-s4/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1dc5608db82dc822d7c8dc987d7dcd9ff2862a34 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-11, -23], [-20, -10], [20, 11], [-6, -15], [-14, -10], [1, 4], [-6, 11], [-11, -25], [-9, -2], [9, 14], [-1, -7], [-23, 13], [20, -11], [0, 25], [16, -20], [23, -15], [24, 23], [-5, 18], [-17, -17], [-25, -12], [21, 3], [3, -2], [-9, -9], [-15, -18], [7, 2]], "area": 89, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s4/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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-largest-rectangle-l4-s4/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-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-matrix-permutation-equivalence-l3-s7/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s7/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e150bb94966076363e7f03fb7c46adfe89edece --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": ["1001111", "1110011", "1110101", "1111110"], "B": ["1101110", "1011011", "1110011", "1111101"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..76176aa706f6f4869e4874415d0f43d13fa57410 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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": [0, 1, 2, 3], "b": [0, 4, 1, 5, 3, 6, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/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-s7/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e150bb94966076363e7f03fb7c46adfe89edece --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": ["1001111", "1110011", "1110101", "1111110"], "B": ["1101110", "1011011", "1110011", "1111101"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s7/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-max-achromatic-coloring-l2-s3/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-rlve-max-achromatic-coloring-l2-s3/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89b90d72b1a2223d2231a3be019396dbc3f09c30 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 3], [1, 5], [1, 7], [2, 4], [2, 6], [2, 7], [3, 4], [3, 6], [3, 7], [4, 5], [4, 7], [5, 6], [5, 7], [6, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s3/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..957b1170dd00dc84795293ff3bc905a849f16a19 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 1, 2, 3, 2, 0, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-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-l2-s3/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89b90d72b1a2223d2231a3be019396dbc3f09c30 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [1, 3], [1, 5], [1, 7], [2, 4], [2, 6], [2, 7], [3, 4], [3, 6], [3, 7], [4, 5], [4, 7], [5, 6], [5, 7], [6, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-rlve-max-achromatic-coloring-l2-s3/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-rlve-max-achromatic-coloring-l2-s4/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-rlve-max-achromatic-coloring-l2-s4/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..60db346f8f5f75ce7a425c16bb91f804fd5e3d32 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 3], [0, 5], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 7], [3, 4], [3, 5], [4, 5], [4, 6], [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-s4/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e09a6849ed934b8264e0084bc3aed66186705534 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 2, 3, 4, 1, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s4/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-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-l2-s4/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..60db346f8f5f75ce7a425c16bb91f804fd5e3d32 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 3], [0, 5], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 7], [3, 4], [3, 5], [4, 5], [4, 6], [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-s4/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-rlve-max-achromatic-coloring-l2-s4/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-rlve-max-achromatic-coloring-l6-s2/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s2/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6c0fd086a7897c60cccf1e6bc92e6b81bf6ea10 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 9, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 9], [0, 13], [1, 3], [1, 4], [1, 6], [1, 10], [1, 11], [1, 12], [1, 13], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 11], [2, 12], [2, 13], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [4, 5], [4, 6], [4, 7], [4, 11], [4, 13], [5, 6], [5, 7], [5, 11], [5, 13], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [7, 8], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 13], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s2/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3df0f3e6011ee35dfca3d03455f1a2f00b91abd2 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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, 0, 2, 3, 4, 2, 5, 1, 3, 4, 6, 7, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/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-s2/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6c0fd086a7897c60cccf1e6bc92e6b81bf6ea10 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 9, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 9], [0, 13], [1, 3], [1, 4], [1, 6], [1, 10], [1, 11], [1, 12], [1, 13], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 11], [2, 12], [2, 13], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [4, 5], [4, 6], [4, 7], [4, 11], [4, 13], [5, 6], [5, 7], [5, 11], [5, 13], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [7, 8], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 13], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s2/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s5/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s5/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b007d8f09c5be946ddaef1f8c33bd0c872d0a45 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 1], [0, 2], [0, 4], [0, 7], [0, 9], [0, 11], [0, 13], [1, 4], [1, 5], [1, 6], [1, 8], [1, 10], [1, 11], [1, 12], [2, 5], [2, 11], [2, 12], [2, 13], [3, 5], [3, 7], [3, 13], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [5, 10], [5, 11], [5, 12], [6, 7], [7, 8], [7, 9], [7, 10], [7, 13], [9, 13], [10, 11], [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-s5/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a6a306640b73993b9564fd886e252b88cc0cdd70 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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, 2, 0, 3, 4, 2, 4, 5, 6, 6, 7, 6, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s5/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-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-l6-s5/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b007d8f09c5be946ddaef1f8c33bd0c872d0a45 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 1], [0, 2], [0, 4], [0, 7], [0, 9], [0, 11], [0, 13], [1, 4], [1, 5], [1, 6], [1, 8], [1, 10], [1, 11], [1, 12], [2, 5], [2, 11], [2, 12], [2, 13], [3, 5], [3, 7], [3, 13], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [5, 10], [5, 11], [5, 12], [6, 7], [7, 8], [7, 9], [7, 10], [7, 13], [9, 13], [10, 11], [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-s5/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s5/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-min-chromatic-number-l3-s3/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s3/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73bafd47c72b86c4ef77612ad6c6b841c3166332 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 3, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [1, 2], [1, 9], [1, 12], [2, 8], [2, 9], [3, 6], [3, 7], [3, 9], [3, 10], [3, 12], [4, 6], [4, 10], [5, 6], [5, 7], [6, 7], [6, 12], [7, 9], [8, 11]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s3/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a8a6a102c45aa9e18be4700879b431a21db522d --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 2, 1, 1, 1, 0, 2, 0, 0, 0, 1, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s3/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-s3/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73bafd47c72b86c4ef77612ad6c6b841c3166332 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 3, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [1, 2], [1, 9], [1, 12], [2, 8], [2, 9], [3, 6], [3, 7], [3, 9], [3, 10], [3, 12], [4, 6], [4, 10], [5, 6], [5, 7], [6, 7], [6, 12], [7, 9], [8, 11]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s3/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s4/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s4/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a935792a3dae45afbed99d713db40c82d06ffc0 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 7, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 12], [0, 13], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 12], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 10], [2, 11], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 5], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 8], [7, 9], [7, 10], [7, 12], [8, 10], [8, 11], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [11, 12], [11, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s4/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..701613eaa9650a08b13fb4048fa19d386692458d --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 0, 1, 2, 3, 2, 4, 2, 0, 5, 4, 6, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s4/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-s4/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a935792a3dae45afbed99d713db40c82d06ffc0 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 7, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 12], [0, 13], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 12], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 10], [2, 11], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 5], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 8], [7, 9], [7, 10], [7, 12], [8, 10], [8, 11], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [11, 12], [11, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s4/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-harmonious-coloring-l3-s0/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-rlve-min-harmonious-coloring-l3-s0/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..378ad1f12f76e055be30b6b0a407c39d4ede8489 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [5, 6], [5, 8], [6, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s0/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5d20bd50523acd284abb075a779387c75e030c65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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' +{"colors": [0, 0, 0, 1, 0, 0, 2, 0, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/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-s0/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..378ad1f12f76e055be30b6b0a407c39d4ede8489 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [5, 6], [5, 8], [6, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-rlve-min-harmonious-coloring-l3-s0/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-rlve-min-harmonious-coloring-l3-s7/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s7/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c8bafd478abf860fc33cedfc47202d6bbb0ea423 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 1], [2, 6], [3, 5], [5, 8]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s7/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..89a58e0d8df9abb588a875b97e088d0486cfa56f --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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' +{"colors": [0, 1, 0, 0, 0, 2, 3, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/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-s7/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c8bafd478abf860fc33cedfc47202d6bbb0ea423 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 1], [2, 6], [3, 5], [5, 8]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s7/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s9/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s9/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..71dbcb75287f8403ff935aa6af87e312c5655896 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 7, "edges": [[0, 3], [0, 6], [0, 9], [1, 5], [1, 9], [2, 5], [2, 7], [3, 4], [4, 5], [4, 6], [6, 7], [6, 8], [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-s9/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e1bd72b6005b37c03d7ae82fc3e09dbcec005320 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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' +{"colors": [0, 1, 0, 1, 2, 3, 4, 5, 3, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s9/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/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-s9/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..71dbcb75287f8403ff935aa6af87e312c5655896 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 7, "edges": [[0, 3], [0, 6], [0, 9], [1, 5], [1, 9], [2, 5], [2, 7], [3, 4], [4, 5], [4, 6], [6, 7], [6, 8], [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-s9/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s9/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-pairwise-sums-recovery-l1-s0/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s0/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bdc4198d1cf0728d34d35ddb90f479cdaaeeb449 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 8, 7], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eaf3102311960f69f3bba559ecc23685a553f976 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [3, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-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-l1-s0/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bdc4198d1cf0728d34d35ddb90f479cdaaeeb449 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 8, 7], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s0/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s7/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s7/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..366afc85e04c4e6542f8d82d174cab7ae71e4079 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [6, 7, 3], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..05884bf8b59e7c3dcf8d8efa83e6aee350a42396 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/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-l1-s7/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..366afc85e04c4e6542f8d82d174cab7ae71e4079 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [6, 7, 3], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s7/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s9/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s9/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..00688abdb35030c920b0d2dc6ed082880a8bff6e --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [6, 7, 5], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9847cab33a62240b6f3adbf78940bc21d7cd02e1 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [2, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/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-l1-s9/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..00688abdb35030c920b0d2dc6ed082880a8bff6e --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [6, 7, 5], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s9/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s1/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s1/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae667896b66e5522683414233aad29246e5a7fc8 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [41, 51, 32, 57, 35, 31, 7, 26, 9, 32, 56, 46, 45, 69, 38, 41, 17, 30, 42, 33, 42, 39, 40, 47, 3, 57, 6, 49, 26, 71, 25, 40, 23, 11, 25, 29, 38, 44, 61, 64, 60, 33, 34, 49, 54, 48, 58, 41, 29, 49, 51, 58, 23, 56, 47, 6, 52, 55, 27, 24, 37, 66, 16, 22, 52, 10, 28, 32, 37, 26, 35, 56, 34, 30, 20, 34, 65, 65, 47, 39, 37, 45, 39, 69, 5, 41, 38, 68, 29, 37, 39, 68, 13, 21, 32, 18, 36, 46, 15, 12, 22, 67, 38, 63, 59, 50, 25, 27, 9, 51, 37, 12, 54, 43, 9, 26, 70, 23, 28, 62, 38, 53, 40, 39, 67, 31, 24, 19, 8, 55, 29, 36, 42, 19, 22, 40, 57, 66, 40, 57, 43, 55, 50, 36, 36, 35, 58, 59, 60, 54, 37, 53, 43], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..06110e7c555308a6c350e0f17b8c2eea5ea2fb50 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 2, 4, 5, 7, 8, 15, 17, 21, 22, 24, 25, 30, 32, 33, 34, 35, 36]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/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-s1/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae667896b66e5522683414233aad29246e5a7fc8 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [41, 51, 32, 57, 35, 31, 7, 26, 9, 32, 56, 46, 45, 69, 38, 41, 17, 30, 42, 33, 42, 39, 40, 47, 3, 57, 6, 49, 26, 71, 25, 40, 23, 11, 25, 29, 38, 44, 61, 64, 60, 33, 34, 49, 54, 48, 58, 41, 29, 49, 51, 58, 23, 56, 47, 6, 52, 55, 27, 24, 37, 66, 16, 22, 52, 10, 28, 32, 37, 26, 35, 56, 34, 30, 20, 34, 65, 65, 47, 39, 37, 45, 39, 69, 5, 41, 38, 68, 29, 37, 39, 68, 13, 21, 32, 18, 36, 46, 15, 12, 22, 67, 38, 63, 59, 50, 25, 27, 9, 51, 37, 12, 54, 43, 9, 26, 70, 23, 28, 62, 38, 53, 40, 39, 67, 31, 24, 19, 8, 55, 29, 36, 42, 19, 22, 40, 57, 66, 40, 57, 43, 55, 50, 36, 36, 35, 58, 59, 60, 54, 37, 53, 43], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s1/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s6/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s6/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..62824c697cdf972c289c8a8dc7a088e87f7f89f9 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [29, 8, 43, 34, 29, 52, 35, 26, 21, 52, 20, 15, 18, 49, 48, 47, 37, 58, 22, 21, 15, 14, 7, 45, 41, 42, 41, 31, 48, 58, 68, 40, 38, 59, 5, 30, 71, 14, 13, 18, 7, 30, 62, 47, 41, 54, 21, 48, 55, 42, 38, 37, 42, 15, 57, 65, 25, 17, 11, 43, 19, 14, 51, 23, 45, 36, 40, 36, 38, 31, 17, 39, 36, 37, 61, 68, 27, 24, 29, 69, 49, 32, 36, 25, 31, 16, 46, 23, 35, 12, 13, 24, 17, 25, 22, 35, 44, 26, 28, 30, 35, 13, 39, 12, 6, 39, 48, 34, 56, 38, 30, 18, 16, 11, 45, 33, 46, 25, 49, 34, 63, 37, 35, 22, 28, 59, 42, 43, 32, 10, 53, 40, 53, 55, 20, 32, 44, 39, 60, 45, 38, 44, 24, 46, 67, 19, 9, 12, 36, 28, 29, 62, 40], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..99dd21176b891630da5cb9168b313f9a4e87d028 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [2, 3, 4, 5, 8, 9, 10, 12, 13, 16, 20, 22, 26, 27, 32, 33, 35, 36]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/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-s6/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..62824c697cdf972c289c8a8dc7a088e87f7f89f9 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [29, 8, 43, 34, 29, 52, 35, 26, 21, 52, 20, 15, 18, 49, 48, 47, 37, 58, 22, 21, 15, 14, 7, 45, 41, 42, 41, 31, 48, 58, 68, 40, 38, 59, 5, 30, 71, 14, 13, 18, 7, 30, 62, 47, 41, 54, 21, 48, 55, 42, 38, 37, 42, 15, 57, 65, 25, 17, 11, 43, 19, 14, 51, 23, 45, 36, 40, 36, 38, 31, 17, 39, 36, 37, 61, 68, 27, 24, 29, 69, 49, 32, 36, 25, 31, 16, 46, 23, 35, 12, 13, 24, 17, 25, 22, 35, 44, 26, 28, 30, 35, 13, 39, 12, 6, 39, 48, 34, 56, 38, 30, 18, 16, 11, 45, 33, 46, 25, 49, 34, 63, 37, 35, 22, 28, 59, 42, 43, 32, 10, 53, 40, 53, 55, 20, 32, 44, 39, 60, 45, 38, 44, 24, 46, 67, 19, 9, 12, 36, 28, 29, 62, 40], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s6/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s8/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s8/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56ae62eacd38c7fe724277d37ff6af961c62f1d9 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [37, 21, 15, 22, 12, 38, 32, 30, 33, 40, 61, 53, 50, 41, 25, 33, 35, 60, 23, 37, 43, 17, 63, 32, 42, 43, 28, 60, 39, 45, 10, 42, 48, 14, 45, 34, 28, 21, 48, 20, 44, 31, 65, 23, 47, 26, 54, 9, 16, 5, 43, 47, 24, 47, 41, 49, 32, 64, 33, 29, 36, 23, 41, 61, 11, 46, 44, 46, 11, 30, 36, 58, 35, 59, 18, 69, 43, 33, 54, 30, 37, 27, 53, 55, 62, 27, 50, 34, 42, 45, 35, 43, 22, 38, 68, 25, 30, 40, 48, 35, 38, 55, 63, 39, 26, 38, 29, 61, 52, 36, 40, 35, 52, 57, 42, 53, 28, 40, 36, 60, 8, 15, 36, 51, 39, 44, 36, 13, 16, 41, 19, 58, 43, 37, 37, 19, 62, 56, 51, 67, 59, 29, 31, 45, 18, 23, 12, 55, 50, 19, 28, 17, 34], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6424dc0a5d6a40247ac4f0714281251b42b73bfa --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [2, 3, 6, 8, 9, 10, 13, 15, 17, 20, 25, 26, 27, 28, 30, 33, 34, 35]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/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-s8/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56ae62eacd38c7fe724277d37ff6af961c62f1d9 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [37, 21, 15, 22, 12, 38, 32, 30, 33, 40, 61, 53, 50, 41, 25, 33, 35, 60, 23, 37, 43, 17, 63, 32, 42, 43, 28, 60, 39, 45, 10, 42, 48, 14, 45, 34, 28, 21, 48, 20, 44, 31, 65, 23, 47, 26, 54, 9, 16, 5, 43, 47, 24, 47, 41, 49, 32, 64, 33, 29, 36, 23, 41, 61, 11, 46, 44, 46, 11, 30, 36, 58, 35, 59, 18, 69, 43, 33, 54, 30, 37, 27, 53, 55, 62, 27, 50, 34, 42, 45, 35, 43, 22, 38, 68, 25, 30, 40, 48, 35, 38, 55, 63, 39, 26, 38, 29, 61, 52, 36, 40, 35, 52, 57, 42, 53, 28, 40, 36, 60, 8, 15, 36, 51, 39, 44, 36, 13, 16, 41, 19, 58, 43, 37, 37, 19, 62, 56, 51, 67, 59, 29, 31, 45, 18, 23, 12, 55, 50, 19, 28, 17, 34], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s8/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pan-solar-panels-l4-s3/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-pan-solar-panels-l4-s3/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce532113afcf17e763348b3b4dde0f09896b7e3e --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": 3841404, "B": 5518858, "C": 425225, "D": 1013121, "target": 1013121, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s3/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d9bc7f691aa287ce8a8492b0af3c9ef76cb9e7d3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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": 5065605, "Y": 1013121} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s3/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-s3/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce532113afcf17e763348b3b4dde0f09896b7e3e --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": 3841404, "B": 5518858, "C": 425225, "D": 1013121, "target": 1013121, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-pan-solar-panels-l4-s3/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-pan-solar-panels-l4-s4/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-pan-solar-panels-l4-s4/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e6bc0f6ceaaca676eeb297da5015cb8f27adf53 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": 1377999, "B": 1476291, "C": 1689582, "D": 2487136, "target": 738145, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s4/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..98e47643b76f55f4109c54673fb10484426326b1 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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": 1476290, "Y": 2214435} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s4/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-s4/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e6bc0f6ceaaca676eeb297da5015cb8f27adf53 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": 1377999, "B": 1476291, "C": 1689582, "D": 2487136, "target": 738145, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-pan-solar-panels-l4-s4/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-polynomial-global-minimum-l1-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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-polynomial-global-minimum-l1-s1/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73a6719ab248079483adb4919f17c855b49646bd --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, 2, 1], "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-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..587fa712d6f4b33e8db46fca5bf29f5627f2be44 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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' +{"x0": -1.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s1/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/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-s1/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..73a6719ab248079483adb4919f17c855b49646bd --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, 2, 1], "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-s1/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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-polynomial-global-minimum-l1-s1/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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-polynomial-global-minimum-l1-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l1-s6/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c2617278dd37d025672011346c80d6c543207a64 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [4, 4, 1], "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-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f1950410fa3b584939153d3ef59e69446e7b3733 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -2.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s6/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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-l1-s6/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c2617278dd37d025672011346c80d6c543207a64 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [4, 4, 1], "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-s6/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l1-s6/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l1-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l1-s8/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa755e972d1fbc5f11b57a6cf15bc720b8569a23 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [4, -4, 1], "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-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d7f36b28cb2085c08c88b0949c334857d56020c5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 2.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s8/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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-l1-s8/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa755e972d1fbc5f11b57a6cf15bc720b8569a23 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [4, -4, 1], "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-s8/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l1-s8/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l5-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s0/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2feecf780dbacc7a80961f3176edd3234f413230 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1172, -5548, 12082, -15800, 13701, -8200, 3418, -976, 182, -20, 1], "fmin": "10.7010847634060040633710150034620738750663521", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bfd15e3b6eddb14a347b399cf2873a588a72fea --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.1733649898933909} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/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-s0/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2feecf780dbacc7a80961f3176edd3234f413230 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1172, -5548, 12082, -15800, 13701, -8200, 3418, -976, 182, -20, 1], "fmin": "10.7010847634060040633710150034620738750663521", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s0/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l5-s7/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3c1e59dedeadbeeb149a44cde1a2d6b7f84de5f --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [12, 38, 113, 264, 436, 510, 421, 240, 91, 20, 2], "fmin": "2.84579795605538056483683107621277921429385342", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..07ad6d779bd4a0be5a9842437496962dc687b27c --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -0.9162604681692862} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-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-l5-s7/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3c1e59dedeadbeeb149a44cde1a2d6b7f84de5f --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [12, 38, 113, 264, 436, 510, 421, 240, 91, 20, 2], "fmin": "2.84579795605538056483683107621277921429385342", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l5-s7/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l5-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l5-s9/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40d5631ea1ca995909fcad26b35d7c61d827625d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1316, -6084, 13361, -17136, 14562, -8512, 3474, -976, 181, -20, 1], "fmin": "130.156484856561391265759423015482628774058567", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8e0fa57cc981807dca832c78528e17e31a2a3bf2 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.6994679439729765} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/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-s9/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40d5631ea1ca995909fcad26b35d7c61d827625d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1316, -6084, 13361, -17136, 14562, -8512, 3474, -976, 181, -20, 1], "fmin": "130.156484856561391265759423015482628774058567", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-global-minimum-l5-s9/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-rlve-polynomial-integer-roots-l2-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s2/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5cfbf585eca2a755579aae6da44c62f0ba7dea3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [360, -402, 121, 9, -9, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb0202632ca673e88c8a25b3a04a35a0dbe570bb --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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": [-4, 2, 3, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s2/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5cfbf585eca2a755579aae6da44c62f0ba7dea3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [360, -402, 121, 9, -9, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s2/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l2-s5/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..96602575d2ed58a0f73b0471e1fa5ac0d63abf26 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 32, 16, -18, -1, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0e79411565702af126e769cf780bd886ae39c3f8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-4, -1, 0, 2, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s5/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..96602575d2ed58a0f73b0471e1fa5ac0d63abf26 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 32, 16, -18, -1, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l2-s5/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s3/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecf9c86c8f9978847ae255ddcab30592fda6360e --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [62666254744289280000, -49256056556421120000, -29751691812426547200, 14258051873144340480, 3961117568963506176, -1807720838398126080, -185793005855690496, 120479086953698688, -872801128006704, -4176859492086192, 356660407507536, 62982008174964, -11167823499433, 17718589368, 116889209597, -8786590752, -81921106, 41127000, -1841438, -7380, 3067, -96, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3da24d2a78e482f45eec2e95deff9a0ab06eaff3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-21, -15, -6, -6, -5, -4, -3, -3, 1, 4, 6, 7, 8, 9, 9, 12, 12, 16, 17, 18, 20, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/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-s3/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecf9c86c8f9978847ae255ddcab30592fda6360e --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [62666254744289280000, -49256056556421120000, -29751691812426547200, 14258051873144340480, 3961117568963506176, -1807720838398126080, -185793005855690496, 120479086953698688, -872801128006704, -4176859492086192, 356660407507536, 62982008174964, -11167823499433, 17718589368, 116889209597, -8786590752, -81921106, 41127000, -1841438, -7380, 3067, -96, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s3/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s4/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da3b411bb0b933123abee053091e01d26bf114d6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-2849205705091200000, -532735561932480000, 3753649073002680000, 561074806099036800, -1014641055548433360, -19466985832250688, 115819669332460980, -9809132420214792, -5717329707781251, 967788215743770, 94708192709183, -31305839604276, 671605858389, 393155502070, -32062248105, -1440046272, 276698415, -5726298, -744459, 39740, 207, -54, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..67d346bfebacb4380b52a5b4b81bf16c56997b1a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-19, -19, -10, -9, -6, -4, -3, -2, -1, 1, 5, 5, 6, 6, 9, 9, 12, 13, 14, 15, 15, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/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-s4/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da3b411bb0b933123abee053091e01d26bf114d6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-2849205705091200000, -532735561932480000, 3753649073002680000, 561074806099036800, -1014641055548433360, -19466985832250688, 115819669332460980, -9809132420214792, -5717329707781251, 967788215743770, 94708192709183, -31305839604276, 671605858389, 393155502070, -32062248105, -1440046272, 276698415, -5726298, -744459, 39740, 207, -54, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s4/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-interpolation-l1-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s3/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb9c294174ff1262e631e9382905e57ae719d60d --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"X": [-2, 1, 0], "Y": [11, -1, 1], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..16e9dd145e2db0eb4cc08fb8feffdf6ba8828ba1 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [1, -3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-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-l1-s3/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb9c294174ff1262e631e9382905e57ae719d60d --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"X": [-2, 1, 0], "Y": [11, -1, 1], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s3/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s4/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..90d2db45490d92a57ad864314261769a0c62c69e --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"X": [0, 1, -1], "Y": [-3, -5, 5], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e213311db9652f0bea78695af1250617d9b68b1e --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-3, -5, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s4/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-s4/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..90d2db45490d92a57ad864314261769a0c62c69e --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"X": [0, 1, -1], "Y": [-3, -5, 5], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s4/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s2/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..feb1644b54aefa071cfc30e00b267b72365564b0 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"X": [-6, -5, -10, -1, -7, 4, 11, -13, -12, 7, 9, -9, 1, 6], "Y": [-75167619731, -7189467825, -54710450987295, -21, -548029274343, 237842439, 156038784638655, -1625630917341033, -577381323435113, 409005102627, 11199402696649, -14031017054285, -15, 53265336145], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3ac150027fa68b1f368b191a33ed61534be7e64b --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-5, -1, -3, -3, 1, 0, -1, 5, -4, 0, -1, -3, -5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-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-l5-s2/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..feb1644b54aefa071cfc30e00b267b72365564b0 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"X": [-6, -5, -10, -1, -7, 4, 11, -13, -12, 7, 9, -9, 1, 6], "Y": [-75167619731, -7189467825, -54710450987295, -21, -548029274343, 237842439, 156038784638655, -1625630917341033, -577381323435113, 409005102627, 11199402696649, -14031017054285, -15, 53265336145], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s2/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-rlve-polynomial-interpolation-l5-s5/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2fc82997f5645003eddad25f40caf31b67f84b63 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"X": [6, -10, -7, 0, -8, 12, 11, 2, -2, -5, -6, 7, 10, 1], "Y": [51070916857, -25164222454135, -224460247597, -5, -1319130249309, 367313650781071, 119943690742937, 55181, -7167, -2508794295, -28826256299, 365109415701, 35243818553925, 27], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fa752baf68ce46e0b248c01d35f36e72e815901b --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-5, 3, -1, 4, 5, 5, -2, 2, -2, 4, 4, 2, 5, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s5/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-s5/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2fc82997f5645003eddad25f40caf31b67f84b63 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"X": [6, -10, -7, 0, -8, 12, 11, 2, -2, -5, -6, 7, 10, 1], "Y": [51070916857, -25164222454135, -224460247597, -5, -1319130249309, 367313650781071, 119943690742937, 55181, -7167, -2508794295, -28826256299, 365109415701, 35243818553925, 27], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-rlve-polynomial-interpolation-l5-s5/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-rlve-prefix-product-permutation-l1-s1/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s1/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d5fcf7573bf5010cf54116cb8c01b9dacc71899 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s1/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..863403968ebbccc7308855b6868640a17d7e90ec --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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, 8, 10, 11, 9, 12, 3, 6, 4, 5, 7, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s1/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d5fcf7573bf5010cf54116cb8c01b9dacc71899 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s1/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s6/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l1-s6/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3bc061f0c25bcebb892e477f2de27b5fea8c83d7 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 23, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s6/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..04e89039e66af0c22f62bd0f6213e44d0d7ad6da --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 13, 9, 7, 15, 5, 11, 4, 19, 8, 22, 3, 17, 6, 21, 14, 20, 10, 18, 16, 12, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s6/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3bc061f0c25bcebb892e477f2de27b5fea8c83d7 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 23, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l1-s6/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l1-s8/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l1-s8/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cbada9b4b871d801d0f00ef3320e447ff4c2a862 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 31, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s8/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c6414d69236c8cd4182251527696fe71238308e7 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 17, 22, 9, 26, 27, 10, 5, 8, 29, 18, 14, 13, 21, 30, 3, 12, 20, 19, 15, 4, 25, 28, 23, 6, 7, 24, 11, 16, 31]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s8/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cbada9b4b871d801d0f00ef3320e447ff4c2a862 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 31, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l1-s8/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l5-s0/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s0/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c2d25423cbd695a6c16eb8a020ad8b27ea410113 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 9463, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s0/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..27f3c6e0d1078889d5d45207c1b8556c4e9ce2e7 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 4733, 6310, 2367, 5679, 7887, 1353, 1184, 2104, 2840, 6023, 3944, 729, 677, 5048, 5324, 1671, 5784, 8966, 6152, 3606, 3012, 6584, 6704, 8707, 365, 702, 339, 5222, 7256, 8243, 7394, 8317, 836, 2164, 7624, 8441, 9215, 3398, 7808, 8310, 6535, 3082, 6238, 7992, 8024, 8860, 8084, 1546, 4354, 3712, 183, 7500, 5083, 3098, 170, 9298, 7343, 6577, 8360, 5896, 4122, 4357, 8429, 7717, 4159, 6498, 5150, 8504, 5814, 5199, 8544, 5964, 4221, 2903, 4608, 3565, 6431, 1678, 8636, 3389, 8887, 9350, 3268, 335, 6273, 8050, 7851, 4892, 8728, 105, 8744, 9057, 9162, 1794, 8774, 8586, 5505, 2773, 6909, 8246, 6588, 736, 92, 722, 8482, 5838, 2542, 5210, 6281, 9123, 4817, 3267, 9381, 8888, 3672, 7442, 3289, 5647, 8912, 2269, 7680, 5925, 6793, 7420, 2179, 6260, 4215, 1028, 3859, 2746, 2080, 8041, 7981, 5819, 7307, 2833, 8984, 6877, 7639, 2954, 2600, 2648, 9004, 6723, 7714, 516, 2111, 3113, 1452, 9276, 7036, 1238, 1783, 3542, 3216, 4401, 5571, 5655, 9050, 4997, 1695, 1046, 4444, 7342, 9407, 171, 6366, 57, 168, 3100, 3137, 548, 8757, 8004, 3926, 2193, 7178, 5129, 9096, 5752, 53, 1966, 9104, 1689, 4529, 7035, 9313, 1453, 5629, 5005, 9119, 1570, 9025, 2573, 2753, 1346, 1387, 7657, 3455, 5321, 8855, 8858, 8026, 5448, 5100, 9144, 4778, 816, 5093, 1481, 8973, 4888, 7651, 6295, 6003, 5234, 7337, 5143, 3141, 4497, 4562, 8488, 2409, 7277, 1634, 668, 4691, 6778, 9176, 1189, 6568, 7677, 8453, 5558, 1645, 560, 2824, 2733, 9188, 2514, 1135, 7439, 8572, 310, 2963, 6514, 3397, 9426, 8442, 6184, 1090, 2320, 7862, 6421, 2108, 3499, 5246, 7966, 1930, 2684, 6105, 5686, 5772, 5286, 4021, 7940, 3991, 986, 2910, 1293, 3654, 3190, 1417, 2513, 9224, 2734, 3439, 6174, 3820, 3537, 6209, 2977, 6032, 3753, 6056, 1188, 9234, 6779, 3362, 6017, 8589, 7397, 4990, 6994, 1056, 925, 1557, 4147, 5458, 1793, 9370, 9058, 8250, 1180, 5351, 6135, 892, 246, 6503, 4839, 6340, 908, 2201, 6550, 2786, 807, 2828, 4777, 9257, 5101, 2499, 1085, 848, 7222, 5255, 8046, 6954, 6674, 8403, 3689, 4704, 6196, 86, 3193, 7915, 8762, 29, 4244, 4816, 9353, 6282, 6981, 1569, 9272, 5006, 8155, 4379, 6861, 8734, 8790, 6695, 6542, 1097, 8611, 8321, 1883, 2565, 1688, 9280, 1967, 7608, 757, 27, 8764, 5715, 5751, 9284, 5130, 845, 3776, 2265, 2538, 3518, 2474, 4657, 6226, 727, 3946, 2815, 8396, 2503, 6845, 4560, 4499, 5517, 6652, 4513, 1193, 1287, 7068, 1377, 916, 5405, 2229, 694, 5388, 3829, 2681, 1728, 6349, 2661, 635, 4428, 8249, 9161, 9371, 8745, 5577, 7456, 945, 7282, 4996, 9304, 5656, 7121, 2293, 5140, 2666, 2547, 5980, 741, 7294, 4487, 3853, 7176, 2195, 3826, 7192, 3148, 7971, 3002, 1203, 7349, 5396, 3669, 5328, 2572, 9270, 1571, 3327, 2249, 8695, 7013, 6657, 8976, 7347, 1205, 1392, 3639, 5918, 5549, 6247, 5066, 3807, 2346, 6710, 8121, 6722, 9320, 2649, 595, 2658, 8016, 7490, 3839, 4540, 4227, 2281, 7511, 4622, 823, 6303, 5012, 7930, 6144, 5040, 1367, 6876, 9326, 2834, 5989, 7975, 568, 1718, 3720, 7346, 9018, 6658, 4887, 9252, 1482, 3648, 7989, 2448, 1699, 6151, 9445, 5785, 8953, 3212, 7824, 3726, 5277, 1650, 5892, 3174, 8663, 5597, 3211, 8964, 5786, 1034, 1750, 148, 7355, 5968, 8715, 6492, 5697, 3452, 6074, 580, 3053, 5823, 7575, 4939, 7618, 4813, 7375, 3886, 2011, 2096, 8702, 3061, 1996, 8019, 5225, 1862, 6187, 7365, 647, 1918, 6559, 4828, 6327, 174, 709, 656, 1257, 2268, 9344, 5648, 6099, 3718, 1720, 1581, 7819, 238, 6642, 5500, 1769, 5346, 3105, 6332, 1489, 485, 7748, 1398, 1877, 3763, 7760, 1669, 5326, 3671, 9349, 9382, 3390, 524, 6413, 6744, 3009, 1543, 4295, 7167, 3699, 2000, 7227, 2427, 8229, 6758, 5260, 6815, 463, 6808, 779, 2553, 2074, 7900, 7461, 867, 897, 8083, 9417, 8025, 9261, 8856, 8857, 9262, 5322, 5050, 2676, 6392, 3068, 4971, 5178, 4050, 4855, 5902, 3252, 6203, 2420, 7459, 7902, 5270, 5186, 3427, 1101, 4394, 8007, 4740, 6125, 6803, 404, 5038, 6146, 8127, 2389, 1630, 4629, 1433, 2551, 781, 1250, 2099, 543, 7548, 5156, 7481, 8343, 8054, 2628, 4305, 8755, 550, 8209, 1715, 8069, 1638, 4202, 7517, 1845, 4654, 7084, 1609, 7830, 228, 4775, 2830, 1597, 3978, 3958, 6694, 9113, 8735, 15, 4418, 6854, 5283, 7140, 6532, 4677, 957, 7873, 2460, 3491, 2260, 785, 8585, 9368, 1795, 7235, 397, 4078, 7054, 2190, 3273, 3431, 5714, 9099, 28, 9127, 7916, 3348, 8162, 8003, 9290, 549, 8810, 4306, 6496, 4161, 5708, 942, 2423, 1283, 4066, 5576, 9056, 9372, 106, 984, 3993, 8536, 3238, 379, 5520, 14, 8789, 9114, 6862, 2858, 6740, 2876, 104, 9374, 4893, 7297, 3484, 423, 2172, 6620, 7388, 1133, 2516, 6001, 6297, 6491, 8946, 5969, 4701, 2329, 2062, 7845, 1856, 364, 9439, 6705, 774, 1408, 3060, 8930, 2097, 1252, 2141, 3423, 8514, 7012, 9021, 2250, 1167, 2759, 760, 8058, 6387, 2257, 2656, 597, 6913, 644, 8216, 8266, 7204, 689, 881, 5190, 5977, 2703, 1896, 1115, 5875, 5079, 4822, 7426, 4917, 1915, 4311, 1341, 3862, 5596, 8956, 3175, 6565, 1331, 6678, 318, 6638, 6946, 3709, 4125, 2358, 4581, 3586, 4686, 210, 4373, 8132, 2789, 1064, 8460, 4842, 473, 3163, 8373, 7147, 7230, 3388, 9384, 1679, 7560, 912, 3561, 6215, 1147, 35, 7302, 5213, 6065, 1659, 1274, 5402, 7722, 4334, 371, 5690, 8379, 325, 2244, 993, 1927, 3248, 8320, 9109, 1098, 4406, 6645, 1315, 8328, 2028, 6306, 3551, 3986, 4102, 6233, 2003, 602, 8569, 3675, 1874, 7430, 7780, 1835, 8315, 7396, 9172, 6018, 5504, 9367, 8775, 786, 4276, 1664, 7685, 1125, 2332, 4348, 7565, 3507, 2247, 3329, 309, 9220, 7440, 3674, 8597, 603, 1383, 5428, 3222, 1820, 3782, 7691, 6907, 2775, 6829, 3124, 314, 7265, 3020, 1904, 832, 5905, 4292, 8087, 394, 4061, 1745, 8093, 5963, 9392, 5200, 1325, 8408, 298, 7909, 6061, 3237, 8740, 3994, 8477, 6557, 1920, 4768, 7002, 5193, 2114, 4071, 1141, 6612, 3756, 715, 7043, 2008, 412, 2184, 3152, 4058, 7238, 7011, 8697, 3424, 7804, 8193, 7252, 4787, 684, 1593, 8170, 5813, 9395, 5151, 6149, 1701, 2995, 4100, 3988, 6264, 5016, 6671, 5591, 8353, 6592, 3687, 8405, 2408, 9241, 4563, 8061, 4747, 2444, 5837, 9358, 723, 5473, 270, 6556, 8534, 3995, 3015, 5956, 7220, 850, 7539, 3076, 7210, 4723, 3342, 2893, 2066, 4477, 1731, 6338, 4841, 8644, 1065, 6595, 3384, 2639, 5872, 5557, 9230, 7678, 2271, 6319, 3665, 4332, 7724, 2799, 7876, 1606, 6183, 9214, 9427, 7625, 2983, 5249, 130, 5607, 5482, 4806, 3241, 3678, 514, 7716, 9400, 4358, 3131, 7978, 3972, 2849, 2719, 6458, 5853, 7769, 164, 5022, 5442, 1527, 1291, 2912, 7096, 3788, 6085, 2470, 297, 8541, 1326, 2407, 8490, 3688, 9134, 6675, 820, 1006, 2871, 5780, 2502, 9083, 2816, 1531, 6937, 5730, 5513, 4010, 5045, 2613, 6872, 5663, 2176, 3094, 7792, 3683, 6965, 324, 8618, 5691, 7601, 3280, 253, 7146, 8640, 3164, 3265, 4819, 2922, 355, 855, 5060, 6037, 629, 5072, 5866, 5895, 9404, 6578, 7556, 4865, 3050, 2723, 6591, 8493, 5592, 7568, 791, 3591, 3910, 7812, 4851, 4001, 8053, 8814, 7482, 1779, 885, 7134, 7405, 7474, 1553, 2482, 7898, 2076, 745, 6950, 243, 2027, 8606, 1316, 5431, 5393, 939, 2854, 1882, 9108, 8612, 3249, 835, 9431, 7395, 8591, 1836, 5419, 4675, 6534, 9423, 7809, 6427, 2561, 4994, 7284, 3207, 2218, 8104, 2084, 1505, 7214, 772, 6707, 2148, 2729, 3584, 4583, 1850, 5511, 5732, 3005, 3614, 4833, 1214, 306, 4115, 6940, 8111, 9, 7362, 3898, 3408, 288, 232, 2898, 8136, 4951, 390, 8179, 1277, 2440, 5769, 7203, 8682, 8217, 3731, 6462, 434, 2117, 449, 8074, 4042, 3090, 4709, 6521, 4013, 1431, 4631, 1179, 9160, 9059, 4429, 6587, 9363, 6910, 7393, 9433, 7257, 2949, 6070, 3848, 7928, 5014, 6266, 3181, 2486, 7596, 7321, 3470, 6757, 8874, 2428, 154, 7683, 1666, 6358, 3135, 3102, 3739, 5942, 1886, 3730, 8265, 8683, 645, 7367, 765, 7325, 6141, 1714, 8808, 551, 7198, 6929, 7848, 4004, 4301, 7102, 1994, 3063, 4250, 3402, 6230, 4934, 2432, 7251, 8511, 7805, 841, 4064, 1285, 1195, 7026, 5547, 5920, 2315, 7041, 717, 5400, 1276, 8271, 391, 2398, 5357, 7937, 1050, 6554, 272, 5812, 8506, 1594, 7310, 5940, 3741, 3556, 4172, 8002, 8759, 3349, 6046, 8108, 2153, 3527, 4378, 9117, 5007, 4931, 4105, 2819, 858, 1138, 4035, 6245, 5551, 2017, 6833, 5302, 3759, 4264, 923, 1058, 7059, 4950, 8274, 2899, 805, 2788, 8647, 4374, 4846, 5374, 2388, 8827, 6147, 5153, 799, 5604, 6721, 9006, 6711, 198, 8079, 3619, 4557, 4259, 4368, 1577, 8, 8282, 6941, 2152, 8159, 6047, 2642, 2083, 8302, 2219, 7998, 7159, 2339, 4424, 479, 2590, 3937, 5600, 5962, 8546, 1746, 5308, 5862, 2396, 393, 8550, 4293, 1545, 9416, 8861, 898, 4038, 3618, 8118, 199, 1809, 6771, 4041, 8259, 450, 5827, 7854, 1637, 8806, 1716, 570, 7589, 2037, 4550, 1514, 4746, 8486, 4564, 6386, 8690, 761, 6406, 2627, 8813, 8344, 4002, 7850, 9377, 6274, 275, 6953, 9137, 5256, 6885, 3970, 7980, 9331, 2081, 2644, 7586, 5704, 5203, 5451, 1212, 4835, 642, 6915, 6765, 2131, 7520, 5447, 9260, 8859, 9418, 7993, 4785, 7254, 5224, 8927, 1997, 7489, 9000, 2659, 6351, 151, 190, 3837, 7492, 6882, 4739, 8834, 4395, 3925, 9289, 8758, 8163, 4173, 6161, 7158, 8102, 2220, 6170, 2436, 4784, 8023, 9419, 6239, 2447, 8970, 3649, 4268, 6474, 4371, 212, 493, 5818, 9330, 8042, 3971, 8426, 3132, 567, 8981, 5990, 2051, 3001, 9033, 3149, 6508, 3246, 1929, 9205, 5247, 2985, 7062, 2351, 7380, 1165, 2252, 5763, 1979, 3923, 4397, 5660, 5531, 4914, 1402, 4720, 3705, 3353, 7131, 5119, 6156, 5436, 4213, 6262, 3990, 9197, 4022, 1049, 8175, 5358, 6648, 1071, 2529, 1712, 6143, 8989, 5013, 8238, 3849, 4511, 6654, 5857, 6455, 584, 5171, 1380, 50, 5112, 3347, 8761, 9128, 3194, 1990, 1129, 6984, 6060, 8539, 299, 5319, 3457, 6599, 5054, 5269, 8840, 7460, 8865, 2075, 8334, 2483, 345, 194, 441, 6139, 7327, 4543, 2989, 5096, 1352, 9458, 5680, 7744, 558, 1647, 2938, 3516, 2540, 5840, 7143, 1605, 8445, 2800, 2459, 8780, 958, 1296, 2156, 6634, 671, 5488, 6663, 7008, 7530, 6420, 9210, 2321, 1588, 1021, 3283, 2380, 666, 1636, 8071, 5828, 4891, 9376, 8051, 4003, 8205, 6930, 1855, 8710, 2063, 5722, 5911, 5610, 2291, 7123, 6525, 5951, 7075, 640, 4837, 6505, 2187, 227, 8798, 1610, 1395, 660, 5264, 3725, 8962, 3213, 7153, 3906, 237, 8906, 1582, 6528, 4187, 506, 3574, 4850, 8347, 3911, 6426, 8309, 9424, 3399, 840, 8192, 8512, 3425, 5188, 883, 1781, 1240, 3108, 1704, 574, 4140, 18, 3682, 8383, 3095, 2607, 2532, 3033, 80, 830, 1906, 5369, 6897, 7433, 1834, 8593, 7431, 6899, 360, 186, 4937, 7577, 5737, 4190, 4467, 163, 8420, 5854, 7016, 497, 3315, 964, 6471, 6356, 1668, 8892, 3764, 4555, 3621, 5281, 6856, 6935, 1533, 3323, 1255, 658, 1397, 8896, 486, 5746, 557, 7885, 5681, 1776, 7712, 6725, 7533, 6783, 401, 3117, 4987, 1002, 3128, 5033, 2764, 4285, 5417, 1838, 6484, 5669, 2798, 8447, 4333, 8622, 5403, 918, 1373, 4158, 9399, 8430, 515, 9318, 6724, 7741, 1777, 7484, 5544, 4684, 3588, 4388, 4520, 5125, 6976, 6870, 2615, 5564, 6987, 3843, 3964, 563, 4120, 5898, 3036, 6906, 8562, 3783, 1723, 1754, 1982, 1124, 8581, 1665, 8226, 155, 5924, 9342, 2270, 8452, 9231, 6569, 3746, 4299, 4006, 302, 96, 692, 2231, 7446, 2634, 6343, 7260, 5642, 6716, 6623, 3444, 3846, 6072, 3454, 9265, 1388, 2695, 3415, 3596, 6294, 9250, 4889, 5830, 3633, 5834, 6242, 901, 5684, 6107, 5148, 6500, 2953, 9324, 6878, 3088, 4044, 4792, 4929, 5009, 2031, 1684, 873, 1151, 4047, 1737, 2982, 8440, 9428, 2165, 7332, 1947, 663, 4812, 8936, 4940, 4881, 1173, 3955, 4505, 3031, 2534, 1619, 756, 9102, 1968, 6729, 6028, 4239, 540, 3279, 8377, 5692, 2401, 7116, 7320, 8233, 2487, 2597, 6222, 5789, 870, 2036, 8066, 571, 5703, 8038, 2645, 6610, 1143, 358, 6901, 3522, 1246, 5736, 7774, 4938, 8938, 5824, 3549, 6308, 4735, 6761, 790, 8351, 5593, 3506, 8577, 4349, 4282, 6444, 911, 8634, 1680, 4097, 4864, 8358, 6579, 2394, 5864, 5074, 4547, 797, 5155, 8817, 544, 2907, 933, 4698, 3533, 2576, 6787, 3075, 8471, 851, 6218, 1498, 261, 6782, 7739, 6726, 6419, 7864, 7009, 7240, 3880, 3336, 4447, 2796, 5671, 4177, 5446, 8028, 2132, 1844, 8803, 4203, 2652, 5936, 5089, 4621, 8994, 2282, 3307, 4031, 3028, 2374, 4590, 5954, 3017, 2919, 5082, 9411, 184, 362, 1858, 2737, 3048, 4867, 6881, 8010, 3838, 8999, 8017, 1998, 3701, 1508, 5543, 7710, 1778, 8342, 8815, 5157, 2971, 3770, 4111, 6270, 1552, 8337, 7406, 2362, 1264, 6403, 537, 1447, 1977, 5765, 588, 2239, 3231, 866, 8864, 7901, 8841, 2421, 944, 9054, 5578, 533, 7370, 3298, 4481, 6424, 3913, 1320, 2633, 7668, 2232, 2779, 3288, 9347, 3673, 8571, 9221, 1136, 860, 3160, 4455, 1833, 7782, 6898, 7779, 8594, 1875, 1400, 4916, 8670, 4823, 5535, 4707, 3092, 2178, 9339, 6794, 4714, 4328, 3813, 3474, 1492, 6465, 2625, 6408, 4797, 3975, 2804, 2361, 7473, 8338, 7135, 754, 1621, 3744, 6571, 1000, 4989, 9171, 8590, 8316, 9432, 8244, 6911, 599, 1566, 1132, 8721, 6621, 6718, 133, 1425, 6822, 1360, 1164, 7961, 2352, 2927, 4567, 3885, 8934, 4814, 4246, 7243, 3297, 7453, 534, 764, 8214, 646, 8923, 6188, 3897, 8280, 10, 6626, 4982, 3043, 257, 5967, 8948, 149, 6353, 4271, 937, 5395, 9030, 1204, 9017, 8977, 3721, 6576, 9406, 9299, 4445, 3338, 2664, 5142, 9246, 5235, 2699, 1436, 1946, 7622, 2166, 5983, 4225, 4542, 7892, 6140, 8212, 766, 6043, 3469, 8232, 7597, 7117, 2757, 1169, 6737, 3581, 2523, 1356, 1307, 5939, 8168, 1595, 2832, 9328, 5820, 5379, 6279, 5212, 8628, 36, 1842, 2134, 3483, 8726, 4894, 4486, 9041, 742, 2846, 4800, 3801, 1080, 6372, 2044, 127, 3206, 8305, 4995, 9052, 946, 6314, 2959, 1633, 9239, 2410, 697, 6193, 5538, 178, 2288, 428, 5640, 7262, 2917, 3019, 8556, 315, 2916, 7268, 5641, 7665, 6344, 2948, 8242, 9434, 5223, 8021, 4786, 8510, 8194, 2433, 5525, 6257, 1162, 1362, 1468, 3296, 7372, 4247, 3879, 7528, 7010, 8516, 4059, 396, 8772, 1796, 2020, 6687, 3387, 8638, 7148, 2426, 8876, 2001, 6235, 4027, 5254, 9139, 849, 8473, 5957, 890, 6137, 443, 771, 8299, 1506, 3703, 4722, 8469, 3077, 777, 6810, 5973, 688, 8681, 8267, 5770, 5688, 373, 6928, 8207, 552, 122, 1786, 1014, 3147, 9035, 3827, 5390, 6440, 2716, 3413, 2697, 5237, 470, 1955, 6159, 4175, 5673, 5128, 9286, 2194, 9038, 3854, 1625, 2343, 418, 4326, 4716, 7023, 3698, 8879, 4296, 6097, 5650, 5993, 2710, 3658, 2338, 8101, 7999, 6162, 4712, 6796, 3905, 7822, 3214, 3544, 1281, 2425, 7229, 8639, 8374, 254, 1604, 7878, 5841, 6531, 8784, 5284, 5774, 4763, 753, 7404, 8339, 886, 5118, 7947, 3354, 4694, 5806, 2305, 1365, 5042, 6524, 7839, 2292, 9048, 5657, 457, 2756, 7319, 7598, 2402, 1503, 2086, 6539, 4083, 2417, 6603, 5339, 812, 4885, 6660, 2058, 1993, 8202, 4302, 4056, 3154, 5, 3787, 8413, 2913, 6681, 4958, 6436, 1959, 4876, 5372, 4848, 3576, 6181, 1608, 8800, 4655, 2476, 5624, 4927, 4794, 4090, 1337, 639, 7836, 5952, 4592, 2885, 1911, 3602, 1376, 9073, 1288, 4109, 3772, 1866, 2350, 7963, 2986, 4949, 8138, 1059, 976, 225, 2189, 8769, 4079, 6753, 5809, 6277, 5381, 2355, 2863, 3261, 623, 2007, 8522, 716, 8183, 2316, 2237, 590, 1237, 9312, 9277, 4530, 1270, 2215, 3941, 3294, 1470, 4682, 5546, 8187, 1196, 3697, 7169, 4717, 981, 3629, 3225, 1475, 496, 7767, 5855, 6656, 9020, 8696, 8515, 7239, 7529, 7865, 6664, 1591, 686, 5975, 5192, 8530, 4769, 3661, 2623, 6467, 4604, 3379, 1055, 9169, 4991, 5946, 376, 4809, 2383, 3842, 7699, 5565, 6059, 7911, 1130, 1568, 9121, 6283, 1231, 1870, 6869, 7703, 5126, 5675, 3382, 6597, 3459, 4133, 4943, 4342, 4363, 323, 8381, 3684, 1068, 383, 2621, 3663, 6321, 3071, 6399, 5589, 6673, 9136, 8047, 276, 242, 8331, 746, 3465, 3708, 8656, 6639, 6734, 5883, 2151, 8110, 8283, 4116, 5729, 8393, 1532, 7754, 6857, 1676, 6433, 1854, 7847, 8206, 7199, 374, 5948, 1585, 3626, 109, 4256, 6848, 3903, 6798, 421, 3486, 6764, 8031, 643, 8685, 598, 7392, 8245, 9364, 2774, 8561, 7692, 3037, 1158, 4472, 3521, 7581, 359, 7778, 7432, 7783, 5370, 4878, 4136, 439, 196, 6713, 5931, 1923, 2679, 3831, 3969, 8044, 5257, 4738, 8009, 7493, 4868, 3087, 7638, 9325, 8985, 1368, 5529, 5662, 8387, 2614, 7702, 6977, 1871, 3244, 6510, 143, 6818, 2857, 8733, 9115, 4380, 6369, 1675, 6934, 7755, 5282, 8786, 4419, 1077, 2594, 1764, 3902, 6921, 4257, 4559, 9081, 2504, 5803, 2466, 2999, 2053, 3058, 1410, 653, 5161, 5411, 5301, 8144, 2018, 1798, 3123, 8559, 2776, 6080, 1009, 3594, 3417, 1359, 7383, 1426, 1880, 2856, 6864, 144, 462, 8871, 5261, 1950, 3530, 5972, 7207, 778, 8869, 464, 1450, 3115, 403, 8831, 6126, 2126, 4324, 420, 6919, 3904, 7155, 4713, 7419, 9340, 5926, 3258, 4414, 613, 3074, 7541, 2577, 5635, 400, 7738, 7534, 262, 3361, 9175, 9235, 4692, 3356, 4319, 4831, 3616, 4040, 8076, 1810, 6051, 2279, 4229, 2130, 8030, 6916, 3487, 789, 7570, 4736, 5259, 8873, 8230, 3471, 2303, 5808, 7052, 4080, 6698, 3024, 2277, 6053, 6615, 1042, 3008, 8883, 6414, 1110, 2875, 8731, 2859, 3580, 7316, 1170, 5882, 6944, 6640, 240, 278, 6027, 7606, 1969, 6418, 7532, 7740, 7713, 9319, 9005, 8122, 5605, 132, 7386, 6622, 7663, 5643, 5930, 6891, 197, 8120, 9007, 2347, 2147, 8297, 773, 8706, 9440, 6585, 4431, 1734, 5181, 3023, 6751, 4081, 6541, 9112, 8791, 3959, 100, 2557, 905, 2637, 3386, 7232, 2021, 6178, 4130, 4234, 4957, 7094, 2914, 317, 8659, 1332, 819, 8402, 9135, 6955, 5590, 8495, 5017, 1941, 3795, 1740, 1019, 1590, 7007, 7866, 5489, 2057, 7105, 4886, 8975, 9019, 7014, 5856, 7925, 4512, 9077, 5518, 381, 1070, 7935, 5359, 1314, 8608, 4407, 5499, 8904, 239, 6733, 6945, 8657, 319, 4689, 670, 7869, 2157, 138, 482, 3477, 3883, 4569, 4981, 7360, 11, 3443, 7662, 6717, 7387, 8722, 2173, 4666, 5492, 1041, 6747, 6054, 3755, 8525, 1142, 7584, 2646, 2602, 733, 2726, 5886, 5338, 7109, 2418, 6205, 5053, 7905, 3458, 6972, 3383, 8458, 1066, 3686, 8492, 8354, 2724, 735, 9362, 8247, 4430, 6703, 9441, 3013, 3997, 4872, 2393, 7555, 8359, 9405, 7344, 3722, 4464, 6122, 999, 7400, 3745, 7676, 9232, 1190, 1330, 8661, 3176, 5243, 76, 4858, 4827, 8920, 1919, 8533, 8478, 271, 8173, 1051, 2370, 2785, 9149, 2202, 2198, 6447, 1963, 4384, 4645, 1096, 9111, 6696, 4082, 7112, 2087, 4899, 3081, 9422, 8311, 4676, 8783, 7141, 5842, 4186, 7817, 1583, 5950, 7838, 7124, 5043, 4012, 8255, 4710, 6164, 3120, 2207, 1224, 3396, 9217, 2964, 1825, 142, 6866, 3245, 7969, 3150, 2186, 7833, 4838, 9154, 247, 2952, 7641, 5149, 9397, 4160, 8753, 4307, 1986, 5696, 8945, 8716, 6298, 3255, 284, 3434, 4491, 5668, 7727, 1839, 1026, 4217, 1501, 2404, 4517, 4921, 1575, 4370, 7986, 4269, 6355, 7763, 965, 5366, 4603, 6998, 2624, 7413, 1493, 433, 8263, 3732, 1176, 5852, 8422, 2720, 583, 7923, 5858, 23, 2882, 5469, 990, 3510, 1962, 6547, 2199, 910, 7562, 4283, 2766, 2715, 7189, 5391, 5433, 1958, 7092, 4959, 1853, 6932, 1677, 9386, 3566, 1772, 2560, 8308, 7810, 3912, 7450, 4482, 2107, 9209, 7863, 7531, 6727, 1970, 4599, 1109, 6743, 8884, 525, 3643, 4088, 4796, 7411, 2626, 8056, 762, 536, 7470, 1265, 5216, 5588, 6957, 3072, 615, 4495, 3143, 2507, 3067, 8851, 2677, 1925, 995, 2256, 8689, 8059, 4565, 2929, 44, 3228, 5440, 5024, 4596, 2586, 1828, 5422, 1208, 4757, 2043, 7288, 1081, 1674, 6859, 4381, 56, 9296, 172, 6329, 1243, 5727, 4118, 565, 3134, 8224, 1667, 7762, 6472, 4270, 7353, 150, 8014, 2660, 9063, 1729, 4479, 3300, 2947, 7259, 7666, 2635, 907, 9152, 4840, 8462, 1732, 4433, 5106, 1038, 1488, 8899, 3106, 1242, 6364, 173, 8918, 4829, 4321, 221, 4969, 3070, 6959, 3664, 8450, 2272, 431, 1495, 2958, 7280, 947, 5408, 2366, 9461, 4734, 7572, 3550, 8604, 2029, 5011, 8991, 824, 1093, 6201, 3254, 6490, 8717, 6002, 9249, 7652, 3597, 3572, 508, 803, 2901, 4223, 5985, 6132, 3198, 1230, 6980, 9122, 9354, 5211, 7304, 5380, 7050, 5810, 274, 8049, 9378, 336, 1551, 7476, 4112, 3332, 3180, 8236, 5015, 8497, 3989, 7942, 4214, 9337, 2180, 1161, 7248, 5526, 3867, 511, 502, 1642, 2313, 5922, 157, 5065, 9011, 5550, 8147, 4036, 900, 7646, 5835, 2446, 7991, 9420, 3083, 4026, 7225, 2002, 8600, 4103, 4933, 8197, 3403, 928, 726, 9087, 4658, 1032, 5788, 7593, 2598, 2956, 1497, 7537, 852, 1146, 8631, 3562, 621, 3263, 3166, 2976, 9182, 3538, 2674, 5052, 6601, 2419, 8843, 3253, 6300, 1094, 4647, 114, 85, 9131, 4705, 5537, 7274, 698, 6035, 5062, 3896, 7364, 8924, 1863, 1089, 9213, 8443, 1607, 7086, 3577, 4129, 6685, 2022, 119, 3819, 9185, 3440, 5523, 2435, 7996, 2221, 2094, 2013, 4985, 3119, 6519, 4711, 7157, 8000, 4174, 7182, 1956, 5435, 7945, 5120, 4155, 3605, 9444, 8967, 1700, 8502, 5152, 8126, 8828, 5039, 8988, 7931, 1713, 8211, 7326, 7893, 442, 7217, 891, 9157, 5352, 3197, 6286, 5986, 5584, 1939, 5019, 2125, 6802, 8832, 4741, 998, 6573, 4465, 4192, 4352, 1548, 705, 1304, 3420, 5998, 5759, 1517, 2335, 4772, 2689, 5147, 7643, 5685, 9202, 2685, 291, 3449, 6093, 3717, 8910, 5649, 7165, 4297, 3748, 3716, 6101, 3450, 5699, 4912, 5533, 4825, 4860, 2469, 8411, 3789, 2492, 2869, 1008, 6827, 2777, 2234, 828, 82, 579, 8942, 3453, 7659, 3847, 8240, 2950, 249, 40, 1658, 8626, 5214, 1267, 3236, 8538, 7910, 6985, 5566, 1187, 9178, 3754, 6614, 6748, 2278, 6769, 1811, 5870, 2641, 8107, 8160, 3350, 3468, 7323, 767, 952, 1662, 4278, 628, 8365, 5061, 6191, 699, 3752, 9180, 2978, 4975, 4238, 7605, 6730, 279, 3292, 3943, 9453, 2841, 1804, 5620, 5503, 8588, 9173, 3363, 3373, 3767, 522, 3392, 1807, 201, 4145, 1559, 2867, 2494, 5333, 5233, 9248, 6296, 8718, 2517, 5758, 6114, 3421, 2143, 1234, 2709, 7163, 5651, 2050, 7974, 8982, 2835, 5583, 6131, 6287, 4224, 7330, 2167, 740, 9043, 2548, 2702, 8677, 5191, 7004, 687, 7206, 6811, 3531, 4700, 8714, 8947, 7356, 258, 4220, 9391, 8545, 8094, 5601, 3871, 1899, 889, 7219, 8474, 3016, 7504, 4591, 7074, 7837, 6526, 1584, 6926, 375, 6992, 4992, 2563, 1885, 8220, 3740, 8167, 7311, 1308, 5088, 7514, 2653, 3494, 4766, 1922, 6890, 6714, 5644, 282, 3257, 6792, 9341, 7681, 156, 6250, 2314, 8185, 5548, 9013, 3640, 1892, 3158, 862, 5480, 5609, 7842, 5723, 1300, 5294, 4662, 4291, 8552, 833, 3251, 8845, 4856, 78, 3035, 7694, 4121, 9403, 8361, 5867, 3173, 8958, 1651, 4616, 2378, 3285, 5337, 6605, 2727, 2150, 6943, 6735, 1171, 4883, 814, 4780, 1758, 5078, 8673, 1116, 5556, 8455, 2640, 6049, 1812, 3172, 5894, 8362, 5073, 7553, 2395, 8090, 5309, 3312, 22, 6454, 7924, 6655, 7015, 7768, 8421, 6459, 1177, 4633, 2692, 5426, 1385, 1348, 4909, 1708, 4185, 6530, 7142, 7879, 2541, 9357, 8483, 2445, 6241, 7647, 3634, 1817, 3632, 7649, 4890, 7853, 8072, 451, 3548, 7574, 8939, 3054, 5378, 7306, 9329, 7982, 494, 1477, 5198, 9394, 8505, 8171, 273, 6276, 7051, 6754, 2304, 7128, 4695, 2465, 6843, 2505, 3145, 1016, 5134, 5574, 4068, 437, 4138, 576, 117, 2024, 895, 869, 7592, 6223, 1033, 8952, 8965, 9446, 1672, 1083, 2501, 8398, 2872, 974, 1061, 332, 4762, 7138, 5285, 9200, 5687, 7202, 8268, 2441, 2297, 587, 7466, 1978, 7958, 2253, 4744, 1516, 6113, 5999, 2518, 810, 5341, 5110, 52, 9283, 9097, 5716, 3371, 3365, 556, 7746, 487, 2120, 2890, 5002, 4200, 1640, 504, 4189, 7773, 7578, 1247, 1201, 3004, 8290, 5512, 8392, 6938, 4117, 6362, 1244, 3524, 1299, 5910, 7843, 2064, 2895, 1790, 5167, 3370, 5750, 9098, 8765, 3432, 286, 3410, 2852, 941, 8751, 4162, 1323, 5202, 8037, 7587, 572, 1706, 4911, 6091, 3451, 8944, 6493, 1987, 5355, 2400, 7600, 8378, 8619, 372, 7201, 5771, 9201, 6106, 7644, 902, 1775, 7743, 7886, 9459, 2368, 1053, 3381, 6974, 5127, 7180, 4176, 7523, 2797, 7726, 6485, 4492, 4289, 4664, 2175, 8386, 6873, 5530, 7954, 4398, 456, 7120, 9049, 9305, 5572, 5136, 2049, 5992, 7164, 6098, 8911, 9345, 3290, 281, 5929, 6715, 7664, 7261, 7269, 429, 2274, 4076, 399, 6785, 2578, 5497, 4409, 4198, 5004, 9274, 1454, 1974, 467, 4926, 7081, 2477, 1767, 5502, 6020, 1805, 3394, 1226, 1538, 4955, 4236, 4977, 426, 2290, 7841, 5912, 5481, 8436, 131, 6720, 8123, 800, 3870, 5961, 8095, 3938, 3210, 8955, 8664, 3863, 3505, 7567, 8352, 8494, 6672, 6956, 6400, 5217, 2224, 1938, 6130, 5987, 2836, 4897, 2089, 532, 7455, 9055, 8746, 4067, 5798, 5135, 5654, 9306, 4402, 3276, 2102, 1186, 6058, 6986, 7700, 2616, 2545, 2668, 2311, 1644, 9229, 8454, 5873, 1117, 1654, 3040, 2016, 8146, 6246, 9012, 5919, 8186, 7027, 4683, 7709, 7485, 1509, 5069, 1460, 177, 7273, 6194, 4706, 7424, 4824, 6089, 4913, 7953, 5661, 6874, 1369, 3866, 6256, 7249, 2434, 6172, 3441, 13, 8737, 380, 6651, 9078, 4500, 5316, 4009, 8391, 5731, 8291, 1851, 4961, 5486, 673, 2772, 9366, 8587, 6019, 5621, 1768, 8903, 6643, 4408, 5633, 2579, 1422, 1486, 1040, 6617, 4667, 2056, 6662, 7867, 672, 5508, 4962, 4169, 4805, 8435, 5608, 5913, 863, 5364, 967, 3202, 1524, 269, 8480, 724, 930, 989, 6451, 2883, 4594, 5026, 4613, 1120, 1413, 1616, 1261, 5165, 1792, 9164, 4148, 3951, 1075, 4421, 2943, 1211, 8035, 5204, 5099, 9259, 8027, 7521, 4178, 267, 1526, 8417, 5023, 6381, 3229, 2241, 4212, 7944, 6157, 1957, 6438, 5392, 8326, 1317, 3221, 8566, 1384, 5848, 2693, 1390, 1207, 6376, 1829, 4674, 8313, 1837, 7729, 4286, 618, 4611, 5028, 5300, 6835, 5162, 2365, 6312, 948, 2228, 9070, 917, 7721, 8623, 1275, 8181, 718, 3890, 3668, 9029, 7350, 938, 8325, 5432, 6439, 7190, 3828, 9067, 695, 2412, 2713, 2768, 2925, 2354, 7049, 6278, 7305, 5821, 3055, 4670, 2387, 8129, 4847, 7089, 4877, 6896, 7784, 1907, 4602, 6469, 966, 5478, 864, 3233, 4533, 1313, 6647, 7936, 8176, 2399, 5694, 1988, 3196, 6134, 9158, 1181, 2526, 3737, 3104, 8901, 1770, 3568, 63, 5109, 5755, 811, 7108, 6604, 5887, 3286, 2781, 5232, 6005, 2495, 4523, 4586, 2571, 9027, 3670, 8890, 1670, 9448, 5049, 8854, 9263, 3456, 7907, 300, 4008, 5515, 4501, 5298, 5030, 4361, 4344, 3311, 5861, 8091, 1747, 67, 2968, 713, 3758, 8143, 6834, 5412, 5029, 5314, 4502, 3981, 4661, 5908, 1301, 1464, 3305, 2284, 3793, 1943, 4020, 9199, 5773, 7139, 8785, 6855, 7756, 3622, 2936, 1649, 8960, 3727, 1693, 4999, 3345, 5114, 5185, 8839, 7903, 5055, 3834, 4462, 3724, 7826, 661, 1949, 6814, 8872, 6759, 4737, 6884, 8045, 9138, 7223, 4028, 1522, 3204, 129, 8438, 2984, 7965, 9206, 3500, 75, 6563, 3177, 3481, 2136, 4924, 469, 7185, 2698, 7336, 9247, 6004, 5334, 2782, 4509, 3851, 4489, 3436, 1861, 8926, 8020, 7255, 9435, 340, 4650, 2092, 2223, 5587, 6401, 1266, 6064, 8627, 7303, 6280, 9355, 2543, 2618, 4907, 1350, 5098, 5450, 8036, 5705, 1324, 8543, 9393, 5815, 1478, 2992, 3111, 2113, 8529, 7003, 5976, 8678, 882, 7802, 3426, 8838, 5271, 5115, 1902, 3022, 6700, 1735, 4049, 8848, 4972, 3799, 4802, 3559, 914, 1379, 7921, 585, 2299, 3369, 5718, 1791, 5460, 1262, 2364, 5410, 6836, 654, 711, 2970, 7480, 8816, 7549, 798, 8125, 6148, 8503, 9396, 6499, 7642, 6108, 2690, 4635, 3140, 9245, 7338, 2665, 9046, 2294, 4750, 2048, 5653, 5573, 5799, 1017, 1742, 844, 9095, 9285, 7179, 5674, 6975, 7704, 4521, 2497, 5103, 4154, 6155, 7946, 7132, 887, 1901, 5184, 5272, 3346, 7918, 51, 5754, 5342, 64, 1037, 6335, 4434, 4153, 5122, 2498, 9143, 9258, 5449, 5205, 1351, 7889, 2990, 1480, 9254, 817, 1334, 4620, 7513, 5937, 1309, 349, 2605, 3097, 9410, 7501, 2920, 4821, 8672, 5876, 1759, 4946, 4546, 7552, 5865, 8363, 630, 1459, 5541, 1510, 3806, 9010, 6248, 158, 3895, 6190, 6036, 8366, 856, 2821, 3967, 3833, 5268, 7904, 6600, 6206, 2675, 8853, 5323, 9449, 678, 2612, 8389, 4011, 6523, 7125, 1366, 8987, 6145, 8829, 405, 1217, 2879, 2763, 7732, 3129, 4360, 5313, 5299, 5413, 4612, 5466, 4595, 6380, 5441, 8418, 165, 2124, 6128, 1940, 6670, 8496, 6265, 8237, 7929, 8990, 6304, 2030, 7633, 4930, 8154, 9118, 9273, 5630, 4199, 5742, 2891, 3344, 5274, 1694, 9303, 9051, 7283, 8306, 2562, 5945, 6993, 9170, 7398, 1001, 7735, 3118, 6166, 2014, 3042, 7359, 6627, 4570, 2170, 425, 5613, 4237, 6030, 2979, 3798, 5177, 8849, 3069, 6323, 222, 4904, 386, 3949, 4150, 4168, 5485, 5509, 1852, 6435, 7093, 6682, 4235, 5615, 1539, 2812, 389, 8273, 8137, 7060, 2987, 4545, 5076, 1760, 4341, 6969, 4134, 4880, 7617, 8937, 7576, 7775, 187, 2431, 8196, 6231, 4104, 8153, 5008, 7634, 4793, 7080, 5625, 468, 5239, 2137, 1574, 6477, 4518, 4390, 1914, 8669, 7427, 1401, 7952, 5532, 6090, 5700, 1707, 5845, 1349, 5207, 2619, 385, 4967, 223, 978, 1405, 3080, 6537, 2088, 5581, 2837, 4485, 7296, 8727, 9375, 7852, 5829, 7650, 9251, 8974, 6659, 7106, 813, 5880, 1172, 7616, 4941, 4135, 6895, 5371, 7090, 1960, 3512, 2392, 6581, 3998, 4440, 3086, 6880, 7494, 3049, 8357, 7557, 4098, 2997, 2468, 6087, 4826, 6561, 77, 5901, 8846, 4051, 4438, 4000, 8346, 7813, 3575, 7088, 5373, 8130, 4375, 1953, 472, 8643, 8461, 6339, 9153, 6504, 7834, 641, 8033, 1213, 8287, 3615, 6774, 4320, 6326, 8919, 6560, 4859, 6088, 5534, 7425, 8671, 5080, 2921, 8370, 3266, 9352, 9124, 4245, 7374, 8935, 7619, 664, 2382, 6990, 377, 3240, 8434, 5483, 4170, 3558, 5175, 3800, 7291, 2847, 3974, 7410, 6409, 4089, 7079, 4928, 7635, 4045, 1153, 2932, 683, 8509, 7253, 8022, 7994, 2437, 3920, 1757, 5878, 815, 9256, 9145, 2829, 8796, 229, 2688, 6110, 2336, 3660, 7001, 8531, 1921, 5933, 3495, 752, 7137, 5775, 333, 3270, 3929, 2042, 6374, 1209, 2945, 3302, 2309, 2670, 2047, 5138, 2295, 2443, 8485, 8062, 1515, 5761, 2254, 997, 6124, 8833, 8008, 6883, 5258, 6760, 7571, 6309, 9462, 3, 3156, 1894, 2705, 4207, 2582, 1457, 632, 3341, 8468, 7211, 3704, 7950, 1403, 980, 7022, 7170, 4327, 7418, 6795, 7156, 6163, 6520, 8256, 3091, 7423, 5536, 6195, 9132, 3690, 2328, 8713, 5970, 3532, 7544, 934, 2464, 5805, 7129, 3355, 6777, 9236, 669, 6636, 320, 209, 8650, 3587, 7708, 5545, 7028, 1471, 1443, 2212, 956, 8782, 6533, 8312, 5420, 1830, 4537, 2386, 5376, 3056, 2055, 5491, 6618, 2174, 5665, 4290, 5907, 5295, 3982, 1031, 6225, 9088, 2475, 7083, 8801, 1846, 530, 2091, 5220, 341, 113, 6199, 1095, 6544, 4385, 794, 2040, 3931, 3377, 4606, 2905, 546, 3139, 5145, 2691, 5850, 1178, 8252, 1432, 8824, 1631, 2961, 312, 3126, 1004, 822, 8993, 7512, 5090, 1335, 4092, 2377, 5890, 1652, 1119, 5465, 5027, 5414, 619, 3564, 9388, 2904, 4639, 3378, 6997, 6468, 5367, 1908, 1108, 6416, 1971, 2585, 6379, 5025, 5467, 2884, 7073, 5953, 7505, 2375, 4094, 2570, 5330, 4524, 1849, 8293, 3585, 8652, 2359, 2806, 491, 214, 1815, 3636, 1613, 90, 738, 2169, 4980, 6628, 3884, 7377, 2928, 6385, 8060, 8487, 9242, 4498, 9080, 6846, 4258, 8116, 3620, 7758, 3765, 3375, 3933, 1513, 8064, 2038, 796, 7551, 5075, 4947, 2988, 7891, 7328, 4226, 8997, 3840, 2385, 4672, 1831, 4457, 1312, 5361, 3234, 1269, 7034, 9278, 1690, 1889, 528, 1848, 4585, 5331, 2496, 5124, 7705, 4389, 4920, 6478, 2405, 1328, 1192, 9076, 6653, 7926, 3850, 5230, 2783, 2372, 3030, 7613, 3956, 3980, 5297, 5315, 5516, 9079, 4561, 9243, 3142, 6396, 616, 4288, 5667, 6486, 3435, 5228, 3852, 9040, 7295, 4895, 2838, 2106, 6423, 7451, 3299, 6347, 1730, 8464, 2067, 295, 2472, 3520, 6903, 1159, 2182, 414, 162, 7771, 4191, 6121, 6574, 3723, 5266, 3835, 192, 347, 1311, 4535, 1832, 7435, 3161, 475, 1536, 1228, 3200, 969, 2795, 7525, 3337, 7341, 9300, 1047, 4024, 3085, 4870, 3999, 4853, 4052, 4166, 4152, 5105, 6336, 1733, 6702, 6586, 8248, 9060, 636, 3320, 478, 8099, 2340, 2942, 5454, 1076, 6853, 8787, 16, 4142, 612, 6790, 3259, 2865, 1561, 4197, 5632, 5498, 6644, 8609, 1099, 3429, 3275, 5570, 9307, 3217, 455, 5659, 7955, 3924, 8006, 8835, 1102, 3600, 1913, 4919, 4519, 7706, 3589, 793, 4644, 6545, 1964, 55, 6368, 6860, 9116, 8156, 3528, 1952, 4845, 8131, 8648, 211, 7985, 6475, 1576, 8114, 4260, 4016, 207, 322, 6967, 4343, 5312, 5031, 3130, 8428, 9401, 4123, 3711, 9414, 1547, 6119, 4193, 4281, 7564, 8578, 2333, 1519, 3310, 5311, 4362, 6968, 4944, 1761, 2490, 3791, 2286, 180, 370, 8621, 7723, 8448, 3666, 3892, 3812, 7417, 4715, 7171, 419, 6800, 2127, 220, 6325, 4830, 6775, 3357, 1823, 2966, 69, 962, 3317, 1340, 8667, 1916, 649, 1985, 6495, 8754, 8811, 2629, 4055, 7101, 8203, 4005, 7674, 3747, 6096, 7166, 8880, 1544, 8086, 8551, 5906, 4663, 5666, 4493, 617, 5416, 7730, 2765, 6443, 7563, 4350, 4194, 627, 6039, 1663, 8583, 787, 3489, 2462, 936, 7352, 6354, 6473, 7987, 3650, 72, 922, 8141, 3760, 1429, 4015, 4367, 8115, 4558, 6847, 6922, 110, 3185, 2162, 838, 3401, 8199, 3064, 3878, 7242, 7373, 4815, 9125, 30, 2210, 1445, 539, 7604, 6029, 4976, 5614, 4956, 6683, 4131, 3461, 218, 2129, 6767, 2280, 8996, 4541, 7329, 5984, 6288, 2902, 9390, 5965, 259, 1500, 6481, 1027, 9336, 6261, 7943, 5437, 2242, 327, 1420, 2581, 4728, 2706, 593, 2651, 7516, 8804, 1639, 5741, 5003, 5631, 4410, 1562, 626, 4280, 4351, 6120, 4466, 7772, 5738, 505, 7816, 6529, 5843, 1709, 2610, 680, 2326, 3692, 266, 5445, 7522, 5672, 7181, 6160, 8001, 8164, 3557, 4804, 5484, 4963, 4151, 4436, 4053, 2631, 1322, 5707, 8752, 6497, 9398, 7718, 1374, 3604, 6154, 5121, 5104, 4435, 4167, 4964, 3950, 5457, 9165, 1558, 6009, 202, 611, 4416, 17, 7795, 575, 5795, 438, 6894, 4879, 4942, 6970, 3460, 4233, 6684, 6179, 3578, 2861, 2357, 8654, 3710, 4356, 9402, 5897, 7695, 564, 6361, 5728, 6939, 8284, 307, 3331, 6269, 7477, 3771, 7066, 1289, 1529, 2818, 8152, 4932, 6232, 8601, 3987, 8499, 2996, 4863, 7558, 1681, 2569, 4588, 2376, 4618, 1336, 7078, 4795, 6410, 3644, 2160, 3187, 2416, 7111, 6540, 6697, 6752, 7053, 8770, 398, 5637, 2275, 3026, 4033, 1140, 8527, 2115, 436, 5797, 5575, 8747, 1284, 8190, 842, 1744, 8548, 395, 7237, 8517, 3153, 7100, 4303, 2630, 4165, 4437, 4854, 8847, 5179, 1736, 7628, 1152, 4791, 7636, 3089, 8258, 8075, 6772, 3617, 8081, 899, 6244, 8148, 1139, 4073, 3027, 7508, 3308, 1521, 5253, 7224, 6236, 3084, 4442, 1048, 7939, 9198, 5287, 1944, 1438, 206, 4366, 4261, 1430, 8254, 6522, 5044, 8390, 5514, 5317, 301, 7673, 4300, 8204, 7849, 8052, 8345, 4852, 4439, 4871, 6582, 3014, 8476, 8535, 8741, 985, 9196, 7941, 6263, 8498, 4101, 8602, 3552, 3857, 1030, 4660, 5296, 4503, 3957, 8793, 1598, 2803, 7409, 4798, 2848, 8425, 7979, 8043, 6886, 3832, 5057, 2822, 562, 7697, 3844, 3446, 878, 99, 6693, 8792, 3979, 4504, 7614, 1174, 3734, 1074, 5456, 4149, 4965, 387, 2814, 9085, 728, 9452, 6024, 3293, 7031, 2216, 3209, 5599, 8096, 2591, 3804, 1512, 4552, 3376, 4641, 2041, 4759, 3271, 2192, 9288, 8005, 4396, 7956, 1980, 1756, 4782, 2438, 1279, 3546, 453, 3219, 1319, 7449, 6425, 7811, 8348, 3592, 1011, 236, 7821, 7154, 6797, 6920, 6849, 1765, 2479, 3407, 8279, 7363, 6189, 5063, 159, 3811, 4330, 3667, 5398, 719, 410, 2010, 8933, 7376, 4568, 6629, 3478, 3335, 7527, 7241, 4248, 3065, 2509, 2793, 971, 1113, 1898, 5960, 5602, 801, 510, 6255, 5527, 1370, 3504, 5595, 8665, 1342, 2745, 9334, 1029, 3984, 3553, 1624, 7175, 9039, 4488, 5229, 4510, 7927, 8239, 6071, 7660, 3445, 3963, 7698, 6988, 2384, 4539, 8998, 7491, 8011, 191, 4461, 5267, 5056, 3968, 6887, 2680, 9066, 5389, 7191, 9036, 2196, 2204, 1801, 2750, 3536, 9184, 6175, 120, 554, 3367, 2301, 3473, 7416, 4329, 3893, 160, 416, 2345, 9009, 5067, 1511, 3935, 2592, 1079, 7290, 4801, 5176, 4973, 2980, 1739, 6668, 1942, 5289, 2285, 4338, 2491, 6084, 8412, 7097, 6, 1579, 1722, 7690, 8563, 1821, 3359, 264, 3694, 2264, 9093, 846, 1087, 1865, 7065, 4110, 7478, 2972, 521, 6014, 3374, 4554, 7759, 8893, 1878, 1428, 4263, 8142, 5303, 714, 8524, 6613, 6055, 9179, 6033, 700, 367, 3715, 6095, 4298, 7675, 6570, 7401, 1622, 3555, 8166, 5941, 8221, 3103, 5348, 2527, 1073, 3953, 1175, 6461, 8264, 8218, 1887, 1692, 5276, 8961, 7825, 5265, 4463, 6575, 7345, 8978, 1719, 8909, 6100, 6094, 3749, 368, 182, 9413, 4355, 4124, 8655, 6947, 3466, 3352, 7949, 4721, 7212, 1507, 7487, 1999, 8878, 7168, 7024, 1197, 2263, 3778, 265, 4180, 2327, 4703, 9133, 8404, 8491, 6593, 1067, 6964, 8382, 7793, 19, 500, 513, 8432, 3242, 1873, 8596, 8570, 7441, 9348, 8889, 5327, 9028, 5397, 3891, 4331, 8449, 6320, 6960, 2622, 7000, 4770, 2337, 7161, 2711, 2414, 3189, 9192, 1294, 960, 71, 4267, 7988, 8971, 1483, 136, 2159, 4087, 6411, 526, 1891, 5917, 9014, 1393, 1612, 4575, 1816, 5833, 7648, 5831, 1818, 3224, 7020, 982, 108, 6924, 1586, 2323, 2935, 5280, 7757, 4556, 8117, 8080, 4039, 6773, 4832, 8288, 3006, 1044, 1697, 2450, 2810, 1541, 3011, 9443, 6153, 4156, 1375, 7070, 1912, 4392, 1103, 3571, 6293, 7653, 3416, 6825, 1010, 3909, 8349, 792, 4387, 7707, 4685, 8651, 4582, 8294, 2730, 2522, 7315, 6738, 2860, 4128, 6180, 7087, 4849, 7814, 507, 6292, 3598, 1104, 62, 5344, 1771, 6430, 9387, 4609, 620, 6214, 8632, 913, 5174, 4803, 4171, 8165, 3742, 1623, 3856, 3985, 8603, 6307, 7573, 5825, 452, 3917, 1280, 7151, 3215, 9309, 1784, 124, 2673, 6208, 9183, 3821, 2751, 2575, 7543, 4699, 5971, 6812, 1951, 4377, 8157, 2154, 1298, 5725, 1245, 7580, 6902, 4473, 2473, 9090, 2539, 7881, 2939, 1628, 2391, 4874, 1961, 6449, 991, 2246, 8576, 7566, 5594, 3864, 1371, 920, 74, 5245, 9207, 2109, 518, 751, 4765, 5934, 2654, 2259, 8778, 2461, 4274, 788, 6763, 6917, 422, 8725, 7298, 2135, 5241, 3178, 3334, 3882, 6630, 483, 1491, 7415, 3814, 2302, 6756, 8231, 7322, 6044, 3351, 3707, 6948, 747, 3169, 217, 4232, 4132, 6971, 6598, 7906, 5320, 9264, 7658, 6073, 8943, 5698, 6092, 6102, 292, 877, 3962, 3845, 7661, 6624, 12, 5522, 6173, 9186, 2735, 1860, 5227, 4490, 6487, 285, 5713, 8766, 3274, 4404, 1100, 8837, 5187, 7803, 8513, 8698, 2142, 5997, 6115, 1305, 1358, 6824, 3595, 7654, 2696, 7187, 2717, 2851, 5711, 287, 8278, 3899, 2480, 1555, 927, 6229, 8198, 4251, 839, 7807, 9425, 9216, 6515, 1225, 5618, 1806, 6012, 523, 8886, 9383, 8637, 7231, 6688, 2638, 8457, 6596, 6973, 5676, 1054, 6996, 4605, 4640, 3932, 4553, 3766, 6015, 3364, 5749, 5717, 5168, 2300, 3816, 555, 5748, 3372, 6016, 9174, 6780, 263, 3780, 1822, 4318, 6776, 4693, 7130, 7948, 3706, 3467, 6045, 8161, 8760, 7917, 5113, 5273, 5000, 2892, 8467, 4724, 633, 2663, 7340, 4446, 7526, 3881, 3479, 3179, 6268, 4113, 308, 8574, 2248, 9023, 1572, 2139, 1254, 7752, 1534, 477, 4426, 637, 1339, 4313, 963, 7765, 498, 21, 5860, 5310, 4345, 1520, 4030, 7509, 2283, 5291, 1465, 2308, 4754, 2946, 6346, 4480, 7452, 7371, 7244, 1469, 7030, 3942, 6025, 280, 5646, 9346, 7443, 2780, 5336, 5888, 2379, 7858, 1022, 252, 8376, 7602, 541, 2101, 5569, 4403, 3430, 8767, 2191, 3928, 4760, 334, 9380, 9351, 4818, 8371, 3165, 6212, 622, 7046, 2864, 4413, 6791, 5927, 283, 6489, 6299, 6202, 8844, 5903, 834, 8319, 8613, 1928, 7968, 6509, 6867, 1872, 3677, 8433, 4807, 378, 8739, 8537, 6062, 1268, 4532, 5362, 865, 7463, 2240, 5439, 6382, 45, 1474, 7019, 3630, 1819, 8565, 5429, 1318, 3915, 454, 4400, 9308, 3543, 7152, 7823, 8963, 8954, 5598, 3939, 2217, 8304, 7285, 128, 5251, 1523, 5476, 968, 4450, 1229, 6285, 6133, 5353, 1989, 7914, 9129, 87, 1416, 9191, 3655, 2415, 4085, 2161, 4254, 111, 343, 2485, 8235, 6267, 3333, 3480, 5242, 6564, 8662, 8957, 5893, 5868, 1813, 216, 3463, 748, 2975, 6211, 3264, 8372, 8641, 474, 4454, 7436, 861, 5915, 1893, 4731, 4, 7099, 4057, 8518, 2185, 6507, 7970, 9034, 7193, 1015, 5801, 2506, 6395, 4496, 9244, 5144, 4636, 547, 9292, 3101, 8223, 6359, 566, 7977, 8427, 4359, 5032, 7733, 1003, 4625, 313, 8558, 6830, 1799, 2206, 6518, 6165, 4986, 7736, 402, 6805, 1451, 9315, 2112, 5195, 2993, 1703, 7798, 1241, 6331, 8900, 5347, 3738, 8222, 3136, 9293, 169, 9409, 5084, 2606, 7791, 8384, 2177, 7422, 4708, 8257, 4043, 7637, 6879, 4869, 4441, 4025, 6237, 9421, 6536, 4900, 1406, 776, 7209, 8470, 7540, 6788, 614, 6398, 6958, 6322, 4970, 8850, 6393, 2508, 3877, 4249, 8200, 1995, 8929, 8703, 1409, 6839, 2054, 4669, 5377, 5822, 8940, 581, 2722, 8356, 4866, 7495, 2738, 1934, 1602, 256, 7358, 4983, 2015, 5553, 1655, 1157, 6905, 7693, 5899, 79, 7788, 2533, 7612, 4506, 2373, 7507, 4032, 4074, 2276, 6750, 6699, 5182, 1903, 8555, 7266, 2918, 7503, 5955, 8475, 3996, 6583, 9442, 3607, 1542, 8882, 6745, 1043, 3613, 8289, 5733, 1202, 9032, 7972, 2052, 6841, 2467, 4862, 4099, 8500, 1702, 3110, 5196, 1479, 5095, 7890, 4544, 4948, 7061, 7964, 5248, 8439, 7626, 1738, 3797, 4974, 6031, 9181, 6210, 3167, 749, 520, 3769, 7479, 5158, 712, 5305, 68, 4316, 1824, 6513, 9218, 311, 4627, 1632, 7279, 6315, 1496, 6220, 2599, 9323, 7640, 6501, 248, 6069, 8241, 7258, 6345, 3301, 4755, 1210, 5453, 4422, 2341, 1627, 3515, 7882, 1648, 5279, 3623, 2324, 682, 4789, 1154, 43, 6384, 4566, 7378, 2353, 5383, 2769, 354, 8369, 4820, 5081, 7502, 3018, 7267, 7263, 316, 6680, 7095, 8414, 1292, 9194, 987, 932, 7546, 545, 4638, 4607, 9389, 4222, 6289, 804, 8135, 8275, 233, 1789, 5720, 2065, 8466, 3343, 5001, 5743, 2121, 60, 1106, 1910, 7072, 4593, 5468, 6452, 24, 2762, 5035, 1218, 103, 8730, 6741, 1111, 973, 5779, 8399, 1007, 6082, 2493, 6007, 1560, 4412, 3260, 7047, 2356, 4127, 3579, 6739, 8732, 6863, 6819, 1881, 8323, 940, 5710, 3411, 2718, 8424, 3973, 4799, 7292, 743, 2078, 2748, 1803, 6022, 9454, 2105, 4484, 4896, 5582, 5988, 8983, 9327, 7308, 1596, 8795, 4776, 9146, 808, 2520, 2732, 9226, 561, 3966, 5058, 857, 8151, 4106, 1530, 8395, 9084, 3947, 388, 4953, 1540, 3609, 2451, 446, 490, 4579, 2360, 7408, 3976, 1599, 2458, 7875, 8446, 7725, 5670, 7524, 4448, 970, 3875, 2510, 330, 1063, 8646, 8133, 806, 9148, 6551, 2371, 4508, 5231, 5335, 3287, 7444, 2233, 6079, 6828, 8560, 6908, 9365, 5506, 674, 353, 2924, 5384, 2714, 6442, 4284, 7731, 5034, 2880, 25, 759, 8692, 1168, 7318, 7118, 458, 1345, 9268, 2574, 3535, 3822, 1802, 2843, 2079, 9333, 3860, 1343, 460, 146, 1752, 1725, 1933, 3047, 7496, 1859, 3438, 9187, 9225, 2825, 2521, 3583, 8295, 2149, 5885, 6606, 734, 6590, 8355, 3051, 582, 6457, 8423, 2850, 3412, 7188, 6441, 2767, 5385, 2413, 3657, 7162, 5994, 1235, 592, 4206, 4729, 1895, 8676, 5978, 2549, 1435, 7335, 5236, 7186, 3414, 7655, 1389, 5425, 5849, 4634, 5146, 6109, 4773, 230, 290, 6104, 9203, 1931, 1727, 9065, 3830, 6888, 1924, 6391, 8852, 5051, 6207, 3539, 125, 2046, 4752, 2310, 5561, 2546, 9045, 5141, 7339, 3339, 634, 9062, 6350, 8015, 9001, 596, 8687, 2258, 3493, 5935, 7515, 4204, 594, 9003, 9321, 2601, 6609, 7585, 8039, 2082, 8106, 6048, 5871, 8456, 3385, 6689, 906, 6342, 7667, 7447, 1321, 4164, 4054, 4304, 8812, 8055, 6407, 7412, 6466, 6999, 3662, 6961, 384, 4906, 5208, 2544, 5563, 7701, 6871, 8388, 5046, 679, 4183, 1710, 2531, 7790, 3096, 5085, 350, 732, 6608, 2647, 9322, 2955, 6221, 7594, 2488, 1763, 6851, 1078, 3803, 3936, 8097, 480, 140, 1827, 6378, 4597, 1972, 1456, 4727, 4208, 1421, 5496, 5634, 6786, 7542, 3534, 2752, 9269, 9026, 5329, 4587, 4095, 1682, 2033, 1687, 9106, 1884, 5944, 4993, 8307, 6428, 1773, 904, 6691, 101, 1220, 2073, 8867, 780, 8822, 1434, 2701, 5979, 9044, 2667, 5562, 2617, 5209, 9356, 5839, 7880, 3517, 9091, 2266, 1259, 1618, 7611, 3032, 7789, 2608, 1711, 7933, 1072, 3736, 5349, 1182, 1355, 7314, 3582, 2731, 2826, 809, 5757, 6000, 8719, 1134, 9223, 9189, 1418, 329, 2792, 3876, 3066, 6394, 3144, 5802, 6844, 9082, 8397, 5781, 1084, 9142, 5102, 5123, 4522, 5332, 6006, 2868, 6083, 3790, 4339, 1762, 2596, 7595, 8234, 3182, 344, 7897, 8335, 1554, 3406, 3900, 1766, 5623, 7082, 4656, 9089, 3519, 4474, 296, 8410, 6086, 4861, 2998, 6842, 5804, 4696, 935, 4273, 3490, 8779, 7874, 2801, 1600, 1936, 2226, 950, 769, 445, 2809, 3610, 1698, 8969, 7990, 6240, 5836, 8484, 4748, 2296, 5768, 8269, 1278, 3919, 4783, 7995, 6171, 5524, 7250, 8195, 4935, 188, 153, 8228, 8875, 7228, 7149, 1282, 8749, 943, 7458, 8842, 6204, 6602, 7110, 4084, 3188, 3656, 2712, 5386, 696, 7276, 9240, 8489, 8406, 1327, 4516, 6479, 1502, 7115, 7599, 5693, 5356, 8177, 392, 8089, 5863, 7554, 6580, 4873, 3513, 1629, 8826, 8128, 5375, 4671, 4538, 3841, 6989, 4810, 665, 7857, 3284, 5889, 4617, 4093, 4589, 7506, 3029, 4507, 2784, 6552, 1052, 5678, 9460, 6311, 5409, 5163, 1263, 7472, 7407, 2805, 4580, 8653, 4126, 2862, 7048, 5382, 2926, 7379, 7962, 7063, 1867, 2146, 6709, 9008, 3808, 417, 7173, 1626, 2941, 4423, 8100, 7160, 3659, 4771, 6111, 1518, 4347, 8579, 1126, 2061, 8712, 4702, 3691, 4181, 681, 2934, 3624, 1587, 7861, 9211, 1091, 826, 2236, 7040, 8184, 5921, 6251, 1643, 5560, 2669, 4753, 3303, 1466, 1364, 7127, 5807, 6755, 3472, 3815, 3368, 5169, 586, 5767, 2442, 4749, 5139, 9047, 7122, 7840, 5611, 427, 7271, 179, 4337, 3792, 5290, 3306, 7510, 8995, 4228, 6768, 6052, 6749, 3025, 4075, 5638, 430, 6318, 8451, 7679, 9343, 8913, 1258, 2537, 9092, 3777, 3695, 1198, 784, 8777, 3492, 2655, 8688, 6388, 996, 4743, 5762, 7959, 1166, 8694, 9022, 3328, 8575, 3508, 992, 8616, 326, 4211, 5438, 3230, 7464, 589, 7039, 2317, 827, 6078, 2778, 7445, 7669, 693, 9069, 5406, 949, 2455, 1937, 5586, 5218, 2093, 6169, 7997, 8103, 8303, 3208, 3940, 7032, 1271, 955, 4679, 1444, 4242, 31, 1223, 6517, 3121, 1800, 3824, 2197, 6549, 9150, 909, 6446, 6548, 2203, 3825, 9037, 7177, 9287, 3927, 3272, 8768, 7055, 226, 7832, 6506, 3151, 8519, 413, 4470, 1160, 6259, 9338, 7421, 3093, 8385, 5664, 4665, 6619, 8723, 424, 4979, 4571, 739, 5982, 7331, 7623, 9429, 837, 4253, 3186, 4086, 3645, 137, 6633, 7870, 1297, 3526, 8158, 8109, 6942, 5884, 2728, 8296, 6708, 2348, 1868, 1233, 5996, 3422, 8699, 1253, 3325, 1573, 4923, 5240, 3482, 7299, 1843, 7519, 8029, 6766, 4230, 219, 4323, 6801, 6127, 5020, 166, 59, 2889, 5744, 488, 448, 8261, 435, 4070, 8528, 5194, 3112, 9316, 517, 3498, 9208, 6422, 4483, 2839, 9455, 1185, 5568, 3277, 542, 8819, 1251, 8701, 8931, 2012, 6168, 2222, 5219, 4651, 531, 5580, 4898, 6538, 7113, 1504, 8301, 8105, 2643, 8040, 9332, 2747, 2844, 744, 8333, 7899, 8866, 2554, 1221, 33, 1149, 875, 294, 4476, 8465, 2894, 5721, 7844, 8711, 2330, 1127, 1992, 7104, 6661, 5490, 4668, 3057, 6840, 3000, 7973, 5991, 5652, 5137, 4751, 2671, 126, 7287, 6373, 4758, 3930, 4642, 795, 4549, 8065, 7590, 871, 1686, 2567, 1683, 7632, 5010, 6305, 8605, 8329, 244, 894, 5792, 118, 6177, 6686, 7233, 1797, 6832, 8145, 5552, 3041, 4984, 6167, 2095, 8932, 3887, 411, 8521, 7044, 624, 1564, 601, 8599, 6234, 7226, 8877, 3700, 7488, 8018, 8928, 3062, 8201, 7103, 2059, 1128, 7913, 3195, 5354, 5695, 6494, 4308, 650, 1123, 7687, 1755, 3922, 7957, 5764, 7467, 1448, 466, 5627, 1455, 2584, 4598, 6417, 6728, 7607, 9103, 9281, 54, 4383, 6546, 6448, 3511, 4875, 7091, 6437, 5434, 6158, 7183, 471, 4844, 4376, 3529, 6813, 5262, 662, 7621, 7333, 1437, 4019, 5288, 3794, 6669, 5018, 6129, 5585, 2225, 2456, 1601, 3046, 2739, 1726, 2683, 9204, 7967, 3247, 8614, 994, 6390, 2678, 6889, 5932, 4767, 8532, 6558, 8921, 648, 4310, 8668, 4918, 4391, 3601, 7071, 2886, 1107, 4601, 5368, 7785, 831, 8554, 3021, 5183, 5116, 888, 5959, 3872, 1114, 8675, 2704, 4730, 3157, 5916, 3641, 527, 4527, 1691, 3729, 8219, 5943, 2564, 9107, 8322, 2855, 6820, 1427, 3762, 8894, 1399, 7429, 8595, 3676, 3243, 6868, 6978, 1232, 2145, 2349, 7064, 3773, 1088, 6186, 8925, 5226, 3437, 2736, 7497, 363, 8709, 7846, 6931, 6434, 4960, 5510, 8292, 4584, 4525, 529, 4653, 8802, 7518, 2133, 7300, 37, 1025, 6483, 7728, 5418, 8314, 8592, 7781, 7434, 4456, 4536, 4673, 5421, 6377, 2587, 141, 6512, 2965, 4317, 3358, 3781, 8564, 3223, 3631, 5832, 3635, 4576, 215, 3171, 5869, 6050, 6770, 8077, 200, 6011, 3393, 5619, 6021, 2842, 2749, 3823, 2205, 3122, 6831, 2019, 7234, 8773, 9369, 9163, 5459, 5166, 5719, 2896, 234, 1013, 7195, 123, 3541, 9310, 1239, 7800, 884, 8341, 7483, 7711, 7742, 5682, 903, 2559, 6429, 3567, 5345, 8902, 5501, 5622, 2478, 3901, 6850, 2595, 2489, 4340, 4945, 5077, 5877, 4781, 3921, 1981, 7688, 1724, 2741, 147, 8950, 1035, 66, 5307, 8092, 8547, 4062, 843, 5132, 1018, 6667, 3796, 2981, 7627, 4048, 5180, 6701, 4432, 6337, 8463, 4478, 6348, 9064, 2682, 1932, 2740, 1753, 7689, 3784, 1580, 8908, 3719, 8979, 569, 8068, 8807, 8210, 6142, 7932, 2530, 2609, 4184, 5844, 4910, 5701, 573, 7797, 3109, 2994, 8501, 6150, 8968, 2449, 3611, 1045, 9302, 4998, 5275, 3728, 1888, 4528, 9279, 9105, 2566, 2034, 872, 7631, 2032, 2568, 4096, 7559, 8635, 9385, 6432, 6933, 6858, 6370, 1082, 5783, 9447, 5325, 8891, 7761, 6357, 8225, 7684, 8582, 4277, 6040, 953, 1273, 8625, 6066, 41, 1156, 3039, 5554, 1118, 4615, 5891, 8959, 5278, 2937, 7883, 559, 9228, 5559, 2312, 6252, 503, 5740, 4201, 8805, 8070, 7855, 667, 9238, 7278, 2960, 4628, 8825, 2390, 3514, 2940, 2342, 7174, 3855, 3554, 3743, 7402, 755, 7610, 2535, 1260, 5462, 1414, 89, 4574, 3637, 1394, 7829, 8799, 7085, 6182, 8444, 7877, 7144, 255, 3045, 1935, 2457, 2802, 3977, 8794, 2831, 7309, 8169, 8507, 685, 7006, 6665, 1020, 7860, 2322, 3625, 6925, 5949, 6527, 7818, 8907, 1721, 3785, 7, 8113, 4369, 6476, 4922, 2138, 3326, 9024, 9271, 9120, 6982, 1131, 7390, 600, 2005, 625, 4196, 4411, 2866, 6008, 4146, 9166, 926, 3405, 2481, 8336, 7475, 6271, 337, 704, 6118, 4353, 9415, 8085, 4294, 8881, 3010, 3608, 2811, 4954, 5616, 1227, 4452, 476, 3322, 7753, 6936, 8394, 2817, 4107, 1290, 8416, 5443, 268, 5475, 3203, 5252, 4029, 3309, 4346, 2334, 6112, 5760, 4745, 8063, 4551, 3934, 3805, 5068, 5542, 7486, 3702, 7213, 8300, 2085, 7114, 2403, 6480, 4218, 260, 7536, 6219, 2957, 6316, 432, 6464, 7414, 3475, 484, 8898, 6333, 1039, 5494, 1423, 135, 3647, 8972, 9253, 5094, 2991, 5197, 5816, 495, 7018, 3226, 46, 1442, 4681, 7029, 3295, 7245, 1363, 2307, 3304, 5292, 1302, 707, 176, 5540, 5070, 631, 4726, 2583, 1973, 5628, 9275, 9314, 3114, 6806, 465, 1976, 7468, 538, 4241, 2211, 4680, 1472, 47, 606, 205, 4018, 1945, 7334, 2700, 2550, 8823, 4630, 8253, 4014, 4262, 3761, 1879, 6821, 7384, 134, 1485, 5495, 2580, 4209, 328, 2512, 9190, 3191, 88, 1615, 5463, 1121, 652, 6838, 3059, 8704, 775, 3079, 4901, 979, 4719, 7951, 4915, 7428, 1876, 8895, 7749, 659, 7828, 1611, 3638, 9015, 1206, 5424, 2694, 7656, 9266, 1347, 5847, 5427, 8567, 604, 49, 7920, 5172, 915, 9072, 7069, 3603, 4157, 7719, 919, 3503, 3865, 5528, 6875, 8986, 5041, 7126, 2306, 1467, 7246, 1163, 7382, 6823, 3418, 1306, 7313, 2524, 1183, 9457, 7888, 5097, 5206, 4908, 5846, 1386, 9267, 2754, 459, 2744, 3861, 8666, 4312, 3318, 638, 7077, 4091, 4619, 5091, 818, 6677, 8660, 6566, 1191, 4515, 2406, 8407, 8542, 5201, 5706, 4163, 2632, 7448, 3914, 3220, 5430, 8327, 8607, 6646, 5360, 4534, 4458, 348, 5087, 5938, 7312, 1357, 3419, 6116, 706, 1463, 5293, 5909, 5724, 3525, 2155, 7871, 959, 3653, 9193, 2911, 8415, 1528, 4108, 7067, 9074, 1194, 8189, 4065, 8748, 2424, 7150, 3545, 3918, 2439, 8270, 8180, 5401, 8624, 1660, 954, 2214, 7033, 4531, 3235, 6063, 5215, 6402, 7471, 2363, 5164, 5461, 1617, 2536, 2267, 8914, 657, 7751, 3324, 2140, 8700, 2098, 8820, 782, 1200, 5735, 7579, 3523, 5726, 6363, 6330, 3107, 7799, 1782, 9311, 7037, 591, 2708, 5995, 2144, 1869, 6979, 6284, 3199, 4451, 1537, 5617, 3395, 6516, 2208, 32, 2072, 2555, 102, 2878, 5036, 406, 305, 8286, 4834, 8034, 5452, 2944, 4756, 6375, 5423, 1391, 9016, 7348, 9031, 3003, 5734, 1248, 783, 2262, 3696, 7025, 8188, 1286, 9075, 4514, 1329, 6567, 9233, 9177, 6057, 5567, 2103, 9456, 1354, 2525, 5350, 9159, 8251, 4632, 5851, 6460, 3733, 3954, 7615, 4882, 5881, 6736, 7317, 2758, 8693, 2251, 7960, 7381, 1361, 7247, 6258, 2181, 4471, 6904, 3038, 1656, 42, 2931, 4790, 4046, 7629, 874, 2070, 34, 8630, 6216, 853, 357, 7583, 6611, 8526, 4072, 4034, 8149, 859, 7438, 9222, 2515, 8720, 7389, 1567, 6983, 7912, 1991, 2060, 2331, 8580, 7686, 1983, 651, 1412, 5464, 4614, 1653, 5555, 5874, 8674, 1897, 3873, 972, 2874, 6742, 6415, 4600, 1909, 2887, 61, 3570, 3599, 4393, 8836, 3428, 4405, 8610, 9110, 6543, 4646, 6200, 6301, 825, 2319, 9212, 6185, 1864, 3774, 847, 9141, 2500, 5782, 1673, 6371, 7289, 3802, 2593, 6852, 4420, 5455, 3952, 3735, 2528, 7934, 6649, 382, 6963, 3685, 6594, 8459, 8645, 2790, 331, 5777, 975, 7058, 8139, 924, 9168, 6995, 3380, 5677, 2369, 6553, 8174, 7938, 4023, 4443, 9301, 1696, 3612, 3007, 6746, 6616, 5493, 1487, 6334, 5107, 65, 1749, 8951, 5787, 6224, 4659, 3983, 3858, 9335, 4216, 6482, 1840, 38, 251, 3282, 7859, 1589, 6666, 1741, 5133, 5800, 3146, 7194, 1787, 235, 3908, 3593, 6826, 6081, 2870, 8400, 821, 4624, 3127, 7734, 4988, 7399, 6572, 6123, 4742, 2255, 6389, 1926, 8615, 2245, 3509, 6450, 5470, 931, 2909, 9195, 3992, 8742, 107, 3628, 7021, 4718, 1404, 4902, 224, 7057, 1060, 5778, 2873, 1112, 3874, 2794, 4449, 3201, 5477, 5365, 6470, 7764, 3316, 4314, 70, 3652, 1295, 7872, 8781, 4678, 2213, 1272, 1661, 6041, 768, 2454, 2227, 5407, 6313, 7281, 9053, 7457, 2422, 8750, 5709, 2853, 8324, 5394, 7351, 4272, 2463, 4697, 7545, 2908, 988, 5471, 725, 6228, 3404, 1556, 9167, 1057, 8140, 4265, 73, 3502, 1372, 7720, 5404, 9071, 1378, 5173, 3560, 8633, 7561, 6445, 2200, 9151, 6341, 2636, 6690, 2558, 1774, 5683, 7645, 6243, 4037, 8082, 8862, 868, 5791, 2025, 245, 9156, 6136, 7218, 5958, 1900, 5117, 7133, 8340, 1780, 7801, 5189, 8679, 690, 98, 3961, 3447, 293, 2069, 1150, 7630, 1685, 2035, 7591, 5790, 896, 8863, 7462, 3232, 5363, 5479, 5914, 3159, 7437, 1137, 8150, 2820, 5059, 8367, 356, 1145, 6217, 7538, 8472, 7221, 9140, 1086, 3775, 9094, 5131, 1743, 4063, 8191, 7806, 3400, 4252, 2163, 9430, 8318, 3250, 5904, 8553, 1905, 7786, 81, 6077, 2235, 2318, 1092, 6302, 8992, 4623, 1005, 8401, 6676, 1333, 5092, 9255, 4779, 5879, 4884, 7107, 5340, 5756, 2519, 2827, 9147, 2787, 8134, 2900, 6290, 509, 3869, 5603, 8124, 5154, 7550, 4548, 2039, 4643, 4386, 3590, 8350, 7569, 6762, 3488, 4275, 8584, 8776, 2261, 1199, 1249, 8821, 2552, 8868, 6809, 7208, 3078, 1407, 8705, 6706, 8298, 7215, 444, 2453, 951, 6042, 7324, 8213, 7368, 535, 6405, 8057, 8691, 2760, 26, 9101, 7609, 1620, 7403, 7136, 4764, 3496, 519, 2974, 3168, 3464, 6949, 8332, 2077, 2845, 7293, 9042, 5981, 2168, 4572, 91, 9361, 6589, 2725, 6607, 2603, 351, 676, 9451, 3945, 9086, 6227, 929, 5472, 8481, 9359, 93, 409, 3889, 5399, 8182, 7042, 8523, 3757, 5304, 2969, 5159, 655, 8916, 175, 1462, 1303, 6117, 1549, 338, 9437, 366, 3751, 6034, 6192, 7275, 2411, 5387, 9068, 2230, 7670, 97, 880, 8680, 7205, 5974, 7005, 1592, 8508, 4788, 2933, 2325, 4182, 2611, 5047, 9450, 730, 352, 2771, 5507, 5487, 7868, 6635, 4690, 9237, 1635, 7856, 2381, 4811, 7620, 1948, 5263, 7827, 1396, 7750, 1256, 8915, 710, 5160, 6837, 1411, 1122, 1984, 4309, 1917, 8922, 7366, 8215, 8684, 6914, 8032, 4836, 7835, 7076, 1338, 3319, 4427, 9061, 2662, 3340, 4725, 1458, 5071, 8364, 6038, 4279, 4195, 1563, 2006, 7045, 3262, 6213, 3563, 4610, 5415, 4287, 4494, 6397, 3073, 6789, 4415, 4143, 203, 608, 609, 204, 1440, 48, 1382, 8568, 8598, 2004, 1565, 7391, 6912, 8686, 2657, 9002, 2650, 4205, 2707, 1236, 7038, 2238, 7465, 5766, 2298, 5170, 7922, 6456, 2721, 3052, 8941, 6075, 83, 116, 5794, 4139, 7796, 1705, 5702, 7588, 8067, 1717, 8980, 7976, 3133, 6360, 4119, 7696, 3965, 2823, 9227, 1646, 7884, 7745, 5747, 3366, 3817, 121, 7197, 8208, 8809, 8756, 9291, 3138, 4637, 2906, 7547, 8818, 2100, 3278, 7603, 4240, 1446, 7469, 6404, 763, 7369, 7454, 5579, 2090, 4652, 1847, 4526, 1890, 3642, 6412, 8885, 3391, 6013, 3768, 2973, 750, 3497, 2110, 9317, 7715, 8431, 3679, 501, 6254, 3868, 802, 6291, 3573, 7815, 4188, 5739, 1641, 6253, 512, 3680, 20, 3314, 7766, 7017, 1476, 5817, 7983, 213, 4578, 2807, 447, 2119, 5745, 7747, 8897, 1490, 3476, 6631, 139, 2589, 8098, 4425, 3321, 1535, 4453, 3162, 8642, 4843, 1954, 7184, 5238, 4925, 5626, 1975, 1449, 6807, 8870, 6816, 145, 2743, 1344, 2755, 7119, 5658, 4399, 3218, 3916, 3547, 5826, 8073, 8260, 2118, 489, 2808, 2452, 770, 7216, 6138, 7894, 195, 6893, 4137, 5796, 4069, 2116, 8262, 6463, 1494, 6317, 2273, 5639, 7270, 2289, 5612, 4978, 2171, 8724, 3485, 6918, 6799, 4325, 7172, 2344, 3809, 161, 4469, 2183, 8520, 2009, 3888, 720, 94, 304, 1216, 5037, 8830, 6804, 3116, 7737, 6784, 5636, 4077, 8771, 7236, 4060, 8549, 8088, 2397, 8178, 8272, 4952, 2813, 3948, 4966, 4905, 2620, 6962, 1069, 6650, 5519, 8738, 3239, 4808, 6991, 5947, 6927, 7200, 5689, 8620, 4335, 181, 3714, 3750, 701, 9438, 8708, 1857, 7498, 185, 7777, 6900, 7582, 1144, 854, 8368, 2923, 2770, 675, 731, 2604, 5086, 1310, 4459, 193, 7896, 2484, 3183, 112, 4649, 5221, 9436, 703, 1550, 6272, 9379, 3269, 4761, 5776, 1062, 2791, 2511, 1419, 4210, 2243, 8617, 8380, 6966, 4364, 208, 4688, 6637, 8658, 6679, 2915, 7264, 8557, 3125, 4626, 2962, 9219, 8573, 3330, 4114, 8285, 1215, 407, 95, 7672, 4007, 5318, 7908, 8540, 8409, 2471, 4475, 2068, 876, 3448, 6103, 2686, 231, 8277, 3409, 5712, 3433, 6488, 3256, 5928, 5645, 3291, 6026, 6731, 241, 6952, 8048, 6275, 5811, 8172, 6555, 8479, 5474, 1525, 5444, 4179, 3693, 3779, 3360, 6781, 7535, 1499, 4219, 5966, 7357, 3044, 1603, 7145, 8375, 3281, 1023, 39, 6068, 2951, 6502, 9155, 893, 2026, 8330, 6951, 277, 6732, 6641, 8905, 7820, 3907, 1012, 1788, 2897, 8276, 289, 2687, 4774, 8797, 7831, 2188, 7056, 977, 4903, 4968, 6324, 4322, 2128, 4231, 3462, 3170, 1814, 4577, 492, 7984, 4372, 8649, 4687, 321, 4365, 4017, 1439, 607, 610, 4144, 6010, 1808, 8078, 8119, 6712, 6892, 440, 7895, 346, 4460, 3836, 8012, 152, 2430, 4936, 7776, 361, 7499, 9412, 3713, 369, 4336, 2287, 7272, 5539, 1461, 708, 8917, 6328, 6365, 9297, 9408, 3099, 9294, 58, 2123, 5021, 8419, 7770, 4468, 415, 3810, 3894, 5064, 6249, 5923, 7682, 8227, 2429, 189, 8013, 6352, 7354, 8949, 1751, 2742, 461, 6817, 6865, 6511, 1826, 2588, 481, 6632, 2158, 3646, 1484, 1424, 7385, 6719, 5606, 8437, 5250, 3205, 7286, 2045, 2672, 3540, 1785, 7196, 553, 3818, 6176, 2023, 5793, 577, 84, 6198, 4648, 342, 3184, 4255, 6923, 3627, 983, 8743, 9373, 8729, 2877, 1219, 2556, 6692, 3960, 879, 691, 7671, 303, 408, 721, 9360, 737, 4573, 1614, 1415, 3192, 9130, 6197, 115, 578, 6076, 829, 7787, 3034, 5900, 4857, 6562, 5244, 3501, 921, 4266, 3651, 961, 4315, 2967, 5306, 1748, 1036, 5108, 5343, 3569, 1105, 2888, 2122, 167, 9295, 6367, 4382, 1965, 9282, 5753, 5111, 7919, 1381, 605, 1441, 1473, 3227, 6383, 2930, 1155, 1657, 6067, 250, 1024, 1841, 7301, 8629, 1148, 2071, 1222, 2209, 4243, 9126, 8763, 9100, 758, 2761, 2881, 6453, 5859, 3313, 499, 3681, 7794, 4141, 4417, 8788, 8736, 5521, 3442, 6625, 7361, 8281, 8112, 1578, 3786, 7098, 3155, 4732, 9463]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s0/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-s0/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c2d25423cbd695a6c16eb8a020ad8b27ea410113 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 9463, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s0/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s7/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l5-s7/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b235b38fe6215238c985b1ee5b9312c61cf5815e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 6373, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s7/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb82a4f84396fc98ef32295153f2dd290bdf5d27 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 3188, 4250, 4781, 3825, 5312, 1822, 2391, 5666, 1913, 4636, 5843, 1962, 4098, 3400, 1196, 3375, 6020, 2349, 957, 608, 5505, 3049, 2922, 3315, 4168, 6138, 5236, 5495, 4887, 2468, 3785, 1546, 1688, 4189, 6197, 690, 1175, 2779, 479, 3887, 3491, 2817, 2753, 1134, 1525, 679, 4648, 2082, 1658, 3250, 5271, 482, 6256, 928, 5805, 2908, 2748, 6266, 2444, 2195, 4421, 4452, 1893, 4217, 3960, 2379, 4031, 1017, 2095, 4130, 3099, 5501, 3532, 3230, 588, 2484, 1390, 6132, 240, 4171, 1944, 4608, 1746, 3225, 1409, 6081, 1377, 2006, 3754, 2102, 763, 5072, 340, 5569, 5511, 5717, 4228, 516, 4016, 632, 4812, 496, 2636, 1397, 3428, 2443, 6315, 2749, 3651, 2355, 2903, 283, 4641, 5709, 4561, 927, 6320, 483, 4409, 6216, 1098, 5545, 2211, 3213, 5413, 553, 947, 3064, 2109, 4574, 5167, 5799, 1190, 2503, 2016, 1257, 509, 2431, 1048, 227, 5252, 1338, 1550, 3649, 2751, 2819, 4953, 2439, 4802, 4728, 3481, 1084, 4429, 1769, 3882, 1097, 6253, 4410, 3307, 5899, 2086, 4380, 4159, 310, 5491, 2596, 4060, 2603, 1613, 970, 705, 2506, 3041, 5937, 689, 6338, 4190, 2066, 5064, 3522, 4238, 4981, 382, 2688, 5723, 5522, 3357, 3609, 2785, 1002, 2756, 1586, 2859, 5655, 5301, 5727, 3445, 5093, 5195, 2918, 3503, 5338, 5593, 4602, 3435, 2464, 4505, 4270, 699, 4743, 4901, 5626, 1222, 4388, 3158, 5816, 1375, 6083, 1826, 1241, 1178, 3459, 1452, 5326, 142, 1124, 2321, 1309, 2855, 2953, 2281, 4897, 464, 5235, 6347, 4169, 242, 81, 2205, 239, 6295, 1391, 3736, 4241, 2773, 3123, 1106, 3661, 1607, 2667, 2707, 4913, 277, 3200, 474, 4291, 4719, 5562, 1055, 4152, 5474, 4702, 2584, 3921, 2900, 4918, 3782, 2228, 1252, 1412, 4195, 4950, 629, 1461, 255, 3176, 1216, 5940, 3711, 3471, 114, 1735, 5813, 1857, 3856, 2377, 3962, 1699, 1825, 6155, 1376, 6287, 1410, 1254, 2477, 2297, 1220, 5628, 5588, 4045, 5551, 4460, 1741, 2989, 3729, 4049, 2215, 166, 885, 3833, 5128, 734, 549, 4715, 3127, 966, 5392, 4556, 1654, 815, 2950, 514, 4230, 4668, 5377, 917, 2080, 4650, 3342, 5084, 2746, 2910, 4485, 5575, 5217, 3613, 1302, 95, 807, 1384, 3672, 3940, 353, 4028, 4440, 2811, 1521, 421, 2969, 2434, 345, 2348, 6356, 3376, 5282, 2286, 4220, 4226, 5719, 460, 4948, 4197, 5306, 1101, 2491, 5280, 3378, 1849, 4531, 2801, 2862, 5776, 5948, 3196, 1679, 3365, 1805, 3734, 1393, 185, 3688, 2264, 4565, 5596, 3980, 1022, 1430, 5604, 2828, 4304, 2651, 5774, 2864, 5051, 1723, 3035, 2547, 4058, 2598, 446, 4646, 681, 1752, 835, 5856, 643, 2797, 2759, 5488, 2544, 1718, 896, 4419, 2197, 2253, 811, 5322, 4853, 350, 3407, 2372, 4325, 2451, 3195, 6000, 5777, 3798, 2571, 5381, 5058, 4766, 3710, 6095, 1217, 688, 6199, 3042, 3398, 4100, 5189, 621, 5554, 3776, 402, 1730, 2938, 3913, 4103, 5850, 1513, 3258, 3701, 3749, 4245, 1161, 1786, 655, 362, 1428, 1024, 1477, 235, 1141, 4839, 2449, 4327, 3419, 3072, 2618, 4615, 3174, 257, 2085, 6213, 3308, 3595, 41, 2489, 1103, 54, 120, 1967, 3148, 4968, 696, 5615, 5055, 3585, 2121, 5738, 1387, 4073, 1562, 104, 3740, 5143, 1831, 2964, 804, 866, 1334, 1268, 1354, 3951, 2457, 5117, 139, 3945, 4787, 3518, 3424, 324, 2146, 100, 2360, 642, 5968, 836, 528, 1897, 5263, 1512, 5924, 4104, 5538, 521, 4479, 4844, 1961, 6362, 4637, 4712, 5646, 1764, 5078, 4938, 4301, 3087, 3813, 5785, 3893, 3299, 2098, 5649, 5662, 5640, 315, 1661, 731, 961, 128, 5429, 4775, 3021, 3795, 1374, 6157, 3159, 1856, 6090, 1736, 1665, 3244, 1332, 868, 3328, 2907, 6318, 929, 4365, 5115, 2459, 1189, 6241, 5168, 5148, 850, 4778, 913, 2480, 3078, 5259, 3875, 4010, 3144, 77, 3892, 5833, 3814, 4034, 1239, 1828, 1149, 1372, 3797, 5947, 6001, 2863, 5981, 2652, 2023, 5222, 2776, 1244, 5417, 22, 871, 1780, 1495, 3975, 1865, 5220, 2025, 3659, 1108, 3988, 3270, 1185, 443, 822, 1917, 5750, 5751, 1918, 3554, 1424, 275, 4915, 2358, 102, 1564, 3706, 3670, 1386, 5883, 2122, 5465, 1876, 4014, 518, 408, 3579, 4662, 5712, 3444, 6177, 5302, 2888, 5521, 6188, 2689, 4588, 459, 6014, 4227, 6277, 5512, 794, 4858, 3443, 5729, 4663, 4560, 6259, 4642, 3842, 2243, 3278, 2788, 4256, 2609, 3732, 1807, 1776, 3838, 4849, 48, 1728, 404, 4624, 3879, 5105, 5023, 4076, 5157, 437, 177, 38, 5201, 4760, 5407, 985, 1406, 487, 761, 2104, 211, 1633, 1485, 2092, 4404, 5404, 173, 3870, 4361, 1912, 6365, 2392, 4875, 5639, 5828, 5650, 4330, 1543, 5297, 2152, 5300, 6179, 2860, 2803, 3417, 4329, 5661, 5829, 2099, 1763, 5840, 4713, 551, 5415, 1246, 314, 5827, 5663, 4876, 3114, 925, 4563, 2266, 3166, 1401, 4933, 4618, 5587, 6075, 1221, 6161, 4902, 4785, 3947, 840, 3014, 1683, 2221, 903, 5027, 5054, 5887, 697, 4272, 93, 1304, 5031, 5316, 4319, 4895, 2283, 2827, 5985, 1431, 5177, 3002, 3698, 5453, 3902, 3979, 5989, 4566, 4601, 6170, 5339, 3509, 1326, 4044, 6074, 5629, 4619, 1568, 2526, 3683, 862, 660, 1518, 3432, 1274, 2128, 5216, 6039, 4486, 1640, 3410, 501, 5510, 6279, 341, 4992, 4063, 4121, 418, 1054, 6115, 4720, 322, 3426, 1399, 3168, 1380, 3775, 5931, 622, 4459, 6072, 4046, 2612, 3635, 4748, 2210, 6251, 1099, 5308, 1127, 4622, 406, 520, 5848, 4105, 2427, 753, 3362, 1509, 1704, 3282, 4373, 1796, 2163, 5441, 1226, 579, 1598, 3356, 6187, 5724, 2889, 2744, 5086, 2983, 1286, 4586, 2691, 793, 5716, 6278, 5570, 502, 5042, 567, 3048, 6352, 609, 4596, 3531, 6301, 3100, 5012, 4708, 3133, 4886, 6345, 5237, 1455, 2595, 6208, 311, 2543, 5964, 2760, 5075, 4632, 3388, 5015, 4052, 5068, 4656, 414, 1957, 4001, 2052, 4701, 6112, 4153, 757, 1349, 4816, 4529, 1851, 5046, 1875, 5736, 2123, 1596, 581, 3896, 4080, 997, 328, 4296, 3368, 4356, 3901, 5599, 3699, 3260, 739, 1813, 118, 56, 571, 2011, 2420, 4471, 1225, 5527, 2164, 4929, 1710, 1817, 4723, 4494, 4496, 2175, 2308, 3495, 4774, 5821, 129, 3312, 1043, 2385, 3107, 2447, 4841, 2161, 1798, 4025, 21, 5768, 1245, 5643, 552, 6248, 3214, 4521, 3247, 318, 984, 5682, 4761, 172, 5671, 4405, 3535, 2169, 2808, 3681, 2528, 4391, 1793, 1342, 1061, 4555, 6056, 967, 694, 4970, 2037, 3675, 3968, 5111, 3239, 3583, 5057, 5944, 2572, 2294, 916, 6048, 4669, 3095, 3589, 192, 3620, 5243, 3854, 1859, 3821, 1368, 3864, 4536, 1976, 1205, 1229, 5229, 2559, 2343, 70, 4281, 1973, 4873, 2394, 388, 4946, 462, 4899, 4745, 3349, 3414, 4260, 1314, 3237, 5113, 4367, 2623, 3508, 5592, 6171, 3504, 3605, 4540, 3451, 3062, 949, 3991, 2632, 3404, 3943, 141, 6149, 1453, 5239, 4852, 5956, 812, 261, 2224, 2240, 4318, 5609, 5032, 981, 1821, 6368, 3826, 2319, 1126, 5543, 1100, 6010, 4198, 4069, 2887, 5726, 6178, 5656, 2153, 2151, 5658, 1544, 3787, 1907, 1693, 2893, 154, 1947, 1164, 1650, 1883, 4236, 3524, 2825, 2285, 6018, 3377, 6007, 2492, 158, 123, 831, 1068, 366, 3885, 481, 6322, 3251, 249, 2715, 617, 2388, 1702, 1511, 5852, 1898, 5183, 3874, 5791, 3079, 2403, 1580, 1926, 4115, 1337, 6232, 228, 4055, 1066, 833, 1754, 4809, 2671, 3853, 5371, 3621, 46, 4851, 5324, 1454, 5494, 6346, 6139, 465, 1537, 2183, 4311, 2558, 5361, 1230, 4546, 595, 5004, 3121, 2775, 5771, 2024, 5761, 1866, 3612, 6038, 5576, 2129, 457, 4590, 4427, 1086, 4726, 4804, 2630, 3993, 1938, 3103, 5192, 2031, 4759, 5684, 39, 3597, 5133, 223, 2917, 6174, 5094, 2030, 5204, 3104, 620, 5933, 4101, 3915, 575, 135, 3873, 5261, 1899, 5140, 2974, 17, 3001, 5602, 1432, 3727, 2991, 2235, 4513, 4398, 1012, 5147, 5798, 6242, 4575, 2352, 3809, 4911, 2709, 1677, 3198, 279, 436, 5688, 4077, 299, 748, 215, 1988, 1903, 933, 849, 5797, 5169, 1013, 1147, 1830, 5877, 3741, 2973, 5181, 1900, 4822, 2340, 593, 4548, 222, 5198, 3598, 606, 959, 733, 6062, 3834, 2876, 1644, 4146, 271, 4964, 296, 3899, 4358, 138, 5867, 2458, 5802, 4366, 5343, 3238, 5385, 3969, 2258, 5040, 504, 5022, 5691, 3880, 1771, 2942, 797, 4248, 3190, 2733, 3719, 4125, 2029, 5194, 6175, 3446, 4705, 3391, 859, 1790, 2982, 5518, 2745, 6043, 3343, 4909, 3811, 3089, 4937, 5838, 1765, 4631, 5486, 2761, 339, 6281, 764, 1345, 4655, 5481, 4053, 230, 3521, 6194, 2067, 2114, 1030, 3139, 4765, 5943, 5382, 3584, 5886, 5616, 5028, 1722, 5979, 2865, 785, 2332, 1874, 5467, 1852, 3130, 566, 5508, 503, 5108, 2259, 1122, 144, 4826, 2000, 4581, 980, 5315, 5610, 1305, 1721, 5053, 5617, 904, 1560, 4075, 5690, 5106, 505, 2425, 4107, 3211, 2213, 4051, 5483, 3389, 4707, 5499, 3101, 1940, 3540, 2553, 1008, 2512, 3120, 5225, 596, 2579, 558, 219, 293, 89, 4370, 3206, 819, 2601, 4062, 5567, 342, 2704, 636, 493, 2303, 3890, 79, 244, 2640, 381, 6191, 4239, 3738, 106, 2948, 817, 3208, 743, 1443, 4233, 2036, 5389, 695, 5889, 3149, 87, 295, 5122, 272, 2181, 1539, 4143, 2897, 3183, 3644, 4383, 4335, 2438, 6226, 2820, 628, 6101, 4196, 6012, 461, 5352, 389, 772, 1199, 2649, 4306, 4263, 4300, 5837, 5079, 3090, 3172, 4617, 5631, 1402, 2143, 1709, 5439, 2165, 3084, 2831, 4905, 2915, 225, 1050, 1137, 882, 3781, 6107, 2901, 2357, 5745, 276, 6121, 2708, 5163, 3810, 5082, 3344, 3320, 2914, 4925, 2832, 4784, 5625, 6162, 4744, 5350, 463, 6141, 2282, 5607, 4320, 2712, 4770, 4741, 701, 4284, 2467, 6344, 5496, 3134, 2794, 1715, 3038, 4594, 611, 2401, 3081, 3113, 5638, 5664, 2393, 5355, 1974, 4538, 3607, 3359, 4694, 3012, 842, 4672, 1111, 524, 452, 3118, 2514, 3442, 5714, 795, 2944, 3563, 349, 5955, 5323, 5240, 47, 5697, 3839, 3440, 2516, 1960, 5845, 4480, 2160, 5422, 2448, 5909, 1142, 4193, 1414, 2233, 2993, 2044, 716, 1079, 2589, 34, 4688, 1999, 5036, 145, 2727, 2339, 5138, 1901, 1990, 2042, 2995, 4528, 5470, 1350, 2301, 495, 6272, 633, 2670, 5246, 1755, 790, 3850, 2629, 5209, 4727, 6224, 2440, 2815, 3493, 2310, 2256, 3971, 1119, 4450, 4423, 1842, 3576, 3618, 194, 3517, 5864, 3946, 5624, 4903, 2833, 3824, 6370, 4251, 912, 5795, 851, 3020, 5820, 5430, 3496, 4007, 4740, 4892, 2713, 251, 3709, 5942, 5059, 3140, 3771, 171, 5406, 5683, 5202, 2032, 3154, 2061, 1981, 3396, 3044, 3714, 1929, 3058, 2209, 5547, 3636, 3348, 5349, 4900, 6163, 700, 4891, 4771, 4008, 3877, 4626, 1888, 802, 2966, 4005, 3498, 1250, 2230, 3480, 6223, 4803, 5210, 1087, 4493, 5436, 1818, 321, 5561, 6116, 4292, 51, 3126, 6059, 550, 5645, 5841, 4638, 564, 3132, 5498, 5013, 3390, 5091, 3447, 2583, 6111, 5475, 2053, 3665, 1214, 3178, 377, 3011, 4868, 3360, 755, 4155, 4039, 1998, 4828, 35, 2187, 2680, 4085, 4467, 1082, 3483, 2721, 2569, 3800, 2412, 290, 4551, 3986, 1110, 4865, 843, 3094, 5376, 6049, 4231, 1445, 937, 4559, 5711, 5730, 3580, 1492, 3338, 3830, 413, 5480, 5069, 1346, 1323, 397, 3341, 6045, 2081, 6326, 680, 5972, 447, 3438, 3841, 5708, 6260, 284, 563, 4711, 5842, 6363, 1914, 305, 3387, 5485, 5076, 1766, 85, 3151, 1887, 4737, 3878, 5693, 405, 5541, 1128, 1567, 5586, 5630, 4934, 3173, 5903, 2619, 4275, 728, 536, 1298, 1745, 6291, 1945, 156, 2494, 1272, 3434, 6169, 5594, 4567, 676, 2538, 3530, 5503, 610, 4881, 3039, 2508, 4426, 5213, 458, 5721, 2690, 5515, 1287, 3394, 1983, 979, 5034, 2001, 846, 4213, 955, 2351, 5166, 6243, 2110, 2077, 3009, 379, 2642, 675, 4600, 5595, 5990, 2265, 5635, 926, 6258, 5710, 4664, 938, 1653, 6055, 5393, 1062, 8, 3985, 4675, 291, 221, 5135, 594, 5227, 1231, 499, 3412, 3351, 3450, 5335, 3606, 4871, 1975, 5365, 3865, 1951, 1583, 2800, 6004, 1850, 5469, 4817, 2996, 370, 1845, 907, 1330, 3246, 5411, 3215, 561, 286, 2520, 1006, 2555, 4397, 5172, 2236, 2399, 613, 1156, 2764, 3592, 4269, 6166, 2465, 4286, 4042, 1328, 909, 640, 2362, 2174, 5434, 4495, 5435, 4724, 1088, 2140, 4341, 3223, 1748, 1639, 5574, 6040, 2911, 1922, 65, 2159, 4843, 5846, 522, 1113, 1193, 1236, 1554, 4386, 1224, 5443, 2421, 2587, 1081, 4683, 4086, 2418, 2013, 708, 11, 1740, 6071, 5552, 623, 626, 2822, 3053, 3463, 1892, 6311, 4422, 4794, 1120, 2261, 2660, 1624, 3318, 3346, 3638, 3679, 2810, 6028, 4029, 2381, 1169, 3273, 1365, 2836, 4184, 2203, 83, 1768, 6220, 1085, 5212, 4591, 2509, 1841, 4793, 4451, 6312, 2196, 5960, 897, 2375, 3858, 1530, 531, 14, 2278, 3306, 6215, 6254, 484, 3228, 3534, 5403, 5672, 2093, 1019, 1503, 1838, 1011, 5171, 4514, 2556, 4313, 1620, 2980, 1792, 5397, 2529, 3157, 6159, 1223, 4473, 1555, 4334, 4956, 3645, 4158, 6211, 2087, 2335, 1686, 1548, 1340, 1795, 5530, 3283, 3205, 4997, 90, 2622, 5342, 5114, 5803, 930, 3956, 1911, 5668, 3871, 137, 5119, 3900, 5455, 3369, 4175, 3722, 603, 1154, 615, 2717, 2615, 2249, 1280, 1182, 1172, 1617, 3222, 4490, 2141, 1404, 987, 2701, 2437, 4955, 4384, 1556, 3381, 1542, 5660, 5651, 3418, 5907, 2450, 5951, 2373, 899, 1675, 2711, 4894, 5608, 5317, 2241, 3844, 3220, 1619, 4395, 2557, 5231, 2184, 180, 1312, 4262, 4941, 2650, 5983, 2829, 3086, 5836, 4939, 4264, 1803, 3367, 5457, 329, 1726, 50, 4718, 6117, 475, 163, 1996, 4041, 4503, 2466, 4889, 702, 1972, 5357, 71, 2246, 3075, 545, 727, 4613, 2620, 92, 5613, 698, 6165, 4506, 3593, 3310, 131, 1802, 4299, 4940, 4307, 1313, 5346, 3415, 2805, 2608, 5703, 2789, 491, 638, 911, 4780, 6371, 3189, 5100, 798, 1160, 5919, 3750, 2869, 2772, 6129, 3737, 4980, 6192, 3523, 5286, 1884, 2035, 4972, 1444, 4667, 6050, 515, 6276, 5718, 6015, 4221, 1077, 718, 1076, 4225, 6016, 2287, 3959, 6309, 1894, 1533, 954, 4578, 847, 935, 1447, 3292, 3264, 2839, 974, 3568, 3769, 3142, 4012, 1878, 942, 4068, 5305, 6011, 4949, 6102, 1413, 4837, 1143, 2065, 6196, 6339, 1689, 3696, 3004, 2202, 4433, 2837, 3266, 3930, 62, 1955, 416, 4123, 3721, 4354, 3370, 2190, 1943, 6293, 241, 6137, 6348, 3316, 1626, 829, 125, 3163, 1358, 2325, 309, 6210, 4381, 3646, 4038, 4691, 756, 5473, 6113, 1056, 4136, 3905, 2592, 270, 5124, 1645, 2896, 4960, 1540, 3383, 1202, 1863, 3977, 3904, 4150, 1057, 2058, 2532, 669, 3098, 6303, 2096, 3301, 3759, 2028, 5096, 3720, 4177, 417, 5565, 4064, 1578, 2405, 1266, 1336, 5254, 1927, 3716, 2686, 384, 1811, 741, 3210, 5019, 2426, 5537, 5849, 5925, 3914, 5188, 5934, 3399, 6360, 1963, 3070, 3421, 233, 1479, 769, 3549, 1092, 358, 2156, 2417, 4466, 4684, 2681, 2410, 3802, 996, 5460, 3897, 298, 5156, 5689, 5024, 1561, 5881, 1388, 2486, 2886, 5304, 4199, 943, 2881, 1577, 4120, 5566, 4993, 2602, 6206, 2597, 5975, 2548, 1065, 5250, 229, 5067, 5482, 5016, 2214, 6067, 3730, 2611, 5550, 6073, 5589, 1327, 4502, 4287, 1997, 4690, 4156, 3647, 1552, 1238, 5783, 3815, 1016, 6306, 2380, 4439, 6029, 354, 20, 5419, 1799, 1210, 2567, 2723, 112, 3473, 1459, 631, 6274, 517, 5734, 1877, 4202, 3143, 5789, 3876, 4739, 4772, 3497, 4733, 2967, 423, 2051, 5477, 1958, 2518, 288, 2414, 68, 2345, 1937, 5207, 2631, 5331, 950, 3269, 5757, 1109, 4674, 4552, 9, 710, 1501, 1021, 5988, 5597, 3903, 4138, 1864, 5763, 1496, 3295, 1118, 4796, 2257, 5110, 5386, 3676, 3693, 2292, 2574, 1698, 6086, 2378, 6308, 4218, 2288, 1910, 4363, 931, 1905, 3789, 2456, 5869, 1355, 2269, 839, 5623, 4786, 5865, 140, 5328, 3405, 352, 6031, 3673, 2039, 1421, 150, 1574, 3561, 2946, 108, 61, 4181, 3267, 952, 1535, 467, 2049, 425, 3181, 2899, 6109, 2585, 2423, 507, 1259, 574, 5187, 4102, 5926, 2939, 208, 1871, 2090, 1487, 32, 2591, 4149, 4137, 3978, 5598, 5454, 4357, 5120, 297, 4079, 5461, 582, 3298, 5832, 5786, 78, 4986, 2304, 3490, 6333, 480, 5273, 367, 1096, 6218, 1770, 5104, 5692, 4625, 4738, 4009, 5790, 5260, 5184, 136, 4360, 5669, 174, 3335, 1783, 1950, 4535, 5366, 1369, 3256, 1515, 2934, 1529, 4416, 2376, 6088, 1858, 5370, 5244, 2672, 2628, 4806, 791, 2693, 977, 1985, 3219, 4316, 2242, 5707, 4643, 3439, 4848, 5698, 1777, 2846, 2875, 5127, 6063, 886, 412, 4658, 3339, 399, 2318, 5311, 6369, 4782, 2834, 1367, 5368, 1860, 1979, 2063, 1145, 1015, 4033, 5784, 5834, 3088, 5081, 4910, 5164, 2353, 3653, 1696, 2576, 430, 995, 4082, 2411, 4678, 2570, 5946, 5778, 1373, 5818, 3022, 2927, 1672, 265, 2455, 3953, 1906, 5295, 1545, 6342, 2469, 2227, 6106, 4919, 883, 168, 2316, 401, 5930, 5555, 1381, 2314, 170, 4763, 3141, 4204, 3569, 2118, 673, 2644, 2328, 826, 2741, 3657, 2027, 4127, 3302, 471, 1761, 2101, 6284, 2007, 1034, 2868, 4244, 5920, 3702, 2524, 1570, 1167, 2383, 1045, 2972, 5142, 5878, 105, 4979, 4240, 6130, 1392, 5995, 1806, 5701, 2610, 4048, 6068, 2990, 5175, 1433, 2070, 393, 602, 4353, 4176, 4124, 5097, 2734, 2685, 4113, 1928, 4752, 3045, 3470, 6094, 5941, 4767, 252, 3669, 5741, 1565, 1130, 2523, 3748, 5921, 3259, 5452, 5600, 3003, 4187, 1690, 2291, 3966, 3677, 3640, 2658, 2263, 5992, 186, 653, 1788, 861, 5583, 2527, 5399, 2809, 4442, 3639, 3692, 3967, 5387, 2038, 3939, 6032, 1385, 5740, 3707, 253, 1463, 1213, 4699, 2054, 1482, 1606, 6125, 1107, 5759, 2026, 3761, 2742, 2891, 1695, 3807, 2354, 6264, 2750, 6229, 1551, 4037, 4157, 4382, 4957, 3184, 1277, 2657, 3691, 3678, 4443, 3347, 4747, 5548, 2613, 2719, 3485, 856, 1290, 333, 3466, 59, 110, 2725, 147, 3557, 45, 5242, 5372, 193, 4790, 3577, 410, 888, 1301, 6037, 5218, 1867, 2784, 6185, 3358, 4870, 4539, 5336, 3505, 2133, 247, 3253, 1152, 605, 5132, 5199, 40, 5897, 3309, 4268, 4507, 2765, 191, 5374, 3096, 671, 2120, 5885, 5056, 5383, 3240, 1491, 4661, 5731, 409, 3617, 4791, 1843, 372, 3514, 722, 2959, 2117, 3768, 4205, 975, 2695, 1934, 348, 4855, 2945, 3934, 1575, 2883, 44, 3623, 148, 1423, 5748, 1919, 3323, 2850, 1091, 4091, 770, 391, 2072, 3290, 1449, 1471, 1592, 2552, 5009, 1941, 2192, 3110, 2168, 5402, 4406, 3229, 6300, 5502, 4597, 2539, 3501, 2920, 3051, 2824, 5285, 4237, 6193, 5065, 231, 3423, 5863, 4788, 195, 721, 3573, 373, 600, 395, 1325, 5591, 5340, 2624, 2132, 3604, 5337, 6172, 2919, 3528, 2540, 1249, 4732, 4006, 4773, 5431, 2309, 4799, 2816, 6332, 3888, 2305, 1072, 650, 855, 3632, 2720, 4681, 1083, 6222, 4729, 2231, 1416, 3193, 2453, 267, 1458, 4019, 113, 6093, 3712, 3046, 569, 58, 3628, 334, 1891, 4454, 3054, 1469, 1451, 6151, 1179, 202, 2873, 2848, 3325, 25, 3061, 5334, 4541, 3352, 2582, 4704, 5092, 6176, 5728, 5713, 4859, 2515, 4847, 3840, 4644, 448, 2463, 6168, 4603, 1273, 5579, 1519, 2813, 2442, 6268, 1398, 5559, 323, 5862, 3519, 232, 4095, 3071, 5906, 4328, 5652, 2804, 4259, 5347, 3350, 4543, 500, 5572, 1641, 2371, 5953, 351, 3942, 5329, 2633, 1234, 1195, 6359, 4099, 5935, 3043, 4754, 1982, 4584, 1288, 858, 5090, 4706, 5014, 5484, 4633, 306, 2647, 1201, 4141, 1541, 4332, 1557, 1848, 6006, 5281, 6019, 6357, 1197, 774, 2678, 2189, 4174, 4355, 5456, 4297, 1804, 5997, 1680, 1508, 5534, 754, 4693, 4869, 3608, 6186, 5523, 1599, 556, 2581, 3449, 4542, 3413, 5348, 4746, 3637, 4444, 3319, 4908, 5083, 6044, 4651, 398, 3829, 4659, 1493, 1782, 3868, 175, 439, 2978, 1622, 2662, 2906, 5807, 869, 24, 3454, 2849, 3552, 1920, 2913, 4907, 3345, 4445, 1625, 4167, 6349, 2923, 1042, 5427, 130, 4267, 3594, 5898, 6214, 4411, 2279, 2955, 470, 3758, 4128, 2097, 5831, 3894, 583, 1117, 3973, 1497, 3263, 4209, 1448, 3545, 2073, 540, 2563, 1295, 1439, 3204, 4372, 5531, 1705, 1000, 2787, 5705, 2244, 73, 875, 1364, 4436, 1170, 1184, 5756, 3989, 951, 3929, 4182, 2838, 4208, 3293, 1498, 738, 5451, 3700, 5922, 1514, 3862, 1370, 1151, 3601, 248, 5270, 6323, 1659, 317, 5410, 4522, 1331, 5810, 1666, 878, 1490, 3582, 5384, 5112, 5344, 1315, 1611, 2605, 2172, 2364, 587, 6299, 3533, 4407, 485, 1408, 6289, 1747, 4489, 4342, 1618, 4315, 3845, 1986, 217, 560, 4520, 5412, 6249, 2212, 5018, 4108, 742, 4975, 818, 4996, 4371, 3284, 1440, 1759, 473, 6119, 278, 5160, 1678, 5999, 5949, 2452, 3477, 1417, 2732, 5099, 4249, 6372, 3, 2126, 1276, 3643, 4958, 2898, 3923, 426, 376, 4697, 1215, 6097, 256, 5902, 4616, 4935, 3091, 2004, 1379, 5557, 1400, 5633, 2267, 1357, 4163, 126, 963, 1855, 5815, 6158, 4389, 2530, 2060, 4757, 2033, 1886, 4628, 86, 4967, 5890, 1968, 2842, 76, 5788, 4011, 4203, 3770, 4764, 5060, 1031, 1263, 991, 2793, 4885, 5497, 4709, 565, 5044, 1853, 965, 6058, 4716, 52, 1105, 6127, 2774, 5224, 5005, 2513, 4861, 453, 2675, 924, 5637, 4877, 3082, 2167, 3537, 2193, 2446, 5424, 2386, 619, 5191, 5205, 1939, 5011, 5500, 6302, 4131, 670, 3588, 5375, 4670, 844, 2003, 3171, 4936, 5080, 3812, 5835, 4302, 2830, 4927, 2166, 3112, 4878, 2402, 5258, 5792, 2481, 544, 4278, 2247, 2617, 5905, 3420, 4096, 1964, 161, 477, 2781, 2108, 6245, 948, 5333, 3452, 26, 2208, 4750, 1930, 3030, 1468, 3462, 4455, 2823, 3526, 2921, 6351, 5506, 568, 3469, 3713, 4753, 3397, 5936, 6200, 2507, 4593, 4882, 1716, 2546, 5977, 1724, 331, 1292, 1467, 3056, 1931, 2738, 1629, 1027, 2962, 1833, 2926, 3794, 5819, 4776, 852, 189, 2767, 1506, 1682, 5621, 841, 4867, 4695, 378, 4571, 2078, 919, 2020, 2201, 4186, 3697, 5601, 5178, 18, 356, 1094, 369, 4527, 4818, 2043, 4834, 2234, 5174, 3728, 6069, 1742, 891, 1361, 1669, 1285, 5517, 5087, 1791, 4393, 1621, 3332, 440, 2276, 16, 5180, 5141, 3742, 1046, 2433, 6024, 422, 4004, 4734, 803, 5875, 1832, 3025, 1028, 2116, 3571, 723, 2047, 469, 3304, 2280, 6143, 2856, 513, 6052, 816, 4977, 107, 3933, 3562, 4856, 796, 5102, 1772, 207, 3912, 5927, 1731, 2535, 1528, 3860, 1516, 662, 647, 199, 1283, 1671, 3793, 3023, 1834, 1041, 3314, 6350, 3050, 3527, 3502, 6173, 5196, 224, 4924, 4906, 3321, 1921, 4484, 6041, 2747, 6317, 5806, 3329, 2663, 282, 6262, 2356, 4917, 6108, 3922, 3182, 4959, 4144, 1646, 153, 5292, 1694, 3655, 2743, 5520, 5725, 5303, 4070, 2487, 43, 3559, 1576, 4066, 944, 1602, 2369, 1643, 5126, 3835, 2847, 3456, 203, 1038, 2771, 4243, 3751, 1035, 784, 5050, 5980, 5775, 6002, 2802, 5654, 6180, 1587, 512, 2952, 6144, 1310, 182, 2138, 1090, 3551, 3324, 3455, 2874, 3836, 1778, 873, 75, 3146, 1969, 973, 4207, 3265, 4183, 4434, 1366, 3823, 4783, 4904, 4926, 3085, 4303, 5984, 5605, 2284, 5284, 3525, 3052, 4456, 627, 4952, 6227, 2752, 6331, 3492, 4800, 2441, 3430, 1520, 6027, 4441, 3680, 5400, 2170, 2607, 4258, 3416, 5653, 2861, 6003, 4532, 1584, 2758, 5966, 644, 1714, 4884, 3135, 992, 1319, 490, 4255, 5704, 3279, 1001, 6184, 3610, 1868, 2107, 3066, 478, 6335, 1176, 1243, 5770, 5223, 3122, 6128, 4242, 2870, 1039, 1836, 1505, 3017, 190, 3591, 4508, 1157, 338, 5074, 5487, 5965, 2798, 1585, 6182, 1003, 1133, 6330, 2818, 6228, 3650, 6265, 6316, 2909, 6042, 5085, 5519, 2890, 3656, 3762, 827, 1628, 3028, 1932, 2697, 2684, 3718, 5098, 3191, 1418, 1993, 2218, 2338, 4824, 146, 3625, 111, 4021, 2568, 4680, 3484, 3633, 2614, 4349, 616, 5268, 250, 4769, 4893, 4321, 1676, 5162, 4912, 6122, 2668, 635, 4990, 343, 2436, 4337, 988, 2408, 2683, 2736, 1933, 3566, 976, 3848, 792, 5514, 4587, 5722, 6189, 383, 4112, 3717, 2735, 2698, 2409, 4084, 4685, 2188, 3372, 775, 923, 3116, 454, 2627, 3852, 5245, 4810, 634, 2706, 6123, 1608, 434, 281, 2905, 3330, 1623, 4447, 2262, 3690, 3641, 1278, 2251, 2199, 2022, 5773, 5982, 4305, 4942, 1200, 3385, 307, 2327, 3765, 674, 4569, 380, 4983, 245, 2135, 1396, 6270, 497, 1233, 3403, 5330, 3992, 5208, 4805, 3851, 2673, 455, 2131, 3507, 5341, 4368, 91, 4274, 4614, 5904, 3073, 2248, 4348, 2718, 3634, 5549, 4047, 3731, 5702, 4257, 2806, 2171, 3234, 1612, 6205, 4061, 4994, 820, 445, 5974, 4059, 6207, 5492, 1456, 269, 4148, 3906, 33, 4830, 1080, 4469, 2422, 3920, 6110, 4703, 3448, 3353, 557, 5002, 597, 429, 3805, 1697, 3964, 2293, 5380, 5945, 3799, 4679, 2722, 4022, 1211, 1465, 1294, 3287, 541, 591, 2342, 5360, 5230, 4312, 4396, 4515, 1007, 5008, 3541, 1593, 6, 1064, 4057, 5976, 3036, 1717, 5963, 5489, 312, 1248, 3500, 3529, 4598, 677, 1527, 2936, 1732, 668, 4133, 2059, 3156, 4390, 5398, 3682, 5584, 1569, 3747, 3703, 1131, 1005, 4517, 287, 3999, 1959, 4846, 3441, 4860, 3119, 5006, 1009, 1840, 4425, 4592, 3040, 6201, 706, 2015, 6239, 1191, 1115, 585, 2366, 1637, 1750, 683, 1271, 4605, 157, 5279, 6008, 1102, 5895, 42, 2885, 4071, 1389, 6297, 589, 543, 3077, 5793, 914, 2296, 6078, 1255, 2018, 921, 777, 2397, 2238, 2226, 3784, 6343, 4888, 4285, 4504, 6167, 3436, 449, 2273, 1188, 5801, 5116, 5868, 3952, 3790, 266, 3476, 3194, 5950, 4326, 5908, 4840, 5423, 3108, 2194, 6314, 6267, 3429, 2814, 4801, 6225, 4954, 4336, 2702, 344, 6023, 2970, 1047, 6235, 510, 1589, 752, 5536, 4106, 5020, 506, 3919, 2586, 4470, 5444, 2012, 4465, 4087, 2157, 67, 3997, 289, 4677, 3801, 4083, 2682, 2699, 989, 1265, 4118, 1579, 5257, 3080, 4879, 612, 4511, 2237, 2472, 778, 387, 5354, 4874, 5665, 6366, 1823, 1701, 5266, 618, 3106, 5425, 1044, 3744, 1168, 4438, 4030, 6307, 3961, 6087, 3857, 4417, 898, 4324, 5952, 3408, 1642, 2878, 1603, 1636, 2499, 586, 3232, 2173, 4498, 641, 5858, 101, 5744, 4916, 2902, 6263, 3652, 3808, 5165, 4576, 956, 6355, 6021, 346, 1936, 3995, 69, 5359, 2560, 592, 5137, 4823, 2728, 2219, 1685, 4378, 2088, 1873, 5048, 786, 302, 825, 3764, 2645, 308, 4161, 1359, 893, 1308, 6146, 1125, 5310, 3827, 400, 3778, 169, 3773, 1382, 809, 2255, 4798, 3494, 5432, 2176, 1071, 3489, 3889, 4987, 494, 4814, 1351, 686, 1219, 6077, 2478, 915, 5379, 2573, 3965, 3694, 1691, 1909, 3958, 4219, 6017, 5283, 2826, 5606, 4896, 6142, 2954, 3305, 4412, 15, 2976, 441, 1187, 2461, 450, 526, 838, 3949, 1356, 3165, 5634, 4564, 5991, 3689, 2659, 4448, 1121, 5039, 5109, 3970, 4797, 2311, 810, 5958, 2198, 2655, 1279, 4347, 2616, 3074, 4279, 72, 3277, 5706, 3843, 4317, 5318, 2225, 2471, 2398, 4512, 5173, 2992, 4835, 1415, 3479, 4730, 1251, 6105, 3783, 2470, 2239, 5319, 262, 902, 5619, 1684, 2337, 2729, 1994, 165, 6066, 4050, 5017, 3212, 6250, 5546, 4749, 3059, 27, 238, 6134, 82, 4432, 4185, 3005, 2021, 2654, 2252, 5959, 4420, 6313, 2445, 3109, 3538, 1942, 4173, 3371, 2679, 4686, 36, 179, 4310, 5232, 1538, 4962, 273, 1426, 364, 1070, 2307, 5433, 4497, 2363, 3233, 2606, 2807, 5401, 3536, 3111, 3083, 4928, 5440, 5528, 1797, 5421, 4842, 4481, 66, 2416, 4088, 359, 2150, 5299, 5657, 5298, 2154, 360, 657, 99, 5860, 325, 1708, 4931, 1403, 4340, 4491, 1089, 2852, 183, 1395, 2638, 246, 3603, 3506, 2625, 456, 5215, 5577, 1275, 3186, 4, 1595, 5464, 5737, 5884, 3586, 672, 3767, 3570, 2960, 1029, 5062, 2068, 1435, 2076, 4573, 6244, 3065, 2782, 1869, 210, 5677, 762, 6283, 3755, 1762, 5648, 5830, 3300, 4129, 6304, 1018, 4403, 5673, 1486, 3909, 1872, 2334, 4379, 6212, 5900, 258, 1657, 6325, 4649, 6046, 918, 3008, 4572, 2111, 1436, 539, 3289, 3546, 392, 3725, 1434, 2113, 5063, 6195, 4191, 1144, 3818, 1980, 4756, 3155, 2531, 4134, 1058, 767, 1481, 3664, 4700, 5476, 4002, 424, 3925, 468, 2957, 724, 715, 4833, 2994, 4819, 1991, 1420, 3938, 3674, 5388, 4971, 4234, 1885, 3153, 4758, 5203, 5193, 5095, 4126, 3760, 3658, 5760, 5221, 5772, 2653, 2200, 3006, 920, 2475, 1256, 6238, 2504, 707, 4464, 2419, 5445, 572, 1261, 1033, 3753, 6285, 1378, 3170, 3092, 845, 4580, 5035, 4827, 4689, 4040, 4288, 164, 2217, 2730, 1419, 2041, 4820, 1902, 5152, 216, 3218, 3846, 978, 4583, 3395, 4755, 2062, 3819, 1861, 1204, 5364, 4537, 4872, 5356, 4282, 703, 972, 2841, 3147, 5891, 121, 160, 3069, 4097, 6361, 5844, 4845, 2517, 4000, 5478, 415, 4179, 63, 1924, 1582, 4534, 3866, 1784, 1163, 5290, 155, 4607, 6292, 4172, 2191, 3539, 5010, 3102, 5206, 3994, 2346, 347, 3565, 2696, 2737, 3029, 3057, 4751, 3715, 4114, 5255, 1581, 1953, 64, 4483, 2912, 3322, 3553, 5749, 5752, 823, 304, 4635, 6364, 5667, 4362, 3957, 2289, 1692, 5294, 3788, 3954, 932, 5151, 1989, 4821, 5139, 5182, 5262, 5853, 529, 1532, 4216, 6310, 4453, 3464, 335, 801, 4736, 4627, 3152, 2034, 4235, 5287, 1651, 940, 1880, 941, 4201, 4013, 5735, 5466, 5047, 2333, 2089, 3910, 209, 2106, 2783, 3611, 5219, 5762, 3976, 4139, 1203, 1978, 3820, 5369, 3855, 6089, 5814, 3160, 964, 3129, 5045, 5468, 4530, 6005, 3379, 1558, 906, 4525, 371, 3575, 4792, 4424, 2510, 1010, 4400, 1504, 2769, 1040, 2925, 3024, 2963, 5876, 5144, 1148, 5781, 1240, 6154, 6084, 1700, 2390, 6367, 5313, 982, 320, 4722, 5437, 1711, 665, 117, 5449, 740, 4110, 385, 780, 1775, 5700, 3733, 5996, 3366, 4298, 4265, 132, 1209, 4024, 5420, 2162, 5529, 4374, 1341, 5396, 4392, 2981, 5088, 860, 3685, 654, 5917, 1162, 1949, 3867, 3336, 1494, 5765, 872, 2845, 3837, 5699, 1808, 781, 206, 2941, 5103, 3881, 6219, 4430, 84, 4630, 5077, 5839, 5647, 2100, 3756, 472, 3202, 1441, 745, 789, 4808, 5247, 834, 5970, 682, 2497, 1638, 4488, 3224, 6290, 4609, 1299, 890, 2988, 6070, 4461, 12, 533, 1664, 5812, 6091, 115, 667, 2534, 2937, 5928, 403, 5695, 49, 4294, 330, 3034, 5978, 5052, 5029, 1306, 895, 5962, 2545, 3037, 4883, 2795, 645, 664, 1816, 5438, 4930, 2144, 326, 999, 3281, 5532, 1510, 5265, 2389, 1824, 6085, 3963, 2575, 3806, 3654, 2892, 5293, 1908, 2290, 3695, 4188, 6340, 1547, 4377, 2336, 2220, 5620, 3015, 1507, 3364, 5998, 3197, 5161, 2710, 4322, 900, 264, 3792, 2928, 1284, 2985, 1362, 877, 3243, 5811, 1737, 534, 730, 5825, 316, 3249, 6324, 2083, 259, 814, 6054, 4557, 939, 1882, 5288, 1165, 1572, 152, 2895, 4145, 5125, 2877, 2370, 3409, 5573, 4487, 1749, 2498, 2367, 1604, 1484, 5675, 212, 1475, 1026, 3027, 2739, 828, 4166, 3317, 4446, 2661, 3331, 2979, 4394, 4314, 3221, 4343, 1173, 692, 969, 6204, 2604, 3235, 1316, 433, 2666, 6124, 3662, 1483, 1635, 2368, 2879, 945, 555, 3355, 5524, 580, 5463, 2124, 5, 2551, 3542, 1472, 751, 2429, 511, 2858, 6181, 2757, 2799, 4533, 1952, 1925, 5256, 2404, 4119, 4065, 2882, 3560, 3935, 151, 1648, 1166, 3746, 2525, 5585, 4620, 1129, 3705, 5742, 103, 5880, 4074, 5025, 905, 1847, 3380, 4333, 4385, 4474, 1237, 4036, 3648, 6230, 1339, 4376, 1687, 6341, 3786, 5296, 5659, 4331, 3382, 4142, 4961, 2182, 5233, 466, 3927, 953, 4215, 1895, 530, 4415, 3859, 2935, 2536, 678, 6328, 1135, 1052, 420, 6026, 2812, 3431, 5580, 661, 2933, 3861, 3257, 5923, 5851, 5264, 1703, 5533, 3363, 1681, 3016, 2768, 1837, 4401, 1020, 3982, 711, 737, 3262, 3294, 3974, 5764, 1781, 3337, 4660, 3581, 3241, 879, 31, 3908, 2091, 5674, 1634, 1605, 3663, 2055, 768, 4093, 234, 5912, 1025, 1631, 213, 750, 1591, 3543, 1450, 3461, 3055, 3031, 1293, 2565, 1212, 3667, 254, 6099, 630, 4018, 3474, 268, 2594, 5493, 5238, 5325, 6150, 3460, 1470, 3544, 3291, 4210, 936, 4666, 4232, 4973, 744, 1758, 3203, 3285, 1296, 538, 2075, 2112, 2069, 3726, 5176, 5603, 5986, 1023, 5914, 363, 2179, 274, 5747, 3555, 149, 3937, 2040, 1992, 2731, 3192, 3478, 2232, 4836, 4194, 6103, 1253, 6080, 6288, 3226, 486, 5680, 986, 4339, 2142, 4932, 5632, 3167, 5558, 3427, 6269, 2637, 2136, 184, 5994, 3735, 6131, 6296, 2485, 4072, 5882, 5739, 3671, 6033, 808, 2313, 3774, 5556, 3169, 2005, 6286, 6082, 6156, 5817, 3796, 5779, 1150, 3255, 3863, 5367, 3822, 2835, 4435, 3274, 876, 1668, 2986, 892, 2324, 4162, 3164, 2268, 3950, 5870, 1269, 685, 2300, 4815, 5471, 758, 1322, 4654, 5070, 765, 1060, 5395, 1794, 4375, 1549, 6231, 5253, 4116, 1267, 5872, 867, 5809, 3245, 4523, 908, 4501, 4043, 5590, 3510, 396, 4653, 1347, 759, 489, 2791, 993, 432, 1610, 3236, 5345, 4261, 4308, 181, 2854, 6145, 2322, 894, 1720, 5030, 5611, 94, 6036, 3614, 889, 1744, 4610, 537, 1438, 3286, 2564, 1466, 3032, 332, 3630, 857, 3393, 4585, 5516, 2984, 1670, 2929, 200, 1181, 4346, 2250, 2656, 3642, 3185, 2127, 5578, 3433, 4604, 2495, 684, 1353, 5871, 1335, 4117, 2406, 990, 3137, 1032, 2009, 573, 3917, 508, 6237, 2017, 2476, 6079, 1411, 6104, 2229, 4731, 3499, 2541, 313, 5642, 5416, 5769, 2777, 1177, 6153, 1827, 5782, 4035, 1553, 4475, 1194, 3402, 2634, 498, 4545, 5228, 5362, 1206, 578, 5526, 5442, 4472, 4387, 6160, 5627, 6076, 2298, 687, 5939, 6096, 3177, 4698, 3666, 1464, 2566, 4023, 1800, 133, 577, 1228, 5363, 1977, 1862, 4140, 3384, 2648, 4943, 773, 3374, 6358, 3401, 1235, 4476, 1114, 2502, 6240, 5800, 2460, 2274, 442, 5755, 3271, 1171, 4345, 1281, 201, 3458, 6152, 1242, 2778, 6336, 691, 1616, 4344, 1183, 3272, 4437, 2382, 3745, 1571, 1649, 5289, 1948, 1785, 5918, 4246, 799, 337, 2763, 4509, 614, 4351, 604, 3600, 3254, 1371, 5780, 1829, 5145, 1014, 3817, 2064, 4192, 4838, 5910, 236, 29, 881, 4921, 1051, 1524, 6329, 2754, 1004, 2522, 3704, 1566, 4621, 5542, 5309, 2320, 6147, 143, 5038, 2260, 4449, 4795, 3972, 3296, 584, 2501, 1192, 4477, 523, 4864, 4673, 3987, 5758, 3660, 6126, 3124, 53, 5894, 2490, 6009, 5307, 5544, 6252, 6217, 3883, 368, 2998, 357, 4090, 3550, 2851, 2139, 4492, 4725, 5211, 4428, 6221, 3482, 4682, 4468, 2588, 4831, 717, 4224, 4222, 719, 197, 649, 3488, 2306, 2177, 365, 5275, 832, 5249, 4056, 2549, 7, 4554, 5394, 1343, 766, 2057, 4135, 4151, 6114, 5563, 419, 1523, 1136, 4922, 226, 6234, 2432, 2971, 3743, 2384, 5426, 3313, 2924, 1835, 2770, 2871, 204, 783, 2867, 3752, 2008, 1262, 3138, 5061, 2115, 2961, 3026, 1630, 1476, 5913, 1429, 5987, 3981, 1502, 4402, 2094, 6305, 4032, 3816, 1146, 5146, 5170, 4399, 1839, 2511, 5007, 2554, 4516, 2521, 1132, 2755, 6183, 2786, 3280, 1706, 327, 5459, 4081, 3803, 431, 1318, 2792, 3136, 1264, 2407, 2700, 4338, 1405, 5681, 5408, 319, 1820, 5314, 5033, 4582, 1984, 3847, 2694, 3567, 4206, 2840, 1970, 704, 6203, 1614, 693, 5391, 6057, 3128, 1854, 3161, 127, 5823, 732, 5130, 607, 6354, 2350, 4577, 4214, 1534, 3928, 3268, 3990, 5332, 3063, 6246, 554, 1601, 2880, 4067, 4200, 1879, 1881, 1652, 4558, 4665, 1446, 4211, 848, 5150, 1904, 3955, 4364, 5804, 6319, 6257, 4562, 5636, 3115, 2676, 776, 2474, 2019, 3007, 2079, 6047, 5378, 2295, 2479, 5794, 4779, 4252, 639, 4500, 1329, 4524, 1846, 1559, 5026, 5618, 2222, 263, 1674, 4323, 2374, 4418, 5961, 1719, 1307, 2323, 1360, 2987, 1743, 1300, 3615, 411, 3832, 6064, 167, 3780, 4920, 1138, 30, 1489, 3242, 1667, 1363, 3275, 74, 2844, 1779, 5766, 23, 3327, 5808, 1333, 5873, 805, 97, 659, 5582, 3684, 1789, 5089, 3392, 1289, 3631, 3486, 651, 188, 3019, 4777, 5796, 5149, 934, 4212, 4579, 2002, 3093, 4671, 4866, 3013, 5622, 3948, 2270, 527, 5855, 5969, 1753, 5248, 1067, 5276, 124, 4165, 1627, 2740, 3763, 2329, 303, 1916, 5753, 444, 2600, 4995, 3207, 4976, 2949, 6053, 1655, 260, 5321, 5957, 2254, 2312, 1383, 6034, 96, 865, 5874, 2965, 4735, 1889, 336, 1159, 4247, 5101, 2943, 4857, 5715, 5513, 2692, 3849, 4807, 1756, 746, 301, 2331, 5049, 2866, 1036, 205, 1774, 1809, 386, 2396, 2473, 922, 2677, 3373, 1198, 4944, 390, 3548, 4092, 1480, 2056, 1059, 1344, 5071, 6282, 2103, 5678, 488, 1321, 1348, 5472, 4154, 4692, 3361, 5535, 2428, 1590, 1473, 214, 5154, 300, 788, 1757, 1442, 4974, 3209, 4109, 1812, 5450, 3261, 1499, 712, 548, 6061, 5129, 960, 5824, 1662, 535, 4612, 4276, 546, 714, 2046, 2958, 3572, 3515, 196, 1075, 4223, 1078, 4832, 2045, 725, 547, 736, 1500, 3983, 10, 4463, 2014, 2505, 6202, 971, 1971, 4283, 4890, 4742, 6164, 4271, 5614, 5888, 4969, 5390, 968, 1615, 1174, 6337, 6198, 5938, 1218, 2299, 1352, 1270, 2496, 1751, 5971, 4647, 6327, 1526, 2537, 4599, 4568, 2643, 3766, 2119, 3587, 3097, 4132, 2533, 1733, 116, 1815, 1712, 646, 2932, 1517, 5581, 863, 98, 2148, 361, 5916, 1787, 3686, 187, 854, 3487, 1073, 198, 2931, 663, 1713, 2796, 5967, 5857, 2361, 4499, 910, 4253, 492, 4989, 2705, 2669, 4811, 6273, 4017, 1460, 6100, 4951, 2821, 4457, 624, 625, 4458, 5553, 5932, 5190, 3105, 2387, 5267, 2716, 4350, 1155, 4510, 2400, 4880, 4595, 5504, 6353, 958, 5131, 3599, 1153, 4352, 3723, 394, 3512, 374, 428, 2578, 5003, 5226, 4547, 5136, 2341, 2561, 542, 2483, 6298, 3231, 2365, 2500, 1116, 3297, 3895, 5462, 1597, 5525, 1227, 1207, 134, 5186, 3916, 1260, 2010, 5446, 57, 3468, 3047, 5507, 5043, 3131, 4710, 4639, 285, 4519, 3216, 218, 5001, 2580, 3354, 1600, 946, 6247, 5414, 5644, 4714, 6060, 735, 713, 726, 4277, 3076, 2482, 590, 2562, 3288, 2074, 1437, 1297, 4611, 729, 1663, 1738, 13, 4414, 1531, 1896, 5854, 837, 2271, 451, 4863, 1112, 4478, 5847, 5539, 407, 5733, 4015, 6275, 4229, 6051, 2951, 2857, 1588, 2430, 6236, 1258, 3918, 2424, 5021, 5107, 5041, 5509, 5571, 3411, 4544, 1232, 2635, 6271, 4813, 2302, 4988, 637, 4254, 2790, 1320, 760, 5679, 1407, 3227, 4408, 6255, 6321, 5272, 3886, 6334, 2780, 3067, 162, 4290, 6118, 3201, 1760, 3757, 3303, 2956, 2048, 3926, 1536, 5234, 6140, 4898, 5351, 4947, 6013, 5720, 4589, 5214, 2130, 2626, 2674, 3117, 4862, 525, 2272, 2462, 3437, 4645, 5973, 2599, 821, 5754, 1186, 2275, 2977, 3333, 176, 5687, 5158, 280, 2665, 1609, 1317, 994, 3804, 2577, 598, 375, 3180, 3924, 2050, 4003, 2968, 6025, 1522, 1053, 5564, 4122, 4178, 1956, 5479, 4657, 3831, 887, 3616, 3578, 5732, 519, 5540, 4623, 5694, 1729, 5929, 3777, 2317, 3828, 3340, 4652, 1324, 3511, 601, 3724, 2071, 3547, 771, 4945, 5353, 2395, 779, 1810, 4111, 2687, 6190, 4982, 2641, 4570, 3010, 4696, 3179, 427, 599, 3513, 3574, 1844, 4526, 2997, 1095, 3884, 5274, 1069, 2178, 1427, 5915, 656, 2149, 2155, 4089, 1093, 2999, 19, 4027, 6030, 3941, 3406, 5954, 4854, 3564, 1935, 2347, 6022, 2435, 2703, 4991, 5568, 6280, 5073, 2762, 1158, 800, 1890, 3465, 3629, 1291, 3033, 1725, 4295, 5458, 998, 1707, 2145, 5861, 3425, 5560, 4721, 1819, 983, 5409, 3248, 1660, 5826, 5641, 1247, 2542, 5490, 6209, 4160, 2326, 2646, 3386, 4634, 1915, 824, 2330, 787, 747, 5155, 4078, 3898, 5121, 4965, 88, 4999, 220, 4550, 4676, 2413, 3998, 2519, 4518, 562, 4640, 6261, 2904, 2664, 435, 5159, 3199, 6120, 4914, 5746, 1425, 2180, 4963, 5123, 4147, 2593, 1457, 3475, 2454, 3791, 1673, 901, 2223, 5320, 813, 1656, 2084, 5901, 3175, 6098, 1462, 3668, 3708, 4768, 2714, 5269, 3252, 3602, 2134, 2639, 4984, 80, 6136, 4170, 6294, 6133, 2206, 28, 1140, 5911, 1478, 4094, 3422, 3520, 5066, 4054, 5251, 6233, 1049, 4923, 2916, 5197, 5134, 4549, 292, 5000, 559, 3217, 1987, 5153, 749, 1474, 1632, 5676, 2105, 1870, 3911, 2940, 1773, 782, 1037, 2872, 3457, 1180, 1282, 2930, 648, 1074, 720, 3516, 4789, 3619, 5373, 3590, 2766, 3018, 853, 652, 3687, 5993, 1394, 2137, 2853, 1311, 4309, 2185, 37, 5686, 438, 3334, 3869, 5670, 5405, 4762, 3772, 2315, 3779, 884, 6065, 2216, 1995, 4289, 476, 3068, 1965, 122, 5278, 2493, 4606, 1946, 5291, 2894, 1647, 1573, 3936, 1422, 3556, 3624, 2726, 4825, 5037, 1123, 6148, 5327, 3944, 5866, 5118, 4359, 3872, 5185, 576, 1208, 1801, 4266, 3311, 5428, 5822, 962, 3162, 4164, 830, 5277, 159, 1966, 5892, 55, 5448, 1814, 666, 1734, 6092, 3472, 4020, 2724, 3626, 60, 3932, 2947, 4978, 3739, 5879, 1563, 5743, 2359, 5859, 2147, 658, 864, 806, 6035, 1303, 5612, 4273, 2621, 4369, 4998, 294, 4966, 3150, 4629, 1767, 4431, 2204, 6135, 243, 4985, 3891, 5787, 3145, 2843, 874, 3276, 2245, 4280, 5358, 2344, 3996, 2415, 2158, 4482, 1923, 1954, 4180, 3931, 109, 3627, 3467, 570, 5447, 119, 5893, 1104, 3125, 4717, 4293, 1727, 5696, 4850, 5241, 3622, 3558, 2884, 2488, 5896, 3596, 5200, 5685, 178, 2186, 4687, 4829, 2590, 3907, 1488, 880, 1139, 237, 2207, 3060, 3453, 3326, 870, 5767, 5418, 4026, 355, 3000, 5179, 2975, 2277, 4413, 532, 1739, 4462, 709, 3984, 4553, 1063, 2550, 1594, 2125, 3187, 6373]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-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(), 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-s7/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b235b38fe6215238c985b1ee5b9312c61cf5815e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 6373, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l5-s7/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l5-s9/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l5-s9/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a31f11bc4fa29e9b93181c43bd72e107bab11f6 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 7883, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s9/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bbd4ca782a856867f10e6a6bab0de7af7c5dcf4e --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 3943, 2629, 1972, 4731, 1315, 6758, 4928, 877, 2366, 2151, 658, 3033, 7321, 6833, 6406, 3247, 439, 4150, 5125, 4881, 1076, 1372, 4271, 947, 1517, 293, 3661, 1632, 3417, 6104, 7145, 5973, 1624, 2929, 220, 3836, 6017, 6267, 2563, 5000, 2441, 551, 4480, 4906, 4628, 4865, 2136, 6597, 474, 1083, 759, 2827, 147, 431, 1831, 1384, 4758, 2406, 1709, 1681, 6994, 6883, 3573, 2184, 2987, 4119, 4754, 458, 1465, 3887, 4052, 109, 5860, 2944, 3009, 7065, 3134, 1398, 1282, 2726, 6442, 3990, 1221, 5380, 276, 5800, 6182, 7264, 6395, 7191, 6256, 4663, 2433, 3984, 5010, 3333, 3299, 7247, 4179, 1562, 542, 6736, 380, 977, 1414, 3832, 74, 2026, 216, 3907, 916, 4675, 4634, 5005, 6321, 7345, 5145, 2717, 855, 3063, 841, 4295, 7439, 4920, 3442, 870, 1787, 2812, 5034, 4454, 1494, 2846, 2060, 1636, 6319, 5007, 4171, 4141, 733, 4250, 1944, 7443, 5968, 5057, 55, 7455, 6872, 1694, 5414, 5848, 1505, 5617, 3533, 7528, 5509, 955, 4641, 943, 4583, 1323, 5305, 2806, 7163, 2772, 5937, 2550, 611, 1447, 6632, 462, 4080, 1368, 6842, 6893, 7033, 6058, 7574, 2247, 3198, 1656, 3596, 561, 7070, 768, 2332, 2446, 1217, 2295, 5934, 455, 6447, 6046, 1667, 5984, 1650, 5243, 3624, 6656, 2090, 6629, 4723, 234, 4213, 4154, 7310, 2781, 4132, 4678, 489, 6950, 4649, 3924, 5858, 111, 3979, 1999, 4955, 37, 4050, 3889, 1954, 708, 4400, 982, 2338, 383, 6259, 4958, 2503, 7611, 3161, 204, 3673, 4127, 2573, 5722, 1359, 1980, 428, 1015, 1532, 3537, 421, 6050, 2148, 6384, 3720, 6586, 6402, 6879, 5663, 7292, 4377, 1794, 894, 6289, 5348, 1675, 6459, 1934, 6169, 5636, 4689, 5296, 5365, 2422, 4972, 2404, 4760, 2299, 3160, 7653, 2504, 87, 2086, 7201, 2071, 1555, 367, 5780, 6067, 5962, 4914, 6584, 3722, 7472, 6926, 4829, 2529, 6367, 28, 4225, 3728, 482, 7378, 5044, 4789, 2532, 6649, 3458, 6866, 3149, 753, 337, 2809, 7088, 1767, 2246, 7706, 6059, 2755, 7204, 478, 2954, 2321, 5820, 472, 6599, 2292, 1278, 662, 3491, 2653, 6744, 5345, 676, 3582, 1822, 5328, 906, 2969, 1303, 5217, 7131, 306, 5077, 724, 1559, 7258, 4139, 4173, 6574, 5982, 1669, 4626, 4908, 7363, 3231, 3447, 2449, 3517, 3976, 6971, 5508, 7729, 3534, 1124, 528, 5541, 5613, 4770, 6277, 5740, 6329, 281, 2106, 7477, 4060, 4326, 2657, 5108, 5834, 5165, 6896, 609, 2552, 1148, 105, 6909, 5546, 228, 1627, 3224, 4567, 6965, 938, 834, 7195, 6934, 4255, 4767, 4113, 2622, 1857, 5754, 4012, 7270, 3577, 4987, 5525, 3315, 2896, 2362, 546, 4059, 7516, 2107, 6265, 6019, 6925, 7597, 3723, 1391, 3952, 6008, 1381, 6281, 4347, 245, 1836, 7417, 4045, 2325, 4230, 5904, 241, 6871, 7737, 56, 6055, 1990, 3278, 1000, 4314, 2478, 4637, 19, 3736, 5967, 7741, 1945, 3293, 4919, 7760, 4296, 3193, 6142, 1546, 4433, 3322, 5111, 1950, 192, 1439, 3130, 70, 6421, 1873, 1252, 172, 3806, 4598, 1581, 2510, 4044, 7462, 1837, 6220, 2064, 319, 1287, 51, 6803, 7104, 680, 315, 4932, 7308, 4156, 296, 508, 5697, 4708, 2244, 1769, 3206, 211, 936, 6967, 3212, 5016, 4734, 7134, 6180, 5802, 7313, 7235, 1328, 7143, 6106, 3440, 4922, 2832, 5043, 7588, 483, 2189, 7280, 4839, 4521, 4389, 5410, 3145, 1348, 6616, 4743, 838, 5712, 3230, 7536, 4909, 4357, 3085, 4926, 6760, 360, 2345, 3488, 6590, 2020, 2683, 5843, 5153, 5497, 6428, 6005, 5144, 7767, 6322, 103, 1150, 5808, 5522, 406, 3827, 2033, 5194, 5443, 44, 3406, 4985, 3579, 3601, 5512, 1036, 3525, 778, 4288, 184, 816, 6832, 7870, 3034, 4089, 6923, 6021, 6399, 666, 7234, 7387, 5803, 2780, 7678, 4155, 7405, 4933, 2415, 2016, 1265, 1697, 3184, 5991, 3956, 4623, 2113, 5225, 5806, 1152, 4183, 4376, 7631, 5664, 6464, 5274, 2395, 4847, 5208, 5831, 3325, 4618, 5671, 4838, 7375, 2190, 1575, 988, 377, 5334, 169, 6439, 1405, 3576, 7486, 4013, 884, 6913, 5065, 6394, 7795, 6183, 3030, 4417, 1378, 4138, 7544, 1560, 4181, 1154, 5419, 6135, 1161, 4945, 6852, 3328, 4178, 7785, 3300, 6564, 5088, 2436, 4581, 945, 4273, 5293, 1746, 6824, 1327, 7386, 7314, 667, 2673, 4697, 4280, 7198, 5733, 13, 4853, 3470, 6606, 323, 4395, 1297, 1485, 570, 652, 5213, 2609, 5492, 3566, 1587, 4095, 1594, 2539, 328, 4304, 4286, 780, 477, 7571, 2756, 2070, 7607, 2087, 5732, 7229, 4281, 6933, 7495, 835, 4222, 6255, 7793, 6396, 829, 3682, 3541, 1616, 5324, 1724, 2430, 1225, 3522, 1759, 4004, 5930, 224, 3486, 2347, 6696, 1908, 3865, 3351, 5709, 3066, 4504, 5916, 4206, 911, 2771, 7720, 2807, 339, 6327, 5742, 3139, 3666, 6812, 6435, 3165, 3743, 141, 3636, 4995, 4645, 3739, 1092, 5972, 7852, 6105, 7384, 1329, 4160, 6496, 6646, 6859, 2196, 2583, 6179, 7390, 4735, 305, 7549, 5218, 2747, 4516, 6801, 53, 5059, 3455, 2311, 6715, 5921, 4056, 5854, 814, 186, 5554, 2615, 2284, 2097, 3483, 6905, 4411, 3083, 4359, 559, 3598, 679, 7409, 6804, 2128, 3273, 2384, 3345, 2057, 1213, 5253, 4507, 929, 2921, 6819, 1343, 5948, 1766, 7577, 2810, 1789, 6779, 2494, 808, 2763, 3594, 1658, 1842, 5390, 802, 5123, 4152, 4215, 3821, 2030, 767, 7700, 562, 1054, 3764, 3133, 7807, 3010, 6751, 3463, 1773, 3799, 5285, 1862, 1488, 696, 4204, 5918, 2401, 6946, 389, 691, 3664, 3141, 519, 2174, 4821, 123, 3591, 4860, 4555, 3709, 5020, 2023, 4943, 1163, 1988, 6057, 7708, 6894, 5167, 121, 4823, 3436, 3386, 3869, 2231, 3970, 5119, 3028, 6185, 4937, 1851, 5581, 4238, 4442, 128, 6099, 6988, 5181, 2123, 2319, 2956, 10, 5520, 5810, 1409, 2984, 2229, 3871, 617, 973, 2789, 1647, 6071, 2460, 6882, 7822, 1682, 6090, 257, 1597, 5180, 7013, 6100, 4715, 5648, 2217, 5268, 5603, 3781, 2556, 332, 4917, 3295, 4038, 3678, 720, 5115, 5507, 7530, 3977, 113, 3211, 7394, 937, 7498, 4568, 4991, 4028, 5151, 5845, 1731, 6241, 3377, 791, 4965, 5197, 4912, 5964, 4648, 7673, 490, 919, 388, 7052, 2402, 4974, 3243, 160, 3303, 644, 3613, 26, 6369, 3402, 4254, 7494, 7196, 4282, 2375, 158, 3245, 6408, 4828, 7596, 7473, 6020, 7318, 4090, 5682, 4196, 1210, 2849, 3433, 6296, 3792, 5064, 7267, 885, 5097, 5545, 7504, 106, 6472, 4410, 7111, 3484, 226, 5548, 6224, 6450, 2626, 6309, 608, 7509, 5166, 7032, 7709, 6843, 5558, 3657, 1332, 3618, 5765, 4606, 435, 3572, 7821, 6995, 2461, 5662, 7633, 6403, 3054, 5358, 2587, 2522, 1693, 7736, 7456, 242, 6354, 1095, 3148, 7582, 3459, 2420, 5367, 2261, 4008, 2195, 7138, 6647, 2534, 1573, 2192, 4616, 3327, 7250, 4946, 2372, 557, 4361, 6128, 6798, 6708, 5557, 6892, 7710, 1369, 2455, 2513, 2179, 6333, 1543, 3052, 6405, 7869, 7322, 817, 4122, 4544, 1173, 6467, 5686, 1326, 7237, 1747, 4952, 2159, 1342, 7092, 2922, 6037, 2577, 4514, 2749, 6434, 7156, 3667, 3003, 23, 6514, 5432, 3884, 2127, 7103, 7410, 52, 7127, 4517, 6707, 6846, 6129, 6703, 2093, 4145, 738, 1914, 1530, 1017, 4738, 6539, 2049, 2722, 5768, 3964, 5958, 5645, 2288, 2493, 7085, 1790, 1354, 1801, 1906, 6698, 5876, 4460, 3514, 1763, 1719, 4331, 6529, 6086, 4573, 4034, 6351, 4350, 359, 7358, 4927, 7877, 1316, 5459, 4337, 2045, 3479, 3462, 7063, 3011, 1654, 3200, 5291, 4275, 5344, 7559, 2654, 3694, 4477, 2902, 2569, 5332, 379, 7781, 543, 2078, 590, 3703, 630, 2467, 1523, 1208, 4198, 4950, 1749, 633, 2941, 849, 5898, 5534, 6348, 2996, 2399, 5920, 7122, 2312, 3340, 1057, 1419, 2613, 5556, 6845, 6799, 4518, 6627, 2092, 6796, 6130, 3586, 3816, 5875, 6774, 1907, 7174, 2348, 6579, 1338, 1198, 4970, 2424, 3550, 6546, 1193, 2916, 2335, 1663, 5823, 6251, 4470, 2836, 3357, 6361, 1157, 3688, 966, 5037, 5827, 788, 2633, 4436, 5438, 189, 5591, 6609, 3894, 85, 2506, 3220, 5454, 703, 4364, 5730, 2089, 7685, 3625, 2007, 3427, 4384, 2309, 3457, 7584, 2533, 6858, 7139, 6497, 3898, 3717, 3092, 6159, 5457, 1318, 2209, 6272, 4631, 4135, 6011, 461, 7714, 1448, 4722, 7683, 2091, 6705, 4519, 4841, 2710, 4502, 3068, 5868, 581, 6189, 2473, 4742, 7368, 1349, 5606, 1688, 6031, 3122, 3893, 6666, 5592, 322, 7224, 3471, 6486, 81, 5160, 3282, 2291, 7565, 473, 7835, 2137, 5609, 2647, 1497, 4815, 2019, 7354, 3489, 664, 6401, 7635, 3721, 7599, 4915, 334, 2669, 1337, 6694, 2349, 1539, 6082, 5981, 7541, 4174, 2867, 3153, 7, 1128, 2427, 1246, 5677, 5087, 7245, 3301, 162, 2581, 2198, 1060, 649, 500, 743, 3726, 4227, 996, 4268, 6376, 2607, 5215, 1305, 1192, 6688, 3551, 5725, 1065, 794, 1938, 2048, 6788, 4739, 516, 1270, 2280, 4106, 4243, 6094, 1108, 6085, 6767, 4332, 2162, 239, 5906, 3786, 4235, 5320, 2887, 4977, 3108, 3804, 174, 1044, 5431, 6808, 24, 3615, 1511, 2141, 4748, 3467, 625, 3748, 1876, 418, 1605, 6053, 58, 3128, 1441, 3897, 6645, 7140, 4161, 415, 3934, 5783, 3204, 1771, 3465, 4750, 80, 6604, 3472, 4804, 2488, 5157, 1445, 613, 4310, 5703, 2074, 880, 4902, 5944, 4409, 6907, 107, 4054, 5923, 5685, 6827, 1174, 5273, 7290, 5665, 4896, 3768, 1933, 7624, 1676, 2857, 2855, 1678, 5475, 5361, 6194, 2625, 6900, 6225, 6045, 7692, 456, 4756, 1386, 3989, 7802, 2727, 1404, 7273, 170, 1254, 3164, 7155, 6813, 2750, 1570, 6213, 5775, 6004, 7348, 5498, 3218, 2508, 1583, 3697, 1872, 7426, 71, 3999, 5760, 5568, 2498, 5818, 2323, 4047, 1870, 3699, 4488, 4827, 6928, 3246, 7868, 6834, 3053, 6878, 7634, 6587, 665, 7316, 6022, 828, 7190, 7794, 7265, 5066, 3430, 133, 5040, 5237, 1292, 3071, 3090, 3719, 7637, 2149, 2368, 2036, 153, 2269, 3775, 2606, 6551, 4269, 1374, 5745, 6200, 5529, 3401, 6937, 27, 7593, 2530, 4791, 1728, 5417, 1156, 6678, 3358, 4798, 2961, 5055, 5970, 1094, 6869, 243, 4349, 6763, 4035, 2995, 6719, 5535, 1308, 1804, 5084, 1551, 1049, 4834, 1742, 450, 3453, 5061, 2206, 2800, 1542, 6837, 2180, 5813, 280, 7519, 5741, 7160, 340, 628, 3705, 102, 7344, 7768, 5006, 7748, 1637, 5092, 5134, 1453, 1673, 5350, 1029, 5694, 607, 6898, 2627, 3945, 2254, 3286, 465, 5376, 1461, 4189, 3410, 4318, 672, 3791, 6916, 3434, 4825, 4490, 3789, 674, 5347, 7627, 895, 2706, 3390, 4576, 5189, 4201, 4346, 7466, 1382, 1833, 5739, 7521, 4771, 2872, 4863, 4630, 6637, 2210, 4343, 699, 2562, 7845, 6018, 7475, 2108, 1883, 1911, 35, 4957, 7656, 384, 4662, 7792, 7192, 4223, 30, 4469, 6682, 5824, 136, 1567, 2794, 3904, 5888, 5447, 3306, 3376, 6958, 1732, 5095, 887, 1815, 1900, 197, 2643, 1887, 4873, 1136, 4686, 182, 4290, 805, 6044, 6449, 6901, 5549, 1201, 2063, 7415, 1838, 195, 1902, 346, 3260, 5774, 6431, 1571, 2536, 260, 1427, 5029, 1430, 2411, 6175, 62, 892, 1796, 5528, 6372, 5746, 2278, 1272, 1855, 2624, 6452, 5362, 1012, 150, 2472, 6619, 582, 4702, 4936, 7021, 3029, 7263, 7796, 5801, 7389, 7135, 2584, 5478, 61, 6205, 2412, 4705, 5660, 2463, 5635, 7622, 1935, 6121, 1116, 3555, 5927, 6148, 2560, 701, 5456, 6641, 3093, 1521, 2469, 2039, 926, 1645, 2791, 2753, 6061, 2559, 6163, 5928, 4006, 2263, 3050, 1545, 7436, 3194, 2591, 647, 1062, 2934, 1160, 7253, 5420, 2252, 3947, 3585, 6702, 6797, 6847, 4362, 705, 3882, 5434, 4370, 1115, 6167, 1936, 796, 309, 5640, 487, 4680, 1395, 4421, 824, 4087, 3036, 2679, 5172, 3439, 7383, 7144, 7853, 3418, 4783, 4714, 6987, 7014, 129, 5074, 799, 1107, 6532, 4244, 3507, 256, 6992, 1683, 2358, 4572, 6766, 6530, 1109, 5980, 6576, 1540, 2802, 2700, 1891, 2745, 5220, 4241, 4108, 5281, 2459, 6997, 1648, 5986, 5961, 7602, 5781, 3936, 4302, 330, 2558, 6150, 2754, 7573, 7707, 7034, 1989, 7453, 57, 6502, 1606, 2147, 7639, 422, 469, 1666, 7691, 6448, 6226, 806, 2496, 5570, 5956, 3966, 2576, 6817, 2923, 2947, 866, 2305, 3121, 6612, 1689, 5262, 396, 2132, 2483, 2999, 2599, 827, 6398, 7317, 6924, 7474, 6266, 7846, 3837, 1473, 4187, 1463, 460, 6634, 4136, 1380, 7468, 3953, 5143, 7347, 6429, 5776, 1622, 5975, 4022, 5241, 1652, 3013, 4264, 5184, 1807, 5141, 3955, 7301, 3185, 3175, 5643, 5960, 6069, 1649, 7689, 1668, 7540, 6575, 6083, 1110, 1188, 712, 4021, 6001, 1623, 7851, 7146, 1093, 6356, 5056, 7740, 7444, 3737, 4647, 6952, 4913, 7601, 6068, 5987, 5644, 6783, 3965, 6040, 5571, 4547, 4116, 1425, 262, 1717, 1765, 7090, 1344, 5838, 4408, 6474, 4903, 3634, 143, 443, 4593, 2549, 7718, 2773, 454, 7694, 2296, 3995, 223, 7178, 4005, 6147, 6164, 3556, 4194, 5684, 6469, 4055, 7121, 6716, 2400, 7054, 4205, 7167, 4505, 5255, 5, 3155, 3505, 4246, 5102, 3755, 3785, 6525, 240, 7458, 4231, 3855, 2736, 3422, 5533, 6721, 850, 1829, 433, 4608, 3018, 5751, 5404, 2883, 5446, 6245, 3905, 218, 2931, 5728, 4366, 3911, 3362, 3498, 4259, 1231, 4459, 6773, 6699, 3817, 5289, 3202, 5785, 5469, 580, 6621, 3069, 1294, 532, 5203, 2864, 847, 2943, 7810, 110, 7670, 3925, 4063, 813, 7119, 4057, 548, 2692, 5516, 1504, 7733, 5415, 1730, 6960, 5152, 7351, 2684, 3547, 1131, 4407, 5946, 1345, 1098, 5164, 7511, 5109, 3324, 7285, 5209, 4539, 787, 6673, 5038, 135, 6250, 6683, 1664, 471, 7567, 2322, 6415, 2499, 5128, 683, 279, 6331, 2181, 1408, 7006, 5521, 7341, 1151, 7296, 5226, 2779, 7312, 7388, 6181, 7797, 277, 685, 2154, 1228, 201, 1257, 1181, 1090, 3741, 3167, 5600, 772, 4403, 5468, 5871, 3203, 6492, 3935, 6066, 7603, 368, 409, 1621, 6003, 6430, 6214, 3261, 587, 2661, 3234, 3963, 6785, 2723, 4605, 6887, 3619, 2703, 874, 5567, 6418, 4000, 1080, 783, 4613, 4011, 7488, 1858, 5403, 5892, 3019, 49, 1289, 2277, 6199, 6373, 1375, 3138, 7159, 6328, 7520, 6278, 1834, 247, 1502, 5518, 12, 7228, 7199, 2088, 6658, 4365, 5884, 2932, 1064, 6544, 3552, 1358, 7647, 2574, 3968, 2233, 3564, 5494, 2259, 5369, 3354, 3229, 7365, 839, 3065, 7170, 3352, 5371, 1047, 1553, 2073, 6478, 4311, 66, 4899, 5658, 4707, 7401, 509, 606, 6311, 1030, 3270, 3876, 1025, 748, 5303, 1325, 6826, 6468, 5924, 4195, 6921, 4091, 2823, 1549, 5086, 6566, 1247, 1614, 3543, 5620, 4837, 7282, 4619, 2236, 901, 2618, 4895, 6463, 7291, 7632, 6880, 2462, 6172, 4706, 5699, 4900, 882, 4015, 860, 3916, 2166, 4322, 3265, 2216, 6985, 4716, 2287, 6782, 5959, 5988, 3176, 486, 6117, 310, 180, 4688, 7621, 6170, 2464, 1752, 3939, 1579, 4600, 5395, 2730, 2390, 2169, 2517, 1023, 3878, 1740, 4836, 5673, 3544, 3532, 7731, 1506, 4111, 4769, 7523, 5542, 3861, 2646, 6595, 2138, 1687, 6614, 1350, 3780, 6982, 5269, 771, 5789, 3168, 2239, 1104, 5393, 4602, 1285, 321, 6608, 6667, 190, 1952, 3891, 3124, 272, 4726, 4981, 5318, 4237, 7018, 1852, 4765, 4257, 3500, 1234, 4429, 762, 1171, 4546, 5955, 6041, 2497, 6417, 5761, 875, 4930, 317, 2066, 1471, 3839, 425, 3656, 6891, 6844, 6709, 2614, 7116, 187, 5440, 4968, 1200, 6223, 6902, 227, 7503, 6910, 5098, 3860, 5612, 7524, 529, 4398, 710, 1190, 1307, 6347, 6720, 5899, 3423, 4373, 3400, 6371, 6201, 1797, 3314, 7483, 4988, 405, 7340, 5809, 7007, 11, 5735, 1503, 5850, 2693, 2938, 1035, 7329, 3602, 954, 7728, 7529, 6972, 5116, 3076, 3290, 5338, 4611, 785, 4541, 3217, 6427, 7349, 5154, 2258, 5717, 3565, 7215, 2610, 597, 3039, 5400, 4888, 1168, 1966, 832, 940, 2912, 270, 3126, 60, 6177, 2585, 5360, 6454, 1679, 1711, 3181, 2951, 579, 5870, 5786, 4404, 4425, 1021, 2519, 268, 2914, 1195, 4336, 6756, 1317, 6640, 6160, 702, 6661, 3221, 95, 3902, 2796, 642, 3305, 6244, 5889, 2884, 43, 7335, 5195, 4967, 5552, 188, 6669, 4437, 352, 4369, 6124, 3883, 6807, 6515, 1045, 5373, 3843, 2603, 1813, 889, 1004, 2224, 1714, 2251, 6134, 7254, 1155, 6363, 1729, 5847, 7734, 1695, 1267, 3144, 7371, 4390, 3570, 437, 3249, 2882, 5891, 5752, 1859, 4887, 5488, 3040, 3080, 1402, 2729, 5629, 4601, 5596, 1105, 801, 7078, 1843, 2316, 1469, 2068, 2758, 3006, 2926, 231, 275, 7799, 1222, 4666, 1460, 6303, 466, 3842, 5429, 1046, 5707, 3353, 5715, 2260, 6863, 2421, 7618, 5297, 1011, 6193, 6453, 5476, 2586, 6876, 3055, 291, 1519, 3095, 300, 1237, 1028, 6313, 1674, 7626, 6290, 675, 7558, 6745, 4276, 4786, 2639, 3016, 4610, 5503, 3291, 1947, 168, 7275, 378, 6738, 2570, 4103, 905, 7554, 1823, 1736, 1723, 7185, 1617, 41, 2886, 6522, 4236, 5583, 4982, 1146, 2554, 3783, 3757, 237, 2164, 3918, 1847, 1069, 3372, 2805, 7722, 1324, 5688, 749, 1707, 2408, 2526, 1010, 5364, 7619, 4690, 1745, 7239, 4274, 6747, 3201, 5873, 3818, 4885, 1861, 7059, 3800, 4041, 2458, 6073, 4109, 1508, 1335, 2671, 669, 2394, 7289, 6465, 1175, 2330, 770, 5602, 6983, 2218, 2991, 3336, 3771, 395, 6029, 1690, 1434, 986, 1577, 3941, 4, 5914, 4506, 7096, 1214, 3450, 4565, 3226, 2839, 3098, 2544, 4870, 3623, 7687, 1651, 5999, 4023, 2275, 1291, 6389, 5041, 2834, 4472, 4393, 325, 1142, 4192, 3558, 372, 2778, 5805, 7297, 2114, 4652, 4440, 4240, 6076, 2746, 7130, 7550, 1304, 6549, 2608, 7217, 653, 3189, 4538, 5830, 7286, 4848, 1776, 2714, 2863, 5864, 533, 2043, 4339, 4355, 4911, 6954, 4966, 5442, 7336, 2034, 2370, 4948, 4200, 6284, 4577, 4511, 5082, 1806, 5995, 4265, 2122, 7012, 6989, 1598, 4496, 4075, 3043, 1261, 3384, 3438, 6108, 2680, 5023, 2739, 120, 7031, 6895, 7510, 5835, 1099, 2118, 3281, 6602, 82, 1444, 6482, 2489, 2257, 5496, 7350, 5844, 6961, 4029, 1984, 4464, 2861, 2716, 7766, 7346, 6006, 3954, 5993, 1808, 2666, 756, 3370, 1071, 1452, 6316, 5093, 1734, 1825, 313, 682, 5816, 2500, 4880, 7864, 4151, 7076, 803, 4292, 3027, 7023, 3971, 3075, 5506, 6973, 721, 166, 1949, 7432, 3323, 5833, 7512, 2658, 2081, 574, 208, 3754, 5909, 4247, 2892, 3859, 5544, 6911, 886, 6239, 1733, 5133, 6317, 1638, 3982, 2435, 7244, 6565, 5678, 1550, 6344, 1805, 5186, 4512, 2579, 164, 723, 7547, 307, 798, 6097, 130, 2852, 3106, 4979, 4728, 4382, 3429, 6393, 7266, 6914, 3793, 2205, 6337, 3454, 7125, 54, 7739, 5969, 6357, 2962, 505, 2843, 2650, 3414, 1205, 4529, 4658, 2637, 4788, 7587, 7379, 2833, 5236, 6390, 134, 5826, 6674, 967, 4453, 7754, 2813, 4780, 5027, 1429, 6208, 1428, 5031, 4781, 3420, 2738, 5170, 2681, 2022, 7039, 3710, 1313, 4733, 7392, 3213, 3113, 1610, 3023, 3332, 7788, 3985, 4170, 7747, 6320, 7769, 4635, 2480, 1995, 2440, 7843, 2564, 1364, 2909, 4644, 7150, 3637, 2785, 4027, 6963, 4569, 404, 5524, 7484, 3578, 7332, 3407, 1145, 5317, 5584, 4727, 5070, 3107, 6520, 2888, 3242, 6944, 2403, 7616, 2423, 6691, 1199, 5551, 5441, 5196, 6955, 792, 1067, 1849, 4939, 4878, 2502, 7655, 6260, 36, 7666, 2000, 2158, 6822, 1748, 6726, 4199, 5191, 2371, 6851, 7251, 1162, 7037, 2024, 76, 4877, 4961, 1850, 7020, 6186, 4703, 2414, 7307, 7406, 316, 5565, 876, 7876, 6759, 7359, 3086, 1527, 2831, 7381, 3441, 7759, 7440, 3294, 6978, 333, 6583, 7600, 5963, 6953, 5198, 4356, 7362, 7537, 4627, 7839, 4481, 3633, 5943, 6475, 881, 5657, 5700, 67, 3767, 6462, 5666, 2619, 4550, 4588, 3849, 1536, 1167, 5487, 5401, 1860, 5287, 3819, 4217, 1075, 7863, 5126, 2501, 4960, 4940, 77, 821, 1135, 6232, 1888, 3622, 5245, 2545, 3276, 1992, 2135, 7837, 4629, 6274, 2873, 4554, 7042, 3592, 2765, 863, 1701, 623, 3469, 7226, 14, 565, 3797, 1775, 5207, 7287, 2396, 2486, 4806, 3809, 2709, 6625, 4520, 7374, 7281, 5672, 5621, 1741, 6341, 1050, 1481, 1008, 2528, 7595, 6927, 6409, 4489, 6294, 3435, 7029, 122, 7045, 2175, 716, 3382, 1263, 2018, 6592, 1498, 4796, 3360, 3913, 2768, 2380, 4596, 3808, 4844, 2487, 6484, 3473, 776, 3527, 525, 2960, 6359, 3359, 4813, 1499, 4167, 1243, 1727, 6365, 2531, 7586, 5045, 2638, 5342, 4277, 4713, 6102, 3419, 5026, 5032, 2814, 2907, 1366, 4082, 4210, 3760, 4671, 2871, 6276, 7522, 5614, 4112, 7492, 4256, 5579, 1853, 1274, 3993, 2298, 7614, 2405, 7826, 1385, 6445, 457, 7816, 4120, 819, 79, 6488, 3466, 6509, 2142, 727, 4220, 837, 7367, 6617, 2474, 515, 6538, 6789, 1018, 304, 7133, 7391, 5017, 1314, 7879, 1973, 4381, 5069, 4980, 5585, 273, 233, 7682, 6630, 1449, 731, 4143, 2095, 2286, 5647, 6986, 6101, 4784, 4278, 4699, 1896, 2243, 7400, 5698, 5659, 6173, 2413, 4935, 6187, 583, 1895, 4711, 4279, 7231, 2674, 3348, 3814, 3588, 448, 1744, 5295, 7620, 5637, 181, 6230, 1137, 2595, 2013, 2101, 1394, 6115, 488, 7675, 4133, 4633, 7771, 917, 492, 2870, 4773, 3761, 3343, 2386, 1459, 5378, 1223, 2432, 7791, 6257, 385, 3319, 2636, 5047, 4530, 2172, 521, 350, 4439, 5223, 2115, 3923, 7672, 6951, 5965, 3738, 7149, 4996, 2910, 942, 7726, 956, 1478, 18, 7447, 2479, 5004, 7770, 4676, 4134, 6636, 6273, 4864, 7838, 4907, 7538, 1670, 2112, 7299, 3957, 3562, 2235, 5670, 7283, 3326, 6854, 2193, 4010, 5756, 784, 5502, 5339, 3017, 5894, 434, 6886, 5766, 2724, 1284, 5595, 5394, 5630, 1580, 7421, 3807, 4808, 2381, 2548, 5939, 444, 2967, 908, 3848, 4892, 4551, 99, 639, 1322, 7724, 944, 7242, 2437, 1642, 4510, 5188, 6285, 3391, 4033, 6765, 6087, 2359, 403, 4990, 6964, 7499, 3225, 5250, 3451, 452, 2775, 2053, 601, 3268, 1032, 636, 3708, 7041, 4861, 2874, 98, 4587, 4893, 2620, 4115, 5954, 5572, 1172, 6829, 4123, 3216, 5500, 786, 5829, 5210, 3190, 4072, 4019, 714, 2177, 2515, 2171, 4657, 5048, 1206, 1525, 3088, 3073, 3973, 2004, 4388, 7373, 4840, 6626, 6706, 6800, 7128, 2748, 6815, 2578, 5081, 5187, 4578, 1643, 928, 7095, 5254, 5915, 7168, 3067, 6623, 2711, 4448, 858, 4017, 4074, 5178, 1599, 3310, 3853, 4233, 3788, 6293, 4826, 6410, 3700, 3511, 2355, 1515, 949, 3632, 4905, 7840, 552, 2901, 6741, 3695, 1585, 3568, 4392, 5234, 2835, 6681, 6252, 31, 1782, 3103, 2860, 5148, 1985, 2353, 3513, 6772, 5877, 1232, 3502, 2818, 1493, 7753, 5035, 968, 1590, 3061, 857, 4500, 2712, 1778, 503, 2964, 127, 7016, 4239, 5222, 4653, 351, 5437, 6670, 2634, 3321, 7434, 1547, 2825, 761, 5575, 1235, 302, 1020, 5466, 4405, 1133, 823, 6113, 1396, 3136, 1377, 7261, 3031, 660, 1280, 1400, 3082, 7110, 6906, 6473, 5945, 5839, 1132, 4424, 5467, 5787, 773, 981, 7660, 709, 5539, 530, 1296, 7222, 324, 5233, 4473, 3569, 5409, 7372, 4522, 2005, 3627, 2308, 6652, 3428, 5068, 4729, 1974, 3640, 1793, 7630, 7293, 4184, 3399, 5531, 3424, 1114, 6123, 5435, 353, 3910, 5883, 5729, 6659, 704, 6127, 6848, 558, 7108, 3084, 7361, 4910, 5199, 4340, 2267, 155, 358, 6762, 6352, 244, 7465, 6282, 4202, 698, 6270, 2211, 2266, 4354, 5200, 2044, 6755, 5460, 1196, 1340, 2161, 6528, 6768, 1720, 1959, 3692, 2656, 7514, 4061, 3927, 3264, 5651, 2167, 2392, 671, 6299, 3411, 3494, 2477, 7449, 1001, 65, 5702, 6479, 614, 400, 2899, 554, 4285, 7208, 329, 6064, 3937, 1754, 1184, 4070, 3192, 7438, 7761, 842, 3026, 5121, 804, 6228, 183, 7325, 779, 7207, 4305, 555, 2374, 6932, 7197, 7230, 4698, 4712, 4785, 5343, 6746, 5292, 7240, 946, 7860, 1373, 6375, 6552, 997, 2121, 5183, 5996, 3014, 2641, 199, 1230, 5879, 3499, 5578, 4766, 7493, 6935, 3403, 2981, 1943, 7743, 734, 2891, 5101, 5910, 3506, 6093, 6533, 4107, 6075, 5221, 4441, 7017, 5582, 5319, 6523, 3787, 4492, 3854, 5903, 7459, 2326, 995, 6554, 3727, 7591, 29, 6254, 7193, 836, 4745, 728, 1074, 4883, 3820, 7074, 4153, 7680, 235, 3759, 4775, 4083, 3846, 910, 7166, 5917, 7055, 697, 4345, 6283, 5190, 4949, 6727, 1209, 6920, 5683, 5925, 3557, 5230, 1143, 3409, 6301, 1462, 6014, 1474, 3398, 4375, 7294, 1153, 7256, 1561, 7784, 7248, 3329, 845, 2866, 6573, 7542, 4140, 7746, 5008, 3986, 1242, 4794, 1500, 249, 1300, 287, 414, 6495, 7141, 1330, 3659, 295, 7404, 7309, 7679, 4214, 7075, 5124, 7865, 440, 1919, 3239, 737, 6794, 2094, 4719, 732, 7745, 4172, 7543, 7259, 1379, 6010, 6635, 4632, 4677, 7676, 2782, 1977, 4101, 2572, 7649, 3674, 3111, 3215, 4543, 6830, 818, 4753, 7817, 2988, 1424, 5953, 4548, 2621, 7491, 4768, 5615, 1507, 5280, 6074, 4242, 6534, 2281, 904, 5330, 2571, 4129, 1978, 1361, 3651, 3394, 1593, 7212, 1588, 970, 2822, 5681, 6922, 7319, 3035, 6111, 825, 2601, 3845, 4209, 4776, 1367, 7712, 463, 3288, 3078, 3042, 5177, 4497, 4018, 4536, 3191, 4298, 1185, 2011, 2597, 3001, 3669, 812, 5856, 3926, 4325, 7515, 7478, 547, 5853, 7120, 5922, 6470, 108, 7812, 3888, 7664, 38, 1869, 6413, 2324, 7461, 7418, 2511, 2457, 5283, 3801, 3677, 6976, 3296, 2994, 6350, 6764, 4574, 3392, 3653, 1983, 5150, 6962, 4992, 2786, 2342, 2274, 5240, 6000, 5976, 713, 4535, 4073, 4498, 859, 5655, 883, 7269, 7487, 5755, 4614, 2194, 6861, 2262, 6146, 5929, 7179, 1760, 2452, 1079, 5759, 6419, 72, 3834, 222, 5932, 2297, 4762, 1275, 1220, 7801, 6443, 1387, 1241, 4169, 5009, 7789, 2434, 5090, 1639, 1998, 7668, 112, 6970, 7531, 3518, 2003, 4524, 3074, 5118, 7024, 2232, 5720, 2575, 6039, 5957, 6784, 5769, 3235, 214, 2028, 3823, 3561, 4622, 7300, 5992, 5142, 6007, 7469, 1392, 2103, 1820, 3584, 6132, 2253, 6307, 2628, 7882, 3, 5257, 1578, 5632, 1753, 4301, 6065, 5782, 6493, 416, 1878, 2743, 1893, 585, 3263, 4324, 4062, 5857, 7671, 4650, 2116, 1101, 1928, 1846, 5310, 2165, 5653, 861, 2767, 4811, 3361, 5882, 4367, 354, 915, 7773, 217, 5887, 6246, 2795, 5451, 96, 2876, 3716, 6644, 6498, 1442, 84, 6665, 6610, 3123, 5588, 1953, 7663, 4051, 7813, 1466, 2126, 6806, 5433, 6125, 706, 1956, 1739, 5623, 1024, 5691, 3271, 2130, 398, 616, 7002, 2230, 7026, 3387, 3812, 3350, 7172, 1909, 1885, 2645, 5611, 5543, 5099, 2893, 923, 2735, 5902, 4232, 4493, 3311, 1121, 1535, 4891, 4589, 909, 4208, 4084, 2602, 5428, 5374, 467, 424, 5561, 1472, 6016, 7847, 221, 3997, 73, 7777, 1415, 1963, 765, 2032, 7338, 407, 370, 3560, 3959, 2029, 7073, 4216, 4884, 5288, 5874, 6700, 3587, 4694, 3349, 3867, 3388, 2708, 4843, 4807, 4597, 7422, 173, 6518, 3109, 3676, 4040, 5284, 7060, 1774, 4850, 566, 963, 2204, 5063, 6915, 6297, 673, 6292, 4491, 4234, 6524, 5907, 3756, 5314, 2555, 6981, 5604, 1351, 3643, 1811, 2605, 6378, 2270, 3117, 394, 5264, 3337, 1932, 6461, 4897, 68, 3132, 7067, 1055, 3342, 4670, 4774, 4211, 236, 5313, 3784, 5908, 5103, 209, 3208, 3253, 1250, 1875, 6506, 626, 342, 3713, 140, 7153, 3166, 5791, 1091, 7148, 4646, 5966, 7445, 20, 2761, 810, 3671, 206, 576, 481, 7590, 4226, 6555, 744, 1390, 7471, 7598, 6585, 7636, 6385, 3091, 6643, 3899, 2877, 139, 3745, 343, 1312, 5019, 7040, 4556, 637, 101, 6324, 629, 6732, 591, 3510, 4487, 6411, 1871, 6423, 1584, 4476, 6742, 2655, 4328, 1960, 2202, 965, 6676, 1158, 2936, 2695, 1602, 3540, 7188, 830, 1968, 719, 6975, 4039, 3802, 3110, 4126, 7650, 205, 3732, 811, 4065, 3002, 6811, 7157, 3140, 7049, 692, 1631, 7856, 294, 4158, 1331, 6890, 5559, 426, 1982, 4031, 3393, 4098, 1362, 2566, 2303, 868, 3444, 2664, 1810, 3778, 1352, 1792, 4379, 1975, 2784, 4994, 7151, 142, 5942, 4904, 4482, 950, 392, 3119, 2307, 4386, 2006, 6655, 7686, 5244, 4871, 1889, 2702, 5764, 6888, 1333, 1510, 6512, 25, 6939, 645, 2593, 1139, 2542, 3100, 3173, 3187, 655, 688, 953, 5511, 7330, 3580, 678, 7106, 560, 7702, 1657, 7081, 2764, 4859, 7043, 124, 447, 4693, 3815, 6701, 6131, 3948, 1821, 7556, 677, 3600, 7331, 4986, 7485, 7271, 1406, 2183, 7820, 6884, 436, 5408, 4391, 4474, 1586, 7214, 5493, 5718, 2234, 4621, 3958, 3824, 371, 5229, 4193, 5926, 6165, 1117, 1357, 5724, 6545, 6689, 2425, 1130, 5841, 2685, 3531, 5619, 5674, 1615, 7187, 3683, 1603, 420, 7641, 1533, 1123, 7527, 7730, 5618, 3545, 2686, 2975, 524, 4801, 777, 7327, 1037, 1758, 7181, 1226, 2156, 2002, 3975, 7532, 2450, 1762, 6771, 4461, 2354, 4486, 3701, 592, 255, 6092, 4245, 5911, 3156, 2817, 4457, 1233, 5577, 4258, 5880, 3363, 513, 2476, 4316, 3412, 2652, 7561, 663, 6589, 7355, 2346, 7176, 225, 6904, 7112, 2098, 2418, 3461, 6753, 2046, 1940, 1412, 979, 775, 4803, 6485, 6605, 7225, 4854, 624, 6508, 4749, 6489, 1772, 7062, 6752, 3480, 2419, 6865, 7583, 6650, 2310, 7124, 5060, 6338, 451, 4564, 5251, 1215, 2448, 7534, 3232, 2663, 3646, 869, 7758, 4921, 7382, 6107, 5173, 3385, 7028, 4824, 6295, 6917, 2850, 132, 6392, 5067, 4383, 6653, 2008, 1113, 4372, 5532, 5900, 2737, 5025, 4782, 6103, 7854, 1633, 1204, 5050, 2651, 3493, 4317, 6300, 4190, 1144, 4984, 7333, 45, 2980, 4253, 6936, 6370, 5530, 4374, 4185, 1475, 3059, 1592, 4097, 3652, 4032, 4575, 6286, 2707, 3811, 3868, 7027, 3437, 5174, 1262, 4818, 717, 1970, 2631, 790, 6957, 6242, 3307, 2698, 2804, 5307, 1070, 5137, 757, 1085, 1179, 1259, 3045, 512, 3497, 5881, 3912, 4812, 4797, 6360, 6679, 2837, 3228, 5714, 5370, 5708, 7171, 3866, 3813, 4695, 2675, 2056, 7099, 2385, 4669, 3762, 1056, 6713, 2313, 1931, 3770, 5265, 2992, 3298, 7787, 5011, 3024, 844, 4177, 7249, 6853, 4617, 7284, 5832, 5110, 7433, 4434, 2635, 4660, 386, 921, 2895, 7482, 5526, 1798, 1120, 3852, 4494, 1600, 2697, 3375, 6243, 5448, 643, 6941, 161, 6563, 7246, 7786, 3334, 2993, 4037, 6977, 4918, 7441, 1946, 5337, 5504, 3077, 4078, 464, 6305, 2255, 2491, 2290, 6601, 5161, 2119, 999, 7451, 1991, 4868, 2546, 2383, 7101, 2129, 3875, 5692, 1031, 4559, 602, 2215, 5650, 4323, 3928, 586, 5773, 6215, 347, 2978, 47, 3021, 1612, 1249, 3751, 3209, 115, 2881, 5406, 438, 7867, 6407, 6929, 159, 6943, 4975, 2889, 736, 4147, 1920, 934, 213, 3962, 5770, 2662, 3446, 7535, 7364, 5713, 3355, 2838, 5249, 4566, 7500, 1628, 94, 5453, 6662, 2507, 6426, 5499, 4542, 4124, 3112, 5015, 7393, 6968, 114, 3252, 3752, 210, 7397, 1770, 6491, 5784, 5872, 5290, 6748, 1655, 7704, 2248, 265, 2590, 6141, 7437, 4297, 4071, 4537, 5211, 654, 3606, 3174, 5990, 7302, 1698, 2950, 5472, 1712, 2226, 2187, 485, 5642, 5989, 3186, 3607, 3101, 1784, 899, 2238, 5599, 5790, 3742, 7154, 6436, 1255, 203, 7652, 7612, 2300, 2905, 2816, 3504, 5912, 6, 6571, 2868, 494, 752, 7581, 6867, 1096, 1347, 7370, 5411, 1268, 518, 7048, 3665, 7158, 5743, 1376, 4419, 1397, 7806, 7066, 3765, 69, 7428, 1440, 6500, 59, 5480, 271, 5587, 3892, 6611, 6032, 2306, 3629, 393, 3773, 2271, 363, 1609, 5014, 3214, 4125, 3675, 3803, 6519, 4978, 5071, 2853, 2859, 4466, 1783, 3172, 3608, 2543, 5247, 2840, 299, 5354, 1520, 6158, 6642, 3718, 6386, 3072, 4526, 1526, 4925, 7360, 4358, 7109, 4412, 1401, 5398, 3041, 4077, 3289, 5505, 5117, 3972, 4525, 3089, 6387, 1293, 5867, 6622, 4503, 7169, 5710, 840, 7763, 856, 4450, 1591, 3396, 1476, 958, 290, 5357, 6877, 6404, 6835, 1544, 6144, 2264, 2213, 604, 511, 3365, 1260, 5176, 4076, 3079, 5399, 5489, 598, 2678, 6110, 4088, 7320, 7871, 659, 4416, 7262, 6184, 7022, 5120, 4293, 843, 3331, 5012, 1611, 3256, 48, 5750, 5893, 4609, 5340, 2640, 4263, 5997, 1653, 6750, 7064, 7808, 2945, 2925, 5384, 2759, 22, 6810, 3668, 4066, 2598, 6025, 2484, 2398, 6718, 6349, 4036, 3297, 3335, 5266, 2219, 1423, 4118, 7818, 2185, 2228, 7004, 1410, 1942, 4252, 3404, 46, 3258, 348, 523, 3529, 2687, 932, 1922, 285, 1302, 7552, 907, 4591, 445, 126, 4444, 504, 5054, 6358, 4799, 526, 1126, 9, 7009, 2320, 7569, 479, 578, 5471, 3182, 1699, 865, 6035, 2924, 3008, 7809, 5861, 848, 6723, 634, 1034, 5514, 2694, 3686, 1159, 6137, 1063, 5727, 5885, 219, 7849, 1625, 230, 5383, 3007, 2946, 6036, 6818, 7093, 930, 2689, 2444, 2334, 6686, 1194, 5462, 269, 5482, 941, 4643, 4997, 1365, 4778, 2815, 3158, 2301, 2568, 6740, 4478, 553, 4307, 401, 2361, 7481, 3316, 922, 3858, 5100, 4248, 735, 3241, 4976, 6521, 5321, 42, 5445, 5890, 5405, 3250, 116, 1565, 138, 3715, 3900, 97, 4553, 4862, 6275, 4772, 4672, 493, 3152, 6572, 4175, 846, 5863, 5204, 2715, 5147, 4465, 3104, 2854, 6457, 1677, 6456, 2858, 3105, 5072, 131, 3432, 6918, 1211, 2059, 7751, 1495, 2649, 5052, 506, 298, 3097, 5248, 3227, 3356, 6680, 4471, 5235, 5042, 7380, 4923, 1528, 1916, 146, 7831, 760, 4431, 1548, 5680, 4092, 971, 619, 1492, 4456, 3503, 3157, 2906, 4779, 5033, 7755, 1788, 7087, 7578, 338, 7162, 7721, 5306, 3373, 2699, 6080, 1541, 6335, 2207, 1320, 641, 5450, 3903, 6247, 1568, 2752, 6152, 1646, 6999, 974, 2341, 4026, 4993, 3638, 1976, 4131, 7677, 7311, 5804, 5227, 373, 2052, 4562, 453, 5936, 7719, 7164, 912, 2379, 4810, 3914, 862, 4858, 3593, 7082, 809, 3734, 21, 3005, 5385, 2069, 7203, 7572, 6060, 6151, 2792, 1569, 6433, 6814, 4515, 7129, 5219, 6077, 1892, 3931, 1879, 539, 119, 5169, 5024, 3421, 5901, 3856, 924, 2041, 535, 2389, 5628, 5396, 1403, 6441, 7803, 1283, 4604, 5767, 6786, 2050, 375, 990, 854, 7765, 5146, 2862, 5205, 1777, 4447, 4501, 6624, 4842, 3810, 3389, 6287, 896, 873, 5763, 3620, 1890, 6079, 2803, 3374, 3308, 1601, 3685, 2937, 5515, 5851, 549, 2443, 2919, 931, 2974, 3530, 3546, 5842, 7352, 2021, 5022, 5171, 6109, 3037, 599, 2055, 3347, 4696, 7232, 668, 5277, 1336, 6581, 335, 755, 5139, 1809, 3645, 3445, 3233, 5771, 588, 2080, 5107, 7513, 4327, 3693, 6743, 7560, 3492, 3413, 5051, 2844, 1496, 6594, 5610, 3862, 1886, 6234, 198, 4262, 3015, 5341, 4787, 5046, 4659, 3320, 4435, 6671, 789, 3379, 1971, 7881, 3944, 6308, 6899, 6451, 6195, 1856, 7490, 4114, 4549, 4894, 5667, 902, 2283, 7115, 5555, 6710, 1420, 596, 5491, 7216, 5214, 6550, 6377, 3776, 1812, 5427, 3844, 4085, 826, 6024, 3000, 4067, 2012, 4684, 1138, 3611, 646, 6140, 3195, 266, 2521, 6875, 5359, 5477, 6178, 7136, 2197, 6561, 163, 5080, 4513, 6816, 6038, 3967, 5721, 7648, 4128, 4102, 5331, 6739, 2903, 2302, 3649, 1363, 4999, 7844, 6268, 700, 6162, 6149, 6062, 331, 6980, 3782, 5315, 1147, 7507, 610, 7717, 5938, 4594, 2382, 3275, 4869, 5246, 3099, 3609, 1140, 327, 7210, 1595, 259, 6211, 1572, 6857, 6648, 7585, 4790, 6366, 7594, 4830, 1009, 5299, 2409, 1432, 1692, 6874, 2588, 267, 5464, 1022, 5625, 2170, 4532, 2178, 6839, 2456, 4043, 7419, 1582, 6425, 3219, 6663, 86, 7610, 7654, 4959, 4879, 5127, 5817, 6416, 5569, 6042, 807, 7084, 6780, 2289, 3284, 2256, 5156, 6483, 4805, 4845, 2397, 2998, 6026, 2133, 1994, 5003, 4636, 7448, 4315, 3495, 514, 4741, 6618, 6190, 151, 2038, 6156, 1522, 6730, 631, 1751, 5634, 6171, 5661, 6881, 6996, 6072, 5282, 4042, 2512, 6840, 1370, 1078, 4002, 1761, 3516, 7533, 3448, 1216, 7697, 2333, 2918, 2690, 550, 7842, 5001, 1996, 1641, 4580, 7243, 5089, 3983, 7790, 4664, 1224, 7183, 1725, 1245, 6568, 1129, 3549, 6690, 4971, 7617, 5366, 6864, 3460, 3481, 2099, 2015, 7306, 4934, 4704, 6174, 6206, 1431, 2525, 5300, 1708, 7825, 4759, 7615, 4973, 6945, 7053, 5919, 6717, 2997, 2485, 4846, 7288, 5275, 670, 4320, 2168, 5627, 2731, 536, 1458, 4668, 3344, 7100, 3274, 2547, 4595, 4809, 2769, 913, 356, 157, 6931, 4283, 556, 6850, 4947, 5192, 2035, 6382, 2150, 7874, 878, 2076, 545, 7480, 2897, 402, 4571, 6088, 1684, 1514, 4485, 3512, 4462, 1986, 1165, 1538, 6578, 6695, 7175, 3487, 7356, 361, 2273, 4025, 2787, 975, 382, 7658, 983, 1662, 6685, 2917, 2445, 7698, 769, 5271, 1176, 1041, 994, 4229, 7460, 4046, 6414, 5819, 7568, 2955, 7010, 2124, 1468, 5388, 1844, 1930, 3339, 6714, 7123, 3456, 6651, 4385, 3628, 3120, 6033, 867, 3648, 2567, 2904, 3159, 7613, 4761, 3994, 5933, 7695, 1218, 1277, 7564, 6600, 3283, 2492, 6781, 5646, 4717, 2096, 7114, 2616, 903, 4105, 6535, 1271, 6198, 5747, 1290, 5239, 4024, 2343, 362, 3116, 3774, 6379, 154, 4353, 4341, 2212, 3049, 6145, 4007, 6862, 5368, 5716, 5495, 5155, 2490, 3285, 6306, 3946, 6133, 5421, 1715, 264, 3197, 7705, 7575, 1768, 7399, 4709, 1897, 1926, 1103, 5598, 3169, 900, 5669, 4620, 3563, 5719, 3969, 7025, 3870, 7003, 2985, 2186, 3179, 1713, 5423, 1005, 253, 594, 1422, 2990, 5267, 6984, 5649, 3266, 603, 3048, 2265, 4342, 6271, 6638, 1319, 2799, 6336, 5062, 3794, 964, 3690, 1961, 1417, 1059, 6560, 2582, 7137, 6860, 4009, 4615, 6855, 1574, 7279, 7376, 484, 3178, 2227, 2986, 7819, 3574, 1407, 5812, 6332, 6838, 2514, 4533, 715, 4820, 7046, 520, 4656, 4531, 2516, 5626, 2391, 4321, 5652, 3917, 5311, 238, 6527, 4333, 1341, 6821, 4953, 2001, 3520, 1227, 5797, 686, 657, 7873, 2367, 6383, 7638, 6051, 1607, 365, 1557, 726, 4747, 6510, 1512, 1686, 5608, 6596, 7836, 4866, 1993, 2482, 6027, 397, 3874, 3272, 7102, 6805, 3885, 1467, 2318, 7011, 5182, 4266, 998, 3280, 5162, 1100, 3922, 4651, 5224, 7298, 4624, 1671, 1455, 1882, 6264, 7476, 7517, 282, 1819, 3950, 1393, 4682, 2014, 2417, 3482, 7113, 2285, 4718, 4144, 6795, 6704, 6628, 7684, 6657, 5731, 7200, 7608, 88, 1704, 497, 573, 5106, 2659, 589, 6734, 544, 2364, 879, 6477, 5704, 1554, 7606, 7202, 2757, 5386, 1470, 5563, 318, 7414, 6221, 1202, 1635, 7750, 2847, 1212, 7098, 3346, 2676, 600, 4561, 2776, 374, 2721, 6787, 6540, 1939, 3478, 6754, 4338, 5201, 534, 2733, 925, 6155, 2470, 152, 6381, 2369, 5193, 7337, 3828, 766, 7072, 3822, 3960, 215, 7775, 75, 4942, 7038, 5021, 2682, 7353, 6591, 4816, 1264, 7305, 2416, 2100, 4683, 2596, 4068, 1186, 1112, 3426, 6654, 3626, 4387, 4523, 3974, 3519, 2157, 4954, 7667, 3980, 1640, 2439, 5002, 2481, 2134, 4867, 3277, 7452, 6056, 7035, 1164, 2352, 4463, 5149, 4030, 3654, 427, 7645, 1360, 4100, 4130, 2783, 3639, 4380, 4730, 7880, 2630, 3380, 718, 3680, 831, 5485, 1169, 764, 3830, 1416, 2201, 3691, 4329, 1721, 1738, 3880, 707, 7662, 3890, 5589, 191, 7431, 5112, 167, 5336, 3292, 7442, 7742, 4251, 2982, 1411, 3477, 2047, 6541, 795, 6120, 6168, 7623, 6460, 3769, 3338, 2314, 1845, 3920, 1102, 2241, 1898, 1817, 284, 2972, 933, 3238, 4148, 441, 145, 2829, 1529, 6792, 739, 34, 6262, 1884, 3864, 7173, 6697, 6775, 1802, 1310, 345, 6217, 196, 6236, 1816, 1925, 2242, 4710, 4700, 584, 3930, 2744, 6078, 2701, 3621, 4872, 6233, 2644, 3863, 1910, 6263, 2109, 1456, 538, 2742, 3932, 417, 6505, 3749, 1251, 7425, 6422, 3698, 6412, 4048, 39, 1619, 411, 961, 568, 1487, 7058, 5286, 4886, 5402, 5753, 7489, 2623, 6196, 1273, 4764, 5580, 7019, 4938, 4962, 1068, 5309, 3919, 1929, 2315, 5389, 7079, 1659, 1437, 194, 6219, 7416, 7463, 246, 5738, 6279, 1383, 7828, 432, 5896, 851, 178, 312, 5131, 1735, 5327, 7555, 3583, 3949, 2104, 283, 1924, 1899, 6237, 888, 5426, 2604, 3777, 3644, 2665, 5140, 5994, 5185, 5083, 6345, 1309, 1905, 6776, 1355, 1119, 3313, 5527, 6202, 893, 7629, 4378, 3641, 1353, 6778, 7086, 2811, 7756, 871, 898, 3171, 3102, 4467, 32, 741, 502, 4446, 2713, 5206, 4849, 3798, 7061, 3464, 6490, 3205, 7398, 2245, 7576, 7089, 5949, 1718, 6770, 3515, 2451, 4003, 7180, 3523, 1038, 1088, 1183, 4300, 3938, 5633, 2465, 632, 6725, 4951, 6823, 7238, 5294, 4691, 449, 6340, 4835, 5622, 3879, 1957, 1722, 5326, 1824, 5132, 5094, 6240, 6959, 5846, 5416, 6364, 4792, 1244, 2429, 7184, 5325, 1737, 1958, 4330, 6769, 1764, 5950, 263, 2250, 5422, 2225, 3180, 5473, 1680, 7824, 2407, 5301, 750, 496, 2084, 89, 622, 4856, 864, 2949, 3183, 7303, 1266, 5413, 7735, 6873, 2523, 1433, 5261, 6030, 6613, 5607, 2139, 1513, 2357, 6089, 6993, 7823, 1710, 5474, 6455, 2856, 6458, 7625, 5349, 6314, 1454, 2111, 4625, 7539, 5983, 7690, 6047, 470, 5822, 6684, 2336, 984, 1436, 1841, 7080, 3595, 7703, 3199, 6749, 3012, 5998, 5242, 7688, 5985, 6070, 6998, 2790, 6153, 927, 4509, 4579, 2438, 1997, 3981, 5091, 6318, 7749, 2061, 1203, 3416, 7855, 3662, 693, 93, 3223, 7501, 229, 2928, 7850, 5974, 6002, 5777, 410, 1867, 40, 5323, 7186, 3542, 5675, 1248, 3255, 3022, 5013, 3114, 364, 2146, 6052, 6503, 419, 3539, 3684, 2696, 3309, 4495, 5179, 6990, 258, 2538, 7211, 4096, 3395, 3060, 4451, 969, 4094, 7213, 3567, 4475, 3696, 6424, 2509, 7420, 4599, 5631, 3940, 5258, 987, 7278, 2191, 6856, 2535, 6212, 6432, 2751, 2793, 6248, 137, 2879, 117, 541, 7783, 4180, 7257, 7545, 725, 2144, 366, 7605, 2072, 5705, 1048, 6343, 5085, 5679, 2824, 4432, 7435, 6143, 3051, 6836, 6334, 2801, 6081, 6577, 2350, 1166, 4890, 3850, 1122, 3536, 7642, 1016, 6791, 1915, 2830, 4924, 3087, 4527, 1207, 6729, 2468, 6157, 3094, 5355, 292, 7858, 948, 4484, 2356, 1685, 2140, 6511, 3616, 1334, 5279, 4110, 5616, 7732, 5849, 5517, 5736, 248, 4166, 4795, 4814, 6593, 2648, 2845, 7752, 4455, 2819, 620, 91, 695, 7057, 1863, 569, 7220, 1298, 251, 1007, 4832, 1051, 17, 4639, 957, 3058, 3397, 4186, 6015, 3838, 5562, 2067, 5387, 2317, 2125, 3886, 7814, 459, 6013, 4188, 6302, 5377, 4667, 2387, 537, 1881, 2110, 1672, 6315, 5135, 1072, 730, 4721, 6631, 7715, 612, 6481, 5158, 83, 3896, 6499, 3129, 7429, 193, 1840, 1660, 985, 5260, 1691, 2524, 2410, 6207, 5030, 5028, 6209, 261, 5952, 4117, 2989, 2220, 595, 2612, 6711, 1058, 2200, 1962, 3831, 7778, 978, 3476, 1941, 2983, 7005, 5811, 2182, 3575, 7272, 6440, 2728, 5397, 3081, 4413, 1281, 7805, 3135, 4420, 6114, 4681, 2102, 3951, 7470, 3724, 745, 1240, 3988, 6444, 4757, 7827, 1832, 6280, 7467, 6009, 4137, 7260, 4418, 3137, 5744, 6374, 4270, 7861, 1077, 2454, 6841, 7711, 4081, 4777, 2908, 4998, 2565, 3650, 4099, 1979, 7646, 5723, 3553, 1118, 1800, 6777, 1791, 3642, 3779, 5605, 6615, 7369, 3146, 1097, 5837, 5947, 7091, 6820, 2160, 4334, 1197, 6693, 6580, 2670, 5278, 1509, 3617, 6889, 3658, 4159, 7142, 7385, 7236, 6825, 5687, 5304, 7723, 4584, 640, 2798, 2208, 6639, 5458, 6757, 7878, 4732, 5018, 3711, 344, 1904, 1803, 6346, 5536, 1191, 6548, 5216, 7551, 2970, 286, 4164, 250, 1484, 7221, 4396, 531, 5866, 3070, 6388, 5238, 2276, 5748, 50, 7412, 320, 5594, 4603, 2725, 7804, 1399, 4414, 661, 7563, 2293, 1219, 3992, 4763, 1854, 6197, 2279, 6536, 517, 3143, 5412, 1696, 7304, 2017, 4817, 3383, 5175, 3044, 3366, 1180, 5794, 202, 3163, 6437, 171, 7424, 1874, 3750, 3254, 1613, 5676, 6567, 2428, 1726, 4793, 4168, 3987, 1388, 746, 1027, 5352, 301, 4428, 5576, 3501, 4458, 5878, 4260, 200, 5796, 2155, 3521, 7182, 2431, 4665, 5379, 7800, 3991, 1276, 2294, 7696, 2447, 3449, 5252, 7097, 2058, 2848, 6919, 4197, 6728, 1524, 4528, 5049, 3415, 1634, 2062, 6222, 5550, 4969, 6692, 1339, 4335, 5461, 2915, 6687, 6547, 1306, 5537, 711, 5978, 1111, 2010, 4069, 4299, 1755, 1089, 5793, 1258, 3367, 1086, 1040, 2329, 5272, 6466, 6828, 4545, 5573, 763, 1965, 5486, 4889, 1537, 2351, 1987, 7036, 4944, 7252, 6136, 2935, 3687, 6677, 6362, 5418, 7255, 4182, 7295, 5807, 7342, 104, 7506, 2553, 5316, 4983, 3408, 4191, 5231, 326, 2541, 3610, 2594, 4685, 6231, 4874, 822, 4423, 4406, 5840, 3548, 2426, 6569, 8, 2958, 527, 7526, 3535, 1534, 3851, 3312, 1799, 1356, 3554, 6166, 6122, 4371, 3425, 2009, 1187, 5979, 6084, 6531, 6095, 800, 5392, 5597, 2240, 1927, 3921, 2117, 5163, 5836, 1346, 3147, 6868, 6355, 5971, 7147, 3740, 5792, 1182, 1756, 1039, 1178, 3368, 758, 7833, 475, 782, 5758, 4001, 2453, 1371, 7862, 4882, 4218, 729, 1451, 5136, 3371, 5308, 1848, 4963, 793, 6543, 5726, 2933, 6138, 648, 6559, 2199, 1418, 6712, 3341, 3763, 7068, 563, 16, 1480, 4833, 6342, 1552, 5706, 5372, 5430, 6516, 175, 993, 2328, 1177, 1087, 1757, 3524, 7328, 5513, 2939, 635, 4558, 3269, 5693, 6312, 5351, 1238, 747, 5690, 3877, 5624, 2518, 5465, 4426, 303, 4737, 6790, 1531, 7643, 429, 149, 6192, 5363, 5298, 2527, 4831, 1482, 252, 2223, 5424, 890, 64, 4313, 7450, 3279, 2120, 4267, 6553, 4228, 2327, 1042, 176, 853, 2719, 376, 7277, 1576, 5259, 1435, 1661, 2337, 7659, 4401, 774, 3475, 1413, 7779, 381, 2340, 2788, 7000, 618, 2821, 4093, 1589, 4452, 5036, 6675, 3689, 2203, 3795, 567, 1865, 412, 289, 3057, 1477, 4640, 7727, 5510, 3603, 689, 391, 3631, 4483, 1516, 7859, 4272, 7241, 4582, 7725, 4642, 2911, 5483, 833, 7497, 6966, 7395, 212, 3237, 1921, 2973, 2688, 2920, 7094, 4508, 1644, 6154, 2040, 2734, 3857, 2894, 3317, 387, 6948, 491, 4674, 7772, 3908, 355, 2378, 2770, 7165, 4207, 3847, 4590, 2968, 7553, 5329, 4104, 2282, 2617, 5668, 2237, 3170, 1785, 872, 2705, 6288, 7628, 1795, 6203, 63, 1003, 5425, 1814, 6238, 5096, 6912, 7268, 4014, 5656, 4901, 6476, 2075, 2365, 7875, 4929, 5566, 5762, 2704, 897, 1786, 7757, 3443, 3647, 2304, 6034, 2948, 1700, 4857, 2766, 3915, 5654, 4016, 4499, 4449, 3062, 7764, 2718, 991, 177, 1828, 5897, 6722, 2942, 5862, 2865, 4176, 3330, 3025, 4294, 7762, 3064, 5711, 7366, 4744, 4221, 7194, 7496, 939, 5484, 1967, 3681, 7189, 6397, 6023, 2600, 4086, 6112, 4422, 1134, 4875, 78, 4752, 4121, 6831, 7323, 185, 7118, 5855, 4064, 3670, 3733, 2762, 7083, 2495, 6043, 6227, 4291, 5122, 7077, 5391, 1106, 6096, 5075, 308, 6119, 1937, 6542, 1066, 4964, 6956, 3378, 2632, 6672, 5828, 4540, 5501, 4612, 5757, 1081, 476, 7206, 4287, 7326, 3526, 4802, 3474, 980, 4402, 5788, 5601, 5270, 2331, 7699, 7071, 2031, 3829, 1964, 1170, 5574, 4430, 2826, 7832, 1084, 3369, 5138, 2667, 336, 7580, 3150, 495, 1706, 5302, 5689, 1026, 1239, 1389, 3725, 6556, 501, 1780, 33, 1913, 6793, 4146, 3240, 2890, 4249, 7744, 4142, 4720, 1450, 1073, 4219, 4746, 2143, 1558, 7546, 5078, 165, 5114, 6974, 3679, 1969, 3381, 4819, 2176, 4534, 4020, 5977, 1189, 5538, 4399, 7661, 1955, 3881, 6126, 4363, 6660, 5455, 6161, 2561, 6269, 4344, 4203, 7056, 1489, 92, 1630, 3663, 7050, 390, 952, 3604, 656, 2153, 5798, 278, 5815, 5129, 314, 7408, 7105, 3599, 3581, 7557, 5346, 6291, 3790, 6298, 4319, 2393, 5276, 2672, 7233, 7315, 6400, 6588, 3490, 7562, 1279, 4415, 3032, 7872, 2152, 687, 3605, 3188, 5212, 7218, 571, 499, 6558, 1061, 6139, 2592, 3612, 6940, 3304, 5449, 2797, 1321, 4585, 100, 3707, 4557, 1033, 2940, 6724, 1750, 2466, 6731, 3704, 6325, 341, 3747, 6507, 3468, 4855, 1702, 90, 1491, 2820, 972, 7001, 3872, 399, 4309, 6480, 1446, 7716, 2551, 7508, 6897, 6310, 5695, 510, 3047, 2214, 3267, 4560, 2054, 2677, 3038, 5490, 2611, 1421, 2221, 254, 3509, 3702, 6733, 2079, 2660, 5772, 3262, 3929, 1894, 4701, 6188, 6620, 5869, 5470, 2952, 480, 3730, 207, 5105, 2082, 498, 651, 7219, 1486, 1864, 962, 3796, 4851, 15, 1053, 7069, 7701, 3597, 7107, 4360, 6849, 2373, 4284, 4306, 2900, 4479, 7841, 2442, 2691, 5852, 4058, 7479, 2363, 2077, 6735, 7782, 1563, 118, 2741, 1880, 1457, 2388, 2732, 2042, 5202, 5865, 1295, 4397, 5540, 7525, 1125, 2959, 4800, 3528, 2976, 349, 4655, 2173, 7047, 3142, 1269, 6537, 4740, 2475, 3496, 3364, 3046, 605, 5696, 7402, 297, 2842, 5053, 2963, 4445, 1779, 742, 6557, 650, 572, 2083, 1705, 751, 3151, 2869, 4673, 918, 6949, 7674, 4679, 6116, 5641, 3177, 2188, 7377, 7589, 3729, 577, 2953, 7570, 7205, 781, 1082, 7834, 6598, 7566, 5821, 1665, 6048, 423, 3841, 5375, 6304, 3287, 4079, 7713, 6633, 6012, 1464, 7815, 4755, 6446, 7693, 5935, 2774, 4563, 3452, 6339, 1743, 4692, 3589, 125, 2966, 4592, 5940, 144, 1918, 4149, 7866, 3248, 5407, 3571, 6885, 4607, 5895, 1830, 7829, 148, 1014, 7644, 1981, 3655, 5560, 3840, 468, 6049, 7640, 3538, 1604, 6504, 1877, 3933, 6494, 4162, 288, 960, 1866, 1620, 5778, 369, 3826, 7339, 5523, 4989, 4570, 2360, 2898, 4308, 615, 3873, 2131, 6028, 5263, 3772, 3118, 3630, 951, 690, 7051, 6947, 920, 3318, 4661, 6258, 7657, 2339, 976, 7780, 6737, 5333, 7276, 989, 2720, 2051, 2777, 5228, 3559, 3825, 408, 5779, 7604, 1556, 2145, 1608, 3115, 2272, 2344, 7357, 6761, 4351, 156, 2377, 914, 3909, 4368, 5436, 4438, 4654, 522, 2977, 3259, 6216, 1903, 1311, 3712, 3746, 627, 6326, 7161, 2808, 7579, 754, 2668, 6582, 4916, 6979, 2557, 6063, 4303, 7209, 2540, 1141, 5232, 4394, 7223, 6607, 5593, 1286, 7413, 2065, 5564, 4931, 7407, 681, 5130, 1826, 179, 5639, 6118, 797, 5076, 7548, 7132, 4736, 1019, 4427, 1236, 5353, 3096, 2841, 507, 7403, 4157, 3660, 7857, 1518, 5356, 3056, 959, 413, 4163, 1301, 2971, 1923, 1818, 2105, 7518, 6330, 5814, 684, 5799, 7798, 5381, 232, 4725, 5586, 3125, 5481, 2913, 5463, 2520, 2589, 3196, 2249, 1716, 5951, 1426, 6210, 2537, 1596, 6991, 6091, 3508, 593, 2222, 1006, 1483, 1299, 4165, 1501, 5737, 1835, 7464, 4348, 6353, 6870, 7457, 5905, 6526, 2163, 5312, 3758, 4212, 7681, 4724, 274, 5382, 2927, 1626, 7502, 5547, 6903, 3485, 7177, 5931, 3996, 3835, 7848, 2930, 5886, 3906, 7774, 2027, 3961, 3236, 935, 7396, 3207, 3753, 5104, 575, 3731, 3672, 7651, 3162, 1256, 5795, 1229, 4261, 2642, 6235, 1901, 6218, 1839, 1438, 7430, 1951, 5590, 6668, 5439, 5553, 7117, 815, 7324, 4289, 6229, 4687, 5638, 311, 1827, 852, 992, 1043, 6517, 3805, 7423, 1253, 6438, 7274, 5335, 1948, 5113, 722, 5079, 2580, 6562, 3302, 6942, 3244, 6930, 2376, 357, 4352, 2268, 6380, 2037, 2471, 6191, 1013, 430, 7830, 2828, 1917, 442, 5941, 3635, 7152, 3744, 3714, 2878, 1566, 6249, 5825, 5039, 6391, 3431, 2851, 5073, 6098, 7015, 4443, 2965, 446, 3590, 7044, 4822, 7030, 5168, 2740, 540, 1564, 2880, 3251, 3210, 6969, 3978, 7669, 5859, 7811, 4053, 6471, 6908, 7505, 1149, 7343, 6323, 3706, 638, 4586, 4552, 2875, 3901, 5452, 3222, 1629, 694, 1490, 621, 1703, 2085, 7609, 2505, 6664, 3895, 1443, 5159, 6603, 6487, 4751, 820, 4876, 4941, 2025, 7776, 3833, 3998, 6420, 7427, 3131, 3766, 4898, 5701, 4312, 1002, 891, 6204, 6176, 5479, 3127, 6501, 6054, 7454, 7738, 5058, 7126, 6802, 7411, 1288, 5749, 3020, 3257, 2979, 3405, 7334, 5444, 2885, 5322, 1618, 1868, 4049, 7665, 4956, 6261, 1912, 740, 1781, 4468, 6253, 4224, 7592, 6368, 6938, 3614, 6513, 6809, 3004, 2760, 3735, 7446, 4638, 1479, 1052, 564, 4852, 7227, 5734, 5519, 7008, 2957, 1127, 6570, 3154, 5913, 5256, 3942, 7883]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-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-l5-s9/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a31f11bc4fa29e9b93181c43bd72e107bab11f6 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 7883, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-product-permutation-l5-s9/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-rlve-prefix-sum-permutation-l4-s0/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l4-s0/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ae937a0e280570f4d25b83d5e67f29a65bae583 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 1362, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s0/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..394d51986b680538efa05f97a53b955e7f0654d6 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [1362, 1, 1360, 3, 1358, 5, 1356, 7, 1354, 9, 1352, 11, 1350, 13, 1348, 15, 1346, 17, 1344, 19, 1342, 21, 1340, 23, 1338, 25, 1336, 27, 1334, 29, 1332, 31, 1330, 33, 1328, 35, 1326, 37, 1324, 39, 1322, 41, 1320, 43, 1318, 45, 1316, 47, 1314, 49, 1312, 51, 1310, 53, 1308, 55, 1306, 57, 1304, 59, 1302, 61, 1300, 63, 1298, 65, 1296, 67, 1294, 69, 1292, 71, 1290, 73, 1288, 75, 1286, 77, 1284, 79, 1282, 81, 1280, 83, 1278, 85, 1276, 87, 1274, 89, 1272, 91, 1270, 93, 1268, 95, 1266, 97, 1264, 99, 1262, 101, 1260, 103, 1258, 105, 1256, 107, 1254, 109, 1252, 111, 1250, 113, 1248, 115, 1246, 117, 1244, 119, 1242, 121, 1240, 123, 1238, 125, 1236, 127, 1234, 129, 1232, 131, 1230, 133, 1228, 135, 1226, 137, 1224, 139, 1222, 141, 1220, 143, 1218, 145, 1216, 147, 1214, 149, 1212, 151, 1210, 153, 1208, 155, 1206, 157, 1204, 159, 1202, 161, 1200, 163, 1198, 165, 1196, 167, 1194, 169, 1192, 171, 1190, 173, 1188, 175, 1186, 177, 1184, 179, 1182, 181, 1180, 183, 1178, 185, 1176, 187, 1174, 189, 1172, 191, 1170, 193, 1168, 195, 1166, 197, 1164, 199, 1162, 201, 1160, 203, 1158, 205, 1156, 207, 1154, 209, 1152, 211, 1150, 213, 1148, 215, 1146, 217, 1144, 219, 1142, 221, 1140, 223, 1138, 225, 1136, 227, 1134, 229, 1132, 231, 1130, 233, 1128, 235, 1126, 237, 1124, 239, 1122, 241, 1120, 243, 1118, 245, 1116, 247, 1114, 249, 1112, 251, 1110, 253, 1108, 255, 1106, 257, 1104, 259, 1102, 261, 1100, 263, 1098, 265, 1096, 267, 1094, 269, 1092, 271, 1090, 273, 1088, 275, 1086, 277, 1084, 279, 1082, 281, 1080, 283, 1078, 285, 1076, 287, 1074, 289, 1072, 291, 1070, 293, 1068, 295, 1066, 297, 1064, 299, 1062, 301, 1060, 303, 1058, 305, 1056, 307, 1054, 309, 1052, 311, 1050, 313, 1048, 315, 1046, 317, 1044, 319, 1042, 321, 1040, 323, 1038, 325, 1036, 327, 1034, 329, 1032, 331, 1030, 333, 1028, 335, 1026, 337, 1024, 339, 1022, 341, 1020, 343, 1018, 345, 1016, 347, 1014, 349, 1012, 351, 1010, 353, 1008, 355, 1006, 357, 1004, 359, 1002, 361, 1000, 363, 998, 365, 996, 367, 994, 369, 992, 371, 990, 373, 988, 375, 986, 377, 984, 379, 982, 381, 980, 383, 978, 385, 976, 387, 974, 389, 972, 391, 970, 393, 968, 395, 966, 397, 964, 399, 962, 401, 960, 403, 958, 405, 956, 407, 954, 409, 952, 411, 950, 413, 948, 415, 946, 417, 944, 419, 942, 421, 940, 423, 938, 425, 936, 427, 934, 429, 932, 431, 930, 433, 928, 435, 926, 437, 924, 439, 922, 441, 920, 443, 918, 445, 916, 447, 914, 449, 912, 451, 910, 453, 908, 455, 906, 457, 904, 459, 902, 461, 900, 463, 898, 465, 896, 467, 894, 469, 892, 471, 890, 473, 888, 475, 886, 477, 884, 479, 882, 481, 880, 483, 878, 485, 876, 487, 874, 489, 872, 491, 870, 493, 868, 495, 866, 497, 864, 499, 862, 501, 860, 503, 858, 505, 856, 507, 854, 509, 852, 511, 850, 513, 848, 515, 846, 517, 844, 519, 842, 521, 840, 523, 838, 525, 836, 527, 834, 529, 832, 531, 830, 533, 828, 535, 826, 537, 824, 539, 822, 541, 820, 543, 818, 545, 816, 547, 814, 549, 812, 551, 810, 553, 808, 555, 806, 557, 804, 559, 802, 561, 800, 563, 798, 565, 796, 567, 794, 569, 792, 571, 790, 573, 788, 575, 786, 577, 784, 579, 782, 581, 780, 583, 778, 585, 776, 587, 774, 589, 772, 591, 770, 593, 768, 595, 766, 597, 764, 599, 762, 601, 760, 603, 758, 605, 756, 607, 754, 609, 752, 611, 750, 613, 748, 615, 746, 617, 744, 619, 742, 621, 740, 623, 738, 625, 736, 627, 734, 629, 732, 631, 730, 633, 728, 635, 726, 637, 724, 639, 722, 641, 720, 643, 718, 645, 716, 647, 714, 649, 712, 651, 710, 653, 708, 655, 706, 657, 704, 659, 702, 661, 700, 663, 698, 665, 696, 667, 694, 669, 692, 671, 690, 673, 688, 675, 686, 677, 684, 679, 682, 681, 680, 683, 678, 685, 676, 687, 674, 689, 672, 691, 670, 693, 668, 695, 666, 697, 664, 699, 662, 701, 660, 703, 658, 705, 656, 707, 654, 709, 652, 711, 650, 713, 648, 715, 646, 717, 644, 719, 642, 721, 640, 723, 638, 725, 636, 727, 634, 729, 632, 731, 630, 733, 628, 735, 626, 737, 624, 739, 622, 741, 620, 743, 618, 745, 616, 747, 614, 749, 612, 751, 610, 753, 608, 755, 606, 757, 604, 759, 602, 761, 600, 763, 598, 765, 596, 767, 594, 769, 592, 771, 590, 773, 588, 775, 586, 777, 584, 779, 582, 781, 580, 783, 578, 785, 576, 787, 574, 789, 572, 791, 570, 793, 568, 795, 566, 797, 564, 799, 562, 801, 560, 803, 558, 805, 556, 807, 554, 809, 552, 811, 550, 813, 548, 815, 546, 817, 544, 819, 542, 821, 540, 823, 538, 825, 536, 827, 534, 829, 532, 831, 530, 833, 528, 835, 526, 837, 524, 839, 522, 841, 520, 843, 518, 845, 516, 847, 514, 849, 512, 851, 510, 853, 508, 855, 506, 857, 504, 859, 502, 861, 500, 863, 498, 865, 496, 867, 494, 869, 492, 871, 490, 873, 488, 875, 486, 877, 484, 879, 482, 881, 480, 883, 478, 885, 476, 887, 474, 889, 472, 891, 470, 893, 468, 895, 466, 897, 464, 899, 462, 901, 460, 903, 458, 905, 456, 907, 454, 909, 452, 911, 450, 913, 448, 915, 446, 917, 444, 919, 442, 921, 440, 923, 438, 925, 436, 927, 434, 929, 432, 931, 430, 933, 428, 935, 426, 937, 424, 939, 422, 941, 420, 943, 418, 945, 416, 947, 414, 949, 412, 951, 410, 953, 408, 955, 406, 957, 404, 959, 402, 961, 400, 963, 398, 965, 396, 967, 394, 969, 392, 971, 390, 973, 388, 975, 386, 977, 384, 979, 382, 981, 380, 983, 378, 985, 376, 987, 374, 989, 372, 991, 370, 993, 368, 995, 366, 997, 364, 999, 362, 1001, 360, 1003, 358, 1005, 356, 1007, 354, 1009, 352, 1011, 350, 1013, 348, 1015, 346, 1017, 344, 1019, 342, 1021, 340, 1023, 338, 1025, 336, 1027, 334, 1029, 332, 1031, 330, 1033, 328, 1035, 326, 1037, 324, 1039, 322, 1041, 320, 1043, 318, 1045, 316, 1047, 314, 1049, 312, 1051, 310, 1053, 308, 1055, 306, 1057, 304, 1059, 302, 1061, 300, 1063, 298, 1065, 296, 1067, 294, 1069, 292, 1071, 290, 1073, 288, 1075, 286, 1077, 284, 1079, 282, 1081, 280, 1083, 278, 1085, 276, 1087, 274, 1089, 272, 1091, 270, 1093, 268, 1095, 266, 1097, 264, 1099, 262, 1101, 260, 1103, 258, 1105, 256, 1107, 254, 1109, 252, 1111, 250, 1113, 248, 1115, 246, 1117, 244, 1119, 242, 1121, 240, 1123, 238, 1125, 236, 1127, 234, 1129, 232, 1131, 230, 1133, 228, 1135, 226, 1137, 224, 1139, 222, 1141, 220, 1143, 218, 1145, 216, 1147, 214, 1149, 212, 1151, 210, 1153, 208, 1155, 206, 1157, 204, 1159, 202, 1161, 200, 1163, 198, 1165, 196, 1167, 194, 1169, 192, 1171, 190, 1173, 188, 1175, 186, 1177, 184, 1179, 182, 1181, 180, 1183, 178, 1185, 176, 1187, 174, 1189, 172, 1191, 170, 1193, 168, 1195, 166, 1197, 164, 1199, 162, 1201, 160, 1203, 158, 1205, 156, 1207, 154, 1209, 152, 1211, 150, 1213, 148, 1215, 146, 1217, 144, 1219, 142, 1221, 140, 1223, 138, 1225, 136, 1227, 134, 1229, 132, 1231, 130, 1233, 128, 1235, 126, 1237, 124, 1239, 122, 1241, 120, 1243, 118, 1245, 116, 1247, 114, 1249, 112, 1251, 110, 1253, 108, 1255, 106, 1257, 104, 1259, 102, 1261, 100, 1263, 98, 1265, 96, 1267, 94, 1269, 92, 1271, 90, 1273, 88, 1275, 86, 1277, 84, 1279, 82, 1281, 80, 1283, 78, 1285, 76, 1287, 74, 1289, 72, 1291, 70, 1293, 68, 1295, 66, 1297, 64, 1299, 62, 1301, 60, 1303, 58, 1305, 56, 1307, 54, 1309, 52, 1311, 50, 1313, 48, 1315, 46, 1317, 44, 1319, 42, 1321, 40, 1323, 38, 1325, 36, 1327, 34, 1329, 32, 1331, 30, 1333, 28, 1335, 26, 1337, 24, 1339, 22, 1341, 20, 1343, 18, 1345, 16, 1347, 14, 1349, 12, 1351, 10, 1353, 8, 1355, 6, 1357, 4, 1359, 2, 1361]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/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-s0/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ae937a0e280570f4d25b83d5e67f29a65bae583 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 1362, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l4-s0/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prime-graph-coloring-l5-s7/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-rlve-prime-graph-coloring-l5-s7/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a1785f13bf0076048dbd40b907b0c3161c79850e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 558, "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-s7/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cc5fced7013c4c1a6fa4d3d35fccc0282c048e3e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s7/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-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-l5-s7/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a1785f13bf0076048dbd40b907b0c3161c79850e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 558, "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-s7/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-rlve-prime-graph-coloring-l5-s7/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-rlve-recursive-sequence-sum-l3-s2/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s2/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75d93e55d5cbb7f8ef0551b2e4ebef9dc4cdc59a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"F0": 55, "A": 16, "B": 5969, "S": 529130839929766, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s2/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..22017b60862501f462f26d253fc75b1c16a926a0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 4, 9, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/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-s2/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75d93e55d5cbb7f8ef0551b2e4ebef9dc4cdc59a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"F0": 55, "A": 16, "B": 5969, "S": 529130839929766, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s2/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s5/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s5/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9a6150d2f258b3790b0f148033580b3487f1a3 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"F0": 107, "A": 16, "B": 5128, "S": 8421046432173616, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s5/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c9fb1120a4218c35c1609c02c64c83bac62cdc11 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [2, 4, 7, 9, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/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-s5/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ec9a6150d2f258b3790b0f148033580b3487f1a3 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"F0": 107, "A": 16, "B": 5128, "S": 8421046432173616, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s5/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-smallest-enclosing-circle-l3-s8/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l3-s8/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0cc572d5594860e185b58363b9b9f42b2eb2896d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s8/environment/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-s9/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l3-s9/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9aacdc78b162168dcef362736175e4711901925d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 0], [3, 11], [5, 9], [5, 28], [7, 0], [8, 30], [11, 2], [13, 14], [23, 26], [23, 30], [24, 26], [24, 29], [26, 25], [29, 15], [29, 17]], "r_opt": 18.9010581714358, "r2_num": 1429, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..61f6e231ffc0b824580d4b3a02ddc4baf4a81d31 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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' +{"x": 11.5, "y": 15.0, "r": 18.9010581724358} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/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-s9/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9aacdc78b162168dcef362736175e4711901925d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 0], [3, 11], [5, 9], [5, 28], [7, 0], [8, 30], [11, 2], [13, 14], [23, 26], [23, 30], [24, 26], [24, 29], [26, 25], [29, 15], [29, 17]], "r_opt": 18.9010581714358, "r2_num": 1429, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l3-s9/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-subgraph-isomorphism-l3-s2/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s2/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cbd617b5cb218b9c190af390d0cb109812d896e --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n1": 11, "n2": 12, "edges1": [[8, 9], [5, 7], [4, 9], [5, 9], [7, 9], [5, 6], [2, 9], [0, 6], [7, 10], [8, 10], [2, 10], [1, 6], [6, 10], [9, 10], [4, 6], [3, 9], [1, 7], [1, 9], [3, 8], [2, 8], [0, 1], [3, 7], [1, 5], [0, 9], [2, 4], [0, 5], [1, 8], [0, 4], [4, 7], [1, 4], [6, 7], [2, 7], [0, 3], [0, 10], [5, 8], [4, 5], [2, 3], [3, 6], [6, 8], [7, 8], [5, 10], [3, 10], [0, 8], [3, 5]], "edges2": [[7, 11], [7, 8], [9, 11], [6, 10], [4, 8], [9, 10], [0, 11], [2, 7], [5, 9], [2, 5], [1, 3], [3, 5], [2, 4], [0, 9], [2, 11], [0, 10], [1, 11], [2, 8], [1, 8], [5, 6], [1, 9], [8, 11], [4, 9], [3, 7], [1, 4], [2, 9], [6, 11], [0, 4], [8, 10], [5, 10], [3, 10], [3, 9], [4, 5], [2, 3], [0, 7], [1, 5], [0, 8], [4, 11], [0, 1], [1, 2], [5, 11], [1, 10], [7, 10], [4, 7], [10, 11], [2, 10], [6, 9], [0, 6], [0, 5]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s2/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..76a81de33c290b0d8df5849907a15841230ca889 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [4, 8, 3, 9, 7, 11, 0, 10, 1, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cbd617b5cb218b9c190af390d0cb109812d896e --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n1": 11, "n2": 12, "edges1": [[8, 9], [5, 7], [4, 9], [5, 9], [7, 9], [5, 6], [2, 9], [0, 6], [7, 10], [8, 10], [2, 10], [1, 6], [6, 10], [9, 10], [4, 6], [3, 9], [1, 7], [1, 9], [3, 8], [2, 8], [0, 1], [3, 7], [1, 5], [0, 9], [2, 4], [0, 5], [1, 8], [0, 4], [4, 7], [1, 4], [6, 7], [2, 7], [0, 3], [0, 10], [5, 8], [4, 5], [2, 3], [3, 6], [6, 8], [7, 8], [5, 10], [3, 10], [0, 8], [3, 5]], "edges2": [[7, 11], [7, 8], [9, 11], [6, 10], [4, 8], [9, 10], [0, 11], [2, 7], [5, 9], [2, 5], [1, 3], [3, 5], [2, 4], [0, 9], [2, 11], [0, 10], [1, 11], [2, 8], [1, 8], [5, 6], [1, 9], [8, 11], [4, 9], [3, 7], [1, 4], [2, 9], [6, 11], [0, 4], [8, 10], [5, 10], [3, 10], [3, 9], [4, 5], [2, 3], [0, 7], [1, 5], [0, 8], [4, 11], [0, 1], [1, 2], [5, 11], [1, 10], [7, 10], [4, 7], [10, 11], [2, 10], [6, 9], [0, 6], [0, 5]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s2/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s5/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s5/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..676d22f4a2fc93bad3050813ee6902c0d6c506ea --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n1": 6, "n2": 12, "edges1": [[1, 3], [1, 2]], "edges2": [[0, 5], [4, 9], [5, 11], [9, 11], [3, 4], [1, 10], [5, 10], [4, 8], [1, 11]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s5/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0a60fd425e5ab7ac73dd95873a463ade31deaac8 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [6, 11, 9, 5, 2, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..676d22f4a2fc93bad3050813ee6902c0d6c506ea --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n1": 6, "n2": 12, "edges1": [[1, 3], [1, 2]], "edges2": [[0, 5], [4, 9], [5, 11], [9, 11], [3, 4], [1, 10], [5, 10], [4, 8], [1, 11]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s5/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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/optimize-ae-p37-turan-tetrahedron/environment/Dockerfile b/tasks/optimize-ae-p37-turan-tetrahedron/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/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-p37-turan-tetrahedron/environment/instance.json b/tasks/optimize-ae-p37-turan-tetrahedron/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a1f50e2b213847c57f924822d4bfe8018e2098b --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/environment/instance.json @@ -0,0 +1 @@ +{"max_classes": 30, "direction": "maximize", "family": "ae_p37_turan_tetrahedron", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p37-turan-tetrahedron/solution/solve.sh b/tasks/optimize-ae-p37-turan-tetrahedron/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5122796bfc031a1012abb312560d3fb179226993 --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/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' +{"weights": [1.0, 1.0, 1.0], "edges": [[0, 1, 2], [0, 0, 1], [1, 1, 2], [0, 2, 2]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p37-turan-tetrahedron/tests/check.py b/tasks/optimize-ae-p37-turan-tetrahedron/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..6b0e9cbadd3166c810c19a79b01915ab1a5989c0 --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/tests/check.py @@ -0,0 +1,39 @@ +"""Hypergraph Turan density of the tetrahedron K_4^(3) via weighted blow-up patterns (AlphaEvolve problem 37). + +Upstream silently *deleted* edges to repair K4 copies; we instead reject any pattern whose blow-up contains a +K_4^(3), and check it exactly (combinatorial condition on 4-multisets of classes).""" +import itertools + +from run import Invalid, float_list, int_list + + +def check(inst, ans): + w = float_list(ans.get("weights"), None, "weights") + k = len(w) + if not 1 <= k <= inst["max_classes"]: + raise Invalid(f"need 1..{inst['max_classes']} classes") + if any(x < 0 for x in w) or sum(w) <= 0: + raise Invalid("weights must be non-negative with positive sum") + edges = ans.get("edges") + if not isinstance(edges, list): + raise Invalid("edges must be a list") + es = set() + for e in edges: + int_list(e, 3, 0, k - 1, "edge") + if not (e[0] <= e[1] <= e[2]): + raise Invalid("each edge type must be sorted: [a, b, c] with a <= b <= c") + if e[0] == e[2]: + raise Invalid("edge type [a, a, a] is not allowed (its blow-up contains K_4^(3))") + if tuple(e) in es: + raise Invalid("duplicate edge type") + es.add(tuple(e)) + for m in itertools.combinations_with_replacement(range(k), 4): + subs = {tuple(sorted(m[:i] + m[i + 1:])) for i in range(4)} + if subs <= es: + raise Invalid(f"blow-up contains a tetrahedron on classes {list(m)}") + t = sum(w) + p = [x / t for x in w] + dens = 0.0 + for a, b, c in es: + dens += (6.0 if len({a, b, c}) == 3 else 3.0) * p[a] * p[b] * p[c] + return dens, {"classes": k, "edge_types": len(es)} diff --git a/tasks/optimize-ae-p37-turan-tetrahedron/tests/instance.json b/tasks/optimize-ae-p37-turan-tetrahedron/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae3f410e5f3db36e033e67007ffb6e632464efc2 --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/tests/instance.json @@ -0,0 +1 @@ +{"max_classes": 30, "direction": "maximize", "best_known": 0.5555555555555556, "baseline": 0.2222222222222222, "family": "ae_p37_turan_tetrahedron", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p37-turan-tetrahedron/tests/run.py b/tasks/optimize-ae-p37-turan-tetrahedron/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/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-p37-turan-tetrahedron/tests/test.sh b/tasks/optimize-ae-p37-turan-tetrahedron/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p37-turan-tetrahedron/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/tests/check.py b/tasks/optimize-ea-flat-polynomials-n70/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..af293bdd4aa98117c053859850e2d938f39dabe3 --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/tests/check.py @@ -0,0 +1,18 @@ +"""Flat Littlewood polynomial of degree 69 (EinsteinArena flat-polynomials, MIT). + +Score = max_{z in grid} |g(z)| / sqrt(71) over 10^6 equally spaced points of the unit circle (minimize), +exactly as the upstream verifier (np.poly1d, np.linspace(0, 2pi, 10^6)). Change: coefficients must be the +JSON integers 1/-1 (upstream cast to float first, so 1.0 and true were accepted).""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n_coeffs"] + c = int_list(ans.get("coefficients"), n, -1, 1, "coefficients") + if any(x == 0 for x in c): + raise Invalid("coefficients must be +1 or -1") + zs = np.exp(1j * np.linspace(0, 2 * np.pi, inst["grid"])) + vals = np.abs(np.poly1d(np.array(c, dtype=np.float64))(zs)) + return float(np.max(vals) / np.sqrt(n + 1)), {} diff --git a/tasks/optimize-ea-flat-polynomials-n70/tests/instance.json b/tasks/optimize-ea-flat-polynomials-n70/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b8bad1c917393f34497086e92d93a6b5098d97 --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/tests/instance.json @@ -0,0 +1 @@ +{"n_coeffs": 70, "grid": 1000000, "direction": "minimize", "best_known": 1.280932, "baseline": 8.307471607356973, "family": "ea_flat_polynomials_70", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-flat-polynomials-n70/tests/run.py b/tasks/optimize-ea-flat-polynomials-n70/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-flat-polynomials-n70/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-newman-n200/environment/Dockerfile b/tasks/optimize-finch-newman-n200/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-newman-n200/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-newman-n200/environment/instance.json b/tasks/optimize-finch-newman-n200/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd5795c76ac1bed2cd749a890111c447a8b6ccbe --- /dev/null +++ b/tasks/optimize-finch-newman-n200/environment/instance.json @@ -0,0 +1 @@ +{"N": 200, "n_max": 100, "direction": "maximize", "family": "finch_newman_200", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-newman-n200/solution/solve.sh b/tasks/optimize-finch-newman-n200/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7a5bdc6656c05746cb2a1862d0be3bc9fe2db032 --- /dev/null +++ b/tasks/optimize-finch-newman-n200/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.6054907284176355, 0.2082220832014918, 0.8703364918950646, 0.4730678466789209, 0.0757992014627772, 0.688255029504332, 0.29098638428818835, 0.9531007929817612, 0.5558321477656175, 0.1585635025494738, 0.8206779112430467, 0.42340926602690293, 0.026140620810759237, 0.6362317545355514, 0.23896310931940767, 0.9010775180129804, 0.5038088727968367, 0.10654022758069308, 0.7189960556222479, 0.32172741040610425, 0.983841819099677, 0.5865731738835334, 0.1893045286673897, 0.8514189373609624, 0.4541502921448188, 0.05688164692867512, 0.6693374749702299, 0.27206882975408625, 0.9341832384476592, 0.5369145932315154, 0.13964594801537172, 0.8017603567089445, 0.40449171149280083, 0.007223066276657158, 0.6171852166750804, 0.2199165714589367, 0.8820309801525095, 0.4847623349363658, 0.08749368972022212, 0.6999495177617769, 0.3026808725456333, 0.9647952812392061, 0.5675266360230624, 0.17025799080691875, 0.8323723995004915, 0.43510375428434783, 0.03783510906820416, 0.6479262427929963, 0.2506575975768526, 0.9127720062704253, 0.5155033610542816, 0.118234715838138, 0.7306905438796929, 0.33342189866354915, 0.995536307357122, 0.5982676621409784, 0.2009990169248346, 0.8631134256184074, 0.46584478040226374, 0.06857613518612005, 0.6810319632276749, 0.2837633180115312, 0.945877726705104, 0.5486090814889604, 0.15134043627281665, 0.8134548449663894, 0.4161861997502458, 0.01891755453410208, 0.6290086882588942, 0.2317400430427505, 0.8938544517363233, 0.4965858065201796, 0.09931716130403592, 0.7117729893455907, 0.31450434412944706, 0.97661875282302, 0.5793501076068762, 0.18208146239073253, 0.8441958710843054, 0.44692722586816164, 0.04965858065201796, 0.6621144086935727, 0.2648457634774291, 0.926960172171002, 0.5296915269548582, 0.13242288173871455, 0.7945372904322874, 0.3972686452161437, 0.0, 0.6099544210605136, 0.21268577584436976, 0.8748001845379426, 0.4775315393217989, 0.08026289410565521, 0.6927187221472101, 0.29545007693106634, 0.9575644856246393, 0.5602958404084956, 0.16302719519235181, 0.8251416038859247, 0.4278729586697809, 0.030604313453637254, 0.6406954471784294, 0.2434268019622857, 0.9055412106558584, 0.5082725654397147, 0.1110039202235711, 0.7234597482651259, 0.3261911030489822, 0.9883055117425551, 0.5910368665264114, 0.19376822131026772, 0.8558826300038404, 0.4586139847876968, 0.06134533957155314, 0.6738011676131079, 0.2765325223969643, 0.9386469310905373, 0.5413782858743934, 0.14410964065824974, 0.8062240493518225, 0.4089554041356788, 0.011686758919535179, 0.6216489093179585, 0.22438026410181472, 0.8864946727953874, 0.4892260275792438, 0.09195738236310014, 0.704413210404655, 0.3071445651885113, 0.9692589738820842, 0.5719903286659405, 0.17472168344979674, 0.8368360921433696, 0.4395674469272259, 0.042298801711082176, 0.6523899354358742, 0.25512129021973057, 0.9172356989133034, 0.5199670536971597, 0.12269840848101603, 0.735154236522571, 0.3378855913064272, 1.0, 0.6027313547838563, 0.20546270956771262, 0.8675771182612855, 0.47030847304514173, 0.07303982782899807, 0.685495655870553, 0.2882270106544092, 0.950341419347982, 0.5530727741318383, 0.15580412891569467, 0.8179185376092675, 0.4206498923931238, 0.023381247176980098, 0.6334723809017722, 0.23620373568562852, 0.8983181443792012, 0.5010494991630575, 0.10378085394691394, 0.7162366819884687, 0.31896803677232505, 0.9810824454658981, 0.5838138002497543, 0.18654515503361058, 0.8486595637271834, 0.4513909185110397, 0.054122273294895974, 0.6665781013364507, 0.26930945612030716, 0.9314238648138801, 0.5341552195977363, 0.13688657438159257, 0.7990009830751654, 0.4017323378590217, 0.004463692642878019, 0.6144181137033915, 0.21714946848724775, 0.8792638771808206, 0.4819952319646769, 0.08472658674853323, 0.697182414790088, 0.29991376957394433, 0.9620281782675173, 0.5647595330513736, 0.16749088783522983, 0.8296052965288027, 0.43233665131265897, 0.035068006096515274, 0.6451591398213075, 0.2478904946051637, 0.9100049032987364, 0.5127362580825927, 0.11546761286644912, 0.7279234409080039, 0.3306547956918602, 0.9927692043854331, 0.5955005591692895]} +RLMATH_EOF diff --git a/tasks/optimize-finch-newman-n200/tests/check.py b/tasks/optimize-finch-newman-n200/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..82b1fa7c191ddae1c98bc318742e6cca87ed7d73 --- /dev/null +++ b/tasks/optimize-finch-newman-n200/tests/check.py @@ -0,0 +1,16 @@ +"""Erdos #480 (Newman / Chung-Graham) finite version: x_1..x_200 in [0,1], maximize +g = min_{1<=n<=100} min_m n |x_{m+n} - x_m| (Finch/EFT skydiscover erdos_480_newman_density, Apache-2.0). +Ported from the upstream evaluator. Change: values must lie in [0, 1] exactly (upstream allowed a 1e-6 +slack and then clipped).""" +import numpy as np + +from run import Invalid, float_list + + +def check(inst, ans): + N, H = inst["N"], inst["n_max"] + x = np.array(float_list(ans.get("x"), N, "x")) + if np.any(x < 0) or np.any(x > 1): + raise Invalid("all values must lie in [0, 1]") + g = min(n * float(np.min(np.abs(x[n:] - x[:-n]))) for n in range(1, H + 1)) + return g, {} diff --git a/tasks/optimize-finch-newman-n200/tests/instance.json b/tasks/optimize-finch-newman-n200/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7457b612152d7689bba8ecfcc30f6c331eccff43 --- /dev/null +++ b/tasks/optimize-finch-newman-n200/tests/instance.json @@ -0,0 +1 @@ +{"N": 200, "n_max": 100, "direction": "maximize", "best_known": 0.3972686452161306, "baseline": 0.00497512437810943, "family": "finch_newman_200", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-newman-n200/tests/run.py b/tasks/optimize-finch-newman-n200/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-newman-n200/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-newman-n200/tests/test.sh b/tasks/optimize-finch-newman-n200/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-newman-n200/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