diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s2/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s2/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98c5cae5137b9d3c8110727a14d5a5493ff924ee --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"N": 44, "t": 12, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s2/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a625beac35df018b6aaa9df4ceadf9a6ca58359d --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [96, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 17, 17, 19, 19, 22, 22, 22, 22, 23, 29, 31, 37, 41, 43]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98c5cae5137b9d3c8110727a14d5a5493ff924ee --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"N": 44, "t": 12, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s2/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s5/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s5/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5eafedf0bf72ae2a44adcdb113f77eb63ac4f5c3 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"N": 52, "t": 15, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s5/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..98e3852ea12c4795108c2392cf173f6a50e9997f --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [45, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 18, 19, 19, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 26, 26, 26, 26, 29, 31, 37, 41, 43, 47]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5eafedf0bf72ae2a44adcdb113f77eb63ac4f5c3 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"N": 52, "t": 15, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s5/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p52-erdos-squarefree-l1-s9/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s9/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d476c8f376669000bcb42ff6107e3f40c45cacbe --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"N": 55, "t": 2, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s9/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..64edc60b2777c8ab206ef2453c453061679e49f0 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d476c8f376669000bcb42ff6107e3f40c45cacbe --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"N": 55, "t": 2, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s9/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s1/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s1/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9d81f89014c4e43015bed1c7b331d0aafb28043 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"N": 8984, "t": 360, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s1/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a3fd36b838bd7e198c02db62f5661f9333e8a261 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332, 1357, 1382, 1407, 1432, 1457, 1482, 1507, 1532, 1557, 1582, 1607, 1632, 1657, 1682, 1707, 1732, 1757, 1782, 1807, 1832, 1857, 1882, 1907, 1932, 1957, 1982, 2007, 2032, 2057, 2082, 2107, 2132, 2157, 2182, 2207, 2232, 2257, 2282, 2307, 2332, 2357, 2382, 2407, 2432, 2457, 2482, 2507, 2532, 2557, 2582, 2607, 2632, 2657, 2682, 2707, 2732, 2757, 2782, 2807, 2832, 2857, 2882, 2907, 2932, 2957, 2982, 3007, 3032, 3057, 3082, 3107, 3132, 3157, 3182, 3207, 3232, 3257, 3282, 3307, 3332, 3357, 3382, 3407, 3432, 3457, 3482, 3507, 3532, 3557, 3582, 3607, 3632, 3657, 3682, 3707, 3732, 3757, 3782, 3807, 3832, 3857, 3882, 3907, 3932, 3957, 3982, 4007, 4032, 4057, 4082, 4107, 4132, 4157, 4182, 4207, 4232, 4257, 4282, 4307, 4332, 4357, 4382, 4407, 4432, 4457, 4482, 4507, 4532, 4557, 4582, 4607, 4632, 4657, 4682, 4707, 4732, 4757, 4782, 4807, 4832, 4857, 4882, 4907, 4932, 4957, 4982, 5007, 5032, 5057, 5082, 5107, 5132, 5157, 5182, 5207, 5232, 5257, 5282, 5307, 5332, 5357, 5382, 5407, 5432, 5457, 5482, 5507, 5532, 5557, 5582, 5607, 5632, 5657, 5682, 5707, 5732, 5757, 5782, 5807, 5832, 5857, 5882, 5907, 5932, 5957, 5982, 6007, 6032, 6057, 6082, 6107, 6132, 6157, 6182, 6207, 6232, 6257, 6282, 6307, 6332, 6357, 6382, 6407, 6432, 6457, 6482, 6507, 6532, 6557, 6582, 6607, 6632, 6657, 6682, 6707, 6732, 6757, 6782, 6807, 6832, 6857, 6882, 6907, 6932, 6957, 6982, 7007, 7032, 7057, 7082, 7107, 7132, 7157, 7182, 7207, 7232, 7257, 7282, 7307, 7332, 7357, 7382, 7407, 7432, 7457, 7482, 7507, 7532, 7557, 7582, 7607, 7632, 7657, 7682, 7707, 7732, 7757, 7782, 7807, 7832, 7857, 7882, 7907, 7932, 7957, 7982, 8007, 8032, 8057, 8082, 8107, 8132, 8157, 8182, 8207, 8232, 8257, 8282, 8307, 8332, 8357, 8382, 8407, 8432, 8457, 8482, 8507, 8532, 8557, 8582, 8607, 8632, 8657, 8682, 8707, 8732, 8757, 8782, 8807, 8832, 8857, 8882, 8907, 8932, 8957, 8982]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9d81f89014c4e43015bed1c7b331d0aafb28043 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"N": 8984, "t": 360, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s1/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-mc-all-interval-l5-s3/environment/Dockerfile b/tasks/construct-mc-all-interval-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s3/environment/instance.json b/tasks/construct-mc-all-interval-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4363f90de65461ae571165fee585605e35f1941a --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 52, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s3/solution/solve.sh b/tasks/construct-mc-all-interval-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..02aec5d5e643b53601dc62e2b1ad4d7ba045a69f --- /dev/null +++ b/tasks/construct-mc-all-interval-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": [0, 51, 1, 50, 2, 49, 3, 48, 4, 47, 5, 46, 6, 45, 7, 44, 8, 43, 9, 42, 10, 41, 11, 40, 12, 39, 13, 38, 14, 37, 15, 36, 16, 35, 17, 34, 18, 33, 19, 32, 20, 31, 21, 30, 22, 29, 23, 28, 24, 27, 25, 26]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l5-s3/tests/check.py b/tasks/construct-mc-all-interval-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s3/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l5-s3/tests/instance.json b/tasks/construct-mc-all-interval-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4363f90de65461ae571165fee585605e35f1941a --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 52, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s3/tests/run.py b/tasks/construct-mc-all-interval-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s3/tests/test.sh b/tasks/construct-mc-all-interval-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s4/environment/Dockerfile b/tasks/construct-mc-all-interval-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-mc-all-interval-l5-s4/environment/instance.json b/tasks/construct-mc-all-interval-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..160b9901610942fb8e7fde933cf6aeeda8fd8d7e --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 56, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s4/solution/solve.sh b/tasks/construct-mc-all-interval-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..faa87e4f8c545d78a08150f1e12f4ade10e3d0a0 --- /dev/null +++ b/tasks/construct-mc-all-interval-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": [0, 55, 1, 54, 2, 53, 3, 52, 4, 51, 5, 50, 6, 49, 7, 48, 8, 47, 9, 46, 10, 45, 11, 44, 12, 43, 13, 42, 14, 41, 15, 40, 16, 39, 17, 38, 18, 37, 19, 36, 20, 35, 21, 34, 22, 33, 23, 32, 24, 31, 25, 30, 26, 29, 27, 28]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l5-s4/tests/check.py b/tasks/construct-mc-all-interval-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s4/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l5-s4/tests/instance.json b/tasks/construct-mc-all-interval-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..160b9901610942fb8e7fde933cf6aeeda8fd8d7e --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 56, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s4/tests/run.py b/tasks/construct-mc-all-interval-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-mc-all-interval-l5-s4/tests/test.sh b/tasks/construct-mc-all-interval-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-mc-bibd-l2-s0/environment/Dockerfile b/tasks/construct-mc-bibd-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s0/environment/instance.json b/tasks/construct-mc-bibd-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e354973c7bcb45e5cd6779513bd3cb8057c043a --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"v": 11, "k": 5, "lambda": 2, "b": 11, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s0/solution/solve.sh b/tasks/construct-mc-bibd-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe02fb6624ca7023aed3735eddee980b55390421 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[1, 3, 4, 5, 9], [2, 4, 5, 6, 10], [0, 3, 5, 6, 7], [1, 4, 6, 7, 8], [2, 5, 7, 8, 9], [3, 6, 8, 9, 10], [0, 4, 7, 9, 10], [0, 1, 5, 8, 10], [0, 1, 2, 6, 9], [1, 2, 3, 7, 10], [0, 2, 3, 4, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l2-s0/tests/check.py b/tasks/construct-mc-bibd-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s0/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-l2-s0/tests/instance.json b/tasks/construct-mc-bibd-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e354973c7bcb45e5cd6779513bd3cb8057c043a --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"v": 11, "k": 5, "lambda": 2, "b": 11, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s0/tests/run.py b/tasks/construct-mc-bibd-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l2-s0/tests/test.sh b/tasks/construct-mc-bibd-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l6-s1/environment/Dockerfile b/tasks/construct-mc-bibd-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l6-s1/environment/instance.json b/tasks/construct-mc-bibd-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d36efaeb100d11239abdc617c814799fcd3198e9 --- /dev/null +++ b/tasks/construct-mc-bibd-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"v": 31, "k": 15, "lambda": 7, "b": 31, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l6-s1/solution/solve.sh b/tasks/construct-mc-bibd-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e9d9beee1e0464e382dd8e77606099a9340d1e5 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[1, 2, 4, 5, 7, 8, 9, 10, 14, 16, 18, 19, 20, 25, 28], [2, 3, 5, 6, 8, 9, 10, 11, 15, 17, 19, 20, 21, 26, 29], [3, 4, 6, 7, 9, 10, 11, 12, 16, 18, 20, 21, 22, 27, 30], [0, 4, 5, 7, 8, 10, 11, 12, 13, 17, 19, 21, 22, 23, 28], [1, 5, 6, 8, 9, 11, 12, 13, 14, 18, 20, 22, 23, 24, 29], [2, 6, 7, 9, 10, 12, 13, 14, 15, 19, 21, 23, 24, 25, 30], [0, 3, 7, 8, 10, 11, 13, 14, 15, 16, 20, 22, 24, 25, 26], [1, 4, 8, 9, 11, 12, 14, 15, 16, 17, 21, 23, 25, 26, 27], [2, 5, 9, 10, 12, 13, 15, 16, 17, 18, 22, 24, 26, 27, 28], [3, 6, 10, 11, 13, 14, 16, 17, 18, 19, 23, 25, 27, 28, 29], [4, 7, 11, 12, 14, 15, 17, 18, 19, 20, 24, 26, 28, 29, 30], [0, 5, 8, 12, 13, 15, 16, 18, 19, 20, 21, 25, 27, 29, 30], [0, 1, 6, 9, 13, 14, 16, 17, 19, 20, 21, 22, 26, 28, 30], [0, 1, 2, 7, 10, 14, 15, 17, 18, 20, 21, 22, 23, 27, 29], [1, 2, 3, 8, 11, 15, 16, 18, 19, 21, 22, 23, 24, 28, 30], [0, 2, 3, 4, 9, 12, 16, 17, 19, 20, 22, 23, 24, 25, 29], [1, 3, 4, 5, 10, 13, 17, 18, 20, 21, 23, 24, 25, 26, 30], [0, 2, 4, 5, 6, 11, 14, 18, 19, 21, 22, 24, 25, 26, 27], [1, 3, 5, 6, 7, 12, 15, 19, 20, 22, 23, 25, 26, 27, 28], [2, 4, 6, 7, 8, 13, 16, 20, 21, 23, 24, 26, 27, 28, 29], [3, 5, 7, 8, 9, 14, 17, 21, 22, 24, 25, 27, 28, 29, 30], [0, 4, 6, 8, 9, 10, 15, 18, 22, 23, 25, 26, 28, 29, 30], [0, 1, 5, 7, 9, 10, 11, 16, 19, 23, 24, 26, 27, 29, 30], [0, 1, 2, 6, 8, 10, 11, 12, 17, 20, 24, 25, 27, 28, 30], [0, 1, 2, 3, 7, 9, 11, 12, 13, 18, 21, 25, 26, 28, 29], [1, 2, 3, 4, 8, 10, 12, 13, 14, 19, 22, 26, 27, 29, 30], [0, 2, 3, 4, 5, 9, 11, 13, 14, 15, 20, 23, 27, 28, 30], [0, 1, 3, 4, 5, 6, 10, 12, 14, 15, 16, 21, 24, 28, 29], [1, 2, 4, 5, 6, 7, 11, 13, 15, 16, 17, 22, 25, 29, 30], [0, 2, 3, 5, 6, 7, 8, 12, 14, 16, 17, 18, 23, 26, 30], [0, 1, 3, 4, 6, 7, 8, 9, 13, 15, 17, 18, 19, 24, 27]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l6-s1/tests/check.py b/tasks/construct-mc-bibd-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l6-s1/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-l6-s1/tests/instance.json b/tasks/construct-mc-bibd-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d36efaeb100d11239abdc617c814799fcd3198e9 --- /dev/null +++ b/tasks/construct-mc-bibd-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"v": 31, "k": 15, "lambda": 7, "b": 31, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l6-s1/tests/run.py b/tasks/construct-mc-bibd-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l6-s1/tests/test.sh b/tasks/construct-mc-bibd-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-costas-array-l3-s2/environment/Dockerfile b/tasks/construct-mc-costas-array-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l3-s2/environment/instance.json b/tasks/construct-mc-costas-array-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61559fca87e44d4c49739bba020a74df53459ae3 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l3-s2/solution/solve.sh b/tasks/construct-mc-costas-array-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1685719660d0c2a15bc2dbf66fd406db6bad3ea1 --- /dev/null +++ b/tasks/construct-mc-costas-array-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' +{"x": [8, 7, 5, 10, 3, 0, 4, 12, 6, 1, 2, 9, 11]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l3-s2/tests/check.py b/tasks/construct-mc-costas-array-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s2/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l3-s2/tests/instance.json b/tasks/construct-mc-costas-array-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61559fca87e44d4c49739bba020a74df53459ae3 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l3-s2/tests/run.py b/tasks/construct-mc-costas-array-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l3-s2/tests/test.sh b/tasks/construct-mc-costas-array-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-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-debruijn-l2-s0/environment/Dockerfile b/tasks/construct-mc-debruijn-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l2-s0/environment/instance.json b/tasks/construct-mc-debruijn-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3635ff64a475398f63f7a366245abfa8ba024bac --- /dev/null +++ b/tasks/construct-mc-debruijn-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"b": 2, "n": 5, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l2-s0/solution/solve.sh b/tasks/construct-mc-debruijn-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7bc71f9a4388ca15609f513a6dcd9f273bde8590 --- /dev/null +++ b/tasks/construct-mc-debruijn-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' +{"seq": [0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l2-s0/tests/check.py b/tasks/construct-mc-debruijn-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l2-s0/tests/check.py @@ -0,0 +1,15 @@ +"""De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + b, n = inst["b"], inst["n"] + m = b ** n + x = int_list(ans.get("seq"), m, 0, b - 1, "seq") + seen = set() + for i in range(m): + w = tuple(x[(i + k) % m] for k in range(n)) + if w in seen: + raise Invalid(f"window {w} occurs twice") + seen.add(w) + return None, {} diff --git a/tasks/construct-mc-debruijn-l2-s0/tests/instance.json b/tasks/construct-mc-debruijn-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3635ff64a475398f63f7a366245abfa8ba024bac --- /dev/null +++ b/tasks/construct-mc-debruijn-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"b": 2, "n": 5, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l2-s0/tests/run.py b/tasks/construct-mc-debruijn-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l2-s0/tests/test.sh b/tasks/construct-mc-debruijn-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-golomb-l4-s1/environment/Dockerfile b/tasks/construct-mc-golomb-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l4-s1/environment/instance.json b/tasks/construct-mc-golomb-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e5cab54cb2ee2c9f86822903f76a315c9b164706 --- /dev/null +++ b/tasks/construct-mc-golomb-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "max_length": 85, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l4-s1/solution/solve.sh b/tasks/construct-mc-golomb-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..726b1cddc8660389c0721ac6d0439e998d43599b --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 2, 6, 24, 29, 40, 43, 55, 68, 75, 76, 85]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l4-s1/tests/check.py b/tasks/construct-mc-golomb-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l4-s1/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-l4-s1/tests/instance.json b/tasks/construct-mc-golomb-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e5cab54cb2ee2c9f86822903f76a315c9b164706 --- /dev/null +++ b/tasks/construct-mc-golomb-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "max_length": 85, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l4-s1/tests/run.py b/tasks/construct-mc-golomb-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l4-s1/tests/test.sh b/tasks/construct-mc-golomb-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-graph-k-coloring-l2-s3/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l2-s3/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc643b195ee236887efbe5f90f9cb74b98e3e87f --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 37, "k": 4, "edges": [[0, 1], [0, 3], [0, 6], [0, 7], [0, 9], [0, 18], [0, 21], [0, 24], [1, 7], [1, 8], [1, 12], [1, 13], [1, 24], [1, 26], [1, 28], [2, 3], [2, 11], [2, 15], [2, 20], [2, 21], [2, 22], [2, 24], [2, 36], [3, 11], [3, 12], [3, 28], [3, 29], [3, 36], [4, 5], [4, 14], [4, 20], [4, 30], [4, 35], [5, 17], [5, 25], [5, 30], [5, 33], [5, 34], [6, 8], [6, 20], [6, 24], [6, 30], [7, 11], [7, 17], [7, 19], [7, 21], [7, 24], [7, 25], [7, 27], [7, 32], [8, 12], [8, 13], [8, 17], [8, 21], [8, 22], [8, 28], [8, 36], [9, 12], [9, 13], [9, 19], [9, 21], [9, 27], [9, 28], [9, 29], [9, 32], [9, 34], [10, 21], [10, 31], [11, 12], [11, 13], [11, 16], [11, 29], [13, 14], [13, 18], [13, 30], [13, 35], [13, 36], [14, 16], [14, 31], [15, 22], [15, 24], [15, 25], [15, 28], [15, 30], [15, 33], [16, 18], [16, 27], [16, 28], [16, 34], [17, 19], [17, 23], [17, 25], [17, 30], [17, 32], [17, 36], [18, 30], [18, 35], [18, 36], [19, 24], [19, 34], [19, 36], [20, 21], [20, 24], [20, 27], [20, 33], [21, 26], [21, 33], [21, 36], [22, 28], [22, 34], [23, 31], [23, 36], [24, 29], [24, 32], [24, 35], [25, 31], [25, 32], [25, 35], [26, 29], [26, 34], [27, 29], [27, 30], [27, 34], [27, 35], [27, 36], [28, 29], [28, 32], [28, 35], [30, 32], [30, 36], [32, 36], [33, 35], [33, 36]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l2-s3/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb816998ca6293b7f21e6164dc31443d70096e95 --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [0, 1, 0, 1, 0, 1, 1, 2, 2, 3, 0, 3, 0, 0, 1, 1, 2, 0, 1, 1, 2, 1, 3, 1, 3, 3, 3, 1, 0, 2, 2, 2, 1, 0, 0, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l2-s3/tests/check.py b/tasks/construct-mc-graph-k-coloring-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s3/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-l2-s3/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc643b195ee236887efbe5f90f9cb74b98e3e87f --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 37, "k": 4, "edges": [[0, 1], [0, 3], [0, 6], [0, 7], [0, 9], [0, 18], [0, 21], [0, 24], [1, 7], [1, 8], [1, 12], [1, 13], [1, 24], [1, 26], [1, 28], [2, 3], [2, 11], [2, 15], [2, 20], [2, 21], [2, 22], [2, 24], [2, 36], [3, 11], [3, 12], [3, 28], [3, 29], [3, 36], [4, 5], [4, 14], [4, 20], [4, 30], [4, 35], [5, 17], [5, 25], [5, 30], [5, 33], [5, 34], [6, 8], [6, 20], [6, 24], [6, 30], [7, 11], [7, 17], [7, 19], [7, 21], [7, 24], [7, 25], [7, 27], [7, 32], [8, 12], [8, 13], [8, 17], [8, 21], [8, 22], [8, 28], [8, 36], [9, 12], [9, 13], [9, 19], [9, 21], [9, 27], [9, 28], [9, 29], [9, 32], [9, 34], [10, 21], [10, 31], [11, 12], [11, 13], [11, 16], [11, 29], [13, 14], [13, 18], [13, 30], [13, 35], [13, 36], [14, 16], [14, 31], [15, 22], [15, 24], [15, 25], [15, 28], [15, 30], [15, 33], [16, 18], [16, 27], [16, 28], [16, 34], [17, 19], [17, 23], [17, 25], [17, 30], [17, 32], [17, 36], [18, 30], [18, 35], [18, 36], [19, 24], [19, 34], [19, 36], [20, 21], [20, 24], [20, 27], [20, 33], [21, 26], [21, 33], [21, 36], [22, 28], [22, 34], [23, 31], [23, 36], [24, 29], [24, 32], [24, 35], [25, 31], [25, 32], [25, 35], [26, 29], [26, 34], [27, 29], [27, 30], [27, 34], [27, 35], [27, 36], [28, 29], [28, 32], [28, 35], [30, 32], [30, 36], [32, 36], [33, 35], [33, 36]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l2-s3/tests/run.py b/tasks/construct-mc-graph-k-coloring-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l2-s3/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s2/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s2/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..394db76f3efeff2afc290d54ca5a4aaf61a64ae2 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 28], [0, 38], [0, 57], [0, 131], [0, 189], [0, 241], [1, 32], [1, 55], [1, 97], [1, 127], [1, 145], [1, 147], [1, 150], [1, 167], [1, 189], [1, 199], [1, 207], [1, 225], [2, 11], [2, 159], [2, 181], [2, 209], [2, 228], [2, 233], [3, 61], [3, 66], [3, 74], [3, 136], [3, 137], [3, 141], [3, 160], [3, 234], [4, 44], [4, 46], [4, 64], [4, 128], [4, 133], [4, 186], [5, 19], [5, 62], [5, 87], [5, 195], [5, 222], [5, 234], [6, 74], [6, 84], [6, 104], [6, 175], [6, 181], [6, 208], [6, 209], [6, 237], [7, 46], [7, 60], [7, 65], [7, 122], [7, 161], [7, 220], [8, 19], [8, 20], [8, 50], [8, 66], [8, 77], [8, 87], [8, 140], [8, 151], [8, 152], [8, 176], [8, 177], [8, 185], [8, 219], [9, 65], [9, 76], [9, 184], [10, 26], [10, 128], [10, 146], [10, 183], [10, 218], [10, 224], [10, 240], [11, 33], [11, 163], [11, 206], [11, 210], [11, 211], [11, 221], [11, 236], [12, 45], [12, 65], [12, 76], [12, 124], [12, 137], [12, 182], [12, 234], [13, 27], [13, 72], [13, 100], [13, 165], [13, 179], [13, 207], [13, 218], [13, 244], [14, 28], [14, 51], [14, 73], [14, 123], [14, 161], [14, 187], [14, 214], [14, 224], [14, 226], [15, 20], [15, 40], [15, 64], [15, 73], [15, 103], [15, 104], [15, 109], [15, 130], [15, 191], [15, 237], [16, 42], [16, 48], [16, 116], [16, 162], [16, 180], [16, 205], [17, 66], [17, 70], [17, 110], [17, 235], [18, 25], [18, 31], [18, 76], [18, 104], [18, 128], [18, 139], [18, 157], [18, 234], [19, 21], [19, 88], [19, 116], [19, 130], [19, 168], [19, 214], [19, 233], [20, 28], [20, 53], [20, 56], [20, 57], [20, 110], [20, 129], [20, 172], [20, 188], [21, 54], [21, 63], [21, 78], [21, 93], [21, 96], [21, 150], [21, 160], [21, 175], [21, 190], [22, 180], [22, 199], [22, 225], [22, 233], [22, 240], [23, 24], [23, 45], [23, 63], [23, 112], [23, 121], [23, 126], [23, 134], [23, 136], [23, 142], [23, 145], [23, 190], [23, 206], [23, 228], [24, 76], [24, 82], [24, 116], [24, 128], [24, 131], [24, 144], [24, 148], [24, 149], [24, 159], [24, 180], [24, 202], [24, 223], [25, 30], [25, 65], [25, 73], [25, 83], [25, 85], [25, 123], [25, 124], [25, 128], [25, 146], [25, 155], [25, 157], [25, 166], [25, 192], [25, 228], [25, 244], [25, 248], [26, 35], [26, 47], [26, 99], [26, 170], [26, 179], [26, 181], [26, 213], [26, 238], [26, 247], [27, 51], [27, 82], [27, 88], [27, 92], [27, 105], [27, 114], [27, 115], [27, 160], [27, 165], [27, 204], [27, 245], [28, 65], [28, 97], [28, 104], [28, 135], [28, 161], [28, 179], [28, 186], [28, 192], [28, 209], [28, 223], [29, 41], [29, 45], [29, 60], [29, 76], [29, 86], [29, 191], [29, 205], [30, 113], [30, 228], [30, 241], [31, 69], [31, 101], [31, 151], [31, 199], [31, 204], [31, 206], [32, 51], [32, 72], [32, 78], [32, 89], [32, 103], [32, 122], [32, 132], [32, 181], [32, 209], [32, 210], [32, 214], [32, 219], [32, 230], [33, 100], [33, 122], [33, 124], [33, 160], [33, 162], [33, 200], [33, 209], [33, 227], [33, 239], [34, 40], [34, 48], [34, 54], [34, 107], [34, 127], [34, 184], [34, 191], [34, 212], [34, 219], [35, 50], [35, 116], [35, 174], [35, 183], [35, 232], [35, 243], [36, 47], [36, 83], [36, 98], [36, 124], [36, 142], [36, 161], [36, 177], [36, 180], [37, 102], [37, 150], [37, 199], [37, 219], [37, 236], [38, 63], [38, 66], [38, 70], [38, 73], [38, 140], [38, 202], [38, 248], [39, 42], [39, 116], [39, 128], [39, 134], [39, 139], [39, 194], [39, 197], [39, 204], [39, 219], [39, 233], [40, 58], [40, 122], [40, 203], [40, 205], [40, 223], [41, 86], [41, 87], [41, 99], [41, 102], [41, 153], [41, 169], [41, 172], [41, 184], [41, 208], [42, 52], [42, 79], [42, 90], [42, 103], [42, 123], [42, 129], [42, 148], [42, 179], [42, 225], [43, 119], [43, 126], [43, 147], [43, 150], [43, 187], [43, 213], [43, 221], [43, 234], [43, 245], [44, 53], [44, 62], [44, 68], [44, 113], [44, 236], [44, 237], [45, 53], [45, 59], [45, 68], [45, 82], [45, 108], [45, 131], [45, 179], [45, 245], [46, 65], [46, 68], [46, 214], [46, 219], [46, 249], [47, 67], [47, 117], [47, 124], [47, 202], [48, 161], [48, 178], [48, 191], [48, 200], [49, 60], [49, 81], [49, 84], [49, 187], [49, 219], [49, 230], [49, 238], [50, 55], [50, 83], [50, 136], [50, 189], [50, 246], [51, 68], [51, 87], [51, 129], [51, 133], [51, 180], [51, 211], [51, 218], [51, 230], [51, 234], [52, 55], [52, 71], [52, 72], [52, 94], [52, 107], [52, 155], [52, 160], [52, 176], [52, 191], [53, 55], [53, 59], [53, 85], [53, 107], [53, 175], [53, 224], [53, 228], [54, 58], [54, 89], [54, 99], [54, 118], [54, 155], [54, 220], [54, 230], [54, 247], [55, 66], [55, 79], [55, 99], [55, 128], [55, 176], [55, 184], [55, 206], [55, 214], [55, 243], [56, 100], [56, 108], [56, 111], [56, 134], [56, 135], [56, 159], [56, 220], [56, 221], [56, 224], [57, 68], [57, 150], [57, 189], [57, 221], [57, 226], [57, 237], [58, 68], [58, 154], [58, 195], [58, 221], [58, 223], [59, 65], [59, 69], [59, 119], [59, 164], [59, 175], [59, 180], [60, 103], [60, 136], [60, 139], [60, 159], [60, 182], [60, 190], [60, 196], [60, 216], [60, 230], [61, 70], [61, 71], [61, 87], [61, 111], [61, 183], [62, 85], [62, 115], [62, 128], [62, 230], [62, 236], [63, 72], [63, 135], [63, 153], [63, 208], [64, 70], [64, 86], [64, 87], [64, 92], [64, 113], [64, 116], [64, 132], [64, 153], [64, 169], [64, 196], [64, 225], [65, 97], [65, 102], [65, 165], [65, 247], [66, 72], [66, 130], [66, 160], [66, 233], [67, 78], [67, 175], [67, 216], [67, 218], [67, 219], [67, 221], [67, 247], [68, 158], [68, 246], [69, 114], [69, 120], [69, 128], [69, 155], [69, 161], [69, 188], [69, 192], [69, 233], [70, 118], [70, 141], [70, 177], [70, 218], [70, 242], [71, 100], [71, 113], [71, 127], [71, 190], [71, 197], [71, 215], [72, 81], [72, 103], [72, 145], [72, 176], [72, 196], [72, 200], [72, 233], [72, 246], [73, 82], [73, 88], [73, 112], [73, 122], [73, 130], [73, 131], [73, 180], [73, 184], [73, 219], [73, 234], [74, 86], [74, 90], [74, 119], [74, 120], [74, 150], [74, 158], [74, 179], [75, 92], [75, 116], [75, 151], [75, 159], [75, 183], [75, 202], [76, 122], [76, 125], [76, 142], [76, 182], [76, 193], [76, 204], [76, 208], [76, 214], [76, 231], [76, 234], [76, 244], [77, 89], [77, 105], [77, 114], [77, 155], [77, 160], [77, 192], [77, 220], [77, 245], [78, 95], [78, 100], [78, 111], [78, 155], [78, 172], [79, 80], [79, 101], [79, 107], [79, 114], [79, 130], [79, 140], [79, 210], [80, 94], [80, 100], [80, 102], [80, 119], [80, 126], [80, 217], [81, 95], [81, 157], [81, 163], [81, 194], [81, 210], [82, 84], [82, 88], [82, 132], [82, 238], [83, 102], [83, 123], [83, 148], [83, 170], [83, 180], [83, 202], [83, 212], [83, 213], [83, 234], [83, 240], [84, 98], [84, 104], [84, 163], [84, 209], [84, 218], [84, 228], [84, 244], [85, 103], [85, 139], [85, 179], [85, 227], [85, 230], [86, 95], [86, 136], [86, 206], [86, 221], [87, 235], [88, 92], [88, 123], [88, 157], [88, 217], [89, 109], [89, 147], [89, 153], [89, 157], [89, 224], [89, 228], [89, 241], [89, 245], [90, 109], [90, 173], [90, 219], [90, 226], [91, 100], [91, 148], [91, 172], [91, 178], [91, 196], [92, 152], [93, 98], [93, 108], [93, 169], [93, 194], [93, 203], [93, 216], [93, 222], [94, 95], [94, 124], [94, 144], [94, 147], [94, 168], [95, 108], [95, 118], [95, 140], [95, 164], [95, 171], [95, 221], [95, 238], [96, 177], [96, 189], [96, 206], [97, 109], [97, 157], [97, 188], [97, 230], [98, 128], [98, 228], [98, 248], [99, 129], [99, 222], [99, 230], [100, 110], [100, 140], [100, 172], [100, 174], [100, 207], [100, 208], [101, 162], [101, 163], [101, 164], [101, 180], [101, 215], [101, 227], [101, 230], [102, 118], [102, 135], [102, 174], [102, 180], [102, 214], [102, 238], [103, 163], [103, 194], [103, 211], [103, 239], [103, 241], [104, 167], [104, 195], [104, 207], [105, 120], [105, 138], [105, 227], [106, 146], [106, 166], [106, 211], [106, 221], [106, 243], [106, 247], [108, 149], [108, 184], [108, 246], [109, 135], [109, 141], [109, 180], [109, 193], [109, 198], [110, 141], [110, 207], [110, 234], [111, 112], [111, 113], [111, 122], [111, 145], [111, 156], [111, 172], [111, 215], [111, 221], [111, 238], [112, 148], [112, 167], [112, 197], [112, 226], [113, 120], [113, 129], [113, 189], [113, 204], [113, 242], [113, 243], [113, 245], [114, 133], [114, 147], [114, 174], [114, 222], [115, 151], [115, 168], [115, 186], [115, 201], [115, 212], [115, 245], [116, 147], [116, 185], [116, 224], [117, 154], [119, 185], [119, 192], [120, 133], [120, 206], [121, 142], [121, 151], [121, 215], [122, 130], [122, 133], [122, 150], [122, 167], [122, 187], [123, 135], [123, 142], [123, 159], [123, 173], [123, 237], [124, 169], [124, 199], [124, 215], [124, 247], [125, 132], [125, 142], [125, 154], [125, 196], [125, 229], [126, 164], [126, 178], [126, 191], [126, 193], [126, 203], [126, 220], [126, 222], [127, 180], [127, 186], [127, 212], [127, 220], [128, 173], [128, 186], [128, 195], [128, 224], [128, 240], [129, 136], [129, 149], [129, 200], [129, 205], [129, 249], [130, 166], [130, 229], [131, 153], [131, 169], [131, 173], [131, 184], [131, 214], [131, 215], [131, 224], [132, 144], [132, 154], [132, 159], [132, 186], [132, 197], [132, 217], [133, 150], [133, 157], [133, 161], [133, 164], [133, 190], [133, 208], [134, 169], [134, 173], [134, 236], [135, 163], [135, 181], [135, 197], [135, 198], [135, 214], [136, 182], [136, 185], [136, 242], [137, 232], [138, 180], [138, 192], [139, 169], [139, 181], [139, 183], [139, 193], [140, 154], [140, 156], [140, 166], [140, 219], [140, 222], [140, 247], [140, 249], [141, 153], [141, 195], [141, 197], [141, 200], [142, 185], [142, 232], [143, 149], [143, 194], [143, 234], [143, 241], [144, 158], [144, 229], [144, 239], [144, 246], [145, 160], [145, 181], [145, 214], [145, 234], [146, 158], [146, 171], [146, 186], [146, 200], [146, 206], [146, 222], [146, 228], [146, 240], [147, 203], [148, 167], [149, 157], [149, 165], [149, 167], [149, 187], [150, 154], [150, 160], [150, 189], [150, 207], [150, 248], [151, 185], [151, 199], [152, 191], [152, 192], [152, 245], [153, 214], [153, 237], [154, 176], [154, 193], [154, 214], [154, 227], [154, 240], [155, 159], [155, 249], [156, 235], [157, 170], [157, 171], [157, 203], [157, 230], [157, 231], [157, 237], [157, 246], [158, 174], [158, 180], [159, 166], [159, 169], [159, 178], [159, 185], [159, 213], [159, 217], [159, 239], [160, 200], [160, 225], [161, 170], [162, 249], [163, 170], [163, 205], [164, 174], [164, 186], [164, 217], [166, 207], [166, 211], [166, 249], [167, 229], [167, 247], [168, 174], [168, 178], [170, 191], [170, 194], [170, 205], [170, 237], [171, 186], [171, 200], [171, 215], [171, 223], [171, 225], [172, 180], [172, 201], [172, 222], [173, 192], [173, 230], [174, 197], [174, 227], [175, 189], [175, 208], [175, 242], [176, 192], [176, 210], [176, 215], [176, 220], [176, 232], [176, 234], [177, 243], [178, 179], [178, 219], [178, 222], [180, 196], [180, 200], [180, 204], [180, 210], [180, 225], [180, 239], [180, 242], [180, 243], [180, 245], [181, 231], [182, 185], [182, 208], [182, 217], [182, 223], [182, 234], [183, 203], [183, 212], [183, 225], [183, 226], [183, 234], [183, 244], [183, 245], [184, 187], [184, 217], [184, 239], [185, 201], [185, 216], [185, 245], [186, 188], [186, 197], [186, 203], [186, 219], [186, 236], [187, 204], [187, 236], [187, 241], [188, 215], [188, 233], [190, 194], [190, 241], [191, 225], [191, 241], [192, 221], [193, 204], [193, 223], [194, 208], [194, 218], [195, 196], [196, 234], [196, 241], [197, 198], [197, 232], [198, 230], [198, 237], [199, 201], [199, 229], [200, 228], [201, 208], [201, 218], [201, 236], [201, 244], [202, 203], [202, 204], [202, 244], [203, 213], [203, 217], [203, 244], [204, 234], [205, 218], [205, 223], [206, 223], [206, 243], [207, 217], [207, 246], [211, 239], [212, 239], [212, 240], [214, 248], [215, 234], [215, 237], [217, 235], [217, 241], [218, 225], [219, 229], [219, 240], [220, 236], [222, 245], [224, 230], [225, 229], [231, 241], [231, 244], [231, 245], [232, 240], [233, 247], [237, 246], [244, 247], [245, 249], [246, 248]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s2/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..efa199bd3ae235adde2376033b2435d54dccb3ec --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [2, 1, 0, 1, 1, 1, 2, 3, 2, 1, 3, 1, 1, 1, 3, 1, 1, 3, 1, 0, 3, 1, 1, 1, 2, 3, 0, 0, 1, 2, 0, 0, 0, 2, 1, 2, 2, 0, 3, 1, 2, 3, 3, 1, 0, 0, 2, 3, 2, 2, 0, 1, 2, 1, 0, 3, 1, 1, 1, 2, 1, 2, 2, 2, 2, 0, 0, 1, 3, 3, 0, 3, 3, 0, 3, 2, 0, 0, 3, 0, 3, 1, 3, 1, 1, 0, 1, 0, 2, 3, 2, 2, 3, 0, 1, 0, 0, 2, 3, 1, 0, 2, 2, 2, 0, 2, 1, 3, 3, 0, 1, 0, 3, 1, 1, 1, 3, 0, 1, 0, 0, 2, 1, 0, 0, 2, 0, 0, 0, 2, 3, 3, 1, 3, 0, 3, 3, 0, 0, 2, 1, 2, 3, 0, 3, 2, 0, 0, 0, 1, 2, 3, 0, 0, 3, 1, 3, 0, 2, 3, 3, 0, 3, 0, 1, 2, 2, 2, 2, 1, 2, 3, 1, 1, 3, 0, 0, 3, 1, 2, 3, 1, 2, 1, 2, 1, 2, 0, 0, 3, 2, 3, 2, 1, 3, 3, 0, 0, 2, 2, 1, 0, 0, 3, 2, 3, 2, 3, 1, 3, 2, 3, 3, 2, 1, 1, 2, 0, 2, 3, 2, 3, 3, 0, 2, 0, 0, 1, 2, 1, 3, 3, 1, 2, 3, 1, 3, 3, 1, 1, 2, 1, 2, 0, 2, 2, 1, 3, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l6-s2/tests/check.py b/tasks/construct-mc-graph-k-coloring-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s2/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-l6-s2/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..394db76f3efeff2afc290d54ca5a4aaf61a64ae2 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 28], [0, 38], [0, 57], [0, 131], [0, 189], [0, 241], [1, 32], [1, 55], [1, 97], [1, 127], [1, 145], [1, 147], [1, 150], [1, 167], [1, 189], [1, 199], [1, 207], [1, 225], [2, 11], [2, 159], [2, 181], [2, 209], [2, 228], [2, 233], [3, 61], [3, 66], [3, 74], [3, 136], [3, 137], [3, 141], [3, 160], [3, 234], [4, 44], [4, 46], [4, 64], [4, 128], [4, 133], [4, 186], [5, 19], [5, 62], [5, 87], [5, 195], [5, 222], [5, 234], [6, 74], [6, 84], [6, 104], [6, 175], [6, 181], [6, 208], [6, 209], [6, 237], [7, 46], [7, 60], [7, 65], [7, 122], [7, 161], [7, 220], [8, 19], [8, 20], [8, 50], [8, 66], [8, 77], [8, 87], [8, 140], [8, 151], [8, 152], [8, 176], [8, 177], [8, 185], [8, 219], [9, 65], [9, 76], [9, 184], [10, 26], [10, 128], [10, 146], [10, 183], [10, 218], [10, 224], [10, 240], [11, 33], [11, 163], [11, 206], [11, 210], [11, 211], [11, 221], [11, 236], [12, 45], [12, 65], [12, 76], [12, 124], [12, 137], [12, 182], [12, 234], [13, 27], [13, 72], [13, 100], [13, 165], [13, 179], [13, 207], [13, 218], [13, 244], [14, 28], [14, 51], [14, 73], [14, 123], [14, 161], [14, 187], [14, 214], [14, 224], [14, 226], [15, 20], [15, 40], [15, 64], [15, 73], [15, 103], [15, 104], [15, 109], [15, 130], [15, 191], [15, 237], [16, 42], [16, 48], [16, 116], [16, 162], [16, 180], [16, 205], [17, 66], [17, 70], [17, 110], [17, 235], [18, 25], [18, 31], [18, 76], [18, 104], [18, 128], [18, 139], [18, 157], [18, 234], [19, 21], [19, 88], [19, 116], [19, 130], [19, 168], [19, 214], [19, 233], [20, 28], [20, 53], [20, 56], [20, 57], [20, 110], [20, 129], [20, 172], [20, 188], [21, 54], [21, 63], [21, 78], [21, 93], [21, 96], [21, 150], [21, 160], [21, 175], [21, 190], [22, 180], [22, 199], [22, 225], [22, 233], [22, 240], [23, 24], [23, 45], [23, 63], [23, 112], [23, 121], [23, 126], [23, 134], [23, 136], [23, 142], [23, 145], [23, 190], [23, 206], [23, 228], [24, 76], [24, 82], [24, 116], [24, 128], [24, 131], [24, 144], [24, 148], [24, 149], [24, 159], [24, 180], [24, 202], [24, 223], [25, 30], [25, 65], [25, 73], [25, 83], [25, 85], [25, 123], [25, 124], [25, 128], [25, 146], [25, 155], [25, 157], [25, 166], [25, 192], [25, 228], [25, 244], [25, 248], [26, 35], [26, 47], [26, 99], [26, 170], [26, 179], [26, 181], [26, 213], [26, 238], [26, 247], [27, 51], [27, 82], [27, 88], [27, 92], [27, 105], [27, 114], [27, 115], [27, 160], [27, 165], [27, 204], [27, 245], [28, 65], [28, 97], [28, 104], [28, 135], [28, 161], [28, 179], [28, 186], [28, 192], [28, 209], [28, 223], [29, 41], [29, 45], [29, 60], [29, 76], [29, 86], [29, 191], [29, 205], [30, 113], [30, 228], [30, 241], [31, 69], [31, 101], [31, 151], [31, 199], [31, 204], [31, 206], [32, 51], [32, 72], [32, 78], [32, 89], [32, 103], [32, 122], [32, 132], [32, 181], [32, 209], [32, 210], [32, 214], [32, 219], [32, 230], [33, 100], [33, 122], [33, 124], [33, 160], [33, 162], [33, 200], [33, 209], [33, 227], [33, 239], [34, 40], [34, 48], [34, 54], [34, 107], [34, 127], [34, 184], [34, 191], [34, 212], [34, 219], [35, 50], [35, 116], [35, 174], [35, 183], [35, 232], [35, 243], [36, 47], [36, 83], [36, 98], [36, 124], [36, 142], [36, 161], [36, 177], [36, 180], [37, 102], [37, 150], [37, 199], [37, 219], [37, 236], [38, 63], [38, 66], [38, 70], [38, 73], [38, 140], [38, 202], [38, 248], [39, 42], [39, 116], [39, 128], [39, 134], [39, 139], [39, 194], [39, 197], [39, 204], [39, 219], [39, 233], [40, 58], [40, 122], [40, 203], [40, 205], [40, 223], [41, 86], [41, 87], [41, 99], [41, 102], [41, 153], [41, 169], [41, 172], [41, 184], [41, 208], [42, 52], [42, 79], [42, 90], [42, 103], [42, 123], [42, 129], [42, 148], [42, 179], [42, 225], [43, 119], [43, 126], [43, 147], [43, 150], [43, 187], [43, 213], [43, 221], [43, 234], [43, 245], [44, 53], [44, 62], [44, 68], [44, 113], [44, 236], [44, 237], [45, 53], [45, 59], [45, 68], [45, 82], [45, 108], [45, 131], [45, 179], [45, 245], [46, 65], [46, 68], [46, 214], [46, 219], [46, 249], [47, 67], [47, 117], [47, 124], [47, 202], [48, 161], [48, 178], [48, 191], [48, 200], [49, 60], [49, 81], [49, 84], [49, 187], [49, 219], [49, 230], [49, 238], [50, 55], [50, 83], [50, 136], [50, 189], [50, 246], [51, 68], [51, 87], [51, 129], [51, 133], [51, 180], [51, 211], [51, 218], [51, 230], [51, 234], [52, 55], [52, 71], [52, 72], [52, 94], [52, 107], [52, 155], [52, 160], [52, 176], [52, 191], [53, 55], [53, 59], [53, 85], [53, 107], [53, 175], [53, 224], [53, 228], [54, 58], [54, 89], [54, 99], [54, 118], [54, 155], [54, 220], [54, 230], [54, 247], [55, 66], [55, 79], [55, 99], [55, 128], [55, 176], [55, 184], [55, 206], [55, 214], [55, 243], [56, 100], [56, 108], [56, 111], [56, 134], [56, 135], [56, 159], [56, 220], [56, 221], [56, 224], [57, 68], [57, 150], [57, 189], [57, 221], [57, 226], [57, 237], [58, 68], [58, 154], [58, 195], [58, 221], [58, 223], [59, 65], [59, 69], [59, 119], [59, 164], [59, 175], [59, 180], [60, 103], [60, 136], [60, 139], [60, 159], [60, 182], [60, 190], [60, 196], [60, 216], [60, 230], [61, 70], [61, 71], [61, 87], [61, 111], [61, 183], [62, 85], [62, 115], [62, 128], [62, 230], [62, 236], [63, 72], [63, 135], [63, 153], [63, 208], [64, 70], [64, 86], [64, 87], [64, 92], [64, 113], [64, 116], [64, 132], [64, 153], [64, 169], [64, 196], [64, 225], [65, 97], [65, 102], [65, 165], [65, 247], [66, 72], [66, 130], [66, 160], [66, 233], [67, 78], [67, 175], [67, 216], [67, 218], [67, 219], [67, 221], [67, 247], [68, 158], [68, 246], [69, 114], [69, 120], [69, 128], [69, 155], [69, 161], [69, 188], [69, 192], [69, 233], [70, 118], [70, 141], [70, 177], [70, 218], [70, 242], [71, 100], [71, 113], [71, 127], [71, 190], [71, 197], [71, 215], [72, 81], [72, 103], [72, 145], [72, 176], [72, 196], [72, 200], [72, 233], [72, 246], [73, 82], [73, 88], [73, 112], [73, 122], [73, 130], [73, 131], [73, 180], [73, 184], [73, 219], [73, 234], [74, 86], [74, 90], [74, 119], [74, 120], [74, 150], [74, 158], [74, 179], [75, 92], [75, 116], [75, 151], [75, 159], [75, 183], [75, 202], [76, 122], [76, 125], [76, 142], [76, 182], [76, 193], [76, 204], [76, 208], [76, 214], [76, 231], [76, 234], [76, 244], [77, 89], [77, 105], [77, 114], [77, 155], [77, 160], [77, 192], [77, 220], [77, 245], [78, 95], [78, 100], [78, 111], [78, 155], [78, 172], [79, 80], [79, 101], [79, 107], [79, 114], [79, 130], [79, 140], [79, 210], [80, 94], [80, 100], [80, 102], [80, 119], [80, 126], [80, 217], [81, 95], [81, 157], [81, 163], [81, 194], [81, 210], [82, 84], [82, 88], [82, 132], [82, 238], [83, 102], [83, 123], [83, 148], [83, 170], [83, 180], [83, 202], [83, 212], [83, 213], [83, 234], [83, 240], [84, 98], [84, 104], [84, 163], [84, 209], [84, 218], [84, 228], [84, 244], [85, 103], [85, 139], [85, 179], [85, 227], [85, 230], [86, 95], [86, 136], [86, 206], [86, 221], [87, 235], [88, 92], [88, 123], [88, 157], [88, 217], [89, 109], [89, 147], [89, 153], [89, 157], [89, 224], [89, 228], [89, 241], [89, 245], [90, 109], [90, 173], [90, 219], [90, 226], [91, 100], [91, 148], [91, 172], [91, 178], [91, 196], [92, 152], [93, 98], [93, 108], [93, 169], [93, 194], [93, 203], [93, 216], [93, 222], [94, 95], [94, 124], [94, 144], [94, 147], [94, 168], [95, 108], [95, 118], [95, 140], [95, 164], [95, 171], [95, 221], [95, 238], [96, 177], [96, 189], [96, 206], [97, 109], [97, 157], [97, 188], [97, 230], [98, 128], [98, 228], [98, 248], [99, 129], [99, 222], [99, 230], [100, 110], [100, 140], [100, 172], [100, 174], [100, 207], [100, 208], [101, 162], [101, 163], [101, 164], [101, 180], [101, 215], [101, 227], [101, 230], [102, 118], [102, 135], [102, 174], [102, 180], [102, 214], [102, 238], [103, 163], [103, 194], [103, 211], [103, 239], [103, 241], [104, 167], [104, 195], [104, 207], [105, 120], [105, 138], [105, 227], [106, 146], [106, 166], [106, 211], [106, 221], [106, 243], [106, 247], [108, 149], [108, 184], [108, 246], [109, 135], [109, 141], [109, 180], [109, 193], [109, 198], [110, 141], [110, 207], [110, 234], [111, 112], [111, 113], [111, 122], [111, 145], [111, 156], [111, 172], [111, 215], [111, 221], [111, 238], [112, 148], [112, 167], [112, 197], [112, 226], [113, 120], [113, 129], [113, 189], [113, 204], [113, 242], [113, 243], [113, 245], [114, 133], [114, 147], [114, 174], [114, 222], [115, 151], [115, 168], [115, 186], [115, 201], [115, 212], [115, 245], [116, 147], [116, 185], [116, 224], [117, 154], [119, 185], [119, 192], [120, 133], [120, 206], [121, 142], [121, 151], [121, 215], [122, 130], [122, 133], [122, 150], [122, 167], [122, 187], [123, 135], [123, 142], [123, 159], [123, 173], [123, 237], [124, 169], [124, 199], [124, 215], [124, 247], [125, 132], [125, 142], [125, 154], [125, 196], [125, 229], [126, 164], [126, 178], [126, 191], [126, 193], [126, 203], [126, 220], [126, 222], [127, 180], [127, 186], [127, 212], [127, 220], [128, 173], [128, 186], [128, 195], [128, 224], [128, 240], [129, 136], [129, 149], [129, 200], [129, 205], [129, 249], [130, 166], [130, 229], [131, 153], [131, 169], [131, 173], [131, 184], [131, 214], [131, 215], [131, 224], [132, 144], [132, 154], [132, 159], [132, 186], [132, 197], [132, 217], [133, 150], [133, 157], [133, 161], [133, 164], [133, 190], [133, 208], [134, 169], [134, 173], [134, 236], [135, 163], [135, 181], [135, 197], [135, 198], [135, 214], [136, 182], [136, 185], [136, 242], [137, 232], [138, 180], [138, 192], [139, 169], [139, 181], [139, 183], [139, 193], [140, 154], [140, 156], [140, 166], [140, 219], [140, 222], [140, 247], [140, 249], [141, 153], [141, 195], [141, 197], [141, 200], [142, 185], [142, 232], [143, 149], [143, 194], [143, 234], [143, 241], [144, 158], [144, 229], [144, 239], [144, 246], [145, 160], [145, 181], [145, 214], [145, 234], [146, 158], [146, 171], [146, 186], [146, 200], [146, 206], [146, 222], [146, 228], [146, 240], [147, 203], [148, 167], [149, 157], [149, 165], [149, 167], [149, 187], [150, 154], [150, 160], [150, 189], [150, 207], [150, 248], [151, 185], [151, 199], [152, 191], [152, 192], [152, 245], [153, 214], [153, 237], [154, 176], [154, 193], [154, 214], [154, 227], [154, 240], [155, 159], [155, 249], [156, 235], [157, 170], [157, 171], [157, 203], [157, 230], [157, 231], [157, 237], [157, 246], [158, 174], [158, 180], [159, 166], [159, 169], [159, 178], [159, 185], [159, 213], [159, 217], [159, 239], [160, 200], [160, 225], [161, 170], [162, 249], [163, 170], [163, 205], [164, 174], [164, 186], [164, 217], [166, 207], [166, 211], [166, 249], [167, 229], [167, 247], [168, 174], [168, 178], [170, 191], [170, 194], [170, 205], [170, 237], [171, 186], [171, 200], [171, 215], [171, 223], [171, 225], [172, 180], [172, 201], [172, 222], [173, 192], [173, 230], [174, 197], [174, 227], [175, 189], [175, 208], [175, 242], [176, 192], [176, 210], [176, 215], [176, 220], [176, 232], [176, 234], [177, 243], [178, 179], [178, 219], [178, 222], [180, 196], [180, 200], [180, 204], [180, 210], [180, 225], [180, 239], [180, 242], [180, 243], [180, 245], [181, 231], [182, 185], [182, 208], [182, 217], [182, 223], [182, 234], [183, 203], [183, 212], [183, 225], [183, 226], [183, 234], [183, 244], [183, 245], [184, 187], [184, 217], [184, 239], [185, 201], [185, 216], [185, 245], [186, 188], [186, 197], [186, 203], [186, 219], [186, 236], [187, 204], [187, 236], [187, 241], [188, 215], [188, 233], [190, 194], [190, 241], [191, 225], [191, 241], [192, 221], [193, 204], [193, 223], [194, 208], [194, 218], [195, 196], [196, 234], [196, 241], [197, 198], [197, 232], [198, 230], [198, 237], [199, 201], [199, 229], [200, 228], [201, 208], [201, 218], [201, 236], [201, 244], [202, 203], [202, 204], [202, 244], [203, 213], [203, 217], [203, 244], [204, 234], [205, 218], [205, 223], [206, 223], [206, 243], [207, 217], [207, 246], [211, 239], [212, 239], [212, 240], [214, 248], [215, 234], [215, 237], [217, 235], [217, 241], [218, 225], [219, 229], [219, 240], [220, 236], [222, 245], [224, 230], [225, 229], [231, 241], [231, 244], [231, 245], [232, 240], [233, 247], [237, 246], [244, 247], [245, 249], [246, 248]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s2/tests/run.py b/tasks/construct-mc-graph-k-coloring-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s2/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s5/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s5/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..96fbc0ea0d298efd02fb4f5fd1504f30fcf655d4 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 15], [0, 41], [0, 73], [0, 86], [0, 99], [0, 128], [0, 164], [0, 186], [0, 240], [1, 15], [1, 39], [1, 53], [1, 74], [1, 96], [1, 108], [1, 116], [1, 126], [1, 159], [1, 175], [1, 201], [1, 202], [1, 213], [1, 214], [1, 233], [1, 240], [2, 41], [2, 56], [2, 120], [2, 163], [2, 176], [2, 194], [2, 203], [2, 216], [2, 217], [3, 13], [3, 36], [3, 97], [3, 174], [3, 188], [3, 189], [3, 192], [3, 211], [3, 212], [3, 227], [4, 30], [4, 108], [4, 110], [4, 122], [4, 137], [4, 145], [4, 150], [4, 204], [5, 12], [5, 18], [5, 65], [5, 89], [5, 153], [5, 162], [5, 208], [5, 231], [6, 30], [6, 34], [6, 68], [6, 148], [6, 170], [6, 189], [6, 244], [7, 43], [7, 77], [7, 100], [7, 151], [7, 220], [8, 49], [8, 54], [8, 124], [8, 131], [8, 141], [8, 160], [9, 23], [9, 38], [9, 65], [9, 102], [9, 105], [9, 111], [9, 148], [9, 158], [9, 176], [9, 177], [9, 187], [9, 219], [10, 42], [10, 58], [10, 77], [10, 100], [10, 101], [10, 128], [10, 144], [10, 165], [10, 170], [10, 189], [10, 234], [11, 28], [11, 42], [11, 43], [11, 50], [11, 66], [11, 97], [11, 105], [11, 140], [11, 155], [11, 162], [11, 184], [11, 186], [11, 207], [12, 26], [12, 61], [12, 73], [12, 111], [12, 119], [12, 131], [12, 221], [12, 224], [13, 39], [13, 92], [13, 112], [13, 140], [13, 217], [13, 219], [14, 123], [14, 203], [14, 246], [15, 31], [15, 53], [15, 56], [15, 71], [15, 95], [15, 97], [15, 107], [15, 126], [15, 151], [15, 164], [15, 182], [15, 194], [15, 220], [16, 25], [16, 40], [16, 43], [16, 71], [16, 125], [16, 196], [16, 200], [16, 225], [17, 34], [17, 49], [17, 64], [17, 69], [17, 165], [17, 223], [18, 78], [18, 80], [18, 174], [18, 212], [18, 245], [19, 51], [19, 111], [19, 169], [19, 242], [20, 103], [20, 122], [20, 150], [20, 153], [20, 206], [20, 208], [20, 224], [20, 237], [21, 51], [21, 110], [21, 113], [21, 164], [21, 179], [21, 207], [21, 226], [21, 227], [21, 229], [21, 239], [21, 247], [22, 23], [22, 67], [22, 89], [22, 98], [22, 105], [22, 130], [22, 131], [22, 140], [22, 151], [22, 171], [22, 214], [22, 217], [23, 36], [23, 136], [23, 185], [23, 202], [23, 205], [23, 248], [24, 40], [24, 52], [24, 91], [24, 92], [24, 100], [24, 186], [24, 194], [24, 222], [25, 78], [25, 124], [25, 133], [25, 136], [25, 139], [25, 165], [25, 180], [26, 75], [26, 98], [26, 114], [26, 149], [26, 151], [26, 215], [26, 229], [26, 247], [27, 123], [27, 135], [27, 150], [28, 30], [28, 55], [28, 76], [28, 108], [28, 130], [28, 184], [29, 99], [29, 138], [29, 181], [29, 203], [29, 218], [29, 237], [30, 52], [30, 86], [30, 120], [30, 123], [30, 140], [31, 56], [31, 58], [31, 117], [31, 122], [31, 129], [31, 140], [31, 141], [31, 166], [31, 191], [31, 221], [31, 224], [32, 34], [32, 64], [32, 86], [32, 104], [32, 123], [32, 186], [32, 191], [32, 247], [33, 36], [33, 61], [33, 100], [33, 107], [33, 113], [33, 115], [33, 189], [33, 197], [34, 55], [34, 65], [34, 105], [34, 111], [34, 147], [34, 156], [34, 189], [34, 246], [35, 43], [35, 82], [35, 95], [35, 183], [35, 185], [35, 202], [35, 203], [35, 247], [36, 45], [36, 48], [36, 53], [36, 151], [36, 153], [36, 166], [36, 186], [36, 187], [36, 211], [36, 234], [36, 238], [37, 49], [37, 69], [37, 85], [37, 154], [37, 156], [37, 174], [37, 183], [37, 248], [38, 47], [38, 70], [38, 92], [38, 114], [38, 116], [38, 214], [38, 229], [38, 234], [39, 68], [39, 73], [39, 99], [39, 106], [39, 110], [39, 185], [39, 188], [39, 210], [40, 41], [40, 93], [40, 97], [40, 123], [40, 180], [40, 210], [40, 235], [40, 238], [40, 239], [40, 242], [40, 249], [41, 118], [41, 217], [42, 70], [42, 71], [42, 88], [42, 90], [42, 105], [42, 130], [42, 192], [42, 193], [42, 229], [42, 243], [43, 60], [43, 70], [43, 92], [43, 96], [43, 128], [43, 137], [43, 139], [43, 163], [43, 179], [43, 206], [43, 220], [44, 45], [44, 58], [44, 80], [44, 115], [44, 129], [44, 183], [44, 186], [44, 199], [44, 236], [45, 108], [45, 112], [45, 189], [45, 212], [45, 218], [45, 245], [46, 65], [46, 72], [46, 73], [46, 85], [46, 95], [46, 122], [46, 132], [46, 133], [46, 191], [46, 194], [46, 248], [46, 249], [47, 92], [47, 149], [47, 176], [47, 197], [48, 51], [48, 53], [48, 60], [48, 100], [48, 115], [48, 170], [48, 198], [48, 208], [48, 237], [49, 51], [49, 52], [49, 66], [49, 122], [49, 160], [49, 162], [49, 216], [49, 240], [50, 106], [50, 118], [50, 132], [50, 153], [50, 162], [50, 182], [50, 202], [51, 55], [51, 56], [51, 57], [51, 131], [51, 149], [51, 183], [51, 184], [51, 186], [51, 227], [51, 228], [52, 126], [52, 168], [52, 187], [52, 217], [52, 219], [53, 114], [53, 118], [53, 130], [53, 137], [53, 193], [54, 87], [54, 88], [54, 94], [54, 122], [54, 141], [54, 175], [54, 188], [54, 201], [54, 226], [55, 76], [55, 79], [55, 113], [55, 117], [56, 84], [56, 150], [56, 168], [56, 230], [57, 95], [57, 106], [57, 133], [57, 140], [57, 153], [57, 160], [57, 170], [57, 174], [57, 204], [57, 206], [57, 227], [58, 97], [58, 210], [59, 64], [59, 76], [59, 94], [59, 138], [59, 156], [59, 222], [60, 81], [60, 100], [60, 123], [60, 149], [60, 159], [60, 164], [60, 168], [60, 179], [60, 185], [60, 202], [60, 232], [61, 150], [61, 172], [61, 211], [61, 230], [61, 238], [62, 142], [62, 148], [62, 153], [62, 185], [62, 202], [62, 231], [63, 132], [63, 148], [63, 153], [63, 165], [63, 179], [63, 204], [63, 221], [64, 156], [64, 173], [64, 189], [64, 196], [64, 207], [65, 82], [65, 93], [65, 104], [65, 133], [65, 136], [65, 192], [65, 200], [65, 209], [65, 225], [65, 233], [66, 67], [66, 74], [66, 134], [66, 141], [66, 149], [66, 185], [67, 110], [67, 148], [67, 180], [67, 195], [68, 130], [68, 141], [68, 195], [68, 243], [69, 106], [69, 114], [69, 130], [69, 158], [69, 186], [69, 205], [69, 234], [70, 118], [70, 165], [70, 172], [70, 204], [70, 223], [70, 233], [71, 78], [71, 125], [71, 147], [71, 171], [71, 177], [71, 201], [71, 226], [71, 229], [72, 80], [72, 82], [72, 84], [72, 126], [72, 131], [72, 156], [72, 171], [72, 248], [73, 98], [73, 119], [73, 199], [73, 248], [74, 112], [74, 128], [74, 167], [74, 176], [74, 177], [74, 209], [75, 109], [75, 116], [75, 123], [75, 141], [75, 151], [75, 180], [75, 192], [75, 219], [75, 237], [76, 98], [76, 111], [76, 116], [76, 186], [76, 217], [76, 221], [76, 241], [76, 247], [77, 100], [77, 121], [77, 165], [77, 180], [77, 184], [77, 190], [77, 221], [77, 223], [77, 224], [77, 241], [77, 248], [78, 102], [78, 148], [78, 150], [78, 158], [78, 213], [79, 94], [79, 98], [79, 100], [79, 126], [79, 200], [79, 218], [80, 94], [80, 115], [80, 132], [80, 165], [80, 198], [80, 209], [80, 224], [80, 245], [81, 113], [81, 147], [81, 169], [82, 92], [82, 111], [82, 130], [82, 159], [82, 180], [82, 210], [82, 223], [82, 244], [83, 90], [83, 91], [83, 137], [83, 148], [83, 168], [83, 171], [83, 201], [83, 221], [84, 88], [84, 107], [84, 118], [84, 150], [84, 153], [84, 171], [84, 189], [84, 214], [84, 216], [84, 237], [85, 103], [85, 106], [85, 125], [85, 130], [85, 140], [85, 165], [85, 181], [85, 190], [85, 198], [85, 213], [85, 222], [86, 113], [86, 133], [86, 182], [86, 198], [86, 230], [87, 182], [87, 185], [87, 186], [87, 190], [87, 225], [88, 129], [88, 136], [88, 143], [88, 191], [88, 207], [88, 236], [89, 102], [89, 218], [89, 220], [90, 118], [90, 151], [90, 176], [90, 180], [90, 237], [90, 241], [91, 93], [91, 121], [91, 126], [91, 225], [92, 95], [92, 113], [92, 145], [92, 164], [92, 208], [92, 244], [93, 125], [93, 129], [94, 96], [94, 98], [94, 113], [94, 117], [94, 152], [94, 204], [94, 237], [95, 100], [95, 136], [95, 160], [95, 196], [95, 221], [95, 223], [96, 112], [96, 122], [96, 131], [96, 201], [96, 205], [96, 232], [97, 153], [97, 161], [97, 170], [98, 133], [99, 133], [99, 231], [99, 236], [100, 103], [100, 139], [100, 211], [100, 218], [100, 234], [101, 145], [101, 169], [101, 184], [101, 212], [102, 193], [102, 208], [102, 230], [103, 143], [103, 148], [103, 192], [103, 206], [103, 219], [103, 226], [104, 158], [104, 208], [104, 243], [104, 246], [105, 131], [105, 140], [105, 150], [105, 151], [105, 156], [105, 185], [105, 192], [105, 245], [106, 139], [106, 153], [106, 158], [106, 210], [107, 123], [108, 110], [108, 160], [108, 208], [109, 162], [109, 174], [109, 227], [110, 141], [110, 152], [110, 156], [110, 180], [111, 146], [111, 208], [111, 222], [111, 236], [111, 237], [113, 172], [113, 183], [113, 187], [113, 246], [114, 187], [114, 226], [114, 233], [115, 147], [115, 189], [116, 163], [116, 165], [116, 193], [117, 122], [117, 130], [117, 238], [118, 178], [118, 186], [118, 195], [118, 234], [118, 240], [119, 147], [119, 185], [119, 202], [120, 154], [120, 189], [120, 190], [121, 145], [121, 158], [121, 193], [121, 215], [122, 126], [122, 227], [122, 230], [122, 232], [122, 243], [123, 140], [123, 160], [123, 163], [123, 168], [123, 170], [123, 206], [123, 208], [124, 147], [124, 161], [124, 174], [124, 207], [124, 241], [125, 138], [125, 144], [125, 155], [125, 169], [125, 174], [125, 207], [125, 211], [126, 206], [126, 246], [127, 140], [127, 144], [127, 159], [127, 211], [127, 225], [127, 242], [128, 130], [128, 168], [128, 192], [128, 211], [128, 240], [129, 137], [129, 166], [129, 170], [129, 238], [129, 239], [129, 240], [129, 249], [130, 138], [130, 147], [130, 167], [130, 239], [131, 164], [131, 180], [132, 170], [132, 184], [132, 219], [132, 237], [133, 136], [133, 140], [133, 152], [133, 155], [133, 177], [133, 211], [133, 223], [134, 153], [134, 192], [134, 214], [134, 232], [135, 140], [135, 149], [135, 166], [135, 222], [135, 231], [136, 187], [136, 199], [136, 207], [136, 227], [137, 211], [138, 202], [138, 228], [138, 236], [139, 229], [140, 148], [140, 151], [140, 201], [140, 226], [140, 230], [141, 163], [141, 177], [142, 155], [142, 169], [142, 180], [143, 147], [143, 176], [143, 196], [143, 207], [143, 243], [143, 248], [144, 145], [144, 167], [144, 231], [145, 155], [145, 192], [145, 193], [146, 215], [146, 227], [147, 192], [147, 204], [147, 205], [147, 224], [147, 228], [148, 184], [148, 186], [148, 239], [148, 242], [149, 189], [149, 216], [149, 224], [150, 164], [150, 181], [150, 238], [151, 155], [151, 176], [151, 182], [152, 175], [152, 186], [152, 191], [152, 202], [152, 220], [153, 203], [153, 204], [154, 229], [155, 208], [155, 233], [155, 243], [156, 185], [156, 211], [156, 213], [156, 234], [156, 237], [157, 223], [157, 225], [157, 235], [158, 221], [158, 231], [158, 248], [159, 235], [160, 164], [160, 177], [160, 209], [161, 196], [161, 197], [161, 198], [161, 199], [161, 200], [161, 207], [161, 244], [161, 249], [162, 215], [162, 220], [162, 233], [163, 215], [163, 249], [164, 166], [164, 169], [164, 193], [165, 200], [165, 210], [165, 222], [165, 243], [165, 244], [166, 188], [166, 223], [166, 238], [166, 246], [167, 189], [167, 205], [167, 227], [168, 169], [168, 207], [168, 224], [168, 238], [168, 244], [168, 249], [169, 183], [169, 184], [169, 198], [170, 202], [170, 209], [170, 225], [171, 191], [171, 214], [171, 230], [172, 196], [173, 249], [174, 183], [175, 210], [177, 231], [178, 232], [179, 202], [179, 235], [180, 185], [180, 203], [182, 248], [183, 210], [184, 192], [185, 188], [185, 205], [185, 217], [186, 218], [186, 232], [187, 210], [187, 211], [188, 225], [189, 195], [189, 198], [189, 230], [190, 238], [191, 199], [191, 207], [191, 231], [191, 232], [192, 196], [192, 223], [193, 202], [193, 212], [193, 240], [193, 246], [194, 201], [194, 240], [194, 243], [194, 245], [196, 223], [196, 227], [198, 225], [198, 239], [199, 239], [200, 215], [203, 207], [203, 235], [203, 248], [204, 208], [205, 208], [205, 214], [206, 221], [208, 221], [209, 216], [209, 222], [210, 220], [211, 235], [211, 240], [211, 248], [212, 232], [212, 240], [214, 218], [214, 234], [215, 248], [216, 234], [217, 230], [218, 220], [218, 232], [218, 235], [218, 243], [219, 248], [222, 227], [222, 236], [223, 247], [224, 228], [224, 240], [225, 231], [226, 232], [227, 247], [228, 238], [229, 247], [230, 238], [230, 246], [230, 249], [233, 246], [234, 249], [246, 247], [247, 248]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s5/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..46fac3d2f8d8bbc17725d246bca7c85fccaa70ba --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [3, 3, 1, 1, 2, 1, 1, 1, 0, 1, 0, 3, 2, 3, 2, 1, 1, 2, 0, 3, 2, 1, 1, 2, 0, 2, 1, 2, 2, 1, 3, 2, 0, 1, 3, 1, 0, 0, 3, 1, 3, 0, 1, 0, 0, 3, 2, 2, 1, 3, 1, 2, 1, 2, 3, 1, 0, 1, 3, 0, 2, 0, 1, 2, 3, 0, 0, 2, 3, 3, 2, 3, 0, 0, 2, 0, 3, 2, 1, 0, 2, 0, 3, 0, 1, 1, 1, 0, 0, 0, 2, 3, 1, 2, 1, 0, 2, 2, 2, 0, 3, 3, 2, 0, 2, 2, 2, 0, 1, 1, 0, 0, 0, 2, 0, 3, 1, 3, 3, 1, 0, 1, 1, 1, 3, 0, 2, 1, 1, 1, 0, 3, 0, 3, 2, 1, 1, 3, 2, 1, 0, 1, 3, 1, 2, 0, 3, 2, 3, 3, 3, 3, 2, 3, 2, 2, 1, 3, 0, 0, 2, 1, 2, 3, 0, 3, 3, 3, 3, 2, 3, 2, 1, 1, 2, 1, 0, 0, 0, 3, 1, 2, 2, 3, 1, 3, 1, 3, 0, 2, 3, 1, 3, 3, 3, 0, 2, 3, 0, 3, 2, 1, 0, 0, 0, 1, 3, 2, 3, 1, 0, 2, 2, 0, 0, 0, 0, 2, 2, 2, 3, 1, 2, 1, 1, 2, 2, 0, 3, 0, 3, 3, 3, 1, 2, 1, 1, 3, 2, 2, 0, 1, 0, 0, 0, 1, 0, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l6-s5/tests/check.py b/tasks/construct-mc-graph-k-coloring-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..96fbc0ea0d298efd02fb4f5fd1504f30fcf655d4 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 15], [0, 41], [0, 73], [0, 86], [0, 99], [0, 128], [0, 164], [0, 186], [0, 240], [1, 15], [1, 39], [1, 53], [1, 74], [1, 96], [1, 108], [1, 116], [1, 126], [1, 159], [1, 175], [1, 201], [1, 202], [1, 213], [1, 214], [1, 233], [1, 240], [2, 41], [2, 56], [2, 120], [2, 163], [2, 176], [2, 194], [2, 203], [2, 216], [2, 217], [3, 13], [3, 36], [3, 97], [3, 174], [3, 188], [3, 189], [3, 192], [3, 211], [3, 212], [3, 227], [4, 30], [4, 108], [4, 110], [4, 122], [4, 137], [4, 145], [4, 150], [4, 204], [5, 12], [5, 18], [5, 65], [5, 89], [5, 153], [5, 162], [5, 208], [5, 231], [6, 30], [6, 34], [6, 68], [6, 148], [6, 170], [6, 189], [6, 244], [7, 43], [7, 77], [7, 100], [7, 151], [7, 220], [8, 49], [8, 54], [8, 124], [8, 131], [8, 141], [8, 160], [9, 23], [9, 38], [9, 65], [9, 102], [9, 105], [9, 111], [9, 148], [9, 158], [9, 176], [9, 177], [9, 187], [9, 219], [10, 42], [10, 58], [10, 77], [10, 100], [10, 101], [10, 128], [10, 144], [10, 165], [10, 170], [10, 189], [10, 234], [11, 28], [11, 42], [11, 43], [11, 50], [11, 66], [11, 97], [11, 105], [11, 140], [11, 155], [11, 162], [11, 184], [11, 186], [11, 207], [12, 26], [12, 61], [12, 73], [12, 111], [12, 119], [12, 131], [12, 221], [12, 224], [13, 39], [13, 92], [13, 112], [13, 140], [13, 217], [13, 219], [14, 123], [14, 203], [14, 246], [15, 31], [15, 53], [15, 56], [15, 71], [15, 95], [15, 97], [15, 107], [15, 126], [15, 151], [15, 164], [15, 182], [15, 194], [15, 220], [16, 25], [16, 40], [16, 43], [16, 71], [16, 125], [16, 196], [16, 200], [16, 225], [17, 34], [17, 49], [17, 64], [17, 69], [17, 165], [17, 223], [18, 78], [18, 80], [18, 174], [18, 212], [18, 245], [19, 51], [19, 111], [19, 169], [19, 242], [20, 103], [20, 122], [20, 150], [20, 153], [20, 206], [20, 208], [20, 224], [20, 237], [21, 51], [21, 110], [21, 113], [21, 164], [21, 179], [21, 207], [21, 226], [21, 227], [21, 229], [21, 239], [21, 247], [22, 23], [22, 67], [22, 89], [22, 98], [22, 105], [22, 130], [22, 131], [22, 140], [22, 151], [22, 171], [22, 214], [22, 217], [23, 36], [23, 136], [23, 185], [23, 202], [23, 205], [23, 248], [24, 40], [24, 52], [24, 91], [24, 92], [24, 100], [24, 186], [24, 194], [24, 222], [25, 78], [25, 124], [25, 133], [25, 136], [25, 139], [25, 165], [25, 180], [26, 75], [26, 98], [26, 114], [26, 149], [26, 151], [26, 215], [26, 229], [26, 247], [27, 123], [27, 135], [27, 150], [28, 30], [28, 55], [28, 76], [28, 108], [28, 130], [28, 184], [29, 99], [29, 138], [29, 181], [29, 203], [29, 218], [29, 237], [30, 52], [30, 86], [30, 120], [30, 123], [30, 140], [31, 56], [31, 58], [31, 117], [31, 122], [31, 129], [31, 140], [31, 141], [31, 166], [31, 191], [31, 221], [31, 224], [32, 34], [32, 64], [32, 86], [32, 104], [32, 123], [32, 186], [32, 191], [32, 247], [33, 36], [33, 61], [33, 100], [33, 107], [33, 113], [33, 115], [33, 189], [33, 197], [34, 55], [34, 65], [34, 105], [34, 111], [34, 147], [34, 156], [34, 189], [34, 246], [35, 43], [35, 82], [35, 95], [35, 183], [35, 185], [35, 202], [35, 203], [35, 247], [36, 45], [36, 48], [36, 53], [36, 151], [36, 153], [36, 166], [36, 186], [36, 187], [36, 211], [36, 234], [36, 238], [37, 49], [37, 69], [37, 85], [37, 154], [37, 156], [37, 174], [37, 183], [37, 248], [38, 47], [38, 70], [38, 92], [38, 114], [38, 116], [38, 214], [38, 229], [38, 234], [39, 68], [39, 73], [39, 99], [39, 106], [39, 110], [39, 185], [39, 188], [39, 210], [40, 41], [40, 93], [40, 97], [40, 123], [40, 180], [40, 210], [40, 235], [40, 238], [40, 239], [40, 242], [40, 249], [41, 118], [41, 217], [42, 70], [42, 71], [42, 88], [42, 90], [42, 105], [42, 130], [42, 192], [42, 193], [42, 229], [42, 243], [43, 60], [43, 70], [43, 92], [43, 96], [43, 128], [43, 137], [43, 139], [43, 163], [43, 179], [43, 206], [43, 220], [44, 45], [44, 58], [44, 80], [44, 115], [44, 129], [44, 183], [44, 186], [44, 199], [44, 236], [45, 108], [45, 112], [45, 189], [45, 212], [45, 218], [45, 245], [46, 65], [46, 72], [46, 73], [46, 85], [46, 95], [46, 122], [46, 132], [46, 133], [46, 191], [46, 194], [46, 248], [46, 249], [47, 92], [47, 149], [47, 176], [47, 197], [48, 51], [48, 53], [48, 60], [48, 100], [48, 115], [48, 170], [48, 198], [48, 208], [48, 237], [49, 51], [49, 52], [49, 66], [49, 122], [49, 160], [49, 162], [49, 216], [49, 240], [50, 106], [50, 118], [50, 132], [50, 153], [50, 162], [50, 182], [50, 202], [51, 55], [51, 56], [51, 57], [51, 131], [51, 149], [51, 183], [51, 184], [51, 186], [51, 227], [51, 228], [52, 126], [52, 168], [52, 187], [52, 217], [52, 219], [53, 114], [53, 118], [53, 130], [53, 137], [53, 193], [54, 87], [54, 88], [54, 94], [54, 122], [54, 141], [54, 175], [54, 188], [54, 201], [54, 226], [55, 76], [55, 79], [55, 113], [55, 117], [56, 84], [56, 150], [56, 168], [56, 230], [57, 95], [57, 106], [57, 133], [57, 140], [57, 153], [57, 160], [57, 170], [57, 174], [57, 204], [57, 206], [57, 227], [58, 97], [58, 210], [59, 64], [59, 76], [59, 94], [59, 138], [59, 156], [59, 222], [60, 81], [60, 100], [60, 123], [60, 149], [60, 159], [60, 164], [60, 168], [60, 179], [60, 185], [60, 202], [60, 232], [61, 150], [61, 172], [61, 211], [61, 230], [61, 238], [62, 142], [62, 148], [62, 153], [62, 185], [62, 202], [62, 231], [63, 132], [63, 148], [63, 153], [63, 165], [63, 179], [63, 204], [63, 221], [64, 156], [64, 173], [64, 189], [64, 196], [64, 207], [65, 82], [65, 93], [65, 104], [65, 133], [65, 136], [65, 192], [65, 200], [65, 209], [65, 225], [65, 233], [66, 67], [66, 74], [66, 134], [66, 141], [66, 149], [66, 185], [67, 110], [67, 148], [67, 180], [67, 195], [68, 130], [68, 141], [68, 195], [68, 243], [69, 106], [69, 114], [69, 130], [69, 158], [69, 186], [69, 205], [69, 234], [70, 118], [70, 165], [70, 172], [70, 204], [70, 223], [70, 233], [71, 78], [71, 125], [71, 147], [71, 171], [71, 177], [71, 201], [71, 226], [71, 229], [72, 80], [72, 82], [72, 84], [72, 126], [72, 131], [72, 156], [72, 171], [72, 248], [73, 98], [73, 119], [73, 199], [73, 248], [74, 112], [74, 128], [74, 167], [74, 176], [74, 177], [74, 209], [75, 109], [75, 116], [75, 123], [75, 141], [75, 151], [75, 180], [75, 192], [75, 219], [75, 237], [76, 98], [76, 111], [76, 116], [76, 186], [76, 217], [76, 221], [76, 241], [76, 247], [77, 100], [77, 121], [77, 165], [77, 180], [77, 184], [77, 190], [77, 221], [77, 223], [77, 224], [77, 241], [77, 248], [78, 102], [78, 148], [78, 150], [78, 158], [78, 213], [79, 94], [79, 98], [79, 100], [79, 126], [79, 200], [79, 218], [80, 94], [80, 115], [80, 132], [80, 165], [80, 198], [80, 209], [80, 224], [80, 245], [81, 113], [81, 147], [81, 169], [82, 92], [82, 111], [82, 130], [82, 159], [82, 180], [82, 210], [82, 223], [82, 244], [83, 90], [83, 91], [83, 137], [83, 148], [83, 168], [83, 171], [83, 201], [83, 221], [84, 88], [84, 107], [84, 118], [84, 150], [84, 153], [84, 171], [84, 189], [84, 214], [84, 216], [84, 237], [85, 103], [85, 106], [85, 125], [85, 130], [85, 140], [85, 165], [85, 181], [85, 190], [85, 198], [85, 213], [85, 222], [86, 113], [86, 133], [86, 182], [86, 198], [86, 230], [87, 182], [87, 185], [87, 186], [87, 190], [87, 225], [88, 129], [88, 136], [88, 143], [88, 191], [88, 207], [88, 236], [89, 102], [89, 218], [89, 220], [90, 118], [90, 151], [90, 176], [90, 180], [90, 237], [90, 241], [91, 93], [91, 121], [91, 126], [91, 225], [92, 95], [92, 113], [92, 145], [92, 164], [92, 208], [92, 244], [93, 125], [93, 129], [94, 96], [94, 98], [94, 113], [94, 117], [94, 152], [94, 204], [94, 237], [95, 100], [95, 136], [95, 160], [95, 196], [95, 221], [95, 223], [96, 112], [96, 122], [96, 131], [96, 201], [96, 205], [96, 232], [97, 153], [97, 161], [97, 170], [98, 133], [99, 133], [99, 231], [99, 236], [100, 103], [100, 139], [100, 211], [100, 218], [100, 234], [101, 145], [101, 169], [101, 184], [101, 212], [102, 193], [102, 208], [102, 230], [103, 143], [103, 148], [103, 192], [103, 206], [103, 219], [103, 226], [104, 158], [104, 208], [104, 243], [104, 246], [105, 131], [105, 140], [105, 150], [105, 151], [105, 156], [105, 185], [105, 192], [105, 245], [106, 139], [106, 153], [106, 158], [106, 210], [107, 123], [108, 110], [108, 160], [108, 208], [109, 162], [109, 174], [109, 227], [110, 141], [110, 152], [110, 156], [110, 180], [111, 146], [111, 208], [111, 222], [111, 236], [111, 237], [113, 172], [113, 183], [113, 187], [113, 246], [114, 187], [114, 226], [114, 233], [115, 147], [115, 189], [116, 163], [116, 165], [116, 193], [117, 122], [117, 130], [117, 238], [118, 178], [118, 186], [118, 195], [118, 234], [118, 240], [119, 147], [119, 185], [119, 202], [120, 154], [120, 189], [120, 190], [121, 145], [121, 158], [121, 193], [121, 215], [122, 126], [122, 227], [122, 230], [122, 232], [122, 243], [123, 140], [123, 160], [123, 163], [123, 168], [123, 170], [123, 206], [123, 208], [124, 147], [124, 161], [124, 174], [124, 207], [124, 241], [125, 138], [125, 144], [125, 155], [125, 169], [125, 174], [125, 207], [125, 211], [126, 206], [126, 246], [127, 140], [127, 144], [127, 159], [127, 211], [127, 225], [127, 242], [128, 130], [128, 168], [128, 192], [128, 211], [128, 240], [129, 137], [129, 166], [129, 170], [129, 238], [129, 239], [129, 240], [129, 249], [130, 138], [130, 147], [130, 167], [130, 239], [131, 164], [131, 180], [132, 170], [132, 184], [132, 219], [132, 237], [133, 136], [133, 140], [133, 152], [133, 155], [133, 177], [133, 211], [133, 223], [134, 153], [134, 192], [134, 214], [134, 232], [135, 140], [135, 149], [135, 166], [135, 222], [135, 231], [136, 187], [136, 199], [136, 207], [136, 227], [137, 211], [138, 202], [138, 228], [138, 236], [139, 229], [140, 148], [140, 151], [140, 201], [140, 226], [140, 230], [141, 163], [141, 177], [142, 155], [142, 169], [142, 180], [143, 147], [143, 176], [143, 196], [143, 207], [143, 243], [143, 248], [144, 145], [144, 167], [144, 231], [145, 155], [145, 192], [145, 193], [146, 215], [146, 227], [147, 192], [147, 204], [147, 205], [147, 224], [147, 228], [148, 184], [148, 186], [148, 239], [148, 242], [149, 189], [149, 216], [149, 224], [150, 164], [150, 181], [150, 238], [151, 155], [151, 176], [151, 182], [152, 175], [152, 186], [152, 191], [152, 202], [152, 220], [153, 203], [153, 204], [154, 229], [155, 208], [155, 233], [155, 243], [156, 185], [156, 211], [156, 213], [156, 234], [156, 237], [157, 223], [157, 225], [157, 235], [158, 221], [158, 231], [158, 248], [159, 235], [160, 164], [160, 177], [160, 209], [161, 196], [161, 197], [161, 198], [161, 199], [161, 200], [161, 207], [161, 244], [161, 249], [162, 215], [162, 220], [162, 233], [163, 215], [163, 249], [164, 166], [164, 169], [164, 193], [165, 200], [165, 210], [165, 222], [165, 243], [165, 244], [166, 188], [166, 223], [166, 238], [166, 246], [167, 189], [167, 205], [167, 227], [168, 169], [168, 207], [168, 224], [168, 238], [168, 244], [168, 249], [169, 183], [169, 184], [169, 198], [170, 202], [170, 209], [170, 225], [171, 191], [171, 214], [171, 230], [172, 196], [173, 249], [174, 183], [175, 210], [177, 231], [178, 232], [179, 202], [179, 235], [180, 185], [180, 203], [182, 248], [183, 210], [184, 192], [185, 188], [185, 205], [185, 217], [186, 218], [186, 232], [187, 210], [187, 211], [188, 225], [189, 195], [189, 198], [189, 230], [190, 238], [191, 199], [191, 207], [191, 231], [191, 232], [192, 196], [192, 223], [193, 202], [193, 212], [193, 240], [193, 246], [194, 201], [194, 240], [194, 243], [194, 245], [196, 223], [196, 227], [198, 225], [198, 239], [199, 239], [200, 215], [203, 207], [203, 235], [203, 248], [204, 208], [205, 208], [205, 214], [206, 221], [208, 221], [209, 216], [209, 222], [210, 220], [211, 235], [211, 240], [211, 248], [212, 232], [212, 240], [214, 218], [214, 234], [215, 248], [216, 234], [217, 230], [218, 220], [218, 232], [218, 235], [218, 243], [219, 248], [222, 227], [222, 236], [223, 247], [224, 228], [224, 240], [225, 231], [226, 232], [227, 247], [228, 238], [229, 247], [230, 238], [230, 246], [230, 249], [233, 246], [234, 249], [246, 247], [247, 248]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s5/tests/run.py b/tasks/construct-mc-graph-k-coloring-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l6-s5/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-hadamard-l6-s2/environment/Dockerfile b/tasks/construct-mc-hadamard-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l6-s2/environment/instance.json b/tasks/construct-mc-hadamard-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35000fcc7b2506d69a926dc3ed1fbfc77e9811ff --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 143, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s2/solution/solve.sh b/tasks/construct-mc-hadamard-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eeb280d4a9d5228ae26db349faa7568b2161d8e3 --- /dev/null +++ b/tasks/construct-mc-hadamard-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": [-1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1], "y": [-1, -1, -1, -1, -1, 1, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l6-s2/tests/check.py b/tasks/construct-mc-hadamard-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s2/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-l6-s2/tests/instance.json b/tasks/construct-mc-hadamard-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35000fcc7b2506d69a926dc3ed1fbfc77e9811ff --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 143, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s2/tests/run.py b/tasks/construct-mc-hadamard-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l6-s2/tests/test.sh b/tasks/construct-mc-hadamard-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l6-s5/environment/Dockerfile b/tasks/construct-mc-hadamard-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l6-s5/environment/instance.json b/tasks/construct-mc-hadamard-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ecb74cc02ccd2a40771b403a479e6cb180fe2d7 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 83, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s5/solution/solve.sh b/tasks/construct-mc-hadamard-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..835195f232618594037c8f88d970f682fed8d813 --- /dev/null +++ b/tasks/construct-mc-hadamard-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": [1, 1, -1, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 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, 1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, -1, -1, 1, -1, 1, 1, -1, -1, 1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l6-s5/tests/check.py b/tasks/construct-mc-hadamard-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-mc-hadamard-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ecb74cc02ccd2a40771b403a479e6cb180fe2d7 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 83, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s5/tests/run.py b/tasks/construct-mc-hadamard-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l6-s5/tests/test.sh b/tasks/construct-mc-hadamard-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-langford-l2-s2/environment/Dockerfile b/tasks/construct-mc-langford-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-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-langford-l2-s2/environment/instance.json b/tasks/construct-mc-langford-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c64611e6d1b93878d735b2bde08b247d0865c252 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l2-s2/solution/solve.sh b/tasks/construct-mc-langford-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb9d03de06cb3e4d3bd82d935a26e33ea6253094 --- /dev/null +++ b/tasks/construct-mc-langford-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' +{"seq": [6, 2, 3, 11, 2, 10, 3, 6, 9, 1, 8, 1, 4, 7, 5, 11, 10, 4, 9, 8, 5, 7]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l2-s2/tests/check.py b/tasks/construct-mc-langford-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s2/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l2-s2/tests/instance.json b/tasks/construct-mc-langford-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c64611e6d1b93878d735b2bde08b247d0865c252 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l2-s2/tests/run.py b/tasks/construct-mc-langford-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-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-langford-l2-s2/tests/test.sh b/tasks/construct-mc-langford-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-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-low-autocorrelation-l4-s0/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-low-autocorrelation-l4-s0/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1994148b9f5792cfdb3cacc170498ca6cffb62ca --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "bound": 68, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s0/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..801945bf34e8ad65c4c208f95da51769449ad6d8 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l4-s0/tests/check.py b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s0/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-l4-s0/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1994148b9f5792cfdb3cacc170498ca6cffb62ca --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "bound": 68, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s0/tests/run.py b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-low-autocorrelation-l4-s0/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l3-s1/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s1/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f84b85ba7410f5c4f9312d9421141371d294c6f6 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "fixed": [["x", 11, 0], ["x", 12, 0]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s1/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53c20901125b9cdae23c3358d7a101ee348c085c --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [10, 2, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s1/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s1/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-l3-s1/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f84b85ba7410f5c4f9312d9421141371d294c6f6 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "fixed": [["x", 11, 0], ["x", 12, 0]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s1/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s1/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l3-s6/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-magic-sequence-l3-s6/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b69ed0335086e9b3569a5238f58111cdbcb5f847 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "fixed": [["x", 7, 0], ["x", 8, 1]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s6/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..57c1d33fa7983d0a5b0b0a0a0d04ef8701a7de76 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [8, 2, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s6/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/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-l3-s6/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b69ed0335086e9b3569a5238f58111cdbcb5f847 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "fixed": [["x", 7, 0], ["x", 8, 1]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s6/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-magic-sequence-l3-s6/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l3-s0/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l3-s0/environment/instance.json b/tasks/construct-mc-number-partitioning-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..39915632288f7725271fdded160ca86aa5e2f0cf --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s0/solution/solve.sh b/tasks/construct-mc-number-partitioning-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b70b534f4965a198807c7b3dfa8fbfa547085ca8 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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": [0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 1, 1, 4, 1, 2, 1, 0, 0, 2, 0, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l3-s0/tests/check.py b/tasks/construct-mc-number-partitioning-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s0/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-l3-s0/tests/instance.json b/tasks/construct-mc-number-partitioning-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..39915632288f7725271fdded160ca86aa5e2f0cf --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s0/tests/run.py b/tasks/construct-mc-number-partitioning-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l3-s0/tests/test.sh b/tasks/construct-mc-number-partitioning-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l3-s7/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s7/environment/instance.json b/tasks/construct-mc-number-partitioning-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95192e0cdce2fb2b213e5dce41bcc68269572ad9 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s7/solution/solve.sh b/tasks/construct-mc-number-partitioning-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..16743ecf8bfa92de3a5e2d0c3ff236ec72d41380 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 2, 2, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l3-s7/tests/check.py b/tasks/construct-mc-number-partitioning-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s7/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-l3-s7/tests/instance.json b/tasks/construct-mc-number-partitioning-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95192e0cdce2fb2b213e5dce41bcc68269572ad9 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s7/tests/run.py b/tasks/construct-mc-number-partitioning-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s7/tests/test.sh b/tasks/construct-mc-number-partitioning-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s9/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s9/environment/instance.json b/tasks/construct-mc-number-partitioning-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f872e19c35c8e813a1747516e895d7fd8dd7d28 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s9/solution/solve.sh b/tasks/construct-mc-number-partitioning-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc2516e0b44e5f8047381d0c6529106c060a3071 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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": [0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 1, 2, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l3-s9/tests/check.py b/tasks/construct-mc-number-partitioning-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s9/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-l3-s9/tests/instance.json b/tasks/construct-mc-number-partitioning-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f872e19c35c8e813a1747516e895d7fd8dd7d28 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s9/tests/run.py b/tasks/construct-mc-number-partitioning-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l3-s9/tests/test.sh b/tasks/construct-mc-number-partitioning-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-ortholatin-l1-s0/environment/Dockerfile b/tasks/construct-mc-ortholatin-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-mc-ortholatin-l1-s0/environment/instance.json b/tasks/construct-mc-ortholatin-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8701ea079d77ff2a0c367a63ed5c742cf05f4e9a --- /dev/null +++ b/tasks/construct-mc-ortholatin-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l1-s0/solution/solve.sh b/tasks/construct-mc-ortholatin-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..55c045234dc7a8e5a59fbbd7cd42f6528bf96b5a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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' +{"X": [[0, 1, 2], [1, 2, 0], [2, 0, 1]], "Y": [[0, 2, 1], [1, 0, 2], [2, 1, 0]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l1-s0/tests/check.py b/tasks/construct-mc-ortholatin-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l1-s0/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-l1-s0/tests/instance.json b/tasks/construct-mc-ortholatin-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8701ea079d77ff2a0c367a63ed5c742cf05f4e9a --- /dev/null +++ b/tasks/construct-mc-ortholatin-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l1-s0/tests/run.py b/tasks/construct-mc-ortholatin-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-mc-ortholatin-l1-s0/tests/test.sh b/tasks/construct-mc-ortholatin-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-pysms-chromatic-girth-l1-s0/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-chromatic-girth-l1-s0/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d824862f982cb02d9e2885cf4a23f5ee4dcdd932 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [[4, 8]], "max_chromatic_number": 5, "min_edges": 9, "min_girth": 5, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s0/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36c9b85364ec71d1398e4ae3e45f8f0941d7f951 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 8], [1, 8], [2, 7], [3, 6], [3, 8], [4, 5], [4, 8], [5, 6], [7, 8]], "coloring": [1, 1, 0, 1, 1, 0, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d824862f982cb02d9e2885cf4a23f5ee4dcdd932 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [[4, 8]], "max_chromatic_number": 5, "min_edges": 9, "min_girth": 5, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-chromatic-girth-l1-s0/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l5-s1/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-chromatic-girth-l5-s1/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ee4036bb7533520a2b43847cd5127113c85d75d --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 30, "required_edges": [], "max_chromatic_number": 3, "min_edges": 33, "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-l5-s1/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..95cbba326c091899c82fa95504002a317e4c7ce7 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [1, 11], [1, 29], [2, 8], [2, 9], [2, 10], [2, 28], [3, 6], [3, 7], [3, 27], [4, 5], [4, 7], [5, 26], [6, 10], [7, 11], [9, 11]], "coloring": [0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l5-s1/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l5-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-chromatic-girth-l5-s1/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ee4036bb7533520a2b43847cd5127113c85d75d --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 30, "required_edges": [], "max_chromatic_number": 3, "min_edges": 33, "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-l5-s1/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-chromatic-girth-l5-s1/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-mc-pysms-clique-coloring-l2-s2/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-pysms-clique-coloring-l2-s2/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba04ab693774a52078f2a02626e3f47b60eee2d3 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[2, 8], [1, 9], [0, 6], [3, 10], [0, 9], [3, 9]], "max_chromatic_number": 2, "max_clique": 2, "min_degree": 4, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l2-s2/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5cc8c634d855e460e894e9651f5a895cf8b74d94 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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' +{"edges": [[0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11]], "coloring": [0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l2-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-clique-coloring-l2-s2/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba04ab693774a52078f2a02626e3f47b60eee2d3 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[2, 8], [1, 9], [0, 6], [3, 10], [0, 9], [3, 9]], "max_chromatic_number": 2, "max_clique": 2, "min_degree": 4, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-pysms-clique-coloring-l2-s2/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-pysms-degree-bounds-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-mc-pysms-degree-bounds-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..887496e5bbf51d937d6ba7eab8663a52956ab032 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [[1, 11], [0, 13], [7, 9], [1, 13], [4, 11], [6, 9]], "max_degree": 5, "min_degree": 4, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s1/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7f6af11e0b05d742af8d2a8ffededa7395b1d45e --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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' +{"edges": [[0, 10], [0, 11], [0, 12], [0, 13], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 8], [3, 10], [3, 11], [3, 12], [3, 13], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-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-degree-bounds-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..887496e5bbf51d937d6ba7eab8663a52956ab032 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [[1, 11], [0, 13], [7, 9], [1, 13], [4, 11], [6, 9]], "max_degree": 5, "min_degree": 4, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-mc-pysms-degree-bounds-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-mc-pysms-girth-degree-l2-s2/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-pysms-girth-degree-l2-s2/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d66fb9bcb57cca9e55d9fdcd9f29ffb5c16982a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [[2, 5]], "max_degree": 5, "min_degree": 2, "min_girth": 8, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l2-s2/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c71e300f2752d3018211d42374ea88811d53c934 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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' +{"edges": [[0, 7], [0, 8], [1, 6], [1, 8], [2, 5], [2, 7], [3, 4], [3, 6], [4, 5]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l2-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-girth-degree-l2-s2/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d66fb9bcb57cca9e55d9fdcd9f29ffb5c16982a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [[2, 5]], "max_degree": 5, "min_degree": 2, "min_girth": 8, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-pysms-girth-degree-l2-s2/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-pysms-min-connectivity-l5-s2/environment/Dockerfile b/tasks/construct-mc-pysms-min-connectivity-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-pysms-min-connectivity-l5-s2/environment/instance.json b/tasks/construct-mc-pysms-min-connectivity-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..71dd3a5e867198cc8d80ecabdd0669bf0799e645 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 17, "required_edges": [], "min_connectivity": 4, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l5-s2/solution/solve.sh b/tasks/construct-mc-pysms-min-connectivity-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..91678b0bbaa9db4dc3d237a7c871b1f009c90fd7 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [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], [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, 16], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [12, 13], [12, 14], [12, 15], [12, 16], [13, 14], [13, 15], [13, 16], [14, 15], [14, 16], [15, 16]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/check.py b/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l5-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-min-connectivity-l5-s2/tests/instance.json b/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..71dd3a5e867198cc8d80ecabdd0669bf0799e645 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 17, "required_edges": [], "min_connectivity": 4, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/run.py b/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-pysms-min-connectivity-l5-s2/tests/test.sh b/tasks/construct-mc-pysms-min-connectivity-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-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-pysms-mtf-l5-s1/environment/Dockerfile b/tasks/construct-mc-pysms-mtf-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-mc-pysms-mtf-l5-s1/environment/instance.json b/tasks/construct-mc-pysms-mtf-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6d458092d8c754cef4a145d66a105d1f10848a9 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 17, "required_edges": [[0, 15], [3, 15], [6, 15], [9, 15], [11, 15], [14, 16]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l5-s1/solution/solve.sh b/tasks/construct-mc-pysms-mtf-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d929ba889373adf528b08ff1361f24b0d9d4ff85 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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' +{"edges": [[0, 15], [0, 16], [1, 15], [1, 16], [2, 15], [2, 16], [3, 15], [3, 16], [4, 15], [4, 16], [5, 15], [5, 16], [6, 15], [6, 16], [7, 15], [7, 16], [8, 15], [8, 16], [9, 15], [9, 16], [10, 15], [10, 16], [11, 15], [11, 16], [12, 15], [12, 16], [13, 15], [13, 16], [14, 15], [14, 16]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-mtf-l5-s1/tests/check.py b/tasks/construct-mc-pysms-mtf-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-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-mtf-l5-s1/tests/instance.json b/tasks/construct-mc-pysms-mtf-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6d458092d8c754cef4a145d66a105d1f10848a9 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 17, "required_edges": [[0, 15], [3, 15], [6, 15], [9, 15], [11, 15], [14, 16]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l5-s1/tests/run.py b/tasks/construct-mc-pysms-mtf-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-mc-pysms-mtf-l5-s1/tests/test.sh b/tasks/construct-mc-pysms-mtf-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-mc-pysms-num-edges-bounds-l5-s2/environment/Dockerfile b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-pysms-num-edges-bounds-l5-s2/environment/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c4e7a56e96f27450366aebc03afd0d3b610dfe --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 13, "required_edges": [], "max_edges": 39, "min_edges": 29, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/solution/solve.sh b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dda87a9089c6cb1485ab025de8626c5057016ad3 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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' +{"edges": [[0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/check.py b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l5-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-num-edges-bounds-l5-s2/tests/instance.json b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c4e7a56e96f27450366aebc03afd0d3b610dfe --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 13, "required_edges": [], "max_edges": 39, "min_edges": 29, "family": "mc_pysms_num_edges_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/run.py b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-pysms-num-edges-bounds-l5-s2/tests/test.sh b/tasks/construct-mc-pysms-num-edges-bounds-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-num-edges-bounds-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-ramsey-l3-s2/environment/Dockerfile b/tasks/construct-mc-ramsey-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l3-s2/environment/instance.json b/tasks/construct-mc-ramsey-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29768372f340a3af7f68ce58ef993932de385f39 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "r": 6, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s2/solution/solve.sh b/tasks/construct-mc-ramsey-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6c00f1c06ecd38baa072f5f7c71002b0e3e2c190 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l3-s2/tests/check.py b/tasks/construct-mc-ramsey-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s2/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-l3-s2/tests/instance.json b/tasks/construct-mc-ramsey-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29768372f340a3af7f68ce58ef993932de385f39 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "r": 6, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s2/tests/run.py b/tasks/construct-mc-ramsey-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l3-s2/tests/test.sh b/tasks/construct-mc-ramsey-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l3-s5/environment/Dockerfile b/tasks/construct-mc-ramsey-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-mc-ramsey-l3-s5/environment/instance.json b/tasks/construct-mc-ramsey-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d486fc47748dd853672e288d3b7bb52810fae0f9 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 17, "r": 4, "s": 4, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s5/solution/solve.sh b/tasks/construct-mc-ramsey-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a2ce28f0082759f4ad12aca5aa040bde81271d93 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l3-s5/tests/check.py b/tasks/construct-mc-ramsey-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s5/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-l3-s5/tests/instance.json b/tasks/construct-mc-ramsey-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d486fc47748dd853672e288d3b7bb52810fae0f9 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 17, "r": 4, "s": 4, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s5/tests/run.py b/tasks/construct-mc-ramsey-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-mc-ramsey-l3-s5/tests/test.sh b/tasks/construct-mc-ramsey-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-mc-van-der-waerden-l3-s1/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l3-s1/environment/instance.json b/tasks/construct-mc-van-der-waerden-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66169ab13266bbd7b21b740998f57edf0d78c6d3 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 30, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l3-s1/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..02cc5524c49e0ae38c07df75c2bc70b2f5687188 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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' +{"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, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l3-s1/tests/check.py b/tasks/construct-mc-van-der-waerden-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s1/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-l3-s1/tests/instance.json b/tasks/construct-mc-van-der-waerden-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..66169ab13266bbd7b21b740998f57edf0d78c6d3 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 30, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l3-s1/tests/run.py b/tasks/construct-mc-van-der-waerden-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l3-s1/tests/test.sh b/tasks/construct-mc-van-der-waerden-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-vertex-cover-l2-s7/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l2-s7/environment/instance.json b/tasks/construct-mc-vertex-cover-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a5f6b57c45138c66a2cd07dd943c3d38d6383a9 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 1], [0, 2], [0, 9], [0, 16], [0, 17], [0, 21], [1, 8], [1, 11], [1, 19], [2, 6], [2, 28], [3, 18], [3, 22], [3, 24], [3, 28], [4, 5], [4, 10], [4, 11], [4, 23], [5, 6], [5, 11], [5, 22], [5, 25], [6, 8], [6, 15], [6, 16], [6, 20], [6, 21], [6, 26], [7, 27], [8, 10], [8, 15], [8, 17], [8, 19], [8, 21], [8, 22], [8, 24], [8, 26], [8, 27], [8, 29], [9, 10], [9, 15], [9, 24], [9, 27], [10, 12], [10, 13], [10, 17], [10, 20], [10, 21], [10, 27], [11, 12], [11, 15], [11, 23], [13, 24], [14, 16], [14, 20], [14, 25], [15, 16], [15, 19], [15, 26], [16, 21], [16, 24], [17, 18], [17, 20], [17, 24], [18, 22], [18, 29], [20, 21], [20, 26], [22, 26], [23, 27], [24, 27]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s7/solution/solve.sh b/tasks/construct-mc-vertex-cover-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d12522eef57076957b0474fe9f7bae3c974bd858 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 1, 4, 6, 8, 10, 11, 15, 16, 17, 18, 20, 22, 23, 24, 25, 27, 28]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l2-s7/tests/check.py b/tasks/construct-mc-vertex-cover-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s7/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l2-s7/tests/instance.json b/tasks/construct-mc-vertex-cover-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a5f6b57c45138c66a2cd07dd943c3d38d6383a9 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 1], [0, 2], [0, 9], [0, 16], [0, 17], [0, 21], [1, 8], [1, 11], [1, 19], [2, 6], [2, 28], [3, 18], [3, 22], [3, 24], [3, 28], [4, 5], [4, 10], [4, 11], [4, 23], [5, 6], [5, 11], [5, 22], [5, 25], [6, 8], [6, 15], [6, 16], [6, 20], [6, 21], [6, 26], [7, 27], [8, 10], [8, 15], [8, 17], [8, 19], [8, 21], [8, 22], [8, 24], [8, 26], [8, 27], [8, 29], [9, 10], [9, 15], [9, 24], [9, 27], [10, 12], [10, 13], [10, 17], [10, 20], [10, 21], [10, 27], [11, 12], [11, 15], [11, 23], [13, 24], [14, 16], [14, 20], [14, 25], [15, 16], [15, 19], [15, 26], [16, 21], [16, 24], [17, 18], [17, 20], [17, 24], [18, 22], [18, 29], [20, 21], [20, 26], [22, 26], [23, 27], [24, 27]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s7/tests/run.py b/tasks/construct-mc-vertex-cover-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l2-s7/tests/test.sh b/tasks/construct-mc-vertex-cover-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-mc-vertex-cover-l6-s8/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l6-s8/environment/instance.json b/tasks/construct-mc-vertex-cover-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5265d7198162a2424314ca177ca0eb3edbd518f --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 4], [0, 9], [0, 16], [0, 19], [0, 30], [0, 31], [0, 34], [0, 43], [0, 60], [0, 64], [0, 69], [0, 75], [0, 77], [0, 85], [0, 88], [0, 93], [0, 100], [0, 116], [0, 133], [0, 134], [1, 6], [1, 15], [1, 44], [1, 49], [1, 63], [1, 64], [1, 66], [1, 72], [1, 84], [1, 90], [1, 91], [1, 95], [1, 130], [1, 135], [2, 5], [2, 7], [2, 11], [2, 12], [2, 24], [2, 25], [2, 27], [2, 33], [2, 41], [2, 44], [2, 56], [2, 62], [2, 71], [2, 73], [2, 74], [2, 75], [2, 84], [2, 89], [2, 103], [2, 104], [2, 114], [2, 131], [2, 139], [3, 9], [3, 16], [3, 46], [3, 61], [3, 63], [3, 73], [3, 82], [3, 83], [3, 91], [3, 94], [3, 98], [3, 106], [3, 113], [3, 125], [3, 128], [3, 132], [4, 13], [4, 15], [4, 36], [4, 39], [4, 50], [4, 56], [4, 58], [4, 59], [4, 104], [4, 106], [4, 139], [5, 8], [5, 11], [5, 31], [5, 42], [5, 48], [5, 54], [5, 77], [5, 82], [5, 101], [5, 106], [5, 107], [5, 108], [5, 109], [5, 127], [5, 138], [6, 7], [6, 9], [6, 19], [6, 22], [6, 25], [6, 48], [6, 52], [6, 65], [6, 74], [6, 82], [6, 98], [6, 103], [6, 104], [6, 105], [6, 112], [6, 116], [6, 117], [6, 123], [6, 133], [6, 136], [7, 10], [7, 18], [7, 19], [7, 27], [7, 29], [7, 40], [7, 50], [7, 53], [7, 58], [7, 69], [7, 73], [7, 84], [7, 85], [7, 93], [7, 94], [7, 113], [7, 118], [7, 122], [7, 123], [8, 19], [8, 29], [8, 35], [8, 38], [8, 54], [8, 88], [8, 92], [8, 112], [8, 115], [8, 129], [8, 131], [8, 135], [9, 10], [9, 26], [9, 30], [9, 32], [9, 33], [9, 37], [9, 43], [9, 46], [9, 47], [9, 49], [9, 52], [9, 57], [9, 72], [9, 82], [9, 86], [9, 88], [9, 93], [9, 105], [9, 106], [9, 115], [9, 121], [9, 139], [10, 18], [10, 19], [10, 23], [10, 25], [10, 29], [10, 35], [10, 44], [10, 56], [10, 64], [10, 65], [10, 69], [10, 72], [10, 73], [10, 74], [10, 86], [10, 93], [10, 105], [10, 118], [10, 120], [10, 121], [10, 129], [10, 134], [10, 139], [11, 16], [11, 34], [11, 37], [11, 42], [11, 48], [11, 63], [11, 75], [11, 80], [11, 94], [11, 104], [11, 110], [11, 112], [11, 125], [11, 133], [12, 24], [12, 26], [12, 32], [12, 33], [12, 48], [12, 52], [12, 53], [12, 63], [12, 64], [12, 74], [12, 75], [12, 76], [12, 85], [12, 90], [12, 93], [12, 101], [12, 108], [12, 114], [12, 121], [12, 126], [12, 132], [13, 23], [13, 24], [13, 27], [13, 28], [13, 29], [13, 31], [13, 39], [13, 42], [13, 50], [13, 55], [13, 56], [13, 62], [13, 64], [13, 68], [13, 69], [13, 81], [13, 84], [13, 87], [13, 92], [13, 102], [13, 112], [13, 114], [13, 115], [13, 126], [14, 21], [14, 32], [14, 39], [14, 43], [14, 54], [14, 55], [14, 75], [14, 78], [14, 86], [14, 97], [14, 102], [14, 104], [14, 106], [14, 127], [14, 130], [15, 25], [15, 29], [15, 30], [15, 37], [15, 42], [15, 43], [15, 49], [15, 55], [15, 60], [15, 61], [15, 62], [15, 63], [15, 66], [15, 68], [15, 82], [15, 84], [15, 103], [15, 119], [15, 123], [15, 126], [15, 138], [16, 21], [16, 24], [16, 36], [16, 37], [16, 43], [16, 49], [16, 56], [16, 59], [16, 63], [16, 64], [16, 68], [16, 72], [16, 77], [16, 90], [16, 95], [16, 113], [16, 117], [16, 118], [16, 121], [16, 132], [16, 134], [16, 136], [17, 19], [17, 23], [17, 37], [17, 61], [17, 73], [17, 110], [17, 113], [17, 125], [18, 21], [18, 26], [18, 33], [18, 36], [18, 42], [18, 47], [18, 70], [18, 73], [18, 83], [18, 99], [18, 104], [18, 125], [19, 31], [19, 41], [19, 45], [19, 49], [19, 70], [19, 71], [19, 74], [19, 75], [19, 81], [19, 84], [19, 85], [19, 107], [19, 111], [19, 133], [20, 21], [20, 40], [20, 41], [20, 47], [20, 58], [20, 62], [20, 75], [20, 80], [20, 85], [20, 86], [20, 93], [20, 116], [20, 121], [20, 122], [20, 138], [21, 33], [21, 48], [21, 56], [21, 59], [21, 73], [21, 96], [21, 104], [21, 111], [21, 113], [21, 116], [21, 119], [21, 129], [21, 134], [21, 137], [22, 26], [22, 47], [22, 48], [22, 56], [22, 74], [22, 77], [22, 82], [22, 88], [22, 90], [22, 91], [22, 92], [22, 98], [22, 99], [22, 100], [22, 101], [22, 103], [22, 106], [22, 107], [22, 117], [22, 132], [22, 133], [23, 36], [23, 52], [23, 73], [23, 74], [23, 77], [23, 86], [23, 94], [23, 96], [23, 100], [23, 117], [23, 123], [23, 127], [23, 132], [24, 30], [24, 31], [24, 33], [24, 44], [24, 56], [24, 57], [24, 71], [24, 74], [24, 79], [24, 80], [24, 92], [24, 93], [24, 97], [24, 112], [24, 122], [24, 129], [24, 131], [25, 29], [25, 35], [25, 38], [25, 55], [25, 62], [25, 64], [25, 65], [25, 68], [25, 72], [25, 73], [25, 85], [25, 86], [25, 94], [25, 96], [25, 113], [25, 115], [26, 37], [26, 39], [26, 45], [26, 50], [26, 69], [26, 85], [26, 86], [26, 94], [26, 103], [26, 106], [26, 109], [26, 111], [26, 118], [26, 119], [26, 129], [26, 138], [27, 35], [27, 42], [27, 49], [27, 51], [27, 52], [27, 63], [27, 66], [27, 74], [27, 80], [27, 87], [27, 105], [27, 106], [27, 107], [27, 108], [27, 124], [27, 132], [27, 133], [27, 136], [28, 30], [28, 32], [28, 41], [28, 50], [28, 71], [28, 75], [28, 80], [28, 94], [28, 106], [28, 107], [28, 113], [28, 114], [28, 122], [28, 139], [29, 31], [29, 32], [29, 39], [29, 44], [29, 48], [29, 51], [29, 57], [29, 68], [29, 71], [29, 76], [29, 82], [29, 119], [29, 120], [29, 122], [29, 136], [29, 139], [30, 37], [30, 44], [30, 53], [30, 54], [30, 55], [30, 56], [30, 73], [30, 82], [30, 91], [30, 96], [30, 99], [30, 113], [30, 114], [30, 116], [30, 124], [30, 129], [30, 130], [31, 37], [31, 39], [31, 49], [31, 67], [31, 72], [31, 81], [31, 98], [31, 100], [31, 109], [31, 114], [31, 117], [31, 123], [31, 129], [31, 130], [31, 133], [32, 35], [32, 36], [32, 41], [32, 49], [32, 58], [32, 77], [32, 79], [32, 84], [32, 88], [32, 90], [32, 104], [32, 105], [32, 113], [32, 118], [32, 120], [32, 130], [32, 132], [32, 136], [33, 45], [33, 54], [33, 66], [33, 67], [33, 72], [33, 75], [33, 76], [33, 80], [33, 99], [33, 101], [33, 107], [33, 110], [33, 131], [33, 139], [34, 36], [34, 51], [34, 72], [34, 80], [34, 89], [34, 98], [34, 117], [34, 131], [34, 139], [35, 43], [35, 57], [35, 70], [35, 77], [35, 89], [35, 105], [35, 107], [35, 119], [35, 130], [35, 132], [35, 133], [35, 134], [36, 42], [36, 43], [36, 44], [36, 46], [36, 47], [36, 49], [36, 51], [36, 59], [36, 70], [36, 74], [36, 75], [36, 89], [36, 100], [36, 102], [36, 103], [36, 107], [36, 110], [36, 113], [36, 115], [36, 126], [36, 129], [37, 40], [37, 45], [37, 48], [37, 51], [37, 56], [37, 68], [37, 85], [37, 114], [37, 117], [37, 125], [37, 128], [37, 133], [37, 136], [37, 137], [38, 39], [38, 43], [38, 44], [38, 58], [38, 59], [38, 61], [38, 66], [38, 72], [38, 77], [38, 87], [38, 88], [38, 101], [38, 108], [38, 109], [38, 120], [38, 123], [38, 124], [38, 138], [39, 42], [39, 44], [39, 45], [39, 46], [39, 47], [39, 58], [39, 59], [39, 82], [39, 86], [39, 88], [39, 100], [39, 101], [39, 116], [39, 133], [39, 138], [40, 57], [40, 64], [40, 67], [40, 74], [40, 93], [40, 97], [40, 100], [40, 101], [40, 106], [40, 107], [40, 120], [40, 128], [40, 134], [40, 137], [40, 138], [41, 45], [41, 48], [41, 64], [41, 72], [41, 79], [41, 81], [41, 88], [41, 95], [41, 101], [41, 103], [41, 113], [41, 115], [41, 120], [41, 127], [41, 129], [41, 130], [41, 132], [41, 136], [41, 138], [42, 57], [42, 61], [42, 69], [42, 94], [42, 129], [42, 133], [43, 45], [43, 49], [43, 55], [43, 57], [43, 63], [43, 64], [43, 67], [43, 70], [43, 92], [43, 95], [43, 99], [43, 102], [43, 111], [43, 115], [43, 117], [43, 121], [43, 122], [43, 123], [43, 124], [43, 132], [43, 138], [44, 54], [44, 62], [44, 68], [44, 70], [44, 71], [44, 74], [44, 84], [44, 92], [44, 100], [44, 107], [44, 121], [44, 125], [44, 126], [44, 134], [44, 137], [45, 48], [45, 49], [45, 50], [45, 56], [45, 68], [45, 81], [45, 87], [45, 88], [45, 92], [45, 99], [45, 118], [45, 119], [45, 127], [45, 133], [46, 74], [46, 75], [46, 87], [46, 100], [46, 110], [46, 115], [46, 116], [46, 121], [46, 125], [47, 49], [47, 57], [47, 71], [47, 72], [47, 84], [47, 85], [47, 105], [47, 106], [47, 118], [47, 125], [47, 127], [47, 137], [47, 139], [48, 66], [48, 68], [48, 71], [48, 72], [48, 86], [48, 89], [48, 99], [48, 103], [48, 113], [48, 118], [48, 126], [48, 128], [49, 53], [49, 63], [49, 70], [49, 82], [49, 94], [49, 106], [49, 109], [49, 122], [49, 134], [50, 53], [50, 56], [50, 68], [50, 75], [50, 83], [50, 89], [50, 102], [50, 112], [50, 114], [50, 116], [50, 130], [50, 134], [50, 136], [51, 54], [51, 57], [51, 61], [51, 72], [51, 87], [51, 89], [51, 93], [51, 102], [51, 123], [51, 126], [51, 130], [51, 139], [52, 58], [52, 61], [52, 63], [52, 70], [52, 73], [52, 88], [52, 89], [52, 92], [52, 109], [52, 111], [52, 114], [52, 124], [52, 125], [52, 134], [52, 137], [52, 139], [53, 56], [53, 57], [53, 62], [53, 63], [53, 68], [53, 72], [53, 82], [53, 91], [53, 94], [53, 112], [53, 114], [53, 120], [53, 128], [54, 69], [54, 74], [54, 88], [54, 94], [54, 95], [54, 96], [54, 111], [54, 113], [54, 116], [54, 118], [54, 127], [54, 130], [54, 133], [55, 56], [55, 62], [55, 63], [55, 71], [55, 73], [55, 84], [55, 89], [55, 92], [55, 96], [55, 105], [55, 109], [55, 124], [56, 63], [56, 77], [56, 82], [56, 104], [56, 112], [56, 122], [56, 129], [56, 130], [57, 61], [57, 62], [57, 71], [57, 76], [57, 85], [57, 90], [57, 92], [57, 96], [57, 101], [57, 108], [57, 115], [57, 120], [57, 122], [57, 123], [58, 72], [58, 76], [58, 90], [58, 95], [58, 99], [58, 110], [58, 118], [58, 122], [59, 64], [59, 68], [59, 69], [59, 71], [59, 82], [59, 83], [59, 84], [59, 97], [59, 98], [59, 101], [59, 104], [59, 118], [59, 125], [59, 135], [60, 63], [60, 73], [60, 76], [60, 79], [60, 85], [60, 86], [60, 105], [60, 114], [60, 123], [61, 79], [61, 81], [61, 92], [61, 95], [61, 117], [61, 118], [61, 129], [61, 138], [62, 70], [62, 86], [62, 95], [62, 97], [62, 104], [62, 107], [62, 110], [62, 115], [62, 117], [62, 120], [62, 123], [62, 131], [63, 68], [63, 73], [63, 75], [63, 76], [63, 90], [63, 92], [63, 96], [63, 108], [63, 111], [63, 117], [63, 133], [64, 71], [64, 73], [64, 74], [64, 75], [64, 77], [64, 85], [64, 88], [64, 92], [64, 94], [64, 103], [64, 130], [64, 131], [64, 139], [65, 68], [65, 71], [65, 92], [65, 100], [65, 103], [65, 117], [65, 120], [65, 130], [65, 132], [65, 139], [66, 69], [66, 75], [66, 76], [66, 79], [66, 111], [66, 119], [66, 124], [67, 82], [67, 84], [67, 87], [67, 91], [67, 111], [67, 136], [67, 137], [67, 138], [68, 94], [68, 121], [68, 136], [69, 73], [69, 75], [69, 83], [69, 84], [69, 98], [69, 100], [69, 103], [69, 112], [69, 123], [69, 131], [69, 134], [70, 74], [70, 77], [70, 98], [70, 106], [70, 108], [70, 116], [70, 118], [70, 122], [70, 134], [71, 75], [71, 91], [71, 93], [71, 97], [71, 100], [71, 107], [71, 112], [71, 138], [72, 73], [72, 84], [72, 92], [72, 93], [72, 105], [72, 116], [72, 136], [73, 74], [73, 88], [73, 97], [73, 98], [73, 105], [73, 114], [73, 116], [73, 118], [73, 132], [73, 133], [74, 107], [74, 112], [74, 124], [74, 126], [74, 132], [74, 137], [75, 86], [75, 91], [75, 95], [75, 99], [75, 106], [75, 109], [75, 112], [75, 119], [75, 128], [76, 93], [76, 99], [76, 108], [76, 115], [76, 121], [76, 123], [76, 127], [76, 129], [77, 104], [77, 110], [77, 112], [77, 113], [77, 130], [77, 133], [78, 82], [78, 84], [78, 94], [78, 100], [79, 83], [79, 89], [79, 101], [79, 105], [79, 110], [80, 84], [80, 89], [80, 114], [80, 134], [81, 85], [81, 86], [81, 87], [81, 89], [81, 102], [81, 109], [81, 110], [81, 111], [81, 115], [81, 119], [81, 130], [81, 131], [81, 135], [81, 138], [82, 85], [82, 89], [82, 90], [82, 99], [82, 104], [82, 115], [82, 130], [82, 131], [82, 132], [83, 87], [83, 90], [83, 101], [83, 102], [83, 105], [83, 110], [83, 112], [83, 127], [83, 136], [84, 91], [84, 98], [84, 104], [84, 120], [84, 125], [84, 130], [84, 132], [84, 137], [85, 109], [85, 120], [85, 133], [86, 89], [86, 122], [86, 130], [86, 132], [87, 90], [87, 98], [87, 100], [87, 102], [87, 103], [87, 108], [87, 111], [87, 115], [87, 127], [87, 128], [87, 129], [87, 130], [88, 91], [88, 108], [88, 119], [88, 139], [89, 94], [89, 108], [89, 126], [89, 134], [90, 95], [90, 100], [90, 105], [90, 109], [90, 114], [90, 121], [90, 122], [90, 123], [90, 125], [91, 101], [91, 102], [91, 119], [91, 120], [91, 121], [91, 123], [91, 126], [91, 135], [92, 112], [92, 113], [92, 117], [92, 119], [92, 137], [93, 104], [93, 106], [93, 109], [93, 118], [93, 131], [93, 134], [94, 99], [94, 126], [94, 132], [94, 135], [95, 97], [95, 100], [95, 106], [95, 115], [95, 118], [95, 121], [95, 124], [95, 125], [95, 128], [95, 132], [95, 139], [96, 105], [96, 106], [96, 130], [96, 132], [96, 133], [96, 135], [96, 137], [97, 113], [97, 117], [97, 139], [98, 104], [98, 113], [98, 116], [98, 128], [98, 132], [99, 103], [99, 112], [99, 117], [99, 131], [99, 136], [100, 102], [100, 106], [100, 108], [100, 109], [100, 116], [100, 117], [100, 118], [100, 124], [101, 111], [101, 116], [101, 124], [101, 139], [102, 111], [102, 118], [102, 125], [102, 128], [102, 132], [103, 108], [103, 113], [103, 137], [104, 113], [105, 109], [105, 121], [105, 122], [105, 136], [106, 108], [106, 109], [106, 129], [106, 132], [106, 134], [107, 113], [107, 118], [107, 122], [107, 123], [107, 127], [107, 137], [108, 112], [108, 129], [108, 132], [108, 137], [109, 112], [109, 113], [109, 120], [109, 124], [109, 131], [110, 114], [110, 122], [110, 136], [111, 112], [111, 117], [111, 123], [111, 128], [112, 119], [112, 121], [112, 127], [112, 133], [112, 135], [113, 136], [113, 139], [115, 116], [115, 118], [115, 120], [115, 139], [116, 126], [117, 121], [117, 132], [117, 135], [117, 138], [117, 139], [118, 122], [118, 135], [118, 139], [119, 121], [119, 123], [119, 124], [120, 125], [120, 136], [120, 137], [121, 125], [121, 127], [121, 129], [121, 131], [121, 139], [122, 123], [122, 128], [122, 129], [122, 132], [123, 125], [123, 126], [123, 127], [123, 130], [123, 133], [123, 135], [123, 138], [124, 125], [125, 126], [125, 128], [126, 127], [126, 129], [126, 134], [127, 129], [127, 133], [127, 137], [128, 131], [128, 137], [129, 132], [129, 138], [129, 139], [130, 134], [130, 137], [130, 138], [132, 133], [132, 135], [132, 136], [133, 134], [133, 137], [133, 139], [135, 136], [137, 139], [138, 139]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s8/solution/solve.sh b/tasks/construct-mc-vertex-cover-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..edc1f0bafc15789020852144e05c34373a067922 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 1, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 36, 38, 39, 40, 41, 43, 44, 45, 46, 48, 49, 50, 51, 56, 57, 58, 59, 61, 62, 63, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 94, 95, 96, 98, 100, 103, 104, 105, 106, 107, 109, 111, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 127, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l6-s8/tests/check.py b/tasks/construct-mc-vertex-cover-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s8/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l6-s8/tests/instance.json b/tasks/construct-mc-vertex-cover-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5265d7198162a2424314ca177ca0eb3edbd518f --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 4], [0, 9], [0, 16], [0, 19], [0, 30], [0, 31], [0, 34], [0, 43], [0, 60], [0, 64], [0, 69], [0, 75], [0, 77], [0, 85], [0, 88], [0, 93], [0, 100], [0, 116], [0, 133], [0, 134], [1, 6], [1, 15], [1, 44], [1, 49], [1, 63], [1, 64], [1, 66], [1, 72], [1, 84], [1, 90], [1, 91], [1, 95], [1, 130], [1, 135], [2, 5], [2, 7], [2, 11], [2, 12], [2, 24], [2, 25], [2, 27], [2, 33], [2, 41], [2, 44], [2, 56], [2, 62], [2, 71], [2, 73], [2, 74], [2, 75], [2, 84], [2, 89], [2, 103], [2, 104], [2, 114], [2, 131], [2, 139], [3, 9], [3, 16], [3, 46], [3, 61], [3, 63], [3, 73], [3, 82], [3, 83], [3, 91], [3, 94], [3, 98], [3, 106], [3, 113], [3, 125], [3, 128], [3, 132], [4, 13], [4, 15], [4, 36], [4, 39], [4, 50], [4, 56], [4, 58], [4, 59], [4, 104], [4, 106], [4, 139], [5, 8], [5, 11], [5, 31], [5, 42], [5, 48], [5, 54], [5, 77], [5, 82], [5, 101], [5, 106], [5, 107], [5, 108], [5, 109], [5, 127], [5, 138], [6, 7], [6, 9], [6, 19], [6, 22], [6, 25], [6, 48], [6, 52], [6, 65], [6, 74], [6, 82], [6, 98], [6, 103], [6, 104], [6, 105], [6, 112], [6, 116], [6, 117], [6, 123], [6, 133], [6, 136], [7, 10], [7, 18], [7, 19], [7, 27], [7, 29], [7, 40], [7, 50], [7, 53], [7, 58], [7, 69], [7, 73], [7, 84], [7, 85], [7, 93], [7, 94], [7, 113], [7, 118], [7, 122], [7, 123], [8, 19], [8, 29], [8, 35], [8, 38], [8, 54], [8, 88], [8, 92], [8, 112], [8, 115], [8, 129], [8, 131], [8, 135], [9, 10], [9, 26], [9, 30], [9, 32], [9, 33], [9, 37], [9, 43], [9, 46], [9, 47], [9, 49], [9, 52], [9, 57], [9, 72], [9, 82], [9, 86], [9, 88], [9, 93], [9, 105], [9, 106], [9, 115], [9, 121], [9, 139], [10, 18], [10, 19], [10, 23], [10, 25], [10, 29], [10, 35], [10, 44], [10, 56], [10, 64], [10, 65], [10, 69], [10, 72], [10, 73], [10, 74], [10, 86], [10, 93], [10, 105], [10, 118], [10, 120], [10, 121], [10, 129], [10, 134], [10, 139], [11, 16], [11, 34], [11, 37], [11, 42], [11, 48], [11, 63], [11, 75], [11, 80], [11, 94], [11, 104], [11, 110], [11, 112], [11, 125], [11, 133], [12, 24], [12, 26], [12, 32], [12, 33], [12, 48], [12, 52], [12, 53], [12, 63], [12, 64], [12, 74], [12, 75], [12, 76], [12, 85], [12, 90], [12, 93], [12, 101], [12, 108], [12, 114], [12, 121], [12, 126], [12, 132], [13, 23], [13, 24], [13, 27], [13, 28], [13, 29], [13, 31], [13, 39], [13, 42], [13, 50], [13, 55], [13, 56], [13, 62], [13, 64], [13, 68], [13, 69], [13, 81], [13, 84], [13, 87], [13, 92], [13, 102], [13, 112], [13, 114], [13, 115], [13, 126], [14, 21], [14, 32], [14, 39], [14, 43], [14, 54], [14, 55], [14, 75], [14, 78], [14, 86], [14, 97], [14, 102], [14, 104], [14, 106], [14, 127], [14, 130], [15, 25], [15, 29], [15, 30], [15, 37], [15, 42], [15, 43], [15, 49], [15, 55], [15, 60], [15, 61], [15, 62], [15, 63], [15, 66], [15, 68], [15, 82], [15, 84], [15, 103], [15, 119], [15, 123], [15, 126], [15, 138], [16, 21], [16, 24], [16, 36], [16, 37], [16, 43], [16, 49], [16, 56], [16, 59], [16, 63], [16, 64], [16, 68], [16, 72], [16, 77], [16, 90], [16, 95], [16, 113], [16, 117], [16, 118], [16, 121], [16, 132], [16, 134], [16, 136], [17, 19], [17, 23], [17, 37], [17, 61], [17, 73], [17, 110], [17, 113], [17, 125], [18, 21], [18, 26], [18, 33], [18, 36], [18, 42], [18, 47], [18, 70], [18, 73], [18, 83], [18, 99], [18, 104], [18, 125], [19, 31], [19, 41], [19, 45], [19, 49], [19, 70], [19, 71], [19, 74], [19, 75], [19, 81], [19, 84], [19, 85], [19, 107], [19, 111], [19, 133], [20, 21], [20, 40], [20, 41], [20, 47], [20, 58], [20, 62], [20, 75], [20, 80], [20, 85], [20, 86], [20, 93], [20, 116], [20, 121], [20, 122], [20, 138], [21, 33], [21, 48], [21, 56], [21, 59], [21, 73], [21, 96], [21, 104], [21, 111], [21, 113], [21, 116], [21, 119], [21, 129], [21, 134], [21, 137], [22, 26], [22, 47], [22, 48], [22, 56], [22, 74], [22, 77], [22, 82], [22, 88], [22, 90], [22, 91], [22, 92], [22, 98], [22, 99], [22, 100], [22, 101], [22, 103], [22, 106], [22, 107], [22, 117], [22, 132], [22, 133], [23, 36], [23, 52], [23, 73], [23, 74], [23, 77], [23, 86], [23, 94], [23, 96], [23, 100], [23, 117], [23, 123], [23, 127], [23, 132], [24, 30], [24, 31], [24, 33], [24, 44], [24, 56], [24, 57], [24, 71], [24, 74], [24, 79], [24, 80], [24, 92], [24, 93], [24, 97], [24, 112], [24, 122], [24, 129], [24, 131], [25, 29], [25, 35], [25, 38], [25, 55], [25, 62], [25, 64], [25, 65], [25, 68], [25, 72], [25, 73], [25, 85], [25, 86], [25, 94], [25, 96], [25, 113], [25, 115], [26, 37], [26, 39], [26, 45], [26, 50], [26, 69], [26, 85], [26, 86], [26, 94], [26, 103], [26, 106], [26, 109], [26, 111], [26, 118], [26, 119], [26, 129], [26, 138], [27, 35], [27, 42], [27, 49], [27, 51], [27, 52], [27, 63], [27, 66], [27, 74], [27, 80], [27, 87], [27, 105], [27, 106], [27, 107], [27, 108], [27, 124], [27, 132], [27, 133], [27, 136], [28, 30], [28, 32], [28, 41], [28, 50], [28, 71], [28, 75], [28, 80], [28, 94], [28, 106], [28, 107], [28, 113], [28, 114], [28, 122], [28, 139], [29, 31], [29, 32], [29, 39], [29, 44], [29, 48], [29, 51], [29, 57], [29, 68], [29, 71], [29, 76], [29, 82], [29, 119], [29, 120], [29, 122], [29, 136], [29, 139], [30, 37], [30, 44], [30, 53], [30, 54], [30, 55], [30, 56], [30, 73], [30, 82], [30, 91], [30, 96], [30, 99], [30, 113], [30, 114], [30, 116], [30, 124], [30, 129], [30, 130], [31, 37], [31, 39], [31, 49], [31, 67], [31, 72], [31, 81], [31, 98], [31, 100], [31, 109], [31, 114], [31, 117], [31, 123], [31, 129], [31, 130], [31, 133], [32, 35], [32, 36], [32, 41], [32, 49], [32, 58], [32, 77], [32, 79], [32, 84], [32, 88], [32, 90], [32, 104], [32, 105], [32, 113], [32, 118], [32, 120], [32, 130], [32, 132], [32, 136], [33, 45], [33, 54], [33, 66], [33, 67], [33, 72], [33, 75], [33, 76], [33, 80], [33, 99], [33, 101], [33, 107], [33, 110], [33, 131], [33, 139], [34, 36], [34, 51], [34, 72], [34, 80], [34, 89], [34, 98], [34, 117], [34, 131], [34, 139], [35, 43], [35, 57], [35, 70], [35, 77], [35, 89], [35, 105], [35, 107], [35, 119], [35, 130], [35, 132], [35, 133], [35, 134], [36, 42], [36, 43], [36, 44], [36, 46], [36, 47], [36, 49], [36, 51], [36, 59], [36, 70], [36, 74], [36, 75], [36, 89], [36, 100], [36, 102], [36, 103], [36, 107], [36, 110], [36, 113], [36, 115], [36, 126], [36, 129], [37, 40], [37, 45], [37, 48], [37, 51], [37, 56], [37, 68], [37, 85], [37, 114], [37, 117], [37, 125], [37, 128], [37, 133], [37, 136], [37, 137], [38, 39], [38, 43], [38, 44], [38, 58], [38, 59], [38, 61], [38, 66], [38, 72], [38, 77], [38, 87], [38, 88], [38, 101], [38, 108], [38, 109], [38, 120], [38, 123], [38, 124], [38, 138], [39, 42], [39, 44], [39, 45], [39, 46], [39, 47], [39, 58], [39, 59], [39, 82], [39, 86], [39, 88], [39, 100], [39, 101], [39, 116], [39, 133], [39, 138], [40, 57], [40, 64], [40, 67], [40, 74], [40, 93], [40, 97], [40, 100], [40, 101], [40, 106], [40, 107], [40, 120], [40, 128], [40, 134], [40, 137], [40, 138], [41, 45], [41, 48], [41, 64], [41, 72], [41, 79], [41, 81], [41, 88], [41, 95], [41, 101], [41, 103], [41, 113], [41, 115], [41, 120], [41, 127], [41, 129], [41, 130], [41, 132], [41, 136], [41, 138], [42, 57], [42, 61], [42, 69], [42, 94], [42, 129], [42, 133], [43, 45], [43, 49], [43, 55], [43, 57], [43, 63], [43, 64], [43, 67], [43, 70], [43, 92], [43, 95], [43, 99], [43, 102], [43, 111], [43, 115], [43, 117], [43, 121], [43, 122], [43, 123], [43, 124], [43, 132], [43, 138], [44, 54], [44, 62], [44, 68], [44, 70], [44, 71], [44, 74], [44, 84], [44, 92], [44, 100], [44, 107], [44, 121], [44, 125], [44, 126], [44, 134], [44, 137], [45, 48], [45, 49], [45, 50], [45, 56], [45, 68], [45, 81], [45, 87], [45, 88], [45, 92], [45, 99], [45, 118], [45, 119], [45, 127], [45, 133], [46, 74], [46, 75], [46, 87], [46, 100], [46, 110], [46, 115], [46, 116], [46, 121], [46, 125], [47, 49], [47, 57], [47, 71], [47, 72], [47, 84], [47, 85], [47, 105], [47, 106], [47, 118], [47, 125], [47, 127], [47, 137], [47, 139], [48, 66], [48, 68], [48, 71], [48, 72], [48, 86], [48, 89], [48, 99], [48, 103], [48, 113], [48, 118], [48, 126], [48, 128], [49, 53], [49, 63], [49, 70], [49, 82], [49, 94], [49, 106], [49, 109], [49, 122], [49, 134], [50, 53], [50, 56], [50, 68], [50, 75], [50, 83], [50, 89], [50, 102], [50, 112], [50, 114], [50, 116], [50, 130], [50, 134], [50, 136], [51, 54], [51, 57], [51, 61], [51, 72], [51, 87], [51, 89], [51, 93], [51, 102], [51, 123], [51, 126], [51, 130], [51, 139], [52, 58], [52, 61], [52, 63], [52, 70], [52, 73], [52, 88], [52, 89], [52, 92], [52, 109], [52, 111], [52, 114], [52, 124], [52, 125], [52, 134], [52, 137], [52, 139], [53, 56], [53, 57], [53, 62], [53, 63], [53, 68], [53, 72], [53, 82], [53, 91], [53, 94], [53, 112], [53, 114], [53, 120], [53, 128], [54, 69], [54, 74], [54, 88], [54, 94], [54, 95], [54, 96], [54, 111], [54, 113], [54, 116], [54, 118], [54, 127], [54, 130], [54, 133], [55, 56], [55, 62], [55, 63], [55, 71], [55, 73], [55, 84], [55, 89], [55, 92], [55, 96], [55, 105], [55, 109], [55, 124], [56, 63], [56, 77], [56, 82], [56, 104], [56, 112], [56, 122], [56, 129], [56, 130], [57, 61], [57, 62], [57, 71], [57, 76], [57, 85], [57, 90], [57, 92], [57, 96], [57, 101], [57, 108], [57, 115], [57, 120], [57, 122], [57, 123], [58, 72], [58, 76], [58, 90], [58, 95], [58, 99], [58, 110], [58, 118], [58, 122], [59, 64], [59, 68], [59, 69], [59, 71], [59, 82], [59, 83], [59, 84], [59, 97], [59, 98], [59, 101], [59, 104], [59, 118], [59, 125], [59, 135], [60, 63], [60, 73], [60, 76], [60, 79], [60, 85], [60, 86], [60, 105], [60, 114], [60, 123], [61, 79], [61, 81], [61, 92], [61, 95], [61, 117], [61, 118], [61, 129], [61, 138], [62, 70], [62, 86], [62, 95], [62, 97], [62, 104], [62, 107], [62, 110], [62, 115], [62, 117], [62, 120], [62, 123], [62, 131], [63, 68], [63, 73], [63, 75], [63, 76], [63, 90], [63, 92], [63, 96], [63, 108], [63, 111], [63, 117], [63, 133], [64, 71], [64, 73], [64, 74], [64, 75], [64, 77], [64, 85], [64, 88], [64, 92], [64, 94], [64, 103], [64, 130], [64, 131], [64, 139], [65, 68], [65, 71], [65, 92], [65, 100], [65, 103], [65, 117], [65, 120], [65, 130], [65, 132], [65, 139], [66, 69], [66, 75], [66, 76], [66, 79], [66, 111], [66, 119], [66, 124], [67, 82], [67, 84], [67, 87], [67, 91], [67, 111], [67, 136], [67, 137], [67, 138], [68, 94], [68, 121], [68, 136], [69, 73], [69, 75], [69, 83], [69, 84], [69, 98], [69, 100], [69, 103], [69, 112], [69, 123], [69, 131], [69, 134], [70, 74], [70, 77], [70, 98], [70, 106], [70, 108], [70, 116], [70, 118], [70, 122], [70, 134], [71, 75], [71, 91], [71, 93], [71, 97], [71, 100], [71, 107], [71, 112], [71, 138], [72, 73], [72, 84], [72, 92], [72, 93], [72, 105], [72, 116], [72, 136], [73, 74], [73, 88], [73, 97], [73, 98], [73, 105], [73, 114], [73, 116], [73, 118], [73, 132], [73, 133], [74, 107], [74, 112], [74, 124], [74, 126], [74, 132], [74, 137], [75, 86], [75, 91], [75, 95], [75, 99], [75, 106], [75, 109], [75, 112], [75, 119], [75, 128], [76, 93], [76, 99], [76, 108], [76, 115], [76, 121], [76, 123], [76, 127], [76, 129], [77, 104], [77, 110], [77, 112], [77, 113], [77, 130], [77, 133], [78, 82], [78, 84], [78, 94], [78, 100], [79, 83], [79, 89], [79, 101], [79, 105], [79, 110], [80, 84], [80, 89], [80, 114], [80, 134], [81, 85], [81, 86], [81, 87], [81, 89], [81, 102], [81, 109], [81, 110], [81, 111], [81, 115], [81, 119], [81, 130], [81, 131], [81, 135], [81, 138], [82, 85], [82, 89], [82, 90], [82, 99], [82, 104], [82, 115], [82, 130], [82, 131], [82, 132], [83, 87], [83, 90], [83, 101], [83, 102], [83, 105], [83, 110], [83, 112], [83, 127], [83, 136], [84, 91], [84, 98], [84, 104], [84, 120], [84, 125], [84, 130], [84, 132], [84, 137], [85, 109], [85, 120], [85, 133], [86, 89], [86, 122], [86, 130], [86, 132], [87, 90], [87, 98], [87, 100], [87, 102], [87, 103], [87, 108], [87, 111], [87, 115], [87, 127], [87, 128], [87, 129], [87, 130], [88, 91], [88, 108], [88, 119], [88, 139], [89, 94], [89, 108], [89, 126], [89, 134], [90, 95], [90, 100], [90, 105], [90, 109], [90, 114], [90, 121], [90, 122], [90, 123], [90, 125], [91, 101], [91, 102], [91, 119], [91, 120], [91, 121], [91, 123], [91, 126], [91, 135], [92, 112], [92, 113], [92, 117], [92, 119], [92, 137], [93, 104], [93, 106], [93, 109], [93, 118], [93, 131], [93, 134], [94, 99], [94, 126], [94, 132], [94, 135], [95, 97], [95, 100], [95, 106], [95, 115], [95, 118], [95, 121], [95, 124], [95, 125], [95, 128], [95, 132], [95, 139], [96, 105], [96, 106], [96, 130], [96, 132], [96, 133], [96, 135], [96, 137], [97, 113], [97, 117], [97, 139], [98, 104], [98, 113], [98, 116], [98, 128], [98, 132], [99, 103], [99, 112], [99, 117], [99, 131], [99, 136], [100, 102], [100, 106], [100, 108], [100, 109], [100, 116], [100, 117], [100, 118], [100, 124], [101, 111], [101, 116], [101, 124], [101, 139], [102, 111], [102, 118], [102, 125], [102, 128], [102, 132], [103, 108], [103, 113], [103, 137], [104, 113], [105, 109], [105, 121], [105, 122], [105, 136], [106, 108], [106, 109], [106, 129], [106, 132], [106, 134], [107, 113], [107, 118], [107, 122], [107, 123], [107, 127], [107, 137], [108, 112], [108, 129], [108, 132], [108, 137], [109, 112], [109, 113], [109, 120], [109, 124], [109, 131], [110, 114], [110, 122], [110, 136], [111, 112], [111, 117], [111, 123], [111, 128], [112, 119], [112, 121], [112, 127], [112, 133], [112, 135], [113, 136], [113, 139], [115, 116], [115, 118], [115, 120], [115, 139], [116, 126], [117, 121], [117, 132], [117, 135], [117, 138], [117, 139], [118, 122], [118, 135], [118, 139], [119, 121], [119, 123], [119, 124], [120, 125], [120, 136], [120, 137], [121, 125], [121, 127], [121, 129], [121, 131], [121, 139], [122, 123], [122, 128], [122, 129], [122, 132], [123, 125], [123, 126], [123, 127], [123, 130], [123, 133], [123, 135], [123, 138], [124, 125], [125, 126], [125, 128], [126, 127], [126, 129], [126, 134], [127, 129], [127, 133], [127, 137], [128, 131], [128, 137], [129, 132], [129, 138], [129, 139], [130, 134], [130, 137], [130, 138], [132, 133], [132, 135], [132, 136], [133, 134], [133, 137], [133, 139], [135, 136], [137, 139], [138, 139]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s8/tests/run.py b/tasks/construct-mc-vertex-cover-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l6-s8/tests/test.sh b/tasks/construct-mc-vertex-cover-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-nppc-3col-l2-s1/environment/Dockerfile b/tasks/construct-nppc-3col-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l2-s1/environment/instance.json b/tasks/construct-nppc-3col-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..620345d62ed05fb3a56ab0a4aa0fda4106a6f27a --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 3], [0, 5], [0, 6], [0, 11], [0, 13], [0, 14], [1, 2], [1, 4], [1, 7], [1, 13], [2, 3], [2, 6], [2, 7], [2, 10], [3, 5], [3, 9], [3, 10], [3, 12], [4, 5], [4, 6], [4, 12], [4, 14], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 9], [6, 12], [6, 13], [7, 8], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 14], [9, 13], [9, 14], [11, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s1/solution/solve.sh b/tasks/construct-nppc-3col-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..00f4c81eb7647a4d14e6479f6d79390c879d31a8 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [0, 2, 1, 2, 0, 1, 2, 0, 2, 0, 0, 2, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l2-s1/tests/check.py b/tasks/construct-nppc-3col-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s1/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-l2-s1/tests/instance.json b/tasks/construct-nppc-3col-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..620345d62ed05fb3a56ab0a4aa0fda4106a6f27a --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 3], [0, 5], [0, 6], [0, 11], [0, 13], [0, 14], [1, 2], [1, 4], [1, 7], [1, 13], [2, 3], [2, 6], [2, 7], [2, 10], [3, 5], [3, 9], [3, 10], [3, 12], [4, 5], [4, 6], [4, 12], [4, 14], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 9], [6, 12], [6, 13], [7, 8], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 14], [9, 13], [9, 14], [11, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s1/tests/run.py b/tasks/construct-nppc-3col-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l2-s1/tests/test.sh b/tasks/construct-nppc-3col-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l2-s6/environment/Dockerfile b/tasks/construct-nppc-3col-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l2-s6/environment/instance.json b/tasks/construct-nppc-3col-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1986ab09cdf6a592a412a9de58a58d9b769899bb --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 2], [0, 3], [0, 5], [1, 2], [1, 7], [1, 9], [1, 12], [1, 13], [2, 4], [2, 8], [2, 9], [2, 11], [3, 4], [3, 8], [3, 11], [4, 5], [4, 8], [4, 9], [4, 12], [4, 13], [4, 14], [5, 7], [5, 8], [5, 9], [5, 11], [5, 13], [6, 10], [6, 11], [6, 12], [6, 14], [7, 11], [7, 14], [8, 11], [8, 12], [8, 14], [9, 11], [9, 12], [10, 14], [11, 13], [12, 13]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s6/solution/solve.sh b/tasks/construct-nppc-3col-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8aa91bb05f08ba2857df829084e964adb7068bb5 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 0, 2, 2, 0, 2, 1, 1, 1, 1, 0, 0, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l2-s6/tests/check.py b/tasks/construct-nppc-3col-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/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-l2-s6/tests/instance.json b/tasks/construct-nppc-3col-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1986ab09cdf6a592a412a9de58a58d9b769899bb --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 2], [0, 3], [0, 5], [1, 2], [1, 7], [1, 9], [1, 12], [1, 13], [2, 4], [2, 8], [2, 9], [2, 11], [3, 4], [3, 8], [3, 11], [4, 5], [4, 8], [4, 9], [4, 12], [4, 13], [4, 14], [5, 7], [5, 8], [5, 9], [5, 11], [5, 13], [6, 10], [6, 11], [6, 12], [6, 14], [7, 11], [7, 14], [8, 11], [8, 12], [8, 14], [9, 11], [9, 12], [10, 14], [11, 13], [12, 13]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s6/tests/run.py b/tasks/construct-nppc-3col-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l2-s6/tests/test.sh b/tasks/construct-nppc-3col-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l2-s8/environment/Dockerfile b/tasks/construct-nppc-3col-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l2-s8/environment/instance.json b/tasks/construct-nppc-3col-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb2c82276efc40979c1f91a3aff1f4fc91edcdcb --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 1], [0, 5], [0, 6], [0, 8], [0, 13], [1, 3], [1, 4], [1, 9], [1, 10], [2, 3], [2, 4], [2, 9], [2, 10], [3, 6], [3, 9], [4, 6], [4, 7], [4, 11], [4, 13], [5, 6], [5, 8], [5, 9], [5, 12], [5, 13], [6, 7], [6, 10], [6, 11], [6, 14], [7, 8], [7, 12], [8, 10], [8, 11], [8, 12], [9, 11], [9, 13], [10, 11], [11, 12], [11, 13], [12, 13], [12, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s8/solution/solve.sh b/tasks/construct-nppc-3col-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d4146bb3b0bcf43ddee44c0a2229dad5726318bd --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [0, 2, 2, 1, 0, 1, 2, 1, 2, 0, 0, 1, 0, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l2-s8/tests/check.py b/tasks/construct-nppc-3col-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s8/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-l2-s8/tests/instance.json b/tasks/construct-nppc-3col-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb2c82276efc40979c1f91a3aff1f4fc91edcdcb --- /dev/null +++ b/tasks/construct-nppc-3col-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 15, "edges": [[0, 1], [0, 5], [0, 6], [0, 8], [0, 13], [1, 3], [1, 4], [1, 9], [1, 10], [2, 3], [2, 4], [2, 9], [2, 10], [3, 6], [3, 9], [4, 6], [4, 7], [4, 11], [4, 13], [5, 6], [5, 8], [5, 9], [5, 12], [5, 13], [6, 7], [6, 10], [6, 11], [6, 14], [7, 8], [7, 12], [8, 10], [8, 11], [8, 12], [9, 11], [9, 13], [10, 11], [11, 12], [11, 13], [12, 13], [12, 14]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l2-s8/tests/run.py b/tasks/construct-nppc-3col-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l2-s8/tests/test.sh b/tasks/construct-nppc-3col-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s0/environment/Dockerfile b/tasks/construct-nppc-3col-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s0/solution/solve.sh b/tasks/construct-nppc-3col-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8e0c38ed0c5e9d5986e5721cb569eadebe51255a --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [1, 0, 2, 2, 1, 0, 1, 1, 1, 1, 2, 1, 2, 2, 1, 2, 1, 0, 0, 1, 1, 2, 1, 0, 2, 1, 2, 0, 2, 2, 1, 1, 1, 0, 1, 0, 2, 0, 2, 2, 1, 1, 0, 0, 0, 0, 1, 2, 2, 0, 1, 0, 0, 0, 0, 2, 0, 1, 2, 2, 1, 1, 2, 1, 0, 2, 1, 2, 2, 2, 0, 1, 0, 2, 2, 0, 0, 1, 1, 1, 2, 2, 1, 2, 2, 2, 1, 0, 1, 1, 2, 1, 0, 2, 0, 2, 2, 0, 0, 0, 2, 1, 1, 2, 2, 2, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l6-s0/tests/check.py b/tasks/construct-nppc-3col-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s0/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-l6-s0/tests/instance.json b/tasks/construct-nppc-3col-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a968cf05cee6505cda6ba1e576d9796835398812 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 23], [0, 29], [0, 33], [0, 36], [0, 65], [0, 67], [0, 81], [0, 84], [0, 85], [0, 116], [1, 2], [1, 8], [1, 16], [1, 24], [1, 30], [1, 61], [1, 66], [1, 77], [1, 86], [1, 95], [2, 30], [2, 51], [2, 52], [2, 64], [2, 89], [3, 5], [3, 27], [3, 41], [3, 45], [3, 61], [3, 63], [3, 75], [3, 78], [3, 101], [3, 110], [4, 42], [4, 51], [4, 54], [4, 73], [4, 80], [4, 87], [5, 9], [5, 60], [5, 61], [5, 73], [5, 78], [5, 102], [5, 103], [6, 12], [6, 13], [6, 21], [6, 24], [6, 29], [6, 39], [6, 85], [6, 115], [7, 13], [7, 24], [7, 28], [7, 33], [7, 37], [7, 70], [7, 80], [7, 87], [7, 95], [7, 97], [7, 98], [7, 103], [7, 115], [8, 43], [8, 59], [8, 62], [8, 69], [8, 94], [8, 104], [8, 109], [9, 28], [9, 54], [9, 99], [10, 33], [10, 45], [10, 53], [10, 72], [10, 97], [10, 102], [10, 108], [10, 111], [11, 35], [11, 54], [11, 84], [11, 90], [12, 42], [12, 53], [12, 60], [12, 63], [12, 91], [12, 98], [12, 108], [13, 23], [13, 34], [13, 40], [13, 71], [13, 102], [13, 115], [13, 119], [14, 15], [14, 17], [14, 43], [14, 49], [14, 55], [14, 75], [14, 80], [14, 98], [14, 100], [14, 103], [15, 20], [15, 46], [15, 64], [15, 102], [15, 115], [16, 36], [16, 37], [16, 38], [16, 42], [16, 54], [16, 58], [16, 85], [16, 96], [16, 114], [16, 116], [16, 118], [17, 59], [17, 81], [17, 100], [18, 22], [18, 40], [18, 88], [18, 102], [19, 28], [19, 39], [19, 43], [19, 44], [19, 45], [19, 51], [19, 54], [19, 65], [19, 83], [19, 99], [19, 103], [19, 111], [19, 112], [20, 29], [20, 45], [20, 47], [20, 49], [20, 74], [20, 75], [20, 110], [21, 31], [21, 33], [21, 41], [21, 44], [21, 52], [21, 56], [21, 72], [21, 76], [21, 87], [21, 114], [22, 42], [22, 59], [22, 69], [22, 92], [22, 98], [22, 108], [23, 47], [23, 50], [23, 65], [23, 66], [23, 82], [23, 96], [24, 31], [24, 34], [24, 46], [24, 54], [24, 64], [24, 92], [25, 64], [25, 83], [25, 84], [25, 92], [25, 95], [25, 99], [25, 106], [25, 108], [25, 110], [25, 113], [25, 115], [26, 49], [26, 50], [26, 71], [26, 72], [26, 78], [26, 89], [26, 117], [27, 30], [27, 34], [27, 78], [27, 85], [27, 88], [28, 34], [28, 37], [28, 42], [28, 54], [28, 64], [28, 70], [28, 92], [29, 33], [29, 42], [29, 63], [30, 35], [30, 56], [30, 65], [30, 81], [30, 105], [30, 109], [30, 115], [30, 116], [30, 118], [31, 38], [31, 47], [31, 99], [31, 103], [32, 38], [32, 45], [32, 54], [32, 67], [32, 70], [32, 72], [33, 84], [33, 88], [33, 96], [34, 36], [34, 55], [34, 90], [34, 96], [34, 103], [34, 106], [34, 110], [34, 116], [35, 61], [35, 67], [35, 68], [35, 71], [35, 74], [35, 83], [35, 90], [35, 93], [35, 100], [35, 117], [36, 44], [36, 45], [36, 79], [36, 82], [36, 98], [36, 99], [37, 38], [37, 39], [37, 89], [37, 95], [37, 105], [38, 60], [38, 77], [38, 79], [38, 87], [38, 115], [39, 44], [39, 57], [39, 70], [39, 75], [39, 88], [39, 92], [39, 116], [40, 59], [40, 84], [40, 105], [40, 112], [40, 116], [41, 43], [41, 59], [41, 69], [41, 74], [41, 103], [42, 59], [42, 65], [42, 95], [42, 107], [43, 46], [43, 61], [43, 78], [43, 89], [44, 58], [44, 62], [44, 86], [44, 93], [45, 60], [45, 68], [45, 77], [45, 101], [45, 107], [46, 52], [46, 69], [46, 80], [46, 90], [46, 100], [46, 111], [47, 50], [47, 52], [47, 87], [47, 102], [47, 108], [47, 110], [47, 117], [47, 118], [48, 78], [48, 99], [48, 112], [48, 115], [49, 59], [49, 85], [49, 88], [49, 100], [49, 103], [49, 119], [50, 53], [50, 58], [50, 59], [50, 64], [50, 72], [50, 74], [50, 80], [50, 84], [50, 96], [50, 110], [51, 58], [51, 82], [51, 84], [51, 85], [51, 88], [51, 117], [52, 77], [52, 95], [52, 113], [53, 55], [53, 58], [53, 68], [53, 71], [53, 73], [53, 95], [54, 59], [54, 73], [54, 91], [54, 100], [55, 71], [55, 86], [55, 88], [55, 98], [56, 65], [56, 66], [56, 73], [56, 84], [56, 90], [56, 101], [57, 68], [57, 75], [57, 87], [57, 94], [57, 114], [58, 72], [58, 89], [58, 91], [58, 101], [58, 107], [58, 110], [59, 72], [59, 79], [59, 97], [59, 107], [59, 117], [59, 119], [60, 62], [60, 68], [60, 95], [60, 106], [60, 110], [61, 70], [61, 85], [61, 97], [61, 98], [61, 100], [61, 108], [61, 110], [61, 115], [61, 118], [63, 83], [63, 87], [63, 100], [64, 74], [64, 81], [64, 84], [64, 91], [65, 82], [65, 97], [65, 102], [66, 70], [66, 110], [67, 76], [67, 77], [67, 82], [68, 71], [68, 77], [68, 78], [68, 89], [68, 118], [69, 79], [69, 91], [69, 101], [69, 114], [70, 79], [70, 83], [70, 84], [70, 93], [70, 100], [70, 103], [71, 109], [71, 110], [71, 111], [72, 77], [72, 102], [72, 104], [72, 119], [73, 94], [73, 102], [73, 115], [74, 89], [74, 117], [75, 85], [75, 104], [76, 88], [76, 100], [77, 92], [77, 100], [78, 80], [79, 96], [79, 100], [79, 109], [80, 92], [81, 102], [82, 84], [82, 99], [82, 113], [83, 91], [83, 102], [83, 112], [84, 88], [84, 92], [84, 111], [85, 91], [85, 94], [85, 97], [85, 106], [85, 110], [85, 114], [86, 98], [86, 110], [86, 115], [88, 90], [88, 99], [88, 106], [88, 110], [89, 90], [89, 118], [90, 118], [91, 103], [91, 109], [91, 115], [93, 119], [95, 117], [96, 106], [97, 101], [98, 113], [100, 118], [101, 105], [101, 106], [102, 105], [102, 110], [103, 118], [104, 114], [105, 111], [113, 117], [113, 119]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s0/tests/run.py b/tasks/construct-nppc-3col-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s0/tests/test.sh b/tasks/construct-nppc-3col-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s7/environment/Dockerfile b/tasks/construct-nppc-3col-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l6-s7/environment/instance.json b/tasks/construct-nppc-3col-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98a1bdd4d6cb9c44235acd86e60458b955825316 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 13], [0, 16], [0, 45], [0, 64], [0, 66], [0, 72], [0, 91], [0, 99], [0, 104], [0, 109], [0, 116], [1, 15], [1, 20], [1, 33], [1, 45], [1, 50], [1, 56], [1, 60], [1, 80], [2, 3], [2, 10], [2, 20], [2, 31], [2, 54], [2, 62], [2, 76], [2, 78], [2, 103], [2, 114], [3, 14], [3, 42], [3, 48], [3, 52], [3, 54], [3, 108], [4, 9], [4, 22], [4, 25], [4, 45], [4, 84], [4, 89], [5, 12], [5, 19], [5, 47], [5, 63], [5, 67], [5, 73], [5, 80], [5, 92], [5, 94], [5, 105], [6, 37], [6, 49], [6, 71], [6, 113], [7, 11], [7, 41], [7, 96], [7, 106], [7, 109], [7, 111], [8, 36], [8, 43], [8, 66], [8, 70], [8, 111], [9, 15], [9, 37], [9, 92], [9, 106], [10, 12], [10, 44], [10, 47], [10, 51], [10, 63], [10, 115], [11, 29], [11, 31], [11, 79], [11, 86], [11, 98], [12, 45], [12, 48], [12, 73], [12, 95], [12, 101], [12, 106], [12, 113], [13, 24], [13, 33], [13, 80], [13, 84], [13, 101], [13, 102], [13, 110], [13, 119], [14, 17], [14, 33], [14, 39], [14, 57], [14, 63], [14, 64], [14, 74], [14, 90], [14, 97], [14, 105], [14, 111], [15, 27], [15, 30], [15, 39], [15, 53], [15, 57], [15, 59], [15, 62], [15, 76], [15, 114], [16, 29], [16, 32], [16, 43], [16, 54], [16, 76], [16, 90], [16, 105], [17, 41], [17, 51], [17, 57], [17, 76], [17, 95], [17, 102], [17, 112], [17, 115], [18, 22], [18, 24], [18, 29], [18, 56], [18, 75], [19, 22], [19, 38], [19, 55], [19, 70], [19, 76], [19, 79], [19, 88], [19, 100], [20, 22], [20, 36], [20, 53], [20, 57], [20, 69], [20, 103], [21, 22], [21, 25], [21, 56], [21, 73], [21, 81], [21, 91], [22, 44], [22, 47], [22, 58], [22, 59], [23, 34], [23, 74], [23, 78], [23, 110], [23, 114], [24, 28], [24, 30], [24, 54], [24, 62], [24, 79], [24, 95], [24, 108], [24, 114], [25, 43], [25, 82], [25, 89], [25, 104], [25, 117], [26, 44], [26, 57], [26, 78], [26, 81], [26, 102], [27, 34], [27, 36], [27, 50], [27, 55], [27, 77], [27, 91], [27, 92], [27, 108], [27, 119], [28, 42], [28, 93], [28, 97], [29, 39], [29, 92], [29, 99], [30, 46], [30, 61], [30, 65], [30, 86], [30, 101], [31, 37], [31, 42], [31, 68], [31, 94], [31, 119], [32, 33], [32, 45], [32, 63], [32, 67], [32, 73], [32, 74], [32, 99], [32, 105], [32, 119], [33, 40], [33, 81], [33, 110], [33, 114], [34, 51], [34, 60], [34, 65], [34, 70], [34, 75], [34, 82], [34, 91], [34, 93], [34, 115], [35, 37], [35, 50], [35, 64], [35, 87], [35, 92], [35, 105], [36, 56], [36, 59], [36, 84], [36, 89], [36, 91], [36, 101], [36, 109], [37, 43], [37, 52], [37, 55], [37, 85], [37, 90], [37, 96], [37, 114], [38, 44], [38, 73], [38, 74], [39, 46], [39, 61], [39, 69], [39, 77], [39, 98], [39, 105], [39, 109], [39, 115], [39, 117], [40, 45], [40, 59], [40, 69], [40, 76], [40, 98], [40, 119], [41, 45], [41, 50], [41, 58], [41, 85], [41, 86], [41, 88], [41, 89], [41, 107], [42, 45], [42, 52], [42, 54], [42, 78], [42, 83], [42, 91], [42, 107], [42, 119], [43, 44], [43, 46], [43, 72], [43, 77], [43, 86], [43, 87], [43, 92], [43, 106], [43, 112], [44, 45], [44, 50], [44, 79], [44, 89], [44, 100], [44, 103], [44, 106], [44, 107], [44, 117], [45, 47], [45, 64], [45, 76], [45, 83], [45, 92], [45, 98], [45, 100], [46, 49], [46, 64], [46, 83], [46, 85], [47, 48], [47, 52], [47, 59], [47, 62], [47, 82], [47, 84], [47, 90], [47, 98], [47, 103], [47, 107], [48, 65], [48, 67], [48, 72], [48, 88], [48, 92], [48, 99], [48, 109], [48, 118], [49, 60], [49, 75], [49, 104], [49, 109], [49, 112], [49, 118], [50, 67], [50, 98], [50, 114], [51, 65], [51, 67], [51, 68], [51, 80], [51, 97], [51, 109], [52, 73], [52, 101], [52, 106], [53, 62], [53, 69], [53, 76], [53, 101], [53, 110], [54, 55], [54, 64], [54, 72], [54, 75], [54, 91], [55, 72], [55, 78], [55, 79], [55, 110], [55, 117], [56, 68], [56, 102], [56, 104], [57, 83], [57, 84], [58, 94], [58, 107], [59, 61], [59, 74], [59, 111], [59, 116], [60, 72], [60, 99], [60, 102], [60, 112], [61, 95], [61, 97], [61, 100], [61, 115], [61, 116], [62, 63], [62, 81], [62, 97], [62, 109], [62, 119], [63, 71], [63, 93], [63, 103], [64, 70], [64, 78], [64, 82], [64, 96], [64, 107], [64, 110], [65, 89], [65, 92], [65, 97], [65, 113], [65, 114], [65, 117], [66, 110], [67, 73], [67, 85], [67, 100], [68, 70], [68, 78], [68, 89], [68, 95], [68, 101], [68, 103], [69, 83], [69, 92], [70, 96], [70, 99], [70, 101], [71, 74], [71, 81], [71, 88], [71, 91], [71, 112], [72, 76], [72, 114], [73, 74], [73, 81], [73, 100], [73, 110], [74, 95], [74, 106], [74, 110], [76, 84], [76, 88], [77, 83], [77, 115], [78, 108], [79, 81], [79, 84], [79, 91], [79, 92], [79, 97], [79, 105], [79, 111], [79, 112], [80, 92], [81, 96], [81, 106], [82, 92], [82, 96], [82, 107], [83, 99], [83, 105], [83, 106], [83, 119], [84, 87], [84, 104], [86, 87], [86, 89], [86, 94], [86, 95], [86, 99], [86, 116], [87, 115], [88, 113], [89, 107], [89, 108], [90, 113], [91, 102], [91, 104], [92, 96], [92, 103], [93, 99], [93, 104], [93, 113], [94, 100], [94, 113], [95, 96], [95, 97], [95, 104], [96, 98], [97, 102], [98, 104], [98, 111], [98, 119], [99, 103], [99, 109], [101, 110], [101, 116], [102, 108], [102, 119], [103, 113], [104, 114], [107, 108], [107, 117], [109, 117], [113, 116], [114, 119], [117, 119]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s7/solution/solve.sh b/tasks/construct-nppc-3col-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6a5195633fe80e0e30580ef4a709b78c5c11ae69 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 2, 2, 1, 2, 0, 1, 0, 1, 0, 1, 2, 2, 2, 0, 1, 2, 1, 2, 2, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 2, 0, 0, 1, 2, 0, 2, 2, 0, 2, 2, 2, 2, 0, 2, 1, 1, 2, 0, 0, 1, 0, 0, 2, 0, 1, 1, 2, 0, 0, 1, 1, 0, 2, 2, 1, 2, 2, 2, 1, 0, 0, 2, 1, 2, 1, 0, 1, 0, 0, 1, 2, 0, 0, 1, 0, 1, 2, 1, 0, 1, 1, 2, 1, 2, 0, 1, 2, 0, 2, 0, 1, 0, 1, 2, 1, 1, 1, 2, 1, 0, 2, 2, 0, 0, 0, 2, 0, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l6-s7/tests/check.py b/tasks/construct-nppc-3col-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/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-l6-s7/tests/instance.json b/tasks/construct-nppc-3col-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..98a1bdd4d6cb9c44235acd86e60458b955825316 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 13], [0, 16], [0, 45], [0, 64], [0, 66], [0, 72], [0, 91], [0, 99], [0, 104], [0, 109], [0, 116], [1, 15], [1, 20], [1, 33], [1, 45], [1, 50], [1, 56], [1, 60], [1, 80], [2, 3], [2, 10], [2, 20], [2, 31], [2, 54], [2, 62], [2, 76], [2, 78], [2, 103], [2, 114], [3, 14], [3, 42], [3, 48], [3, 52], [3, 54], [3, 108], [4, 9], [4, 22], [4, 25], [4, 45], [4, 84], [4, 89], [5, 12], [5, 19], [5, 47], [5, 63], [5, 67], [5, 73], [5, 80], [5, 92], [5, 94], [5, 105], [6, 37], [6, 49], [6, 71], [6, 113], [7, 11], [7, 41], [7, 96], [7, 106], [7, 109], [7, 111], [8, 36], [8, 43], [8, 66], [8, 70], [8, 111], [9, 15], [9, 37], [9, 92], [9, 106], [10, 12], [10, 44], [10, 47], [10, 51], [10, 63], [10, 115], [11, 29], [11, 31], [11, 79], [11, 86], [11, 98], [12, 45], [12, 48], [12, 73], [12, 95], [12, 101], [12, 106], [12, 113], [13, 24], [13, 33], [13, 80], [13, 84], [13, 101], [13, 102], [13, 110], [13, 119], [14, 17], [14, 33], [14, 39], [14, 57], [14, 63], [14, 64], [14, 74], [14, 90], [14, 97], [14, 105], [14, 111], [15, 27], [15, 30], [15, 39], [15, 53], [15, 57], [15, 59], [15, 62], [15, 76], [15, 114], [16, 29], [16, 32], [16, 43], [16, 54], [16, 76], [16, 90], [16, 105], [17, 41], [17, 51], [17, 57], [17, 76], [17, 95], [17, 102], [17, 112], [17, 115], [18, 22], [18, 24], [18, 29], [18, 56], [18, 75], [19, 22], [19, 38], [19, 55], [19, 70], [19, 76], [19, 79], [19, 88], [19, 100], [20, 22], [20, 36], [20, 53], [20, 57], [20, 69], [20, 103], [21, 22], [21, 25], [21, 56], [21, 73], [21, 81], [21, 91], [22, 44], [22, 47], [22, 58], [22, 59], [23, 34], [23, 74], [23, 78], [23, 110], [23, 114], [24, 28], [24, 30], [24, 54], [24, 62], [24, 79], [24, 95], [24, 108], [24, 114], [25, 43], [25, 82], [25, 89], [25, 104], [25, 117], [26, 44], [26, 57], [26, 78], [26, 81], [26, 102], [27, 34], [27, 36], [27, 50], [27, 55], [27, 77], [27, 91], [27, 92], [27, 108], [27, 119], [28, 42], [28, 93], [28, 97], [29, 39], [29, 92], [29, 99], [30, 46], [30, 61], [30, 65], [30, 86], [30, 101], [31, 37], [31, 42], [31, 68], [31, 94], [31, 119], [32, 33], [32, 45], [32, 63], [32, 67], [32, 73], [32, 74], [32, 99], [32, 105], [32, 119], [33, 40], [33, 81], [33, 110], [33, 114], [34, 51], [34, 60], [34, 65], [34, 70], [34, 75], [34, 82], [34, 91], [34, 93], [34, 115], [35, 37], [35, 50], [35, 64], [35, 87], [35, 92], [35, 105], [36, 56], [36, 59], [36, 84], [36, 89], [36, 91], [36, 101], [36, 109], [37, 43], [37, 52], [37, 55], [37, 85], [37, 90], [37, 96], [37, 114], [38, 44], [38, 73], [38, 74], [39, 46], [39, 61], [39, 69], [39, 77], [39, 98], [39, 105], [39, 109], [39, 115], [39, 117], [40, 45], [40, 59], [40, 69], [40, 76], [40, 98], [40, 119], [41, 45], [41, 50], [41, 58], [41, 85], [41, 86], [41, 88], [41, 89], [41, 107], [42, 45], [42, 52], [42, 54], [42, 78], [42, 83], [42, 91], [42, 107], [42, 119], [43, 44], [43, 46], [43, 72], [43, 77], [43, 86], [43, 87], [43, 92], [43, 106], [43, 112], [44, 45], [44, 50], [44, 79], [44, 89], [44, 100], [44, 103], [44, 106], [44, 107], [44, 117], [45, 47], [45, 64], [45, 76], [45, 83], [45, 92], [45, 98], [45, 100], [46, 49], [46, 64], [46, 83], [46, 85], [47, 48], [47, 52], [47, 59], [47, 62], [47, 82], [47, 84], [47, 90], [47, 98], [47, 103], [47, 107], [48, 65], [48, 67], [48, 72], [48, 88], [48, 92], [48, 99], [48, 109], [48, 118], [49, 60], [49, 75], [49, 104], [49, 109], [49, 112], [49, 118], [50, 67], [50, 98], [50, 114], [51, 65], [51, 67], [51, 68], [51, 80], [51, 97], [51, 109], [52, 73], [52, 101], [52, 106], [53, 62], [53, 69], [53, 76], [53, 101], [53, 110], [54, 55], [54, 64], [54, 72], [54, 75], [54, 91], [55, 72], [55, 78], [55, 79], [55, 110], [55, 117], [56, 68], [56, 102], [56, 104], [57, 83], [57, 84], [58, 94], [58, 107], [59, 61], [59, 74], [59, 111], [59, 116], [60, 72], [60, 99], [60, 102], [60, 112], [61, 95], [61, 97], [61, 100], [61, 115], [61, 116], [62, 63], [62, 81], [62, 97], [62, 109], [62, 119], [63, 71], [63, 93], [63, 103], [64, 70], [64, 78], [64, 82], [64, 96], [64, 107], [64, 110], [65, 89], [65, 92], [65, 97], [65, 113], [65, 114], [65, 117], [66, 110], [67, 73], [67, 85], [67, 100], [68, 70], [68, 78], [68, 89], [68, 95], [68, 101], [68, 103], [69, 83], [69, 92], [70, 96], [70, 99], [70, 101], [71, 74], [71, 81], [71, 88], [71, 91], [71, 112], [72, 76], [72, 114], [73, 74], [73, 81], [73, 100], [73, 110], [74, 95], [74, 106], [74, 110], [76, 84], [76, 88], [77, 83], [77, 115], [78, 108], [79, 81], [79, 84], [79, 91], [79, 92], [79, 97], [79, 105], [79, 111], [79, 112], [80, 92], [81, 96], [81, 106], [82, 92], [82, 96], [82, 107], [83, 99], [83, 105], [83, 106], [83, 119], [84, 87], [84, 104], [86, 87], [86, 89], [86, 94], [86, 95], [86, 99], [86, 116], [87, 115], [88, 113], [89, 107], [89, 108], [90, 113], [91, 102], [91, 104], [92, 96], [92, 103], [93, 99], [93, 104], [93, 113], [94, 100], [94, 113], [95, 96], [95, 97], [95, 104], [96, 98], [97, 102], [98, 104], [98, 111], [98, 119], [99, 103], [99, 109], [101, 110], [101, 116], [102, 108], [102, 119], [103, 113], [104, 114], [107, 108], [107, 117], [109, 117], [113, 116], [114, 119], [117, 119]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s7/tests/run.py b/tasks/construct-nppc-3col-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l6-s7/tests/test.sh b/tasks/construct-nppc-3col-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l6-s9/environment/Dockerfile b/tasks/construct-nppc-3col-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l6-s9/environment/instance.json b/tasks/construct-nppc-3col-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..556af5fbf627e4271a8bb6ccc6db799df401a1d1 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 4], [0, 19], [0, 21], [0, 105], [1, 5], [1, 13], [1, 17], [1, 24], [1, 46], [1, 47], [1, 62], [1, 63], [1, 75], [1, 81], [1, 90], [1, 102], [2, 11], [2, 18], [2, 30], [2, 59], [2, 62], [2, 72], [2, 75], [2, 95], [3, 11], [3, 17], [3, 20], [3, 30], [3, 36], [3, 66], [3, 74], [3, 100], [4, 13], [4, 41], [4, 55], [4, 75], [4, 81], [4, 94], [4, 103], [4, 116], [5, 10], [5, 23], [5, 29], [5, 36], [5, 59], [5, 66], [5, 80], [5, 86], [5, 101], [5, 106], [6, 45], [6, 55], [6, 111], [7, 16], [7, 19], [7, 21], [7, 34], [7, 58], [7, 65], [7, 88], [7, 100], [7, 116], [8, 15], [8, 18], [8, 32], [8, 36], [8, 38], [8, 56], [8, 61], [8, 63], [8, 90], [8, 98], [8, 99], [8, 100], [9, 10], [9, 25], [9, 57], [9, 59], [9, 60], [9, 76], [9, 113], [10, 12], [10, 21], [10, 27], [10, 35], [10, 47], [10, 88], [10, 95], [10, 102], [10, 107], [11, 21], [11, 39], [11, 69], [11, 84], [11, 102], [11, 109], [12, 14], [12, 17], [12, 31], [12, 48], [12, 52], [12, 53], [12, 75], [12, 79], [12, 85], [12, 89], [12, 91], [12, 106], [12, 107], [12, 110], [13, 16], [13, 41], [13, 50], [13, 54], [13, 108], [13, 109], [13, 112], [14, 39], [14, 40], [14, 70], [14, 79], [14, 91], [14, 93], [15, 36], [15, 43], [15, 57], [15, 114], [16, 50], [16, 56], [16, 101], [16, 102], [17, 38], [17, 39], [17, 44], [17, 47], [17, 64], [17, 67], [17, 73], [17, 92], [17, 111], [18, 21], [18, 28], [18, 42], [18, 46], [18, 52], [18, 86], [18, 92], [18, 97], [18, 98], [18, 118], [19, 30], [19, 36], [19, 43], [19, 48], [19, 60], [19, 62], [19, 70], [19, 76], [19, 89], [20, 40], [20, 60], [20, 64], [20, 84], [20, 90], [20, 93], [20, 94], [21, 96], [21, 104], [21, 117], [22, 82], [22, 119], [23, 26], [23, 51], [23, 61], [23, 66], [23, 80], [23, 99], [23, 111], [23, 116], [24, 25], [24, 30], [24, 74], [24, 89], [24, 112], [25, 70], [25, 88], [25, 93], [25, 103], [26, 47], [26, 73], [26, 81], [26, 86], [26, 108], [26, 114], [27, 29], [27, 31], [27, 74], [27, 91], [27, 96], [27, 97], [27, 106], [28, 35], [28, 48], [28, 53], [28, 74], [28, 76], [28, 88], [28, 89], [28, 100], [28, 101], [28, 109], [29, 93], [30, 37], [30, 46], [30, 50], [30, 52], [30, 94], [30, 112], [31, 34], [31, 41], [31, 51], [31, 61], [31, 75], [31, 119], [32, 40], [32, 66], [32, 71], [32, 91], [32, 95], [32, 108], [32, 112], [33, 37], [33, 69], [33, 89], [33, 90], [33, 103], [33, 115], [34, 40], [34, 48], [34, 54], [34, 60], [34, 72], [34, 87], [34, 96], [34, 97], [34, 100], [34, 110], [34, 117], [35, 37], [35, 43], [35, 53], [35, 56], [35, 74], [35, 77], [36, 38], [36, 42], [36, 64], [36, 67], [36, 105], [37, 45], [37, 53], [37, 54], [37, 57], [37, 62], [37, 70], [37, 76], [37, 91], [37, 112], [37, 114], [37, 119], [38, 66], [38, 76], [38, 80], [38, 87], [38, 113], [39, 41], [39, 49], [39, 54], [39, 62], [39, 72], [39, 74], [40, 52], [40, 56], [40, 63], [40, 86], [40, 89], [40, 93], [40, 118], [41, 50], [41, 82], [41, 98], [42, 46], [42, 55], [42, 59], [42, 61], [42, 63], [42, 107], [42, 117], [43, 48], [43, 61], [43, 87], [44, 59], [44, 67], [44, 78], [44, 83], [45, 58], [45, 94], [45, 116], [46, 53], [46, 66], [46, 87], [46, 91], [46, 95], [46, 97], [46, 104], [47, 86], [47, 108], [48, 58], [48, 78], [48, 92], [48, 98], [48, 105], [48, 113], [49, 69], [49, 74], [49, 92], [49, 110], [50, 62], [50, 73], [50, 95], [50, 107], [51, 67], [51, 90], [51, 109], [51, 112], [52, 56], [52, 63], [52, 65], [52, 93], [52, 98], [52, 116], [53, 58], [53, 79], [53, 103], [53, 106], [54, 90], [54, 98], [55, 69], [55, 83], [55, 88], [55, 108], [55, 119], [56, 68], [56, 70], [56, 74], [56, 89], [57, 73], [57, 118], [58, 78], [59, 73], [59, 84], [59, 108], [60, 64], [60, 97], [61, 63], [61, 67], [61, 69], [61, 74], [61, 99], [61, 103], [61, 104], [61, 108], [61, 116], [62, 69], [62, 77], [62, 83], [62, 84], [62, 92], [62, 96], [62, 110], [63, 71], [63, 89], [63, 106], [63, 113], [63, 114], [63, 117], [64, 68], [64, 69], [64, 83], [64, 92], [64, 101], [64, 117], [65, 83], [65, 93], [65, 98], [65, 99], [65, 104], [66, 78], [66, 90], [66, 94], [66, 112], [67, 71], [68, 117], [68, 119], [69, 87], [69, 103], [69, 106], [70, 73], [70, 83], [71, 81], [71, 86], [71, 101], [71, 102], [71, 105], [71, 111], [71, 112], [71, 116], [72, 86], [72, 97], [72, 112], [73, 91], [73, 100], [73, 109], [73, 119], [74, 82], [74, 91], [74, 98], [75, 83], [75, 93], [75, 96], [76, 95], [76, 100], [77, 101], [78, 100], [78, 106], [79, 81], [80, 86], [80, 93], [80, 98], [80, 115], [81, 101], [82, 87], [82, 113], [83, 99], [83, 106], [83, 116], [83, 117], [83, 119], [84, 92], [84, 96], [84, 109], [84, 113], [84, 118], [85, 100], [87, 102], [87, 105], [88, 93], [88, 98], [88, 103], [88, 118], [89, 91], [89, 95], [89, 117], [90, 92], [90, 96], [90, 109], [91, 98], [91, 113], [91, 118], [92, 111], [93, 107], [94, 104], [95, 104], [95, 108], [95, 109], [95, 118], [96, 98], [96, 111], [97, 106], [97, 117], [98, 107], [98, 109], [98, 119], [99, 110], [100, 108], [100, 115], [101, 106], [102, 106], [102, 113], [102, 115], [103, 109], [103, 110], [103, 114], [104, 117], [106, 108], [107, 111], [107, 115], [107, 116], [108, 117], [118, 119]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s9/solution/solve.sh b/tasks/construct-nppc-3col-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3036cf2a60286bf6a175e54b4120b6738cc7f198 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 0, 0, 2, 0, 2, 2, 2, 0, 2, 1, 0, 0, 2, 0, 1, 1, 1, 0, 2, 0, 2, 2, 0, 2, 1, 0, 0, 1, 1, 2, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 2, 2, 0, 1, 0, 0, 1, 1, 2, 1, 2, 2, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 2, 2, 1, 1, 1, 0, 2, 1, 2, 0, 2, 1, 1, 0, 0, 2, 0, 2, 2, 1, 1, 2, 0, 1, 2, 0, 0, 1, 2, 2, 0, 0, 1, 2, 0, 0, 2, 0, 1, 1, 2, 2, 2, 0, 2, 2, 2, 2, 0, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l6-s9/tests/check.py b/tasks/construct-nppc-3col-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/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-l6-s9/tests/instance.json b/tasks/construct-nppc-3col-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..556af5fbf627e4271a8bb6ccc6db799df401a1d1 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 4], [0, 19], [0, 21], [0, 105], [1, 5], [1, 13], [1, 17], [1, 24], [1, 46], [1, 47], [1, 62], [1, 63], [1, 75], [1, 81], [1, 90], [1, 102], [2, 11], [2, 18], [2, 30], [2, 59], [2, 62], [2, 72], [2, 75], [2, 95], [3, 11], [3, 17], [3, 20], [3, 30], [3, 36], [3, 66], [3, 74], [3, 100], [4, 13], [4, 41], [4, 55], [4, 75], [4, 81], [4, 94], [4, 103], [4, 116], [5, 10], [5, 23], [5, 29], [5, 36], [5, 59], [5, 66], [5, 80], [5, 86], [5, 101], [5, 106], [6, 45], [6, 55], [6, 111], [7, 16], [7, 19], [7, 21], [7, 34], [7, 58], [7, 65], [7, 88], [7, 100], [7, 116], [8, 15], [8, 18], [8, 32], [8, 36], [8, 38], [8, 56], [8, 61], [8, 63], [8, 90], [8, 98], [8, 99], [8, 100], [9, 10], [9, 25], [9, 57], [9, 59], [9, 60], [9, 76], [9, 113], [10, 12], [10, 21], [10, 27], [10, 35], [10, 47], [10, 88], [10, 95], [10, 102], [10, 107], [11, 21], [11, 39], [11, 69], [11, 84], [11, 102], [11, 109], [12, 14], [12, 17], [12, 31], [12, 48], [12, 52], [12, 53], [12, 75], [12, 79], [12, 85], [12, 89], [12, 91], [12, 106], [12, 107], [12, 110], [13, 16], [13, 41], [13, 50], [13, 54], [13, 108], [13, 109], [13, 112], [14, 39], [14, 40], [14, 70], [14, 79], [14, 91], [14, 93], [15, 36], [15, 43], [15, 57], [15, 114], [16, 50], [16, 56], [16, 101], [16, 102], [17, 38], [17, 39], [17, 44], [17, 47], [17, 64], [17, 67], [17, 73], [17, 92], [17, 111], [18, 21], [18, 28], [18, 42], [18, 46], [18, 52], [18, 86], [18, 92], [18, 97], [18, 98], [18, 118], [19, 30], [19, 36], [19, 43], [19, 48], [19, 60], [19, 62], [19, 70], [19, 76], [19, 89], [20, 40], [20, 60], [20, 64], [20, 84], [20, 90], [20, 93], [20, 94], [21, 96], [21, 104], [21, 117], [22, 82], [22, 119], [23, 26], [23, 51], [23, 61], [23, 66], [23, 80], [23, 99], [23, 111], [23, 116], [24, 25], [24, 30], [24, 74], [24, 89], [24, 112], [25, 70], [25, 88], [25, 93], [25, 103], [26, 47], [26, 73], [26, 81], [26, 86], [26, 108], [26, 114], [27, 29], [27, 31], [27, 74], [27, 91], [27, 96], [27, 97], [27, 106], [28, 35], [28, 48], [28, 53], [28, 74], [28, 76], [28, 88], [28, 89], [28, 100], [28, 101], [28, 109], [29, 93], [30, 37], [30, 46], [30, 50], [30, 52], [30, 94], [30, 112], [31, 34], [31, 41], [31, 51], [31, 61], [31, 75], [31, 119], [32, 40], [32, 66], [32, 71], [32, 91], [32, 95], [32, 108], [32, 112], [33, 37], [33, 69], [33, 89], [33, 90], [33, 103], [33, 115], [34, 40], [34, 48], [34, 54], [34, 60], [34, 72], [34, 87], [34, 96], [34, 97], [34, 100], [34, 110], [34, 117], [35, 37], [35, 43], [35, 53], [35, 56], [35, 74], [35, 77], [36, 38], [36, 42], [36, 64], [36, 67], [36, 105], [37, 45], [37, 53], [37, 54], [37, 57], [37, 62], [37, 70], [37, 76], [37, 91], [37, 112], [37, 114], [37, 119], [38, 66], [38, 76], [38, 80], [38, 87], [38, 113], [39, 41], [39, 49], [39, 54], [39, 62], [39, 72], [39, 74], [40, 52], [40, 56], [40, 63], [40, 86], [40, 89], [40, 93], [40, 118], [41, 50], [41, 82], [41, 98], [42, 46], [42, 55], [42, 59], [42, 61], [42, 63], [42, 107], [42, 117], [43, 48], [43, 61], [43, 87], [44, 59], [44, 67], [44, 78], [44, 83], [45, 58], [45, 94], [45, 116], [46, 53], [46, 66], [46, 87], [46, 91], [46, 95], [46, 97], [46, 104], [47, 86], [47, 108], [48, 58], [48, 78], [48, 92], [48, 98], [48, 105], [48, 113], [49, 69], [49, 74], [49, 92], [49, 110], [50, 62], [50, 73], [50, 95], [50, 107], [51, 67], [51, 90], [51, 109], [51, 112], [52, 56], [52, 63], [52, 65], [52, 93], [52, 98], [52, 116], [53, 58], [53, 79], [53, 103], [53, 106], [54, 90], [54, 98], [55, 69], [55, 83], [55, 88], [55, 108], [55, 119], [56, 68], [56, 70], [56, 74], [56, 89], [57, 73], [57, 118], [58, 78], [59, 73], [59, 84], [59, 108], [60, 64], [60, 97], [61, 63], [61, 67], [61, 69], [61, 74], [61, 99], [61, 103], [61, 104], [61, 108], [61, 116], [62, 69], [62, 77], [62, 83], [62, 84], [62, 92], [62, 96], [62, 110], [63, 71], [63, 89], [63, 106], [63, 113], [63, 114], [63, 117], [64, 68], [64, 69], [64, 83], [64, 92], [64, 101], [64, 117], [65, 83], [65, 93], [65, 98], [65, 99], [65, 104], [66, 78], [66, 90], [66, 94], [66, 112], [67, 71], [68, 117], [68, 119], [69, 87], [69, 103], [69, 106], [70, 73], [70, 83], [71, 81], [71, 86], [71, 101], [71, 102], [71, 105], [71, 111], [71, 112], [71, 116], [72, 86], [72, 97], [72, 112], [73, 91], [73, 100], [73, 109], [73, 119], [74, 82], [74, 91], [74, 98], [75, 83], [75, 93], [75, 96], [76, 95], [76, 100], [77, 101], [78, 100], [78, 106], [79, 81], [80, 86], [80, 93], [80, 98], [80, 115], [81, 101], [82, 87], [82, 113], [83, 99], [83, 106], [83, 116], [83, 117], [83, 119], [84, 92], [84, 96], [84, 109], [84, 113], [84, 118], [85, 100], [87, 102], [87, 105], [88, 93], [88, 98], [88, 103], [88, 118], [89, 91], [89, 95], [89, 117], [90, 92], [90, 96], [90, 109], [91, 98], [91, 113], [91, 118], [92, 111], [93, 107], [94, 104], [95, 104], [95, 108], [95, 109], [95, 118], [96, 98], [96, 111], [97, 106], [97, 117], [98, 107], [98, 109], [98, 119], [99, 110], [100, 108], [100, 115], [101, 106], [102, 106], [102, 113], [102, 115], [103, 109], [103, 110], [103, 114], [104, 117], [106, 108], [107, 111], [107, 115], [107, 116], [108, 117], [118, 119]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s9/tests/run.py b/tasks/construct-nppc-3col-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l6-s9/tests/test.sh b/tasks/construct-nppc-3col-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l5-s2/environment/Dockerfile b/tasks/construct-nppc-clique-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l5-s2/environment/instance.json b/tasks/construct-nppc-clique-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ed35d63c9e516ab1f586158e1c3b956b9fd24ba --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [1, 2], [1, 3], [1, 5], [1, 7], [1, 9], [1, 10], [1, 12], [1, 14], [1, 18], [1, 19], [1, 20], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [1, 33], [1, 35], [1, 36], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 18], [2, 19], [2, 21], [2, 23], [2, 24], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [3, 4], [3, 11], [3, 13], [3, 16], [3, 17], [3, 19], [3, 23], [3, 25], [3, 26], [3, 28], [3, 33], [3, 34], [3, 35], [3, 39], [4, 5], [4, 7], [4, 10], [4, 12], [4, 13], [4, 15], [4, 16], [4, 17], [4, 20], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 32], [4, 33], [4, 34], [4, 35], [4, 38], [4, 39], [5, 6], [5, 8], [5, 9], [5, 11], [5, 14], [5, 15], [5, 18], [5, 19], [5, 20], [5, 23], [5, 26], [5, 30], [5, 31], [5, 33], [5, 36], [5, 37], [5, 39], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 17], [6, 18], [6, 20], [6, 21], [6, 23], [6, 24], [6, 27], [6, 29], [6, 32], [6, 33], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [7, 8], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 17], [7, 18], [7, 21], [7, 22], [7, 23], [7, 24], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [7, 32], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 18], [8, 19], [8, 20], [8, 23], [8, 24], [8, 27], [8, 28], [8, 34], [8, 35], [8, 38], [9, 11], [9, 12], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 29], [9, 30], [9, 32], [9, 33], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [10, 11], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 22], [10, 23], [10, 25], [10, 27], [10, 32], [10, 33], [10, 34], [10, 35], [10, 38], [10, 39], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 29], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 32], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [13, 14], [13, 15], [13, 17], [13, 18], [13, 19], [13, 21], [13, 25], [13, 26], [13, 27], [13, 30], [13, 32], [13, 34], [13, 36], [14, 19], [14, 20], [14, 21], [14, 26], [14, 28], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [15, 16], [15, 17], [15, 19], [15, 23], [15, 26], [15, 27], [15, 29], [15, 31], [15, 35], [15, 36], [15, 38], [15, 39], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 27], [16, 28], [16, 29], [16, 31], [16, 38], [16, 39], [17, 18], [17, 21], [17, 22], [17, 23], [17, 24], [17, 26], [17, 27], [17, 29], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 39], [18, 21], [18, 23], [18, 24], [18, 25], [18, 27], [18, 29], [18, 31], [18, 32], [18, 33], [18, 35], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 29], [19, 34], [19, 36], [20, 21], [20, 22], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 34], [20, 38], [21, 23], [21, 24], [21, 26], [21, 27], [21, 29], [21, 31], [21, 32], [21, 33], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [22, 24], [22, 29], [22, 30], [22, 32], [22, 33], [22, 35], [22, 39], [23, 24], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [24, 25], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 35], [24, 36], [24, 37], [24, 38], [24, 39], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 33], [25, 36], [25, 39], [26, 27], [26, 28], [26, 29], [26, 32], [26, 34], [26, 36], [27, 29], [27, 30], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [28, 29], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 37], [28, 38], [28, 39], [29, 30], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 33], [30, 34], [30, 37], [31, 33], [31, 36], [31, 37], [31, 38], [31, 39], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 36], [33, 38], [33, 39], [34, 35], [34, 37], [34, 39], [35, 36], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s2/solution/solve.sh b/tasks/construct-nppc-clique-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..745d286f4a4dc0e8c1c7a9cf4bbe6840b2be524e --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 2, 6, 7, 9, 11, 12, 17, 18, 21, 23, 24, 27, 29, 32, 35, 36, 37, 38, 39]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l5-s2/tests/check.py b/tasks/construct-nppc-clique-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l5-s2/tests/instance.json b/tasks/construct-nppc-clique-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ed35d63c9e516ab1f586158e1c3b956b9fd24ba --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [1, 2], [1, 3], [1, 5], [1, 7], [1, 9], [1, 10], [1, 12], [1, 14], [1, 18], [1, 19], [1, 20], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [1, 33], [1, 35], [1, 36], [2, 5], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 18], [2, 19], [2, 21], [2, 23], [2, 24], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [3, 4], [3, 11], [3, 13], [3, 16], [3, 17], [3, 19], [3, 23], [3, 25], [3, 26], [3, 28], [3, 33], [3, 34], [3, 35], [3, 39], [4, 5], [4, 7], [4, 10], [4, 12], [4, 13], [4, 15], [4, 16], [4, 17], [4, 20], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 32], [4, 33], [4, 34], [4, 35], [4, 38], [4, 39], [5, 6], [5, 8], [5, 9], [5, 11], [5, 14], [5, 15], [5, 18], [5, 19], [5, 20], [5, 23], [5, 26], [5, 30], [5, 31], [5, 33], [5, 36], [5, 37], [5, 39], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 17], [6, 18], [6, 20], [6, 21], [6, 23], [6, 24], [6, 27], [6, 29], [6, 32], [6, 33], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [7, 8], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 17], [7, 18], [7, 21], [7, 22], [7, 23], [7, 24], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [7, 32], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 18], [8, 19], [8, 20], [8, 23], [8, 24], [8, 27], [8, 28], [8, 34], [8, 35], [8, 38], [9, 11], [9, 12], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 29], [9, 30], [9, 32], [9, 33], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [10, 11], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 22], [10, 23], [10, 25], [10, 27], [10, 32], [10, 33], [10, 34], [10, 35], [10, 38], [10, 39], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 29], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 32], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [13, 14], [13, 15], [13, 17], [13, 18], [13, 19], [13, 21], [13, 25], [13, 26], [13, 27], [13, 30], [13, 32], [13, 34], [13, 36], [14, 19], [14, 20], [14, 21], [14, 26], [14, 28], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [15, 16], [15, 17], [15, 19], [15, 23], [15, 26], [15, 27], [15, 29], [15, 31], [15, 35], [15, 36], [15, 38], [15, 39], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 27], [16, 28], [16, 29], [16, 31], [16, 38], [16, 39], [17, 18], [17, 21], [17, 22], [17, 23], [17, 24], [17, 26], [17, 27], [17, 29], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 39], [18, 21], [18, 23], [18, 24], [18, 25], [18, 27], [18, 29], [18, 31], [18, 32], [18, 33], [18, 35], [18, 36], [18, 37], [18, 38], [18, 39], [19, 20], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 29], [19, 34], [19, 36], [20, 21], [20, 22], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 34], [20, 38], [21, 23], [21, 24], [21, 26], [21, 27], [21, 29], [21, 31], [21, 32], [21, 33], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [22, 24], [22, 29], [22, 30], [22, 32], [22, 33], [22, 35], [22, 39], [23, 24], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [24, 25], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 35], [24, 36], [24, 37], [24, 38], [24, 39], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 33], [25, 36], [25, 39], [26, 27], [26, 28], [26, 29], [26, 32], [26, 34], [26, 36], [27, 29], [27, 30], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [28, 29], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 37], [28, 38], [28, 39], [29, 30], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 33], [30, 34], [30, 37], [31, 33], [31, 36], [31, 37], [31, 38], [31, 39], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 36], [33, 38], [33, 39], [34, 35], [34, 37], [34, 39], [35, 36], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s2/tests/run.py b/tasks/construct-nppc-clique-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l5-s2/tests/test.sh b/tasks/construct-nppc-clique-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l5-s5/environment/Dockerfile b/tasks/construct-nppc-clique-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l5-s5/environment/instance.json b/tasks/construct-nppc-clique-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..932e32495252313420f1f81a551f7c699633c0da --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 26], [0, 27], [0, 29], [0, 30], [0, 32], [0, 33], [0, 35], [0, 36], [0, 37], [0, 39], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 14], [1, 16], [1, 17], [1, 19], [1, 20], [1, 22], [1, 23], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [1, 32], [1, 33], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [2, 4], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [2, 31], [2, 32], [2, 33], [2, 35], [2, 36], [2, 37], [2, 39], [3, 5], [3, 7], [3, 9], [3, 13], [3, 15], [3, 16], [3, 22], [3, 24], [3, 25], [3, 28], [3, 30], [3, 32], [3, 34], [3, 36], [3, 37], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 22], [4, 23], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [5, 6], [5, 8], [5, 13], [5, 15], [5, 17], [5, 20], [5, 21], [5, 22], [5, 25], [5, 26], [5, 27], [5, 28], [5, 32], [5, 34], [5, 35], [5, 37], [5, 38], [5, 39], [6, 7], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 20], [6, 22], [6, 23], [6, 26], [6, 28], [6, 29], [6, 33], [6, 35], [6, 36], [6, 37], [6, 39], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 30], [7, 33], [7, 35], [7, 36], [7, 37], [7, 39], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 18], [8, 19], [8, 21], [8, 24], [8, 26], [8, 27], [8, 28], [8, 30], [8, 31], [8, 32], [8, 35], [8, 36], [8, 39], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 20], [9, 22], [9, 23], [9, 24], [9, 26], [9, 29], [9, 31], [9, 33], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [12, 13], [12, 14], [12, 15], [12, 16], [12, 19], [12, 20], [12, 21], [12, 23], [12, 27], [12, 28], [12, 29], [12, 30], [12, 33], [12, 39], [13, 14], [13, 16], [13, 20], [13, 22], [13, 26], [13, 27], [13, 33], [13, 37], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 31], [14, 33], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [15, 18], [15, 19], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 30], [15, 31], [15, 37], [16, 17], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 28], [16, 29], [16, 31], [16, 32], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [17, 18], [17, 20], [17, 21], [17, 22], [17, 26], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 39], [18, 19], [18, 20], [18, 27], [18, 30], [18, 32], [18, 34], [18, 35], [18, 37], [18, 38], [18, 39], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 31], [19, 33], [19, 34], [19, 35], [19, 38], [20, 22], [20, 23], [20, 26], [20, 28], [20, 29], [20, 30], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [21, 23], [21, 24], [21, 29], [21, 32], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 31], [22, 32], [22, 33], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [23, 24], [23, 25], [23, 27], [23, 28], [23, 32], [23, 33], [23, 34], [23, 36], [23, 38], [24, 25], [24, 26], [24, 28], [24, 30], [24, 31], [24, 33], [24, 34], [24, 36], [24, 38], [24, 39], [25, 26], [25, 27], [25, 29], [25, 36], [25, 37], [26, 27], [26, 28], [26, 31], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [27, 29], [27, 30], [27, 32], [27, 34], [27, 35], [27, 36], [27, 37], [28, 29], [28, 30], [28, 32], [28, 33], [28, 35], [28, 36], [28, 37], [28, 39], [29, 30], [29, 36], [29, 37], [30, 31], [30, 33], [30, 37], [30, 38], [31, 33], [31, 34], [31, 36], [31, 37], [31, 38], [31, 39], [32, 33], [32, 34], [32, 36], [32, 37], [32, 39], [33, 35], [33, 36], [33, 37], [33, 38], [33, 39], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [35, 36], [35, 37], [35, 39], [36, 37], [36, 38], [36, 39], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s5/solution/solve.sh b/tasks/construct-nppc-clique-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ca26428f942d7578b8d980c120fa31091c88fee2 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 1, 2, 4, 6, 7, 9, 10, 11, 14, 16, 17, 20, 22, 26, 33, 35, 36, 37, 39]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l5-s5/tests/check.py b/tasks/construct-nppc-clique-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l5-s5/tests/instance.json b/tasks/construct-nppc-clique-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..932e32495252313420f1f81a551f7c699633c0da --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 26], [0, 27], [0, 29], [0, 30], [0, 32], [0, 33], [0, 35], [0, 36], [0, 37], [0, 39], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 14], [1, 16], [1, 17], [1, 19], [1, 20], [1, 22], [1, 23], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [1, 32], [1, 33], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [2, 4], [2, 6], [2, 7], [2, 9], [2, 10], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [2, 31], [2, 32], [2, 33], [2, 35], [2, 36], [2, 37], [2, 39], [3, 5], [3, 7], [3, 9], [3, 13], [3, 15], [3, 16], [3, 22], [3, 24], [3, 25], [3, 28], [3, 30], [3, 32], [3, 34], [3, 36], [3, 37], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 22], [4, 23], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [5, 6], [5, 8], [5, 13], [5, 15], [5, 17], [5, 20], [5, 21], [5, 22], [5, 25], [5, 26], [5, 27], [5, 28], [5, 32], [5, 34], [5, 35], [5, 37], [5, 38], [5, 39], [6, 7], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 20], [6, 22], [6, 23], [6, 26], [6, 28], [6, 29], [6, 33], [6, 35], [6, 36], [6, 37], [6, 39], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 26], [7, 30], [7, 33], [7, 35], [7, 36], [7, 37], [7, 39], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 18], [8, 19], [8, 21], [8, 24], [8, 26], [8, 27], [8, 28], [8, 30], [8, 31], [8, 32], [8, 35], [8, 36], [8, 39], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 20], [9, 22], [9, 23], [9, 24], [9, 26], [9, 29], [9, 31], [9, 33], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [12, 13], [12, 14], [12, 15], [12, 16], [12, 19], [12, 20], [12, 21], [12, 23], [12, 27], [12, 28], [12, 29], [12, 30], [12, 33], [12, 39], [13, 14], [13, 16], [13, 20], [13, 22], [13, 26], [13, 27], [13, 33], [13, 37], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 31], [14, 33], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [15, 18], [15, 19], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 30], [15, 31], [15, 37], [16, 17], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 28], [16, 29], [16, 31], [16, 32], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [17, 18], [17, 20], [17, 21], [17, 22], [17, 26], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 39], [18, 19], [18, 20], [18, 27], [18, 30], [18, 32], [18, 34], [18, 35], [18, 37], [18, 38], [18, 39], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 31], [19, 33], [19, 34], [19, 35], [19, 38], [20, 22], [20, 23], [20, 26], [20, 28], [20, 29], [20, 30], [20, 32], [20, 33], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [21, 23], [21, 24], [21, 29], [21, 32], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 31], [22, 32], [22, 33], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [23, 24], [23, 25], [23, 27], [23, 28], [23, 32], [23, 33], [23, 34], [23, 36], [23, 38], [24, 25], [24, 26], [24, 28], [24, 30], [24, 31], [24, 33], [24, 34], [24, 36], [24, 38], [24, 39], [25, 26], [25, 27], [25, 29], [25, 36], [25, 37], [26, 27], [26, 28], [26, 31], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [27, 29], [27, 30], [27, 32], [27, 34], [27, 35], [27, 36], [27, 37], [28, 29], [28, 30], [28, 32], [28, 33], [28, 35], [28, 36], [28, 37], [28, 39], [29, 30], [29, 36], [29, 37], [30, 31], [30, 33], [30, 37], [30, 38], [31, 33], [31, 34], [31, 36], [31, 37], [31, 38], [31, 39], [32, 33], [32, 34], [32, 36], [32, 37], [32, 39], [33, 35], [33, 36], [33, 37], [33, 38], [33, 39], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [35, 36], [35, 37], [35, 39], [36, 37], [36, 38], [36, 39], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s5/tests/run.py b/tasks/construct-nppc-clique-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l5-s5/tests/test.sh b/tasks/construct-nppc-clique-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l1-s2/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l1-s2/environment/instance.json b/tasks/construct-nppc-dominating-set-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6e0526038e25dca342b97f2640014f387b655bf --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 3], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 7], [1, 8], [2, 3], [3, 7], [3, 8], [3, 9], [4, 5], [4, 7], [4, 9], [5, 9], [6, 8]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s2/solution/solve.sh b/tasks/construct-nppc-dominating-set-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6afcf02b99bb33f3213b44d21088a8e2a76db01f --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [1, 3, 5, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l1-s2/tests/check.py b/tasks/construct-nppc-dominating-set-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-nppc-dominating-set-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6e0526038e25dca342b97f2640014f387b655bf --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 3], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 7], [1, 8], [2, 3], [3, 7], [3, 8], [3, 9], [4, 5], [4, 7], [4, 9], [5, 9], [6, 8]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s2/tests/run.py b/tasks/construct-nppc-dominating-set-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l1-s2/tests/test.sh b/tasks/construct-nppc-dominating-set-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l1-s5/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l1-s5/environment/instance.json b/tasks/construct-nppc-dominating-set-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..04bad4d53a59186b1064fad6df4d991d4d860406 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 2], [0, 7], [0, 8], [0, 9], [1, 2], [1, 6], [3, 5], [3, 7], [3, 9], [4, 6], [4, 8]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s5/solution/solve.sh b/tasks/construct-nppc-dominating-set-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2042d5fc33a52392aedc72b821c316f1838a4949 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [2, 3, 6, 8, 9]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l1-s5/tests/check.py b/tasks/construct-nppc-dominating-set-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-nppc-dominating-set-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..04bad4d53a59186b1064fad6df4d991d4d860406 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "k": 5, "edges": [[0, 2], [0, 7], [0, 8], [0, 9], [1, 2], [1, 6], [3, 5], [3, 7], [3, 9], [4, 6], [4, 8]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l1-s5/tests/run.py b/tasks/construct-nppc-dominating-set-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l1-s5/tests/test.sh b/tasks/construct-nppc-dominating-set-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l5-s3/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l5-s3/environment/instance.json b/tasks/construct-nppc-dominating-set-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7893f13d5370c7d271bce6cdc1f308aa8c3b25fc --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 4], [0, 13], [0, 21], [0, 22], [0, 23], [0, 28], [0, 32], [0, 37], [0, 38], [0, 48], [0, 49], [0, 55], [0, 68], [0, 78], [0, 82], [0, 84], [0, 86], [0, 87], [0, 88], [0, 99], [0, 102], [0, 103], [0, 107], [0, 110], [0, 122], [0, 123], [0, 127], [0, 130], [0, 132], [0, 134], [0, 142], [0, 146], [0, 150], [0, 153], [0, 155], [0, 157], [0, 159], [0, 160], [0, 162], [0, 167], [1, 2], [1, 4], [1, 7], [1, 9], [1, 11], [1, 14], [1, 15], [1, 19], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 33], [1, 41], [1, 43], [1, 45], [1, 47], [1, 68], [1, 73], [1, 82], [1, 92], [1, 93], [1, 94], [1, 95], [1, 103], [1, 109], [1, 112], [1, 114], [1, 126], [1, 135], [1, 141], [1, 142], [1, 147], [1, 159], [1, 167], [2, 9], [2, 10], [2, 11], [2, 23], [2, 26], [2, 28], [2, 30], [2, 31], [2, 37], [2, 45], [2, 47], [2, 59], [2, 66], [2, 67], [2, 68], [2, 75], [2, 76], [2, 85], [2, 86], [2, 88], [2, 89], [2, 91], [2, 99], [2, 107], [2, 109], [2, 118], [2, 122], [2, 126], [2, 128], [2, 137], [2, 138], [2, 139], [2, 140], [2, 146], [2, 148], [2, 153], [2, 169], [2, 172], [3, 4], [3, 10], [3, 18], [3, 27], [3, 28], [3, 31], [3, 41], [3, 42], [3, 55], [3, 58], [3, 61], [3, 67], [3, 68], [3, 72], [3, 73], [3, 93], [3, 95], [3, 99], [3, 104], [3, 107], [3, 108], [3, 111], [3, 112], [3, 117], [3, 132], [3, 141], [3, 142], [3, 146], [3, 153], [3, 154], [3, 165], [3, 166], [3, 167], [3, 171], [4, 7], [4, 11], [4, 28], [4, 32], [4, 42], [4, 48], [4, 52], [4, 63], [4, 86], [4, 103], [4, 109], [4, 114], [4, 115], [4, 118], [4, 119], [4, 120], [4, 126], [4, 128], [4, 130], [4, 144], [4, 148], [4, 158], [4, 165], [4, 173], [5, 15], [5, 33], [5, 39], [5, 41], [5, 43], [5, 46], [5, 48], [5, 49], [5, 53], [5, 54], [5, 58], [5, 68], [5, 72], [5, 82], [5, 91], [5, 102], [5, 106], [5, 107], [5, 115], [5, 124], [5, 132], [5, 143], [5, 151], [5, 153], [5, 154], [6, 7], [6, 10], [6, 18], [6, 19], [6, 22], [6, 29], [6, 30], [6, 48], [6, 50], [6, 53], [6, 57], [6, 72], [6, 77], [6, 104], [6, 105], [6, 110], [6, 113], [6, 114], [6, 115], [6, 127], [6, 139], [6, 140], [6, 144], [6, 151], [6, 154], [6, 155], [6, 159], [6, 162], [6, 164], [6, 170], [6, 177], [7, 9], [7, 11], [7, 19], [7, 22], [7, 29], [7, 37], [7, 62], [7, 64], [7, 68], [7, 72], [7, 77], [7, 78], [7, 82], [7, 83], [7, 84], [7, 85], [7, 93], [7, 105], [7, 107], [7, 110], [7, 111], [7, 115], [7, 118], [7, 123], [7, 127], [7, 131], [7, 139], [7, 143], [7, 152], [7, 153], [7, 156], [7, 167], [7, 171], [7, 176], [8, 11], [8, 13], [8, 18], [8, 24], [8, 27], [8, 29], [8, 38], [8, 39], [8, 41], [8, 43], [8, 44], [8, 48], [8, 51], [8, 63], [8, 70], [8, 71], [8, 84], [8, 90], [8, 98], [8, 102], [8, 104], [8, 111], [8, 113], [8, 117], [8, 131], [8, 133], [8, 136], [8, 144], [8, 152], [8, 153], [8, 160], [8, 177], [9, 15], [9, 19], [9, 23], [9, 24], [9, 29], [9, 30], [9, 38], [9, 41], [9, 42], [9, 49], [9, 51], [9, 58], [9, 68], [9, 69], [9, 72], [9, 82], [9, 83], [9, 85], [9, 89], [9, 90], [9, 93], [9, 94], [9, 96], [9, 98], [9, 101], [9, 105], [9, 106], [9, 110], [9, 114], [9, 116], [9, 117], [9, 124], [9, 137], [9, 139], [9, 147], [9, 149], [9, 157], [9, 158], [9, 163], [9, 170], [10, 20], [10, 22], [10, 23], [10, 28], [10, 31], [10, 38], [10, 40], [10, 44], [10, 63], [10, 64], [10, 67], [10, 71], [10, 75], [10, 83], [10, 88], [10, 91], [10, 98], [10, 109], [10, 117], [10, 118], [10, 122], [10, 129], [10, 134], [10, 138], [10, 140], [10, 144], [10, 151], [10, 154], [10, 158], [10, 159], [10, 163], [10, 167], [10, 171], [11, 12], [11, 16], [11, 20], [11, 25], [11, 28], [11, 29], [11, 30], [11, 39], [11, 50], [11, 65], [11, 72], [11, 73], [11, 79], [11, 80], [11, 86], [11, 92], [11, 96], [11, 99], [11, 103], [11, 114], [11, 120], [11, 122], [11, 131], [11, 135], [11, 137], [11, 147], [11, 149], [11, 151], [11, 165], [11, 178], [11, 179], [12, 15], [12, 16], [12, 19], [12, 22], [12, 28], [12, 29], [12, 34], [12, 36], [12, 41], [12, 44], [12, 49], [12, 55], [12, 57], [12, 60], [12, 61], [12, 62], [12, 69], [12, 70], [12, 76], [12, 79], [12, 81], [12, 84], [12, 85], [12, 86], [12, 88], [12, 96], [12, 100], [12, 107], [12, 112], [12, 116], [12, 119], [12, 127], [12, 131], [12, 146], [12, 151], [12, 161], [12, 170], [12, 177], [13, 14], [13, 22], [13, 30], [13, 38], [13, 40], [13, 42], [13, 43], [13, 47], [13, 52], [13, 54], [13, 55], [13, 58], [13, 59], [13, 69], [13, 70], [13, 71], [13, 75], [13, 76], [13, 78], [13, 82], [13, 86], [13, 88], [13, 98], [13, 106], [13, 108], [13, 109], [13, 110], [13, 115], [13, 119], [13, 131], [13, 133], [13, 142], [13, 146], [13, 148], [13, 154], [13, 155], [13, 158], [13, 163], [13, 167], [13, 168], [13, 171], [14, 22], [14, 30], [14, 31], [14, 37], [14, 38], [14, 40], [14, 44], [14, 47], [14, 51], [14, 55], [14, 64], [14, 71], [14, 73], [14, 79], [14, 86], [14, 91], [14, 93], [14, 97], [14, 101], [14, 103], [14, 106], [14, 108], [14, 125], [14, 130], [14, 133], [14, 137], [14, 141], [14, 144], [14, 146], [14, 165], [14, 167], [15, 21], [15, 25], [15, 30], [15, 38], [15, 39], [15, 48], [15, 54], [15, 59], [15, 66], [15, 67], [15, 73], [15, 74], [15, 82], [15, 93], [15, 94], [15, 106], [15, 108], [15, 115], [15, 118], [15, 120], [15, 126], [15, 128], [15, 129], [15, 131], [15, 132], [15, 133], [15, 138], [15, 141], [15, 148], [15, 162], [15, 166], [15, 170], [15, 177], [15, 179], [16, 17], [16, 19], [16, 20], [16, 27], [16, 33], [16, 38], [16, 44], [16, 47], [16, 50], [16, 57], [16, 63], [16, 64], [16, 66], [16, 68], [16, 72], [16, 75], [16, 77], [16, 79], [16, 87], [16, 89], [16, 90], [16, 95], [16, 101], [16, 104], [16, 105], [16, 106], [16, 118], [16, 121], [16, 122], [16, 125], [16, 126], [16, 129], [16, 131], [16, 134], [16, 135], [16, 136], [16, 139], [16, 149], [16, 151], [16, 154], [16, 157], [16, 162], [16, 163], [16, 167], [16, 169], [16, 179], [17, 20], [17, 22], [17, 27], [17, 30], [17, 35], [17, 38], [17, 40], [17, 43], [17, 47], [17, 49], [17, 53], [17, 58], [17, 67], [17, 71], [17, 76], [17, 80], [17, 81], [17, 87], [17, 92], [17, 101], [17, 104], [17, 105], [17, 107], [17, 110], [17, 113], [17, 116], [17, 118], [17, 120], [17, 121], [17, 122], [17, 129], [17, 131], [17, 141], [17, 146], [17, 150], [17, 155], [17, 160], [17, 163], [18, 20], [18, 24], [18, 29], [18, 31], [18, 37], [18, 40], [18, 55], [18, 58], [18, 69], [18, 71], [18, 73], [18, 84], [18, 87], [18, 97], [18, 99], [18, 100], [18, 116], [18, 118], [18, 120], [18, 122], [18, 123], [18, 129], [18, 131], [18, 136], [18, 137], [18, 143], [18, 151], [18, 162], [18, 169], [18, 177], [19, 20], [19, 21], [19, 29], [19, 31], [19, 47], [19, 48], [19, 50], [19, 52], [19, 58], [19, 62], [19, 63], [19, 64], [19, 65], [19, 69], [19, 73], [19, 86], [19, 89], [19, 91], [19, 92], [19, 93], [19, 102], [19, 107], [19, 108], [19, 124], [19, 129], [19, 133], [19, 137], [19, 138], [19, 141], [19, 151], [19, 155], [19, 157], [19, 163], [19, 165], [19, 168], [19, 173], [19, 174], [19, 175], [19, 176], [20, 21], [20, 35], [20, 37], [20, 39], [20, 41], [20, 45], [20, 59], [20, 78], [20, 83], [20, 92], [20, 99], [20, 101], [20, 106], [20, 110], [20, 120], [20, 127], [20, 130], [20, 135], [20, 136], [20, 137], [20, 138], [20, 139], [20, 157], [20, 167], [21, 24], [21, 34], [21, 39], [21, 42], [21, 48], [21, 49], [21, 52], [21, 54], [21, 66], [21, 68], [21, 77], [21, 81], [21, 90], [21, 91], [21, 97], [21, 101], [21, 103], [21, 106], [21, 113], [21, 128], [21, 129], [21, 130], [21, 145], [21, 160], [21, 165], [21, 167], [21, 169], [21, 173], [21, 174], [21, 176], [21, 179], [22, 24], [22, 25], [22, 27], [22, 38], [22, 42], [22, 43], [22, 44], [22, 56], [22, 57], [22, 60], [22, 65], [22, 66], [22, 70], [22, 78], [22, 84], [22, 89], [22, 99], [22, 105], [22, 107], [22, 116], [22, 120], [22, 125], [22, 126], [22, 127], [22, 140], [22, 141], [22, 142], [22, 144], [22, 148], [22, 163], [22, 165], [22, 166], [22, 170], [22, 171], [22, 174], [22, 176], [23, 25], [23, 40], [23, 56], [23, 59], [23, 64], [23, 70], [23, 71], [23, 72], [23, 74], [23, 96], [23, 100], [23, 107], [23, 111], [23, 115], [23, 122], [23, 126], [23, 128], [23, 130], [23, 132], [23, 133], [23, 134], [23, 137], [23, 149], [23, 155], [23, 165], [23, 171], [23, 177], [24, 25], [24, 27], [24, 28], [24, 49], [24, 58], [24, 71], [24, 73], [24, 74], [24, 77], [24, 78], [24, 79], [24, 82], [24, 86], [24, 96], [24, 98], [24, 128], [24, 135], [24, 136], [24, 141], [24, 146], [24, 148], [24, 154], [24, 165], [24, 174], [25, 28], [25, 31], [25, 36], [25, 37], [25, 41], [25, 45], [25, 46], [25, 47], [25, 48], [25, 52], [25, 53], [25, 55], [25, 65], [25, 67], [25, 73], [25, 80], [25, 87], [25, 91], [25, 95], [25, 98], [25, 99], [25, 101], [25, 103], [25, 104], [25, 106], [25, 117], [25, 119], [25, 123], [25, 130], [25, 132], [25, 136], [25, 137], [25, 138], [25, 141], [25, 144], [25, 147], [25, 152], [25, 156], [25, 158], [25, 164], [25, 165], [25, 170], [25, 172], [25, 173], [26, 33], [26, 35], [26, 37], [26, 39], [26, 45], [26, 47], [26, 65], [26, 76], [26, 79], [26, 83], [26, 86], [26, 90], [26, 103], [26, 109], [26, 119], [26, 127], [26, 128], [26, 129], [26, 131], [26, 137], [26, 138], [26, 141], [26, 148], [26, 149], [26, 150], [26, 152], [26, 157], [26, 159], [26, 160], [26, 162], [26, 164], [26, 168], [26, 172], [26, 173], [26, 177], [26, 179], [27, 34], [27, 40], [27, 41], [27, 43], [27, 44], [27, 47], [27, 53], [27, 54], [27, 58], [27, 63], [27, 74], [27, 75], [27, 77], [27, 79], [27, 85], [27, 89], [27, 94], [27, 98], [27, 107], [27, 114], [27, 116], [27, 119], [27, 125], [27, 128], [27, 133], [27, 144], [27, 145], [27, 146], [27, 149], [27, 150], [27, 155], [27, 156], [27, 159], [27, 160], [27, 164], [27, 173], [28, 32], [28, 39], [28, 40], [28, 41], [28, 42], [28, 64], [28, 67], [28, 68], [28, 74], [28, 76], [28, 77], [28, 78], [28, 79], [28, 82], [28, 87], [28, 89], [28, 93], [28, 95], [28, 97], [28, 99], [28, 106], [28, 114], [28, 116], [28, 124], [28, 128], [28, 129], [28, 131], [28, 134], [28, 149], [28, 151], [28, 161], [28, 170], [28, 171], [28, 176], [29, 34], [29, 43], [29, 47], [29, 49], [29, 57], [29, 62], [29, 64], [29, 68], [29, 74], [29, 80], [29, 84], [29, 87], [29, 94], [29, 95], [29, 104], [29, 105], [29, 111], [29, 120], [29, 130], [29, 137], [29, 141], [29, 146], [29, 149], [29, 150], [29, 153], [29, 157], [29, 164], [29, 172], [30, 32], [30, 36], [30, 37], [30, 42], [30, 51], [30, 57], [30, 59], [30, 61], [30, 64], [30, 67], [30, 72], [30, 73], [30, 74], [30, 84], [30, 88], [30, 89], [30, 94], [30, 95], [30, 96], [30, 102], [30, 108], [30, 112], [30, 120], [30, 123], [30, 127], [30, 130], [30, 136], [30, 141], [30, 144], [30, 145], [30, 148], [30, 156], [30, 171], [30, 175], [30, 176], [30, 179], [31, 32], [31, 47], [31, 60], [31, 62], [31, 66], [31, 69], [31, 77], [31, 79], [31, 87], [31, 117], [31, 120], [31, 128], [31, 130], [31, 131], [31, 143], [31, 148], [31, 149], [31, 156], [31, 159], [31, 161], [31, 163], [31, 167], [31, 169], [31, 174], [31, 179], [32, 39], [32, 43], [32, 51], [32, 61], [32, 64], [32, 69], [32, 70], [32, 73], [32, 77], [32, 83], [32, 85], [32, 88], [32, 89], [32, 94], [32, 95], [32, 98], [32, 100], [32, 101], [32, 102], [32, 104], [32, 105], [32, 107], [32, 108], [32, 114], [32, 121], [32, 126], [32, 128], [32, 136], [32, 142], [32, 146], [32, 147], [32, 149], [32, 151], [32, 153], [32, 162], [32, 170], [32, 171], [32, 177], [32, 178], [32, 179], [33, 34], [33, 38], [33, 48], [33, 49], [33, 56], [33, 60], [33, 75], [33, 77], [33, 81], [33, 84], [33, 87], [33, 88], [33, 93], [33, 96], [33, 106], [33, 113], [33, 117], [33, 120], [33, 128], [33, 130], [33, 131], [33, 133], [33, 144], [33, 145], [33, 148], [33, 154], [33, 155], [33, 157], [33, 158], [33, 168], [33, 172], [33, 176], [34, 39], [34, 41], [34, 45], [34, 52], [34, 65], [34, 75], [34, 79], [34, 82], [34, 83], [34, 87], [34, 89], [34, 90], [34, 91], [34, 94], [34, 98], [34, 101], [34, 105], [34, 106], [34, 107], [34, 116], [34, 119], [34, 121], [34, 122], [34, 131], [34, 140], [34, 143], [34, 153], [34, 161], [34, 167], [34, 168], [34, 170], [34, 171], [34, 179], [35, 40], [35, 49], [35, 55], [35, 56], [35, 63], [35, 68], [35, 69], [35, 70], [35, 73], [35, 78], [35, 85], [35, 90], [35, 97], [35, 99], [35, 101], [35, 104], [35, 111], [35, 118], [35, 122], [35, 123], [35, 124], [35, 128], [35, 130], [35, 133], [35, 145], [35, 149], [35, 154], [35, 156], [35, 168], [35, 173], [35, 174], [36, 41], [36, 48], [36, 51], [36, 56], [36, 77], [36, 82], [36, 87], [36, 91], [36, 93], [36, 99], [36, 106], [36, 107], [36, 108], [36, 110], [36, 113], [36, 114], [36, 116], [36, 119], [36, 127], [36, 129], [36, 132], [36, 136], [36, 138], [36, 139], [36, 150], [36, 157], [36, 162], [36, 164], [36, 169], [36, 176], [37, 39], [37, 44], [37, 49], [37, 56], [37, 59], [37, 63], [37, 69], [37, 84], [37, 88], [37, 96], [37, 101], [37, 109], [37, 119], [37, 127], [37, 129], [37, 134], [37, 139], [37, 146], [37, 159], [37, 162], [37, 163], [37, 165], [37, 167], [38, 41], [38, 43], [38, 47], [38, 51], [38, 52], [38, 56], [38, 68], [38, 70], [38, 73], [38, 75], [38, 80], [38, 91], [38, 97], [38, 104], [38, 110], [38, 115], [38, 116], [38, 120], [38, 121], [38, 135], [38, 143], [38, 157], [38, 163], [38, 165], [38, 168], [38, 169], [38, 172], [38, 173], [39, 43], [39, 49], [39, 68], [39, 72], [39, 76], [39, 81], [39, 82], [39, 88], [39, 89], [39, 100], [39, 101], [39, 103], [39, 104], [39, 107], [39, 109], [39, 110], [39, 121], [39, 123], [39, 129], [39, 137], [39, 139], [39, 140], [39, 143], [39, 147], [39, 149], [39, 151], [39, 154], [39, 155], [39, 162], [39, 165], [39, 170], [39, 171], [40, 44], [40, 46], [40, 51], [40, 53], [40, 59], [40, 60], [40, 71], [40, 81], [40, 87], [40, 88], [40, 89], [40, 96], [40, 106], [40, 107], [40, 121], [40, 123], [40, 125], [40, 130], [40, 134], [40, 135], [40, 136], [40, 140], [40, 142], [40, 152], [40, 163], [40, 171], [40, 174], [40, 176], [41, 43], [41, 45], [41, 52], [41, 54], [41, 56], [41, 57], [41, 62], [41, 63], [41, 74], [41, 77], [41, 90], [41, 105], [41, 112], [41, 115], [41, 116], [41, 119], [41, 123], [41, 135], [41, 153], [41, 154], [41, 161], [41, 163], [41, 167], [42, 46], [42, 51], [42, 54], [42, 56], [42, 61], [42, 65], [42, 70], [42, 72], [42, 73], [42, 75], [42, 77], [42, 93], [42, 94], [42, 98], [42, 100], [42, 112], [42, 113], [42, 115], [42, 116], [42, 119], [42, 136], [42, 139], [42, 142], [42, 145], [42, 146], [42, 147], [42, 158], [42, 160], [42, 163], [42, 165], [42, 167], [42, 168], [42, 169], [42, 170], [42, 173], [42, 177], [43, 59], [43, 68], [43, 70], [43, 79], [43, 81], [43, 82], [43, 85], [43, 86], [43, 87], [43, 101], [43, 119], [43, 126], [43, 132], [43, 144], [43, 149], [43, 152], [43, 156], [43, 163], [43, 173], [44, 46], [44, 47], [44, 54], [44, 56], [44, 58], [44, 66], [44, 72], [44, 75], [44, 77], [44, 79], [44, 81], [44, 83], [44, 86], [44, 87], [44, 88], [44, 95], [44, 99], [44, 100], [44, 121], [44, 125], [44, 138], [44, 149], [44, 153], [44, 155], [44, 158], [44, 160], [45, 46], [45, 50], [45, 56], [45, 66], [45, 68], [45, 82], [45, 83], [45, 92], [45, 94], [45, 102], [45, 109], [45, 111], [45, 117], [45, 129], [45, 130], [45, 133], [45, 149], [45, 150], [45, 153], [45, 161], [45, 171], [45, 172], [45, 174], [45, 178], [46, 47], [46, 51], [46, 52], [46, 53], [46, 55], [46, 56], [46, 59], [46, 63], [46, 71], [46, 72], [46, 93], [46, 98], [46, 99], [46, 100], [46, 107], [46, 110], [46, 112], [46, 119], [46, 121], [46, 134], [46, 137], [46, 145], [46, 146], [46, 154], [46, 157], [46, 161], [46, 169], [46, 170], [46, 172], [47, 52], [47, 56], [47, 75], [47, 79], [47, 82], [47, 86], [47, 97], [47, 98], [47, 100], [47, 105], [47, 107], [47, 111], [47, 123], [47, 125], [47, 127], [47, 138], [47, 143], [47, 152], [47, 165], [47, 169], [47, 171], [47, 173], [47, 174], [48, 52], [48, 55], [48, 58], [48, 65], [48, 69], [48, 70], [48, 71], [48, 75], [48, 76], [48, 78], [48, 81], [48, 89], [48, 95], [48, 97], [48, 99], [48, 101], [48, 103], [48, 113], [48, 114], [48, 134], [48, 135], [48, 138], [48, 149], [48, 153], [48, 165], [48, 174], [48, 177], [49, 50], [49, 58], [49, 60], [49, 62], [49, 64], [49, 67], [49, 70], [49, 71], [49, 77], [49, 82], [49, 87], [49, 88], [49, 95], [49, 97], [49, 104], [49, 105], [49, 106], [49, 113], [49, 117], [49, 118], [49, 134], [49, 136], [49, 142], [49, 143], [49, 155], [49, 156], [49, 159], [49, 168], [49, 170], [49, 173], [49, 176], [50, 54], [50, 63], [50, 64], [50, 67], [50, 70], [50, 79], [50, 83], [50, 88], [50, 97], [50, 98], [50, 102], [50, 104], [50, 105], [50, 110], [50, 113], [50, 121], [50, 128], [50, 131], [50, 133], [50, 139], [50, 140], [50, 142], [50, 148], [50, 161], [50, 168], [50, 174], [50, 178], [51, 55], [51, 56], [51, 63], [51, 64], [51, 70], [51, 78], [51, 83], [51, 90], [51, 99], [51, 100], [51, 105], [51, 107], [51, 110], [51, 117], [51, 120], [51, 127], [51, 128], [51, 130], [51, 137], [51, 159], [51, 162], [51, 167], [51, 171], [51, 173], [51, 175], [51, 179], [52, 57], [52, 61], [52, 62], [52, 66], [52, 69], [52, 71], [52, 73], [52, 82], [52, 84], [52, 90], [52, 92], [52, 101], [52, 102], [52, 103], [52, 105], [52, 110], [52, 116], [52, 118], [52, 119], [52, 120], [52, 124], [52, 125], [52, 132], [52, 134], [52, 151], [52, 153], [52, 155], [52, 156], [52, 160], [52, 165], [52, 168], [52, 169], [52, 172], [52, 175], [53, 56], [53, 57], [53, 60], [53, 62], [53, 66], [53, 70], [53, 72], [53, 81], [53, 91], [53, 103], [53, 108], [53, 112], [53, 116], [53, 121], [53, 132], [53, 135], [53, 141], [53, 143], [53, 144], [53, 148], [53, 150], [53, 160], [53, 165], [53, 166], [53, 178], [54, 55], [54, 61], [54, 64], [54, 74], [54, 81], [54, 86], [54, 88], [54, 97], [54, 100], [54, 105], [54, 107], [54, 108], [54, 113], [54, 115], [54, 120], [54, 121], [54, 122], [54, 128], [54, 129], [54, 156], [54, 162], [54, 168], [54, 170], [54, 172], [54, 173], [54, 174], [54, 175], [55, 58], [55, 60], [55, 64], [55, 66], [55, 68], [55, 80], [55, 85], [55, 89], [55, 93], [55, 94], [55, 98], [55, 111], [55, 120], [55, 134], [55, 137], [55, 149], [55, 152], [55, 170], [55, 176], [56, 59], [56, 62], [56, 63], [56, 65], [56, 68], [56, 72], [56, 74], [56, 75], [56, 76], [56, 80], [56, 85], [56, 92], [56, 93], [56, 102], [56, 113], [56, 115], [56, 116], [56, 119], [56, 120], [56, 126], [56, 132], [56, 136], [56, 142], [56, 143], [56, 145], [56, 151], [56, 153], [56, 155], [56, 159], [56, 174], [56, 176], [56, 177], [57, 62], [57, 67], [57, 68], [57, 74], [57, 78], [57, 79], [57, 83], [57, 87], [57, 88], [57, 91], [57, 102], [57, 110], [57, 114], [57, 118], [57, 121], [57, 124], [57, 129], [57, 148], [57, 149], [57, 153], [57, 156], [57, 163], [57, 164], [57, 168], [57, 170], [57, 172], [58, 70], [58, 73], [58, 74], [58, 83], [58, 84], [58, 88], [58, 94], [58, 98], [58, 100], [58, 101], [58, 103], [58, 105], [58, 107], [58, 118], [58, 122], [58, 125], [58, 128], [58, 132], [58, 142], [58, 151], [58, 153], [58, 156], [58, 157], [58, 161], [58, 162], [58, 179], [59, 62], [59, 65], [59, 76], [59, 81], [59, 83], [59, 92], [59, 93], [59, 95], [59, 105], [59, 107], [59, 116], [59, 127], [59, 134], [59, 135], [59, 139], [59, 144], [59, 151], [59, 154], [59, 156], [59, 159], [59, 165], [59, 168], [59, 171], [59, 173], [59, 174], [59, 175], [59, 177], [60, 67], [60, 70], [60, 75], [60, 77], [60, 78], [60, 79], [60, 80], [60, 92], [60, 104], [60, 112], [60, 118], [60, 126], [60, 129], [60, 130], [60, 134], [60, 141], [60, 150], [60, 153], [60, 165], [60, 174], [61, 64], [61, 68], [61, 70], [61, 71], [61, 74], [61, 87], [61, 88], [61, 95], [61, 98], [61, 110], [61, 119], [61, 124], [61, 139], [61, 144], [61, 154], [61, 157], [61, 162], [61, 172], [62, 67], [62, 69], [62, 72], [62, 74], [62, 83], [62, 87], [62, 89], [62, 104], [62, 105], [62, 108], [62, 109], [62, 113], [62, 121], [62, 124], [62, 125], [62, 127], [62, 128], [62, 135], [62, 143], [62, 149], [62, 150], [62, 159], [62, 165], [62, 168], [62, 169], [62, 172], [62, 174], [62, 176], [62, 177], [62, 179], [63, 68], [63, 71], [63, 74], [63, 82], [63, 89], [63, 90], [63, 95], [63, 101], [63, 106], [63, 108], [63, 112], [63, 116], [63, 124], [63, 127], [63, 130], [63, 135], [63, 137], [63, 159], [63, 163], [63, 168], [63, 169], [63, 175], [63, 178], [63, 179], [64, 67], [64, 71], [64, 72], [64, 74], [64, 84], [64, 87], [64, 91], [64, 94], [64, 95], [64, 109], [64, 111], [64, 117], [64, 122], [64, 124], [64, 131], [64, 137], [64, 139], [64, 147], [64, 149], [64, 150], [64, 168], [64, 169], [64, 178], [65, 68], [65, 73], [65, 76], [65, 81], [65, 84], [65, 86], [65, 87], [65, 100], [65, 101], [65, 111], [65, 118], [65, 119], [65, 123], [65, 131], [65, 134], [65, 135], [65, 136], [65, 138], [65, 151], [65, 164], [65, 167], [65, 172], [65, 176], [66, 68], [66, 79], [66, 80], [66, 82], [66, 83], [66, 85], [66, 94], [66, 100], [66, 104], [66, 108], [66, 118], [66, 119], [66, 123], [66, 126], [66, 129], [66, 130], [66, 138], [66, 139], [66, 144], [66, 155], [66, 162], [66, 167], [66, 168], [66, 176], [67, 71], [67, 72], [67, 73], [67, 75], [67, 77], [67, 79], [67, 82], [67, 97], [67, 100], [67, 102], [67, 111], [67, 116], [67, 129], [67, 142], [67, 144], [67, 146], [67, 153], [67, 159], [67, 162], [67, 165], [67, 168], [67, 174], [67, 177], [68, 69], [68, 72], [68, 75], [68, 78], [68, 80], [68, 95], [68, 107], [68, 108], [68, 111], [68, 116], [68, 117], [68, 119], [68, 121], [68, 132], [68, 133], [68, 136], [68, 141], [68, 144], [68, 165], [68, 166], [69, 80], [69, 83], [69, 84], [69, 100], [69, 101], [69, 102], [69, 106], [69, 124], [69, 129], [69, 134], [69, 138], [69, 144], [69, 156], [69, 170], [69, 173], [70, 72], [70, 78], [70, 79], [70, 86], [70, 95], [70, 99], [70, 105], [70, 107], [70, 114], [70, 119], [70, 124], [70, 128], [70, 137], [70, 138], [70, 140], [70, 145], [70, 156], [70, 160], [70, 166], [70, 169], [70, 177], [71, 80], [71, 86], [71, 95], [71, 103], [71, 107], [71, 113], [71, 129], [71, 138], [71, 140], [71, 150], [71, 156], [71, 167], [71, 170], [71, 174], [71, 178], [72, 79], [72, 85], [72, 87], [72, 93], [72, 97], [72, 100], [72, 103], [72, 105], [72, 111], [72, 113], [72, 118], [72, 125], [72, 132], [72, 157], [72, 159], [72, 160], [72, 166], [72, 177], [73, 74], [73, 78], [73, 81], [73, 83], [73, 84], [73, 86], [73, 88], [73, 89], [73, 91], [73, 92], [73, 96], [73, 98], [73, 99], [73, 102], [73, 107], [73, 108], [73, 114], [73, 131], [73, 132], [73, 139], [73, 140], [73, 150], [73, 154], [73, 159], [73, 160], [73, 164], [73, 172], [73, 175], [73, 178], [73, 179], [74, 76], [74, 78], [74, 117], [74, 118], [74, 122], [74, 123], [74, 135], [74, 139], [74, 146], [74, 162], [74, 165], [74, 169], [74, 171], [74, 172], [74, 174], [74, 179], [75, 85], [75, 91], [75, 102], [75, 106], [75, 111], [75, 117], [75, 123], [75, 127], [75, 131], [75, 137], [75, 141], [75, 148], [75, 152], [75, 162], [75, 171], [75, 173], [75, 175], [75, 178], [76, 77], [76, 80], [76, 81], [76, 91], [76, 96], [76, 97], [76, 109], [76, 112], [76, 118], [76, 120], [76, 121], [76, 125], [76, 126], [76, 129], [76, 135], [76, 139], [76, 140], [76, 142], [76, 145], [76, 153], [76, 155], [76, 160], [76, 162], [76, 170], [76, 172], [76, 177], [76, 179], [77, 78], [77, 79], [77, 94], [77, 98], [77, 99], [77, 103], [77, 106], [77, 113], [77, 114], [77, 115], [77, 119], [77, 123], [77, 128], [77, 130], [77, 135], [77, 136], [77, 139], [77, 145], [77, 146], [77, 149], [77, 151], [77, 153], [77, 155], [77, 174], [77, 179], [78, 87], [78, 90], [78, 93], [78, 94], [78, 100], [78, 110], [78, 111], [78, 114], [78, 116], [78, 127], [78, 131], [78, 135], [78, 143], [78, 146], [78, 147], [78, 149], [78, 150], [78, 159], [78, 171], [78, 173], [79, 82], [79, 85], [79, 94], [79, 95], [79, 97], [79, 104], [79, 108], [79, 112], [79, 117], [79, 128], [79, 130], [79, 135], [79, 138], [79, 149], [79, 150], [79, 151], [79, 152], [79, 154], [79, 166], [79, 168], [79, 174], [79, 177], [80, 97], [80, 107], [80, 108], [80, 114], [80, 120], [80, 128], [80, 132], [80, 135], [80, 146], [80, 151], [80, 154], [80, 158], [80, 160], [80, 168], [80, 170], [81, 91], [81, 95], [81, 100], [81, 111], [81, 117], [81, 118], [81, 123], [81, 125], [81, 126], [81, 136], [81, 138], [81, 141], [81, 148], [81, 150], [81, 152], [81, 153], [81, 158], [81, 159], [81, 165], [81, 166], [81, 170], [81, 178], [82, 83], [82, 101], [82, 109], [82, 114], [82, 117], [82, 119], [82, 120], [82, 121], [82, 129], [82, 130], [82, 131], [82, 135], [82, 153], [82, 154], [82, 160], [82, 161], [82, 162], [82, 163], [82, 165], [82, 167], [82, 175], [83, 91], [83, 94], [83, 102], [83, 105], [83, 106], [83, 107], [83, 109], [83, 110], [83, 113], [83, 115], [83, 119], [83, 121], [83, 123], [83, 125], [83, 150], [83, 151], [83, 153], [83, 159], [83, 162], [83, 166], [83, 179], [84, 85], [84, 92], [84, 93], [84, 97], [84, 103], [84, 104], [84, 106], [84, 109], [84, 110], [84, 113], [84, 114], [84, 118], [84, 123], [84, 140], [84, 150], [84, 151], [84, 154], [84, 155], [84, 156], [84, 161], [84, 163], [84, 166], [84, 172], [84, 173], [84, 175], [85, 86], [85, 96], [85, 98], [85, 99], [85, 104], [85, 105], [85, 121], [85, 122], [85, 123], [85, 124], [85, 127], [85, 135], [85, 138], [85, 140], [85, 143], [85, 145], [85, 150], [85, 172], [85, 177], [85, 178], [86, 90], [86, 92], [86, 96], [86, 97], [86, 101], [86, 106], [86, 111], [86, 113], [86, 114], [86, 115], [86, 116], [86, 117], [86, 119], [86, 120], [86, 122], [86, 135], [86, 140], [86, 150], [86, 152], [86, 153], [86, 169], [86, 173], [87, 92], [87, 112], [87, 131], [87, 133], [87, 138], [87, 139], [87, 142], [87, 144], [87, 151], [87, 153], [87, 158], [87, 166], [87, 175], [87, 178], [87, 179], [88, 100], [88, 101], [88, 102], [88, 107], [88, 109], [88, 121], [88, 124], [88, 127], [88, 133], [88, 138], [88, 140], [88, 149], [88, 166], [88, 167], [88, 169], [88, 176], [88, 177], [88, 179], [89, 90], [89, 91], [89, 93], [89, 95], [89, 97], [89, 101], [89, 103], [89, 114], [89, 120], [89, 123], [89, 124], [89, 128], [89, 133], [89, 136], [89, 140], [89, 142], [89, 147], [89, 157], [89, 158], [89, 159], [89, 160], [89, 179], [90, 102], [90, 103], [90, 105], [90, 109], [90, 118], [90, 125], [90, 129], [90, 133], [90, 136], [90, 139], [90, 143], [90, 151], [90, 162], [90, 165], [90, 171], [90, 172], [90, 173], [90, 177], [90, 179], [91, 96], [91, 99], [91, 100], [91, 106], [91, 107], [91, 108], [91, 114], [91, 115], [91, 119], [91, 120], [91, 123], [91, 127], [91, 131], [91, 136], [91, 142], [91, 154], [91, 155], [91, 164], [91, 165], [91, 169], [91, 173], [91, 176], [92, 98], [92, 118], [92, 119], [92, 124], [92, 135], [92, 136], [92, 142], [92, 149], [92, 151], [92, 156], [92, 163], [92, 167], [92, 168], [93, 95], [93, 99], [93, 121], [93, 126], [93, 127], [93, 129], [93, 131], [93, 136], [93, 148], [93, 155], [93, 166], [93, 176], [94, 95], [94, 107], [94, 111], [94, 116], [94, 117], [94, 119], [94, 122], [94, 125], [94, 136], [94, 158], [94, 161], [94, 170], [94, 173], [94, 176], [95, 99], [95, 108], [95, 110], [95, 118], [95, 120], [95, 121], [95, 122], [95, 126], [95, 129], [95, 131], [95, 132], [95, 133], [95, 134], [95, 136], [95, 146], [95, 149], [95, 151], [95, 153], [95, 161], [96, 99], [96, 105], [96, 114], [96, 129], [96, 137], [96, 143], [96, 147], [96, 149], [96, 151], [96, 152], [96, 158], [96, 159], [96, 166], [96, 176], [97, 100], [97, 107], [97, 108], [97, 113], [97, 114], [97, 129], [97, 140], [97, 143], [97, 167], [97, 170], [97, 172], [98, 105], [98, 110], [98, 122], [98, 123], [98, 124], [98, 127], [98, 134], [98, 137], [98, 143], [98, 145], [98, 151], [98, 153], [98, 159], [98, 161], [98, 163], [98, 165], [98, 170], [98, 174], [98, 178], [99, 101], [99, 104], [99, 105], [99, 106], [99, 129], [99, 134], [99, 136], [99, 139], [99, 155], [99, 156], [99, 162], [99, 167], [99, 169], [99, 173], [100, 111], [100, 112], [100, 124], [100, 130], [100, 131], [100, 133], [100, 138], [100, 155], [100, 160], [100, 170], [100, 175], [101, 106], [101, 113], [101, 114], [101, 115], [101, 120], [101, 130], [101, 145], [101, 146], [101, 147], [101, 148], [101, 151], [101, 152], [101, 162], [101, 175], [101, 177], [101, 178], [102, 106], [102, 108], [102, 110], [102, 113], [102, 119], [102, 121], [102, 129], [102, 142], [102, 151], [102, 156], [102, 161], [102, 169], [102, 176], [102, 179], [103, 114], [103, 119], [103, 121], [103, 122], [103, 127], [103, 129], [103, 131], [103, 134], [103, 137], [103, 140], [103, 141], [103, 150], [103, 164], [103, 169], [103, 170], [103, 179], [104, 106], [104, 110], [104, 119], [104, 121], [104, 122], [104, 126], [104, 130], [104, 133], [104, 139], [104, 143], [104, 146], [104, 149], [104, 153], [104, 167], [104, 171], [104, 176], [104, 179], [105, 108], [105, 112], [105, 114], [105, 115], [105, 122], [105, 124], [105, 126], [105, 136], [105, 139], [105, 142], [105, 159], [105, 161], [105, 165], [105, 168], [105, 173], [105, 174], [106, 110], [106, 120], [106, 128], [106, 131], [106, 132], [106, 136], [106, 139], [106, 140], [106, 142], [106, 144], [106, 146], [106, 151], [106, 156], [106, 167], [106, 169], [106, 171], [106, 172], [107, 108], [107, 111], [107, 123], [107, 126], [107, 132], [107, 139], [107, 141], [107, 146], [107, 148], [107, 151], [107, 154], [107, 157], [107, 159], [107, 162], [107, 164], [107, 172], [107, 174], [107, 179], [108, 114], [108, 118], [108, 127], [108, 128], [108, 133], [108, 136], [108, 138], [108, 144], [108, 149], [108, 150], [108, 156], [108, 162], [108, 166], [108, 167], [108, 174], [108, 178], [108, 179], [109, 111], [109, 114], [109, 127], [109, 129], [109, 131], [109, 141], [109, 154], [109, 164], [109, 165], [109, 174], [110, 120], [110, 121], [110, 124], [110, 142], [110, 148], [110, 152], [110, 162], [110, 165], [110, 167], [110, 172], [110, 173], [110, 179], [111, 116], [111, 122], [111, 126], [111, 131], [111, 149], [111, 151], [111, 154], [111, 157], [111, 160], [111, 162], [111, 164], [111, 178], [112, 116], [112, 117], [112, 118], [112, 119], [112, 122], [112, 126], [112, 130], [112, 140], [112, 151], [112, 160], [112, 161], [112, 173], [112, 174], [113, 131], [113, 138], [113, 139], [113, 145], [113, 153], [113, 154], [113, 157], [113, 158], [113, 163], [113, 172], [113, 173], [113, 175], [113, 177], [114, 117], [114, 121], [114, 127], [114, 136], [114, 138], [114, 145], [114, 150], [114, 154], [114, 159], [115, 116], [115, 117], [115, 118], [115, 124], [115, 127], [115, 131], [115, 136], [115, 139], [115, 140], [115, 141], [115, 142], [115, 147], [115, 158], [115, 166], [115, 172], [115, 174], [116, 117], [116, 118], [116, 120], [116, 126], [116, 127], [116, 135], [116, 139], [116, 153], [116, 155], [116, 158], [116, 160], [116, 164], [116, 173], [116, 176], [117, 125], [117, 135], [117, 138], [117, 141], [117, 145], [117, 158], [117, 162], [117, 169], [117, 171], [117, 174], [117, 175], [117, 179], [118, 123], [118, 126], [118, 130], [118, 133], [118, 137], [118, 140], [118, 141], [118, 152], [118, 153], [118, 154], [118, 158], [118, 162], [118, 166], [118, 172], [118, 173], [118, 175], [118, 176], [119, 120], [119, 132], [119, 134], [119, 138], [119, 139], [119, 144], [119, 149], [119, 153], [119, 159], [119, 170], [119, 175], [119, 177], [120, 123], [120, 128], [120, 135], [120, 138], [120, 148], [120, 154], [120, 159], [120, 178], [121, 122], [121, 134], [121, 139], [121, 144], [121, 145], [121, 148], [121, 149], [121, 152], [121, 164], [122, 124], [122, 127], [122, 129], [122, 148], [122, 152], [122, 153], [122, 161], [122, 165], [122, 169], [122, 177], [122, 178], [123, 128], [123, 137], [123, 141], [123, 142], [123, 159], [123, 162], [123, 165], [123, 167], [123, 172], [124, 129], [124, 130], [124, 134], [124, 136], [124, 141], [124, 142], [124, 151], [124, 154], [124, 163], [124, 166], [124, 172], [124, 176], [125, 126], [125, 143], [125, 144], [125, 157], [125, 158], [125, 162], [125, 169], [126, 128], [126, 131], [126, 136], [126, 152], [126, 153], [126, 156], [126, 157], [126, 162], [126, 169], [126, 171], [126, 174], [126, 178], [127, 128], [127, 130], [127, 135], [127, 139], [127, 140], [127, 147], [127, 157], [127, 158], [127, 160], [127, 161], [127, 163], [127, 164], [127, 171], [127, 178], [128, 134], [128, 136], [128, 138], [128, 139], [128, 140], [128, 159], [128, 160], [128, 167], [129, 133], [129, 134], [129, 138], [129, 140], [129, 144], [129, 151], [129, 157], [129, 160], [129, 161], [129, 165], [129, 169], [129, 173], [130, 140], [130, 141], [130, 142], [130, 143], [130, 147], [130, 150], [130, 158], [130, 162], [130, 167], [130, 168], [130, 172], [130, 173], [130, 177], [130, 179], [131, 132], [131, 136], [131, 139], [131, 152], [131, 155], [131, 156], [131, 158], [131, 159], [131, 161], [131, 162], [131, 167], [131, 172], [132, 140], [132, 146], [132, 153], [132, 161], [132, 167], [132, 168], [132, 176], [132, 177], [132, 179], [133, 135], [133, 136], [133, 145], [133, 147], [133, 151], [133, 155], [133, 157], [133, 159], [133, 168], [133, 172], [133, 175], [134, 135], [134, 140], [134, 142], [134, 144], [134, 156], [134, 161], [134, 165], [134, 166], [134, 168], [134, 169], [134, 170], [134, 172], [134, 173], [134, 176], [134, 178], [135, 136], [135, 138], [135, 139], [135, 157], [135, 159], [135, 163], [135, 171], [135, 173], [135, 174], [135, 179], [136, 149], [136, 151], [136, 161], [136, 164], [136, 172], [137, 150], [138, 148], [138, 152], [138, 153], [138, 155], [138, 160], [138, 161], [138, 170], [138, 174], [138, 179], [139, 141], [139, 145], [139, 152], [139, 157], [139, 161], [139, 165], [139, 166], [139, 167], [139, 170], [140, 142], [140, 155], [140, 158], [140, 159], [140, 169], [140, 173], [140, 174], [140, 176], [140, 178], [140, 179], [141, 154], [141, 157], [141, 159], [141, 160], [141, 167], [141, 170], [141, 176], [141, 177], [141, 178], [142, 148], [142, 153], [142, 156], [142, 157], [142, 159], [142, 160], [142, 170], [142, 173], [143, 147], [143, 149], [143, 158], [143, 161], [143, 165], [143, 166], [143, 175], [143, 176], [143, 177], [144, 153], [144, 165], [144, 169], [144, 172], [145, 152], [145, 160], [145, 167], [145, 168], [145, 176], [145, 177], [145, 179], [146, 154], [146, 163], [146, 168], [146, 172], [147, 158], [147, 167], [147, 178], [148, 151], [148, 161], [148, 165], [148, 171], [148, 172], [148, 173], [149, 153], [149, 158], [149, 163], [149, 165], [149, 167], [149, 168], [149, 171], [149, 172], [149, 173], [149, 177], [150, 153], [150, 161], [150, 168], [150, 176], [151, 154], [151, 158], [151, 159], [151, 162], [151, 164], [151, 165], [151, 166], [151, 172], [151, 174], [151, 177], [151, 178], [152, 169], [152, 177], [153, 154], [153, 155], [153, 157], [153, 158], [153, 160], [153, 166], [153, 167], [153, 169], [153, 170], [153, 172], [153, 173], [153, 176], [153, 177], [154, 155], [154, 157], [154, 160], [154, 168], [154, 169], [154, 171], [154, 178], [155, 157], [155, 161], [155, 167], [155, 176], [155, 177], [155, 178], [156, 166], [156, 168], [156, 170], [156, 178], [157, 164], [157, 166], [157, 167], [157, 171], [157, 172], [157, 179], [158, 159], [158, 161], [158, 178], [159, 171], [160, 162], [160, 169], [161, 162], [161, 169], [161, 176], [161, 177], [162, 168], [162, 176], [163, 166], [163, 167], [163, 171], [163, 175], [164, 165], [164, 167], [164, 169], [164, 172], [166, 173], [166, 175], [166, 176], [166, 177], [167, 169], [167, 170], [167, 174], [167, 175], [167, 176], [168, 179], [169, 172], [170, 171], [170, 175], [172, 176], [173, 176], [173, 177], [174, 178], [175, 177], [177, 178]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s3/solution/solve.sh b/tasks/construct-nppc-dominating-set-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8be7d97bb3c644e3d2d016eae6ed51ec3f8e80be --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [9, 13, 25, 27, 30, 48, 49, 56, 107, 127, 129, 130, 139, 151, 153]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l5-s3/tests/check.py b/tasks/construct-nppc-dominating-set-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s3/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-l5-s3/tests/instance.json b/tasks/construct-nppc-dominating-set-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7893f13d5370c7d271bce6cdc1f308aa8c3b25fc --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 4], [0, 13], [0, 21], [0, 22], [0, 23], [0, 28], [0, 32], [0, 37], [0, 38], [0, 48], [0, 49], [0, 55], [0, 68], [0, 78], [0, 82], [0, 84], [0, 86], [0, 87], [0, 88], [0, 99], [0, 102], [0, 103], [0, 107], [0, 110], [0, 122], [0, 123], [0, 127], [0, 130], [0, 132], [0, 134], [0, 142], [0, 146], [0, 150], [0, 153], [0, 155], [0, 157], [0, 159], [0, 160], [0, 162], [0, 167], [1, 2], [1, 4], [1, 7], [1, 9], [1, 11], [1, 14], [1, 15], [1, 19], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 33], [1, 41], [1, 43], [1, 45], [1, 47], [1, 68], [1, 73], [1, 82], [1, 92], [1, 93], [1, 94], [1, 95], [1, 103], [1, 109], [1, 112], [1, 114], [1, 126], [1, 135], [1, 141], [1, 142], [1, 147], [1, 159], [1, 167], [2, 9], [2, 10], [2, 11], [2, 23], [2, 26], [2, 28], [2, 30], [2, 31], [2, 37], [2, 45], [2, 47], [2, 59], [2, 66], [2, 67], [2, 68], [2, 75], [2, 76], [2, 85], [2, 86], [2, 88], [2, 89], [2, 91], [2, 99], [2, 107], [2, 109], [2, 118], [2, 122], [2, 126], [2, 128], [2, 137], [2, 138], [2, 139], [2, 140], [2, 146], [2, 148], [2, 153], [2, 169], [2, 172], [3, 4], [3, 10], [3, 18], [3, 27], [3, 28], [3, 31], [3, 41], [3, 42], [3, 55], [3, 58], [3, 61], [3, 67], [3, 68], [3, 72], [3, 73], [3, 93], [3, 95], [3, 99], [3, 104], [3, 107], [3, 108], [3, 111], [3, 112], [3, 117], [3, 132], [3, 141], [3, 142], [3, 146], [3, 153], [3, 154], [3, 165], [3, 166], [3, 167], [3, 171], [4, 7], [4, 11], [4, 28], [4, 32], [4, 42], [4, 48], [4, 52], [4, 63], [4, 86], [4, 103], [4, 109], [4, 114], [4, 115], [4, 118], [4, 119], [4, 120], [4, 126], [4, 128], [4, 130], [4, 144], [4, 148], [4, 158], [4, 165], [4, 173], [5, 15], [5, 33], [5, 39], [5, 41], [5, 43], [5, 46], [5, 48], [5, 49], [5, 53], [5, 54], [5, 58], [5, 68], [5, 72], [5, 82], [5, 91], [5, 102], [5, 106], [5, 107], [5, 115], [5, 124], [5, 132], [5, 143], [5, 151], [5, 153], [5, 154], [6, 7], [6, 10], [6, 18], [6, 19], [6, 22], [6, 29], [6, 30], [6, 48], [6, 50], [6, 53], [6, 57], [6, 72], [6, 77], [6, 104], [6, 105], [6, 110], [6, 113], [6, 114], [6, 115], [6, 127], [6, 139], [6, 140], [6, 144], [6, 151], [6, 154], [6, 155], [6, 159], [6, 162], [6, 164], [6, 170], [6, 177], [7, 9], [7, 11], [7, 19], [7, 22], [7, 29], [7, 37], [7, 62], [7, 64], [7, 68], [7, 72], [7, 77], [7, 78], [7, 82], [7, 83], [7, 84], [7, 85], [7, 93], [7, 105], [7, 107], [7, 110], [7, 111], [7, 115], [7, 118], [7, 123], [7, 127], [7, 131], [7, 139], [7, 143], [7, 152], [7, 153], [7, 156], [7, 167], [7, 171], [7, 176], [8, 11], [8, 13], [8, 18], [8, 24], [8, 27], [8, 29], [8, 38], [8, 39], [8, 41], [8, 43], [8, 44], [8, 48], [8, 51], [8, 63], [8, 70], [8, 71], [8, 84], [8, 90], [8, 98], [8, 102], [8, 104], [8, 111], [8, 113], [8, 117], [8, 131], [8, 133], [8, 136], [8, 144], [8, 152], [8, 153], [8, 160], [8, 177], [9, 15], [9, 19], [9, 23], [9, 24], [9, 29], [9, 30], [9, 38], [9, 41], [9, 42], [9, 49], [9, 51], [9, 58], [9, 68], [9, 69], [9, 72], [9, 82], [9, 83], [9, 85], [9, 89], [9, 90], [9, 93], [9, 94], [9, 96], [9, 98], [9, 101], [9, 105], [9, 106], [9, 110], [9, 114], [9, 116], [9, 117], [9, 124], [9, 137], [9, 139], [9, 147], [9, 149], [9, 157], [9, 158], [9, 163], [9, 170], [10, 20], [10, 22], [10, 23], [10, 28], [10, 31], [10, 38], [10, 40], [10, 44], [10, 63], [10, 64], [10, 67], [10, 71], [10, 75], [10, 83], [10, 88], [10, 91], [10, 98], [10, 109], [10, 117], [10, 118], [10, 122], [10, 129], [10, 134], [10, 138], [10, 140], [10, 144], [10, 151], [10, 154], [10, 158], [10, 159], [10, 163], [10, 167], [10, 171], [11, 12], [11, 16], [11, 20], [11, 25], [11, 28], [11, 29], [11, 30], [11, 39], [11, 50], [11, 65], [11, 72], [11, 73], [11, 79], [11, 80], [11, 86], [11, 92], [11, 96], [11, 99], [11, 103], [11, 114], [11, 120], [11, 122], [11, 131], [11, 135], [11, 137], [11, 147], [11, 149], [11, 151], [11, 165], [11, 178], [11, 179], [12, 15], [12, 16], [12, 19], [12, 22], [12, 28], [12, 29], [12, 34], [12, 36], [12, 41], [12, 44], [12, 49], [12, 55], [12, 57], [12, 60], [12, 61], [12, 62], [12, 69], [12, 70], [12, 76], [12, 79], [12, 81], [12, 84], [12, 85], [12, 86], [12, 88], [12, 96], [12, 100], [12, 107], [12, 112], [12, 116], [12, 119], [12, 127], [12, 131], [12, 146], [12, 151], [12, 161], [12, 170], [12, 177], [13, 14], [13, 22], [13, 30], [13, 38], [13, 40], [13, 42], [13, 43], [13, 47], [13, 52], [13, 54], [13, 55], [13, 58], [13, 59], [13, 69], [13, 70], [13, 71], [13, 75], [13, 76], [13, 78], [13, 82], [13, 86], [13, 88], [13, 98], [13, 106], [13, 108], [13, 109], [13, 110], [13, 115], [13, 119], [13, 131], [13, 133], [13, 142], [13, 146], [13, 148], [13, 154], [13, 155], [13, 158], [13, 163], [13, 167], [13, 168], [13, 171], [14, 22], [14, 30], [14, 31], [14, 37], [14, 38], [14, 40], [14, 44], [14, 47], [14, 51], [14, 55], [14, 64], [14, 71], [14, 73], [14, 79], [14, 86], [14, 91], [14, 93], [14, 97], [14, 101], [14, 103], [14, 106], [14, 108], [14, 125], [14, 130], [14, 133], [14, 137], [14, 141], [14, 144], [14, 146], [14, 165], [14, 167], [15, 21], [15, 25], [15, 30], [15, 38], [15, 39], [15, 48], [15, 54], [15, 59], [15, 66], [15, 67], [15, 73], [15, 74], [15, 82], [15, 93], [15, 94], [15, 106], [15, 108], [15, 115], [15, 118], [15, 120], [15, 126], [15, 128], [15, 129], [15, 131], [15, 132], [15, 133], [15, 138], [15, 141], [15, 148], [15, 162], [15, 166], [15, 170], [15, 177], [15, 179], [16, 17], [16, 19], [16, 20], [16, 27], [16, 33], [16, 38], [16, 44], [16, 47], [16, 50], [16, 57], [16, 63], [16, 64], [16, 66], [16, 68], [16, 72], [16, 75], [16, 77], [16, 79], [16, 87], [16, 89], [16, 90], [16, 95], [16, 101], [16, 104], [16, 105], [16, 106], [16, 118], [16, 121], [16, 122], [16, 125], [16, 126], [16, 129], [16, 131], [16, 134], [16, 135], [16, 136], [16, 139], [16, 149], [16, 151], [16, 154], [16, 157], [16, 162], [16, 163], [16, 167], [16, 169], [16, 179], [17, 20], [17, 22], [17, 27], [17, 30], [17, 35], [17, 38], [17, 40], [17, 43], [17, 47], [17, 49], [17, 53], [17, 58], [17, 67], [17, 71], [17, 76], [17, 80], [17, 81], [17, 87], [17, 92], [17, 101], [17, 104], [17, 105], [17, 107], [17, 110], [17, 113], [17, 116], [17, 118], [17, 120], [17, 121], [17, 122], [17, 129], [17, 131], [17, 141], [17, 146], [17, 150], [17, 155], [17, 160], [17, 163], [18, 20], [18, 24], [18, 29], [18, 31], [18, 37], [18, 40], [18, 55], [18, 58], [18, 69], [18, 71], [18, 73], [18, 84], [18, 87], [18, 97], [18, 99], [18, 100], [18, 116], [18, 118], [18, 120], [18, 122], [18, 123], [18, 129], [18, 131], [18, 136], [18, 137], [18, 143], [18, 151], [18, 162], [18, 169], [18, 177], [19, 20], [19, 21], [19, 29], [19, 31], [19, 47], [19, 48], [19, 50], [19, 52], [19, 58], [19, 62], [19, 63], [19, 64], [19, 65], [19, 69], [19, 73], [19, 86], [19, 89], [19, 91], [19, 92], [19, 93], [19, 102], [19, 107], [19, 108], [19, 124], [19, 129], [19, 133], [19, 137], [19, 138], [19, 141], [19, 151], [19, 155], [19, 157], [19, 163], [19, 165], [19, 168], [19, 173], [19, 174], [19, 175], [19, 176], [20, 21], [20, 35], [20, 37], [20, 39], [20, 41], [20, 45], [20, 59], [20, 78], [20, 83], [20, 92], [20, 99], [20, 101], [20, 106], [20, 110], [20, 120], [20, 127], [20, 130], [20, 135], [20, 136], [20, 137], [20, 138], [20, 139], [20, 157], [20, 167], [21, 24], [21, 34], [21, 39], [21, 42], [21, 48], [21, 49], [21, 52], [21, 54], [21, 66], [21, 68], [21, 77], [21, 81], [21, 90], [21, 91], [21, 97], [21, 101], [21, 103], [21, 106], [21, 113], [21, 128], [21, 129], [21, 130], [21, 145], [21, 160], [21, 165], [21, 167], [21, 169], [21, 173], [21, 174], [21, 176], [21, 179], [22, 24], [22, 25], [22, 27], [22, 38], [22, 42], [22, 43], [22, 44], [22, 56], [22, 57], [22, 60], [22, 65], [22, 66], [22, 70], [22, 78], [22, 84], [22, 89], [22, 99], [22, 105], [22, 107], [22, 116], [22, 120], [22, 125], [22, 126], [22, 127], [22, 140], [22, 141], [22, 142], [22, 144], [22, 148], [22, 163], [22, 165], [22, 166], [22, 170], [22, 171], [22, 174], [22, 176], [23, 25], [23, 40], [23, 56], [23, 59], [23, 64], [23, 70], [23, 71], [23, 72], [23, 74], [23, 96], [23, 100], [23, 107], [23, 111], [23, 115], [23, 122], [23, 126], [23, 128], [23, 130], [23, 132], [23, 133], [23, 134], [23, 137], [23, 149], [23, 155], [23, 165], [23, 171], [23, 177], [24, 25], [24, 27], [24, 28], [24, 49], [24, 58], [24, 71], [24, 73], [24, 74], [24, 77], [24, 78], [24, 79], [24, 82], [24, 86], [24, 96], [24, 98], [24, 128], [24, 135], [24, 136], [24, 141], [24, 146], [24, 148], [24, 154], [24, 165], [24, 174], [25, 28], [25, 31], [25, 36], [25, 37], [25, 41], [25, 45], [25, 46], [25, 47], [25, 48], [25, 52], [25, 53], [25, 55], [25, 65], [25, 67], [25, 73], [25, 80], [25, 87], [25, 91], [25, 95], [25, 98], [25, 99], [25, 101], [25, 103], [25, 104], [25, 106], [25, 117], [25, 119], [25, 123], [25, 130], [25, 132], [25, 136], [25, 137], [25, 138], [25, 141], [25, 144], [25, 147], [25, 152], [25, 156], [25, 158], [25, 164], [25, 165], [25, 170], [25, 172], [25, 173], [26, 33], [26, 35], [26, 37], [26, 39], [26, 45], [26, 47], [26, 65], [26, 76], [26, 79], [26, 83], [26, 86], [26, 90], [26, 103], [26, 109], [26, 119], [26, 127], [26, 128], [26, 129], [26, 131], [26, 137], [26, 138], [26, 141], [26, 148], [26, 149], [26, 150], [26, 152], [26, 157], [26, 159], [26, 160], [26, 162], [26, 164], [26, 168], [26, 172], [26, 173], [26, 177], [26, 179], [27, 34], [27, 40], [27, 41], [27, 43], [27, 44], [27, 47], [27, 53], [27, 54], [27, 58], [27, 63], [27, 74], [27, 75], [27, 77], [27, 79], [27, 85], [27, 89], [27, 94], [27, 98], [27, 107], [27, 114], [27, 116], [27, 119], [27, 125], [27, 128], [27, 133], [27, 144], [27, 145], [27, 146], [27, 149], [27, 150], [27, 155], [27, 156], [27, 159], [27, 160], [27, 164], [27, 173], [28, 32], [28, 39], [28, 40], [28, 41], [28, 42], [28, 64], [28, 67], [28, 68], [28, 74], [28, 76], [28, 77], [28, 78], [28, 79], [28, 82], [28, 87], [28, 89], [28, 93], [28, 95], [28, 97], [28, 99], [28, 106], [28, 114], [28, 116], [28, 124], [28, 128], [28, 129], [28, 131], [28, 134], [28, 149], [28, 151], [28, 161], [28, 170], [28, 171], [28, 176], [29, 34], [29, 43], [29, 47], [29, 49], [29, 57], [29, 62], [29, 64], [29, 68], [29, 74], [29, 80], [29, 84], [29, 87], [29, 94], [29, 95], [29, 104], [29, 105], [29, 111], [29, 120], [29, 130], [29, 137], [29, 141], [29, 146], [29, 149], [29, 150], [29, 153], [29, 157], [29, 164], [29, 172], [30, 32], [30, 36], [30, 37], [30, 42], [30, 51], [30, 57], [30, 59], [30, 61], [30, 64], [30, 67], [30, 72], [30, 73], [30, 74], [30, 84], [30, 88], [30, 89], [30, 94], [30, 95], [30, 96], [30, 102], [30, 108], [30, 112], [30, 120], [30, 123], [30, 127], [30, 130], [30, 136], [30, 141], [30, 144], [30, 145], [30, 148], [30, 156], [30, 171], [30, 175], [30, 176], [30, 179], [31, 32], [31, 47], [31, 60], [31, 62], [31, 66], [31, 69], [31, 77], [31, 79], [31, 87], [31, 117], [31, 120], [31, 128], [31, 130], [31, 131], [31, 143], [31, 148], [31, 149], [31, 156], [31, 159], [31, 161], [31, 163], [31, 167], [31, 169], [31, 174], [31, 179], [32, 39], [32, 43], [32, 51], [32, 61], [32, 64], [32, 69], [32, 70], [32, 73], [32, 77], [32, 83], [32, 85], [32, 88], [32, 89], [32, 94], [32, 95], [32, 98], [32, 100], [32, 101], [32, 102], [32, 104], [32, 105], [32, 107], [32, 108], [32, 114], [32, 121], [32, 126], [32, 128], [32, 136], [32, 142], [32, 146], [32, 147], [32, 149], [32, 151], [32, 153], [32, 162], [32, 170], [32, 171], [32, 177], [32, 178], [32, 179], [33, 34], [33, 38], [33, 48], [33, 49], [33, 56], [33, 60], [33, 75], [33, 77], [33, 81], [33, 84], [33, 87], [33, 88], [33, 93], [33, 96], [33, 106], [33, 113], [33, 117], [33, 120], [33, 128], [33, 130], [33, 131], [33, 133], [33, 144], [33, 145], [33, 148], [33, 154], [33, 155], [33, 157], [33, 158], [33, 168], [33, 172], [33, 176], [34, 39], [34, 41], [34, 45], [34, 52], [34, 65], [34, 75], [34, 79], [34, 82], [34, 83], [34, 87], [34, 89], [34, 90], [34, 91], [34, 94], [34, 98], [34, 101], [34, 105], [34, 106], [34, 107], [34, 116], [34, 119], [34, 121], [34, 122], [34, 131], [34, 140], [34, 143], [34, 153], [34, 161], [34, 167], [34, 168], [34, 170], [34, 171], [34, 179], [35, 40], [35, 49], [35, 55], [35, 56], [35, 63], [35, 68], [35, 69], [35, 70], [35, 73], [35, 78], [35, 85], [35, 90], [35, 97], [35, 99], [35, 101], [35, 104], [35, 111], [35, 118], [35, 122], [35, 123], [35, 124], [35, 128], [35, 130], [35, 133], [35, 145], [35, 149], [35, 154], [35, 156], [35, 168], [35, 173], [35, 174], [36, 41], [36, 48], [36, 51], [36, 56], [36, 77], [36, 82], [36, 87], [36, 91], [36, 93], [36, 99], [36, 106], [36, 107], [36, 108], [36, 110], [36, 113], [36, 114], [36, 116], [36, 119], [36, 127], [36, 129], [36, 132], [36, 136], [36, 138], [36, 139], [36, 150], [36, 157], [36, 162], [36, 164], [36, 169], [36, 176], [37, 39], [37, 44], [37, 49], [37, 56], [37, 59], [37, 63], [37, 69], [37, 84], [37, 88], [37, 96], [37, 101], [37, 109], [37, 119], [37, 127], [37, 129], [37, 134], [37, 139], [37, 146], [37, 159], [37, 162], [37, 163], [37, 165], [37, 167], [38, 41], [38, 43], [38, 47], [38, 51], [38, 52], [38, 56], [38, 68], [38, 70], [38, 73], [38, 75], [38, 80], [38, 91], [38, 97], [38, 104], [38, 110], [38, 115], [38, 116], [38, 120], [38, 121], [38, 135], [38, 143], [38, 157], [38, 163], [38, 165], [38, 168], [38, 169], [38, 172], [38, 173], [39, 43], [39, 49], [39, 68], [39, 72], [39, 76], [39, 81], [39, 82], [39, 88], [39, 89], [39, 100], [39, 101], [39, 103], [39, 104], [39, 107], [39, 109], [39, 110], [39, 121], [39, 123], [39, 129], [39, 137], [39, 139], [39, 140], [39, 143], [39, 147], [39, 149], [39, 151], [39, 154], [39, 155], [39, 162], [39, 165], [39, 170], [39, 171], [40, 44], [40, 46], [40, 51], [40, 53], [40, 59], [40, 60], [40, 71], [40, 81], [40, 87], [40, 88], [40, 89], [40, 96], [40, 106], [40, 107], [40, 121], [40, 123], [40, 125], [40, 130], [40, 134], [40, 135], [40, 136], [40, 140], [40, 142], [40, 152], [40, 163], [40, 171], [40, 174], [40, 176], [41, 43], [41, 45], [41, 52], [41, 54], [41, 56], [41, 57], [41, 62], [41, 63], [41, 74], [41, 77], [41, 90], [41, 105], [41, 112], [41, 115], [41, 116], [41, 119], [41, 123], [41, 135], [41, 153], [41, 154], [41, 161], [41, 163], [41, 167], [42, 46], [42, 51], [42, 54], [42, 56], [42, 61], [42, 65], [42, 70], [42, 72], [42, 73], [42, 75], [42, 77], [42, 93], [42, 94], [42, 98], [42, 100], [42, 112], [42, 113], [42, 115], [42, 116], [42, 119], [42, 136], [42, 139], [42, 142], [42, 145], [42, 146], [42, 147], [42, 158], [42, 160], [42, 163], [42, 165], [42, 167], [42, 168], [42, 169], [42, 170], [42, 173], [42, 177], [43, 59], [43, 68], [43, 70], [43, 79], [43, 81], [43, 82], [43, 85], [43, 86], [43, 87], [43, 101], [43, 119], [43, 126], [43, 132], [43, 144], [43, 149], [43, 152], [43, 156], [43, 163], [43, 173], [44, 46], [44, 47], [44, 54], [44, 56], [44, 58], [44, 66], [44, 72], [44, 75], [44, 77], [44, 79], [44, 81], [44, 83], [44, 86], [44, 87], [44, 88], [44, 95], [44, 99], [44, 100], [44, 121], [44, 125], [44, 138], [44, 149], [44, 153], [44, 155], [44, 158], [44, 160], [45, 46], [45, 50], [45, 56], [45, 66], [45, 68], [45, 82], [45, 83], [45, 92], [45, 94], [45, 102], [45, 109], [45, 111], [45, 117], [45, 129], [45, 130], [45, 133], [45, 149], [45, 150], [45, 153], [45, 161], [45, 171], [45, 172], [45, 174], [45, 178], [46, 47], [46, 51], [46, 52], [46, 53], [46, 55], [46, 56], [46, 59], [46, 63], [46, 71], [46, 72], [46, 93], [46, 98], [46, 99], [46, 100], [46, 107], [46, 110], [46, 112], [46, 119], [46, 121], [46, 134], [46, 137], [46, 145], [46, 146], [46, 154], [46, 157], [46, 161], [46, 169], [46, 170], [46, 172], [47, 52], [47, 56], [47, 75], [47, 79], [47, 82], [47, 86], [47, 97], [47, 98], [47, 100], [47, 105], [47, 107], [47, 111], [47, 123], [47, 125], [47, 127], [47, 138], [47, 143], [47, 152], [47, 165], [47, 169], [47, 171], [47, 173], [47, 174], [48, 52], [48, 55], [48, 58], [48, 65], [48, 69], [48, 70], [48, 71], [48, 75], [48, 76], [48, 78], [48, 81], [48, 89], [48, 95], [48, 97], [48, 99], [48, 101], [48, 103], [48, 113], [48, 114], [48, 134], [48, 135], [48, 138], [48, 149], [48, 153], [48, 165], [48, 174], [48, 177], [49, 50], [49, 58], [49, 60], [49, 62], [49, 64], [49, 67], [49, 70], [49, 71], [49, 77], [49, 82], [49, 87], [49, 88], [49, 95], [49, 97], [49, 104], [49, 105], [49, 106], [49, 113], [49, 117], [49, 118], [49, 134], [49, 136], [49, 142], [49, 143], [49, 155], [49, 156], [49, 159], [49, 168], [49, 170], [49, 173], [49, 176], [50, 54], [50, 63], [50, 64], [50, 67], [50, 70], [50, 79], [50, 83], [50, 88], [50, 97], [50, 98], [50, 102], [50, 104], [50, 105], [50, 110], [50, 113], [50, 121], [50, 128], [50, 131], [50, 133], [50, 139], [50, 140], [50, 142], [50, 148], [50, 161], [50, 168], [50, 174], [50, 178], [51, 55], [51, 56], [51, 63], [51, 64], [51, 70], [51, 78], [51, 83], [51, 90], [51, 99], [51, 100], [51, 105], [51, 107], [51, 110], [51, 117], [51, 120], [51, 127], [51, 128], [51, 130], [51, 137], [51, 159], [51, 162], [51, 167], [51, 171], [51, 173], [51, 175], [51, 179], [52, 57], [52, 61], [52, 62], [52, 66], [52, 69], [52, 71], [52, 73], [52, 82], [52, 84], [52, 90], [52, 92], [52, 101], [52, 102], [52, 103], [52, 105], [52, 110], [52, 116], [52, 118], [52, 119], [52, 120], [52, 124], [52, 125], [52, 132], [52, 134], [52, 151], [52, 153], [52, 155], [52, 156], [52, 160], [52, 165], [52, 168], [52, 169], [52, 172], [52, 175], [53, 56], [53, 57], [53, 60], [53, 62], [53, 66], [53, 70], [53, 72], [53, 81], [53, 91], [53, 103], [53, 108], [53, 112], [53, 116], [53, 121], [53, 132], [53, 135], [53, 141], [53, 143], [53, 144], [53, 148], [53, 150], [53, 160], [53, 165], [53, 166], [53, 178], [54, 55], [54, 61], [54, 64], [54, 74], [54, 81], [54, 86], [54, 88], [54, 97], [54, 100], [54, 105], [54, 107], [54, 108], [54, 113], [54, 115], [54, 120], [54, 121], [54, 122], [54, 128], [54, 129], [54, 156], [54, 162], [54, 168], [54, 170], [54, 172], [54, 173], [54, 174], [54, 175], [55, 58], [55, 60], [55, 64], [55, 66], [55, 68], [55, 80], [55, 85], [55, 89], [55, 93], [55, 94], [55, 98], [55, 111], [55, 120], [55, 134], [55, 137], [55, 149], [55, 152], [55, 170], [55, 176], [56, 59], [56, 62], [56, 63], [56, 65], [56, 68], [56, 72], [56, 74], [56, 75], [56, 76], [56, 80], [56, 85], [56, 92], [56, 93], [56, 102], [56, 113], [56, 115], [56, 116], [56, 119], [56, 120], [56, 126], [56, 132], [56, 136], [56, 142], [56, 143], [56, 145], [56, 151], [56, 153], [56, 155], [56, 159], [56, 174], [56, 176], [56, 177], [57, 62], [57, 67], [57, 68], [57, 74], [57, 78], [57, 79], [57, 83], [57, 87], [57, 88], [57, 91], [57, 102], [57, 110], [57, 114], [57, 118], [57, 121], [57, 124], [57, 129], [57, 148], [57, 149], [57, 153], [57, 156], [57, 163], [57, 164], [57, 168], [57, 170], [57, 172], [58, 70], [58, 73], [58, 74], [58, 83], [58, 84], [58, 88], [58, 94], [58, 98], [58, 100], [58, 101], [58, 103], [58, 105], [58, 107], [58, 118], [58, 122], [58, 125], [58, 128], [58, 132], [58, 142], [58, 151], [58, 153], [58, 156], [58, 157], [58, 161], [58, 162], [58, 179], [59, 62], [59, 65], [59, 76], [59, 81], [59, 83], [59, 92], [59, 93], [59, 95], [59, 105], [59, 107], [59, 116], [59, 127], [59, 134], [59, 135], [59, 139], [59, 144], [59, 151], [59, 154], [59, 156], [59, 159], [59, 165], [59, 168], [59, 171], [59, 173], [59, 174], [59, 175], [59, 177], [60, 67], [60, 70], [60, 75], [60, 77], [60, 78], [60, 79], [60, 80], [60, 92], [60, 104], [60, 112], [60, 118], [60, 126], [60, 129], [60, 130], [60, 134], [60, 141], [60, 150], [60, 153], [60, 165], [60, 174], [61, 64], [61, 68], [61, 70], [61, 71], [61, 74], [61, 87], [61, 88], [61, 95], [61, 98], [61, 110], [61, 119], [61, 124], [61, 139], [61, 144], [61, 154], [61, 157], [61, 162], [61, 172], [62, 67], [62, 69], [62, 72], [62, 74], [62, 83], [62, 87], [62, 89], [62, 104], [62, 105], [62, 108], [62, 109], [62, 113], [62, 121], [62, 124], [62, 125], [62, 127], [62, 128], [62, 135], [62, 143], [62, 149], [62, 150], [62, 159], [62, 165], [62, 168], [62, 169], [62, 172], [62, 174], [62, 176], [62, 177], [62, 179], [63, 68], [63, 71], [63, 74], [63, 82], [63, 89], [63, 90], [63, 95], [63, 101], [63, 106], [63, 108], [63, 112], [63, 116], [63, 124], [63, 127], [63, 130], [63, 135], [63, 137], [63, 159], [63, 163], [63, 168], [63, 169], [63, 175], [63, 178], [63, 179], [64, 67], [64, 71], [64, 72], [64, 74], [64, 84], [64, 87], [64, 91], [64, 94], [64, 95], [64, 109], [64, 111], [64, 117], [64, 122], [64, 124], [64, 131], [64, 137], [64, 139], [64, 147], [64, 149], [64, 150], [64, 168], [64, 169], [64, 178], [65, 68], [65, 73], [65, 76], [65, 81], [65, 84], [65, 86], [65, 87], [65, 100], [65, 101], [65, 111], [65, 118], [65, 119], [65, 123], [65, 131], [65, 134], [65, 135], [65, 136], [65, 138], [65, 151], [65, 164], [65, 167], [65, 172], [65, 176], [66, 68], [66, 79], [66, 80], [66, 82], [66, 83], [66, 85], [66, 94], [66, 100], [66, 104], [66, 108], [66, 118], [66, 119], [66, 123], [66, 126], [66, 129], [66, 130], [66, 138], [66, 139], [66, 144], [66, 155], [66, 162], [66, 167], [66, 168], [66, 176], [67, 71], [67, 72], [67, 73], [67, 75], [67, 77], [67, 79], [67, 82], [67, 97], [67, 100], [67, 102], [67, 111], [67, 116], [67, 129], [67, 142], [67, 144], [67, 146], [67, 153], [67, 159], [67, 162], [67, 165], [67, 168], [67, 174], [67, 177], [68, 69], [68, 72], [68, 75], [68, 78], [68, 80], [68, 95], [68, 107], [68, 108], [68, 111], [68, 116], [68, 117], [68, 119], [68, 121], [68, 132], [68, 133], [68, 136], [68, 141], [68, 144], [68, 165], [68, 166], [69, 80], [69, 83], [69, 84], [69, 100], [69, 101], [69, 102], [69, 106], [69, 124], [69, 129], [69, 134], [69, 138], [69, 144], [69, 156], [69, 170], [69, 173], [70, 72], [70, 78], [70, 79], [70, 86], [70, 95], [70, 99], [70, 105], [70, 107], [70, 114], [70, 119], [70, 124], [70, 128], [70, 137], [70, 138], [70, 140], [70, 145], [70, 156], [70, 160], [70, 166], [70, 169], [70, 177], [71, 80], [71, 86], [71, 95], [71, 103], [71, 107], [71, 113], [71, 129], [71, 138], [71, 140], [71, 150], [71, 156], [71, 167], [71, 170], [71, 174], [71, 178], [72, 79], [72, 85], [72, 87], [72, 93], [72, 97], [72, 100], [72, 103], [72, 105], [72, 111], [72, 113], [72, 118], [72, 125], [72, 132], [72, 157], [72, 159], [72, 160], [72, 166], [72, 177], [73, 74], [73, 78], [73, 81], [73, 83], [73, 84], [73, 86], [73, 88], [73, 89], [73, 91], [73, 92], [73, 96], [73, 98], [73, 99], [73, 102], [73, 107], [73, 108], [73, 114], [73, 131], [73, 132], [73, 139], [73, 140], [73, 150], [73, 154], [73, 159], [73, 160], [73, 164], [73, 172], [73, 175], [73, 178], [73, 179], [74, 76], [74, 78], [74, 117], [74, 118], [74, 122], [74, 123], [74, 135], [74, 139], [74, 146], [74, 162], [74, 165], [74, 169], [74, 171], [74, 172], [74, 174], [74, 179], [75, 85], [75, 91], [75, 102], [75, 106], [75, 111], [75, 117], [75, 123], [75, 127], [75, 131], [75, 137], [75, 141], [75, 148], [75, 152], [75, 162], [75, 171], [75, 173], [75, 175], [75, 178], [76, 77], [76, 80], [76, 81], [76, 91], [76, 96], [76, 97], [76, 109], [76, 112], [76, 118], [76, 120], [76, 121], [76, 125], [76, 126], [76, 129], [76, 135], [76, 139], [76, 140], [76, 142], [76, 145], [76, 153], [76, 155], [76, 160], [76, 162], [76, 170], [76, 172], [76, 177], [76, 179], [77, 78], [77, 79], [77, 94], [77, 98], [77, 99], [77, 103], [77, 106], [77, 113], [77, 114], [77, 115], [77, 119], [77, 123], [77, 128], [77, 130], [77, 135], [77, 136], [77, 139], [77, 145], [77, 146], [77, 149], [77, 151], [77, 153], [77, 155], [77, 174], [77, 179], [78, 87], [78, 90], [78, 93], [78, 94], [78, 100], [78, 110], [78, 111], [78, 114], [78, 116], [78, 127], [78, 131], [78, 135], [78, 143], [78, 146], [78, 147], [78, 149], [78, 150], [78, 159], [78, 171], [78, 173], [79, 82], [79, 85], [79, 94], [79, 95], [79, 97], [79, 104], [79, 108], [79, 112], [79, 117], [79, 128], [79, 130], [79, 135], [79, 138], [79, 149], [79, 150], [79, 151], [79, 152], [79, 154], [79, 166], [79, 168], [79, 174], [79, 177], [80, 97], [80, 107], [80, 108], [80, 114], [80, 120], [80, 128], [80, 132], [80, 135], [80, 146], [80, 151], [80, 154], [80, 158], [80, 160], [80, 168], [80, 170], [81, 91], [81, 95], [81, 100], [81, 111], [81, 117], [81, 118], [81, 123], [81, 125], [81, 126], [81, 136], [81, 138], [81, 141], [81, 148], [81, 150], [81, 152], [81, 153], [81, 158], [81, 159], [81, 165], [81, 166], [81, 170], [81, 178], [82, 83], [82, 101], [82, 109], [82, 114], [82, 117], [82, 119], [82, 120], [82, 121], [82, 129], [82, 130], [82, 131], [82, 135], [82, 153], [82, 154], [82, 160], [82, 161], [82, 162], [82, 163], [82, 165], [82, 167], [82, 175], [83, 91], [83, 94], [83, 102], [83, 105], [83, 106], [83, 107], [83, 109], [83, 110], [83, 113], [83, 115], [83, 119], [83, 121], [83, 123], [83, 125], [83, 150], [83, 151], [83, 153], [83, 159], [83, 162], [83, 166], [83, 179], [84, 85], [84, 92], [84, 93], [84, 97], [84, 103], [84, 104], [84, 106], [84, 109], [84, 110], [84, 113], [84, 114], [84, 118], [84, 123], [84, 140], [84, 150], [84, 151], [84, 154], [84, 155], [84, 156], [84, 161], [84, 163], [84, 166], [84, 172], [84, 173], [84, 175], [85, 86], [85, 96], [85, 98], [85, 99], [85, 104], [85, 105], [85, 121], [85, 122], [85, 123], [85, 124], [85, 127], [85, 135], [85, 138], [85, 140], [85, 143], [85, 145], [85, 150], [85, 172], [85, 177], [85, 178], [86, 90], [86, 92], [86, 96], [86, 97], [86, 101], [86, 106], [86, 111], [86, 113], [86, 114], [86, 115], [86, 116], [86, 117], [86, 119], [86, 120], [86, 122], [86, 135], [86, 140], [86, 150], [86, 152], [86, 153], [86, 169], [86, 173], [87, 92], [87, 112], [87, 131], [87, 133], [87, 138], [87, 139], [87, 142], [87, 144], [87, 151], [87, 153], [87, 158], [87, 166], [87, 175], [87, 178], [87, 179], [88, 100], [88, 101], [88, 102], [88, 107], [88, 109], [88, 121], [88, 124], [88, 127], [88, 133], [88, 138], [88, 140], [88, 149], [88, 166], [88, 167], [88, 169], [88, 176], [88, 177], [88, 179], [89, 90], [89, 91], [89, 93], [89, 95], [89, 97], [89, 101], [89, 103], [89, 114], [89, 120], [89, 123], [89, 124], [89, 128], [89, 133], [89, 136], [89, 140], [89, 142], [89, 147], [89, 157], [89, 158], [89, 159], [89, 160], [89, 179], [90, 102], [90, 103], [90, 105], [90, 109], [90, 118], [90, 125], [90, 129], [90, 133], [90, 136], [90, 139], [90, 143], [90, 151], [90, 162], [90, 165], [90, 171], [90, 172], [90, 173], [90, 177], [90, 179], [91, 96], [91, 99], [91, 100], [91, 106], [91, 107], [91, 108], [91, 114], [91, 115], [91, 119], [91, 120], [91, 123], [91, 127], [91, 131], [91, 136], [91, 142], [91, 154], [91, 155], [91, 164], [91, 165], [91, 169], [91, 173], [91, 176], [92, 98], [92, 118], [92, 119], [92, 124], [92, 135], [92, 136], [92, 142], [92, 149], [92, 151], [92, 156], [92, 163], [92, 167], [92, 168], [93, 95], [93, 99], [93, 121], [93, 126], [93, 127], [93, 129], [93, 131], [93, 136], [93, 148], [93, 155], [93, 166], [93, 176], [94, 95], [94, 107], [94, 111], [94, 116], [94, 117], [94, 119], [94, 122], [94, 125], [94, 136], [94, 158], [94, 161], [94, 170], [94, 173], [94, 176], [95, 99], [95, 108], [95, 110], [95, 118], [95, 120], [95, 121], [95, 122], [95, 126], [95, 129], [95, 131], [95, 132], [95, 133], [95, 134], [95, 136], [95, 146], [95, 149], [95, 151], [95, 153], [95, 161], [96, 99], [96, 105], [96, 114], [96, 129], [96, 137], [96, 143], [96, 147], [96, 149], [96, 151], [96, 152], [96, 158], [96, 159], [96, 166], [96, 176], [97, 100], [97, 107], [97, 108], [97, 113], [97, 114], [97, 129], [97, 140], [97, 143], [97, 167], [97, 170], [97, 172], [98, 105], [98, 110], [98, 122], [98, 123], [98, 124], [98, 127], [98, 134], [98, 137], [98, 143], [98, 145], [98, 151], [98, 153], [98, 159], [98, 161], [98, 163], [98, 165], [98, 170], [98, 174], [98, 178], [99, 101], [99, 104], [99, 105], [99, 106], [99, 129], [99, 134], [99, 136], [99, 139], [99, 155], [99, 156], [99, 162], [99, 167], [99, 169], [99, 173], [100, 111], [100, 112], [100, 124], [100, 130], [100, 131], [100, 133], [100, 138], [100, 155], [100, 160], [100, 170], [100, 175], [101, 106], [101, 113], [101, 114], [101, 115], [101, 120], [101, 130], [101, 145], [101, 146], [101, 147], [101, 148], [101, 151], [101, 152], [101, 162], [101, 175], [101, 177], [101, 178], [102, 106], [102, 108], [102, 110], [102, 113], [102, 119], [102, 121], [102, 129], [102, 142], [102, 151], [102, 156], [102, 161], [102, 169], [102, 176], [102, 179], [103, 114], [103, 119], [103, 121], [103, 122], [103, 127], [103, 129], [103, 131], [103, 134], [103, 137], [103, 140], [103, 141], [103, 150], [103, 164], [103, 169], [103, 170], [103, 179], [104, 106], [104, 110], [104, 119], [104, 121], [104, 122], [104, 126], [104, 130], [104, 133], [104, 139], [104, 143], [104, 146], [104, 149], [104, 153], [104, 167], [104, 171], [104, 176], [104, 179], [105, 108], [105, 112], [105, 114], [105, 115], [105, 122], [105, 124], [105, 126], [105, 136], [105, 139], [105, 142], [105, 159], [105, 161], [105, 165], [105, 168], [105, 173], [105, 174], [106, 110], [106, 120], [106, 128], [106, 131], [106, 132], [106, 136], [106, 139], [106, 140], [106, 142], [106, 144], [106, 146], [106, 151], [106, 156], [106, 167], [106, 169], [106, 171], [106, 172], [107, 108], [107, 111], [107, 123], [107, 126], [107, 132], [107, 139], [107, 141], [107, 146], [107, 148], [107, 151], [107, 154], [107, 157], [107, 159], [107, 162], [107, 164], [107, 172], [107, 174], [107, 179], [108, 114], [108, 118], [108, 127], [108, 128], [108, 133], [108, 136], [108, 138], [108, 144], [108, 149], [108, 150], [108, 156], [108, 162], [108, 166], [108, 167], [108, 174], [108, 178], [108, 179], [109, 111], [109, 114], [109, 127], [109, 129], [109, 131], [109, 141], [109, 154], [109, 164], [109, 165], [109, 174], [110, 120], [110, 121], [110, 124], [110, 142], [110, 148], [110, 152], [110, 162], [110, 165], [110, 167], [110, 172], [110, 173], [110, 179], [111, 116], [111, 122], [111, 126], [111, 131], [111, 149], [111, 151], [111, 154], [111, 157], [111, 160], [111, 162], [111, 164], [111, 178], [112, 116], [112, 117], [112, 118], [112, 119], [112, 122], [112, 126], [112, 130], [112, 140], [112, 151], [112, 160], [112, 161], [112, 173], [112, 174], [113, 131], [113, 138], [113, 139], [113, 145], [113, 153], [113, 154], [113, 157], [113, 158], [113, 163], [113, 172], [113, 173], [113, 175], [113, 177], [114, 117], [114, 121], [114, 127], [114, 136], [114, 138], [114, 145], [114, 150], [114, 154], [114, 159], [115, 116], [115, 117], [115, 118], [115, 124], [115, 127], [115, 131], [115, 136], [115, 139], [115, 140], [115, 141], [115, 142], [115, 147], [115, 158], [115, 166], [115, 172], [115, 174], [116, 117], [116, 118], [116, 120], [116, 126], [116, 127], [116, 135], [116, 139], [116, 153], [116, 155], [116, 158], [116, 160], [116, 164], [116, 173], [116, 176], [117, 125], [117, 135], [117, 138], [117, 141], [117, 145], [117, 158], [117, 162], [117, 169], [117, 171], [117, 174], [117, 175], [117, 179], [118, 123], [118, 126], [118, 130], [118, 133], [118, 137], [118, 140], [118, 141], [118, 152], [118, 153], [118, 154], [118, 158], [118, 162], [118, 166], [118, 172], [118, 173], [118, 175], [118, 176], [119, 120], [119, 132], [119, 134], [119, 138], [119, 139], [119, 144], [119, 149], [119, 153], [119, 159], [119, 170], [119, 175], [119, 177], [120, 123], [120, 128], [120, 135], [120, 138], [120, 148], [120, 154], [120, 159], [120, 178], [121, 122], [121, 134], [121, 139], [121, 144], [121, 145], [121, 148], [121, 149], [121, 152], [121, 164], [122, 124], [122, 127], [122, 129], [122, 148], [122, 152], [122, 153], [122, 161], [122, 165], [122, 169], [122, 177], [122, 178], [123, 128], [123, 137], [123, 141], [123, 142], [123, 159], [123, 162], [123, 165], [123, 167], [123, 172], [124, 129], [124, 130], [124, 134], [124, 136], [124, 141], [124, 142], [124, 151], [124, 154], [124, 163], [124, 166], [124, 172], [124, 176], [125, 126], [125, 143], [125, 144], [125, 157], [125, 158], [125, 162], [125, 169], [126, 128], [126, 131], [126, 136], [126, 152], [126, 153], [126, 156], [126, 157], [126, 162], [126, 169], [126, 171], [126, 174], [126, 178], [127, 128], [127, 130], [127, 135], [127, 139], [127, 140], [127, 147], [127, 157], [127, 158], [127, 160], [127, 161], [127, 163], [127, 164], [127, 171], [127, 178], [128, 134], [128, 136], [128, 138], [128, 139], [128, 140], [128, 159], [128, 160], [128, 167], [129, 133], [129, 134], [129, 138], [129, 140], [129, 144], [129, 151], [129, 157], [129, 160], [129, 161], [129, 165], [129, 169], [129, 173], [130, 140], [130, 141], [130, 142], [130, 143], [130, 147], [130, 150], [130, 158], [130, 162], [130, 167], [130, 168], [130, 172], [130, 173], [130, 177], [130, 179], [131, 132], [131, 136], [131, 139], [131, 152], [131, 155], [131, 156], [131, 158], [131, 159], [131, 161], [131, 162], [131, 167], [131, 172], [132, 140], [132, 146], [132, 153], [132, 161], [132, 167], [132, 168], [132, 176], [132, 177], [132, 179], [133, 135], [133, 136], [133, 145], [133, 147], [133, 151], [133, 155], [133, 157], [133, 159], [133, 168], [133, 172], [133, 175], [134, 135], [134, 140], [134, 142], [134, 144], [134, 156], [134, 161], [134, 165], [134, 166], [134, 168], [134, 169], [134, 170], [134, 172], [134, 173], [134, 176], [134, 178], [135, 136], [135, 138], [135, 139], [135, 157], [135, 159], [135, 163], [135, 171], [135, 173], [135, 174], [135, 179], [136, 149], [136, 151], [136, 161], [136, 164], [136, 172], [137, 150], [138, 148], [138, 152], [138, 153], [138, 155], [138, 160], [138, 161], [138, 170], [138, 174], [138, 179], [139, 141], [139, 145], [139, 152], [139, 157], [139, 161], [139, 165], [139, 166], [139, 167], [139, 170], [140, 142], [140, 155], [140, 158], [140, 159], [140, 169], [140, 173], [140, 174], [140, 176], [140, 178], [140, 179], [141, 154], [141, 157], [141, 159], [141, 160], [141, 167], [141, 170], [141, 176], [141, 177], [141, 178], [142, 148], [142, 153], [142, 156], [142, 157], [142, 159], [142, 160], [142, 170], [142, 173], [143, 147], [143, 149], [143, 158], [143, 161], [143, 165], [143, 166], [143, 175], [143, 176], [143, 177], [144, 153], [144, 165], [144, 169], [144, 172], [145, 152], [145, 160], [145, 167], [145, 168], [145, 176], [145, 177], [145, 179], [146, 154], [146, 163], [146, 168], [146, 172], [147, 158], [147, 167], [147, 178], [148, 151], [148, 161], [148, 165], [148, 171], [148, 172], [148, 173], [149, 153], [149, 158], [149, 163], [149, 165], [149, 167], [149, 168], [149, 171], [149, 172], [149, 173], [149, 177], [150, 153], [150, 161], [150, 168], [150, 176], [151, 154], [151, 158], [151, 159], [151, 162], [151, 164], [151, 165], [151, 166], [151, 172], [151, 174], [151, 177], [151, 178], [152, 169], [152, 177], [153, 154], [153, 155], [153, 157], [153, 158], [153, 160], [153, 166], [153, 167], [153, 169], [153, 170], [153, 172], [153, 173], [153, 176], [153, 177], [154, 155], [154, 157], [154, 160], [154, 168], [154, 169], [154, 171], [154, 178], [155, 157], [155, 161], [155, 167], [155, 176], [155, 177], [155, 178], [156, 166], [156, 168], [156, 170], [156, 178], [157, 164], [157, 166], [157, 167], [157, 171], [157, 172], [157, 179], [158, 159], [158, 161], [158, 178], [159, 171], [160, 162], [160, 169], [161, 162], [161, 169], [161, 176], [161, 177], [162, 168], [162, 176], [163, 166], [163, 167], [163, 171], [163, 175], [164, 165], [164, 167], [164, 169], [164, 172], [166, 173], [166, 175], [166, 176], [166, 177], [167, 169], [167, 170], [167, 174], [167, 175], [167, 176], [168, 179], [169, 172], [170, 171], [170, 175], [172, 176], [173, 176], [173, 177], [174, 178], [175, 177], [177, 178]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s3/tests/run.py b/tasks/construct-nppc-dominating-set-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-dominating-set-l5-s3/tests/test.sh b/tasks/construct-nppc-dominating-set-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-nppc-independent-set-l4-s2/environment/Dockerfile b/tasks/construct-nppc-independent-set-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s2/environment/instance.json b/tasks/construct-nppc-independent-set-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c41e3d04b38b7184738fea24def2a8a7e20a3cb --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 5], [0, 14], [0, 20], [0, 23], [0, 26], [0, 27], [1, 6], [1, 11], [1, 17], [1, 21], [1, 23], [1, 27], [1, 30], [2, 3], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 13], [2, 14], [2, 16], [2, 21], [2, 28], [2, 29], [2, 30], [2, 31], [3, 4], [3, 6], [3, 11], [3, 12], [3, 23], [3, 25], [3, 26], [3, 27], [3, 29], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [5, 9], [5, 13], [5, 15], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 24], [5, 26], [5, 31], [6, 7], [6, 8], [6, 12], [6, 13], [6, 14], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 30], [7, 12], [7, 14], [7, 20], [7, 21], [7, 26], [7, 27], [7, 30], [8, 12], [8, 20], [8, 21], [9, 17], [9, 23], [9, 26], [9, 29], [9, 30], [10, 11], [10, 14], [10, 20], [10, 23], [10, 26], [10, 29], [11, 12], [11, 14], [11, 16], [11, 18], [11, 19], [11, 20], [11, 21], [11, 28], [11, 29], [11, 31], [12, 13], [12, 16], [12, 17], [12, 19], [12, 20], [12, 22], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [13, 14], [13, 17], [13, 20], [13, 23], [13, 25], [13, 27], [13, 29], [13, 30], [14, 16], [14, 17], [14, 20], [14, 21], [14, 22], [14, 28], [15, 25], [15, 26], [16, 17], [16, 20], [16, 21], [16, 25], [16, 29], [17, 19], [17, 24], [17, 27], [17, 28], [17, 29], [17, 31], [18, 21], [18, 23], [18, 26], [18, 27], [18, 29], [18, 30], [19, 25], [19, 26], [19, 27], [20, 21], [20, 26], [20, 28], [20, 29], [20, 30], [21, 22], [21, 23], [21, 26], [21, 29], [21, 31], [22, 23], [22, 25], [22, 27], [22, 29], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 31], [24, 25], [24, 26], [25, 27], [25, 28], [26, 28], [26, 30], [27, 28], [27, 31], [28, 29], [29, 30]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s2/solution/solve.sh b/tasks/construct-nppc-independent-set-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c571bd1f8e7aae9a7e019754087604ce1a3014cc --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [0, 1, 3, 7, 8, 9, 10, 13, 15, 16, 18, 19, 22, 24, 28, 31]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l4-s2/tests/check.py b/tasks/construct-nppc-independent-set-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s2/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-l4-s2/tests/instance.json b/tasks/construct-nppc-independent-set-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c41e3d04b38b7184738fea24def2a8a7e20a3cb --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 5], [0, 14], [0, 20], [0, 23], [0, 26], [0, 27], [1, 6], [1, 11], [1, 17], [1, 21], [1, 23], [1, 27], [1, 30], [2, 3], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 13], [2, 14], [2, 16], [2, 21], [2, 28], [2, 29], [2, 30], [2, 31], [3, 4], [3, 6], [3, 11], [3, 12], [3, 23], [3, 25], [3, 26], [3, 27], [3, 29], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [5, 9], [5, 13], [5, 15], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 24], [5, 26], [5, 31], [6, 7], [6, 8], [6, 12], [6, 13], [6, 14], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 30], [7, 12], [7, 14], [7, 20], [7, 21], [7, 26], [7, 27], [7, 30], [8, 12], [8, 20], [8, 21], [9, 17], [9, 23], [9, 26], [9, 29], [9, 30], [10, 11], [10, 14], [10, 20], [10, 23], [10, 26], [10, 29], [11, 12], [11, 14], [11, 16], [11, 18], [11, 19], [11, 20], [11, 21], [11, 28], [11, 29], [11, 31], [12, 13], [12, 16], [12, 17], [12, 19], [12, 20], [12, 22], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [13, 14], [13, 17], [13, 20], [13, 23], [13, 25], [13, 27], [13, 29], [13, 30], [14, 16], [14, 17], [14, 20], [14, 21], [14, 22], [14, 28], [15, 25], [15, 26], [16, 17], [16, 20], [16, 21], [16, 25], [16, 29], [17, 19], [17, 24], [17, 27], [17, 28], [17, 29], [17, 31], [18, 21], [18, 23], [18, 26], [18, 27], [18, 29], [18, 30], [19, 25], [19, 26], [19, 27], [20, 21], [20, 26], [20, 28], [20, 29], [20, 30], [21, 22], [21, 23], [21, 26], [21, 29], [21, 31], [22, 23], [22, 25], [22, 27], [22, 29], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 31], [24, 25], [24, 26], [25, 27], [25, 28], [26, 28], [26, 30], [27, 28], [27, 31], [28, 29], [29, 30]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s2/tests/run.py b/tasks/construct-nppc-independent-set-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s2/tests/test.sh b/tasks/construct-nppc-independent-set-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s5/environment/Dockerfile b/tasks/construct-nppc-independent-set-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l4-s5/environment/instance.json b/tasks/construct-nppc-independent-set-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..50b794b86276152b22d9d6e4ecca4861d7ebdc15 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 4], [0, 7], [0, 9], [0, 11], [0, 14], [0, 15], [0, 16], [0, 20], [0, 22], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [1, 2], [1, 7], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [2, 4], [2, 8], [2, 9], [2, 12], [2, 15], [2, 23], [2, 26], [2, 30], [3, 4], [3, 5], [3, 6], [3, 9], [3, 17], [3, 26], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 19], [4, 23], [4, 25], [4, 28], [4, 30], [4, 31], [5, 6], [5, 7], [5, 8], [5, 9], [5, 13], [5, 18], [5, 20], [5, 21], [5, 23], [5, 24], [5, 27], [5, 30], [6, 7], [6, 8], [6, 10], [6, 12], [6, 13], [6, 14], [6, 22], [6, 24], [6, 27], [6, 28], [7, 8], [7, 12], [7, 16], [7, 17], [7, 25], [7, 30], [8, 13], [8, 15], [8, 17], [8, 18], [8, 23], [8, 26], [8, 27], [9, 10], [9, 11], [9, 16], [9, 17], [9, 19], [9, 21], [9, 22], [9, 24], [9, 25], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [10, 12], [10, 15], [10, 17], [10, 25], [10, 26], [11, 16], [11, 23], [11, 30], [12, 14], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 24], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [13, 15], [13, 16], [13, 17], [13, 23], [13, 26], [13, 28], [13, 30], [14, 15], [14, 16], [14, 23], [14, 26], [14, 28], [14, 30], [15, 17], [15, 18], [15, 19], [15, 20], [15, 28], [15, 30], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 31], [17, 20], [17, 21], [17, 22], [17, 24], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [18, 25], [18, 26], [18, 28], [18, 30], [19, 25], [19, 28], [19, 30], [20, 23], [20, 26], [20, 28], [21, 28], [21, 30], [22, 28], [23, 24], [24, 28], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [26, 28], [26, 29], [26, 31], [27, 30], [28, 29], [30, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s5/solution/solve.sh b/tasks/construct-nppc-independent-set-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..04d5843a47e4bd5c16bfe20fb3ca7c668061a16e --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [2, 3, 7, 10, 11, 13, 14, 18, 19, 20, 21, 22, 24, 27, 29, 31]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l4-s5/tests/check.py b/tasks/construct-nppc-independent-set-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/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-l4-s5/tests/instance.json b/tasks/construct-nppc-independent-set-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..50b794b86276152b22d9d6e4ecca4861d7ebdc15 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 2], [0, 4], [0, 7], [0, 9], [0, 11], [0, 14], [0, 15], [0, 16], [0, 20], [0, 22], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [1, 2], [1, 7], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [2, 4], [2, 8], [2, 9], [2, 12], [2, 15], [2, 23], [2, 26], [2, 30], [3, 4], [3, 5], [3, 6], [3, 9], [3, 17], [3, 26], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 19], [4, 23], [4, 25], [4, 28], [4, 30], [4, 31], [5, 6], [5, 7], [5, 8], [5, 9], [5, 13], [5, 18], [5, 20], [5, 21], [5, 23], [5, 24], [5, 27], [5, 30], [6, 7], [6, 8], [6, 10], [6, 12], [6, 13], [6, 14], [6, 22], [6, 24], [6, 27], [6, 28], [7, 8], [7, 12], [7, 16], [7, 17], [7, 25], [7, 30], [8, 13], [8, 15], [8, 17], [8, 18], [8, 23], [8, 26], [8, 27], [9, 10], [9, 11], [9, 16], [9, 17], [9, 19], [9, 21], [9, 22], [9, 24], [9, 25], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [10, 12], [10, 15], [10, 17], [10, 25], [10, 26], [11, 16], [11, 23], [11, 30], [12, 14], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 24], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [13, 15], [13, 16], [13, 17], [13, 23], [13, 26], [13, 28], [13, 30], [14, 15], [14, 16], [14, 23], [14, 26], [14, 28], [14, 30], [15, 17], [15, 18], [15, 19], [15, 20], [15, 28], [15, 30], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 31], [17, 20], [17, 21], [17, 22], [17, 24], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [18, 25], [18, 26], [18, 28], [18, 30], [19, 25], [19, 28], [19, 30], [20, 23], [20, 26], [20, 28], [21, 28], [21, 30], [22, 28], [23, 24], [24, 28], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [26, 28], [26, 29], [26, 31], [27, 30], [28, 29], [30, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s5/tests/run.py b/tasks/construct-nppc-independent-set-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l4-s5/tests/test.sh b/tasks/construct-nppc-independent-set-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l5-s3/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s3/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..45e6c60e85599ee79ab0c07e5053e74c2c8cfa9d --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"a": 3901773, "b": 6726142, "c": 88818575970623863070, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s3/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..663a75b8c69a68ccf73f080145f807bf54f6b561 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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": 4771126, "y": 1060091} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l5-s3/tests/check.py b/tasks/construct-nppc-quad-diophantine-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s3/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-l5-s3/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..45e6c60e85599ee79ab0c07e5053e74c2c8cfa9d --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"a": 3901773, "b": 6726142, "c": 88818575970623863070, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s3/tests/run.py b/tasks/construct-nppc-quad-diophantine-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s3/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s4/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s4/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c3ad05ce3668c77bd117587dbe828eb6e7bcd32c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"a": 1539454, "b": 7093930, "c": 37388191491942086216, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s4/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..89228b9ec74e925dab4b2f622f9ae772cd346f56 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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": 4928147, "y": 5271961} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l5-s4/tests/check.py b/tasks/construct-nppc-quad-diophantine-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s4/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-l5-s4/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c3ad05ce3668c77bd117587dbe828eb6e7bcd32c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"a": 1539454, "b": 7093930, "c": 37388191491942086216, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s4/tests/run.py b/tasks/construct-nppc-quad-diophantine-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s4/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quadratic-congruence-l5-s4/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l5-s4/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9575191e231fafa68e84873c17e00601cd06e11d --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"a": 1105246265959234458, "b": 2847013026948502147, "c": 397065541589976370, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s4/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79d70d44f80effdfef4402c2bdd0cf336aca3bd7 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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": 395740645371436700} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s4/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-l5-s4/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9575191e231fafa68e84873c17e00601cd06e11d --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"a": 1105246265959234458, "b": 2847013026948502147, "c": 397065541589976370, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l5-s4/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-vertex-cover-l3-s0/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s0/environment/instance.json b/tasks/construct-nppc-vertex-cover-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a0d8afddb98c68d49c6c411a29bcf6a643f7c49 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 15], [0, 16], [0, 17], [0, 20], [0, 21], [0, 23], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 23], [2, 4], [2, 18], [2, 21], [2, 22], [3, 4], [3, 7], [3, 10], [3, 14], [3, 17], [3, 18], [3, 21], [3, 22], [3, 23], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 17], [4, 18], [4, 19], [4, 20], [4, 22], [5, 7], [5, 14], [5, 18], [5, 22], [6, 7], [6, 8], [6, 10], [6, 18], [6, 22], [6, 23], [7, 9], [7, 10], [7, 13], [7, 14], [7, 16], [7, 18], [7, 20], [7, 21], [7, 22], [7, 23], [8, 9], [8, 10], [8, 13], [8, 15], [8, 16], [8, 18], [8, 22], [8, 23], [9, 10], [9, 18], [9, 21], [9, 22], [9, 23], [10, 11], [10, 15], [10, 17], [10, 18], [10, 19], [10, 23], [11, 18], [11, 21], [11, 22], [11, 23], [12, 14], [12, 17], [12, 21], [12, 23], [13, 14], [13, 17], [13, 18], [13, 21], [13, 22], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [15, 18], [15, 21], [15, 23], [16, 18], [16, 21], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [18, 22], [18, 23], [19, 21], [19, 22], [21, 23], [22, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s0/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e790b0a2fb3b9aac62f0cea549ddc455edb980ec --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [0, 1, 4, 7, 8, 10, 14, 17, 18, 21, 22, 23]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l3-s0/tests/check.py b/tasks/construct-nppc-vertex-cover-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s0/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-l3-s0/tests/instance.json b/tasks/construct-nppc-vertex-cover-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a0d8afddb98c68d49c6c411a29bcf6a643f7c49 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 15], [0, 16], [0, 17], [0, 20], [0, 21], [0, 23], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 23], [2, 4], [2, 18], [2, 21], [2, 22], [3, 4], [3, 7], [3, 10], [3, 14], [3, 17], [3, 18], [3, 21], [3, 22], [3, 23], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 17], [4, 18], [4, 19], [4, 20], [4, 22], [5, 7], [5, 14], [5, 18], [5, 22], [6, 7], [6, 8], [6, 10], [6, 18], [6, 22], [6, 23], [7, 9], [7, 10], [7, 13], [7, 14], [7, 16], [7, 18], [7, 20], [7, 21], [7, 22], [7, 23], [8, 9], [8, 10], [8, 13], [8, 15], [8, 16], [8, 18], [8, 22], [8, 23], [9, 10], [9, 18], [9, 21], [9, 22], [9, 23], [10, 11], [10, 15], [10, 17], [10, 18], [10, 19], [10, 23], [11, 18], [11, 21], [11, 22], [11, 23], [12, 14], [12, 17], [12, 21], [12, 23], [13, 14], [13, 17], [13, 18], [13, 21], [13, 22], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [15, 18], [15, 21], [15, 23], [16, 18], [16, 21], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [18, 22], [18, 23], [19, 21], [19, 22], [21, 23], [22, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s0/tests/run.py b/tasks/construct-nppc-vertex-cover-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s0/tests/test.sh b/tasks/construct-nppc-vertex-cover-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s7/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s7/environment/instance.json b/tasks/construct-nppc-vertex-cover-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..58b07cca8cfce78d97ae03d302c685b86a7c5fad --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 18], [0, 20], [0, 23], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 12], [1, 13], [1, 15], [1, 20], [1, 21], [1, 22], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 5], [3, 8], [3, 12], [3, 20], [3, 23], [4, 6], [4, 8], [4, 12], [4, 16], [4, 20], [4, 22], [5, 6], [5, 7], [5, 11], [5, 12], [5, 13], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 20], [6, 21], [6, 22], [7, 8], [7, 13], [7, 22], [7, 23], [8, 9], [8, 12], [8, 13], [8, 14], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [9, 12], [9, 20], [9, 22], [9, 23], [10, 12], [10, 20], [11, 12], [11, 13], [11, 16], [11, 23], [12, 13], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 22], [12, 23], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [14, 20], [14, 23], [15, 16], [15, 22], [16, 17], [16, 18], [16, 19], [16, 23], [17, 20], [18, 22], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [21, 23], [22, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s7/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..85ad97eeef8a44626d322aa9ae574c6ba27ad941 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [0, 1, 2, 5, 6, 8, 12, 13, 16, 20, 22, 23]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l3-s7/tests/check.py b/tasks/construct-nppc-vertex-cover-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s7/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-l3-s7/tests/instance.json b/tasks/construct-nppc-vertex-cover-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..58b07cca8cfce78d97ae03d302c685b86a7c5fad --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 18], [0, 20], [0, 23], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 12], [1, 13], [1, 15], [1, 20], [1, 21], [1, 22], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 5], [3, 8], [3, 12], [3, 20], [3, 23], [4, 6], [4, 8], [4, 12], [4, 16], [4, 20], [4, 22], [5, 6], [5, 7], [5, 11], [5, 12], [5, 13], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 20], [6, 21], [6, 22], [7, 8], [7, 13], [7, 22], [7, 23], [8, 9], [8, 12], [8, 13], [8, 14], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [9, 12], [9, 20], [9, 22], [9, 23], [10, 12], [10, 20], [11, 12], [11, 13], [11, 16], [11, 23], [12, 13], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 22], [12, 23], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [14, 20], [14, 23], [15, 16], [15, 22], [16, 17], [16, 18], [16, 19], [16, 23], [17, 20], [18, 22], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [21, 23], [22, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s7/tests/run.py b/tasks/construct-nppc-vertex-cover-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s7/tests/test.sh b/tasks/construct-nppc-vertex-cover-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-rg-graph-color-l4-s5/environment/Dockerfile b/tasks/construct-rg-graph-color-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l4-s5/environment/instance.json b/tasks/construct-rg-graph-color-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2832d029805284b5970e7339743e8bb1879bb709 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 20, "num_colors": 3, "edges": [[0, 4], [0, 19], [1, 4], [1, 13], [3, 9], [3, 13], [4, 5], [4, 17], [4, 19], [5, 7], [5, 9], [5, 14], [5, 15], [6, 7], [6, 15], [6, 18], [7, 19], [8, 9], [8, 11], [8, 14], [8, 16], [10, 11], [10, 14], [11, 16], [12, 16], [12, 18], [14, 16], [14, 17], [15, 16], [15, 18], [16, 17], [17, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l4-s5/solution/solve.sh b/tasks/construct-rg-graph-color-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..15b2d409c843b0b9d85d7305702c8dd7703e6e7a --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 2, 2, 3, 1, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l4-s5/tests/check.py b/tasks/construct-rg-graph-color-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/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-l4-s5/tests/instance.json b/tasks/construct-rg-graph-color-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2832d029805284b5970e7339743e8bb1879bb709 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 20, "num_colors": 3, "edges": [[0, 4], [0, 19], [1, 4], [1, 13], [3, 9], [3, 13], [4, 5], [4, 17], [4, 19], [5, 7], [5, 9], [5, 14], [5, 15], [6, 7], [6, 15], [6, 18], [7, 19], [8, 9], [8, 11], [8, 14], [8, 16], [10, 11], [10, 14], [11, 16], [12, 16], [12, 18], [14, 16], [14, 17], [15, 16], [15, 18], [16, 17], [17, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l4-s5/tests/run.py b/tasks/construct-rg-graph-color-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l4-s5/tests/test.sh b/tasks/construct-rg-graph-color-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l2-s0/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s0/environment/instance.json b/tasks/construct-rg-intermediate-integration-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..78e1d28cd8f07f93245c239552e31b9d359fed49 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-6*exp(6*x - 10)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s0/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..330a6a66ad0689434cbec5da82d0f7bdc1cff001 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "-exp(6*x - 10) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l2-s0/tests/check.py b/tasks/construct-rg-intermediate-integration-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-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-intermediate-integration-l2-s0/tests/instance.json b/tasks/construct-rg-intermediate-integration-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..78e1d28cd8f07f93245c239552e31b9d359fed49 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-6*exp(6*x - 10)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s0/tests/run.py b/tasks/construct-rg-intermediate-integration-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s0/tests/test.sh b/tasks/construct-rg-intermediate-integration-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s7/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s7/environment/instance.json b/tasks/construct-rg-intermediate-integration-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc60c3c172ba8ee1ce74167c202eb5a2c741efd0 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "(2*x + 5)*exp(x**2 + 5*x - 2)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s7/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..506651ad377ccccebd86f57e47d680436575070a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "exp(x**2 + 5*x - 2) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l2-s7/tests/check.py b/tasks/construct-rg-intermediate-integration-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-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-intermediate-integration-l2-s7/tests/instance.json b/tasks/construct-rg-intermediate-integration-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc60c3c172ba8ee1ce74167c202eb5a2c741efd0 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "(2*x + 5)*exp(x**2 + 5*x - 2)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s7/tests/run.py b/tasks/construct-rg-intermediate-integration-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s7/tests/test.sh b/tasks/construct-rg-intermediate-integration-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s8/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s8/environment/instance.json b/tasks/construct-rg-intermediate-integration-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be120dd03821b0f96361832f0879b1685142fc16 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-x**4*cos(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s8/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6dc2825ce79043aaadbf2cdbe0023b801a4cfe9b --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "-x**4*sin(x) - 4*x**3*cos(x) + 12*x**2*sin(x) + 24*x*cos(x) - 24*sin(x) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l6-s8/tests/check.py b/tasks/construct-rg-intermediate-integration-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-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-intermediate-integration-l6-s8/tests/instance.json b/tasks/construct-rg-intermediate-integration-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be120dd03821b0f96361832f0879b1685142fc16 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-x**4*cos(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s8/tests/run.py b/tasks/construct-rg-intermediate-integration-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s8/tests/test.sh b/tasks/construct-rg-intermediate-integration-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-simple-integration-l4-s3/environment/Dockerfile b/tasks/construct-rg-simple-integration-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s3/environment/instance.json b/tasks/construct-rg-simple-integration-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..424be1eddc056a22ea762ed261edf8babf753424 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-54*X**8 + 20*X**3 + 24*X**2/5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s3/solution/solve.sh b/tasks/construct-rg-simple-integration-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0aee0ae19a9d16388923776ac88e7867bddfe5fc --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-6*X**9 + 5*X**4 + 8*X**3/5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l4-s3/tests/check.py b/tasks/construct-rg-simple-integration-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s3/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l4-s3/tests/instance.json b/tasks/construct-rg-simple-integration-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..424be1eddc056a22ea762ed261edf8babf753424 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-54*X**8 + 20*X**3 + 24*X**2/5", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s3/tests/run.py b/tasks/construct-rg-simple-integration-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s3/tests/test.sh b/tasks/construct-rg-simple-integration-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-antiderivative-l1-s5/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l1-s5/environment/instance.json b/tasks/construct-rlve-antiderivative-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..36c9761eb58985a445fc786b1a40d2fbaa180a79 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "1/(12*x**(3/4))", "max_ops": 32, "max_len": 600, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s5/solution/solve.sh b/tasks/construct-rlve-antiderivative-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc6655b3fd39f795edb0e3f6209972568c0ee835 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "x**(1/4)/3"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l1-s5/tests/check.py b/tasks/construct-rlve-antiderivative-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-rlve-antiderivative-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..36c9761eb58985a445fc786b1a40d2fbaa180a79 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "1/(12*x**(3/4))", "max_ops": 32, "max_len": 600, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s5/tests/run.py b/tasks/construct-rlve-antiderivative-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l1-s5/tests/test.sh b/tasks/construct-rlve-antiderivative-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s3/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s3/environment/instance.json b/tasks/construct-rlve-antiderivative-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd3969dbad62b88d8c1882630f5f564fc061ab0b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "144*sin(4*x - 4)", "max_ops": 40, "max_len": 720, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s3/solution/solve.sh b/tasks/construct-rlve-antiderivative-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e8cfcd8ef6bb186ba36853b0800642c3d5bd0f47 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "-36*cos(4*x - 4)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l5-s3/tests/check.py b/tasks/construct-rlve-antiderivative-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s3/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-l5-s3/tests/instance.json b/tasks/construct-rlve-antiderivative-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd3969dbad62b88d8c1882630f5f564fc061ab0b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "144*sin(4*x - 4)", "max_ops": 40, "max_len": 720, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s3/tests/run.py b/tasks/construct-rlve-antiderivative-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s3/tests/test.sh b/tasks/construct-rlve-antiderivative-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s4/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s4/environment/instance.json b/tasks/construct-rlve-antiderivative-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b2487c21599aaf6cb20e2f8f505ae4b36330702 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "x**(1/3)*(-12*x**11 - cos(x)*cos(sin(x)))*exp(-x**12 - sin(sin(x))) + exp(-x**12 - sin(sin(x)))/(3*x**(2/3))", "max_ops": 56, "max_len": 1080, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s4/solution/solve.sh b/tasks/construct-rlve-antiderivative-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3779edec2b6394931c1c476e24efb25596b11a3b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "x**(1/3)*exp(-x**12 - sin(sin(x)))"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l5-s4/tests/check.py b/tasks/construct-rlve-antiderivative-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s4/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-l5-s4/tests/instance.json b/tasks/construct-rlve-antiderivative-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b2487c21599aaf6cb20e2f8f505ae4b36330702 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "x**(1/3)*(-12*x**11 - cos(x)*cos(sin(x)))*exp(-x**12 - sin(sin(x))) + exp(-x**12 - sin(sin(x)))/(3*x**(2/3))", "max_ops": 56, "max_len": 1080, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l5-s4/tests/run.py b/tasks/construct-rlve-antiderivative-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l5-s4/tests/test.sh b/tasks/construct-rlve-antiderivative-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-bezout-identity-l4-s0/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s0/environment/instance.json b/tasks/construct-rlve-bezout-identity-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..297dd2368ed51ee13188f093e19e1ae8946d6d8e --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": [-1846, -1207, 1349, 1136, 284, -923, 71, -994], "target": 71, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s0/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..049cfbe132383651acf97d4490f093013e2d415d --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [0, 0, 0, 0, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l4-s0/tests/check.py b/tasks/construct-rlve-bezout-identity-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s0/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-l4-s0/tests/instance.json b/tasks/construct-rlve-bezout-identity-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..297dd2368ed51ee13188f093e19e1ae8946d6d8e --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": [-1846, -1207, 1349, 1136, 284, -923, 71, -994], "target": 71, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s0/tests/run.py b/tasks/construct-rlve-bezout-identity-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s0/tests/test.sh b/tasks/construct-rlve-bezout-identity-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s9/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s9/environment/instance.json b/tasks/construct-rlve-bezout-identity-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..873cc4cb7db5d3080f6b20ba7494fb5d0768c7be --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [-1276, -1954, 1004, -1346, -1690, -1552, 20, -1054], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s9/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8a3a406c45e2d6b34a8a8679a9a008e5d202c74b --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [-464, 303, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l4-s9/tests/check.py b/tasks/construct-rlve-bezout-identity-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s9/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-l4-s9/tests/instance.json b/tasks/construct-rlve-bezout-identity-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..873cc4cb7db5d3080f6b20ba7494fb5d0768c7be --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [-1276, -1954, 1004, -1346, -1690, -1552, 20, -1054], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s9/tests/run.py b/tasks/construct-rlve-bezout-identity-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s9/tests/test.sh b/tasks/construct-rlve-bezout-identity-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-construct-hack-interval-l6-s2/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s2/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2365d1bb71304cc74884cf5ab167523b69d97eda --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"mod": 111762054082994976, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s2/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..34614b4c4edafb9b395bc7594ba2ea19e724a33e --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 62334378580964832, "R": 72334378580964831} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s2/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-l6-s2/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2365d1bb71304cc74884cf5ab167523b69d97eda --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"mod": 111762054082994976, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s2/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s5/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s5/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ef54f9c3cd767fb9f9a69a03d04bbf95e925591 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"mod": 739125710441575665, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s5/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..667fccf2b652b5099a9b42858df8e0ca53c240db --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 19125710441575665, "R": 29125710441575664} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ef54f9c3cd767fb9f9a69a03d04bbf95e925591 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"mod": 739125710441575665, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s5/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-crt-l3-s4/environment/Dockerfile b/tasks/construct-rlve-crt-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l3-s4/environment/instance.json b/tasks/construct-rlve-crt-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..68423ba90f6c948a98900bf1d27ec2b67fcee060 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [165, 1205, 1054, 427], "residues": [126, 571, 722, 68], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s4/solution/solve.sh b/tasks/construct-rlve-crt-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..49e907aa9c1c6956a28dceb6543da5203a03166a --- /dev/null +++ b/tasks/construct-rlve-crt-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' +{"x": 1776} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l3-s4/tests/check.py b/tasks/construct-rlve-crt-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s4/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-l3-s4/tests/instance.json b/tasks/construct-rlve-crt-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..68423ba90f6c948a98900bf1d27ec2b67fcee060 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [165, 1205, 1054, 427], "residues": [126, 571, 722, 68], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s4/tests/run.py b/tasks/construct-rlve-crt-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l3-s4/tests/test.sh b/tasks/construct-rlve-crt-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-distinct-subset-sum-permutation-l2-s3/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l2-s3/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ccf759e7abb7d66073b6f9e102c76fdffde5c7b2 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": [4, 1, 5, 9, 0, 11, 6], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ab9c9d3ca9b5ba76b8a550ef8d0d4a38deb9045b --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [5, 4, 6, 11, 1, 0, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/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-l2-s3/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ccf759e7abb7d66073b6f9e102c76fdffde5c7b2 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": [4, 1, 5, 9, 0, 11, 6], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l2-s3/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l6-s2/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l6-s2/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1aed5c20290af4a409f34414659428600f4a2575 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [20, 43, 34, 15, 5, 14, 2, 30, 35, 33, 41, 27, 29, 21, 26, 38, 28, 32, 9, 17, 42, 40], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a5bb9112963fdf118847214deec38dc9edb9c7a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [21, 2, 35, 17, 9, 15, 5, 32, 38, 34, 42, 28, 30, 26, 27, 40, 29, 33, 14, 20, 43, 41]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/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-l6-s2/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1aed5c20290af4a409f34414659428600f4a2575 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [20, 43, 34, 15, 5, 14, 2, 30, 35, 33, 41, 27, 29, 21, 26, 38, 28, 32, 9, 17, 42, 40], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l6-s2/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l6-s5/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l6-s5/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e85e425f4e7f80c332d906b34fa97926714594d5 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": [37, 2, 24, 7, 35, 20, 40, 25, 19, 4, 34, 38, 12, 15, 18, 10, 13, 8, 43, 14, 3, 39], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a007609fd81264d03d8347af80ba4a15751910b8 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [38, 3, 25, 8, 37, 24, 43, 34, 20, 7, 35, 39, 13, 18, 19, 12, 14, 10, 2, 15, 4, 40]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e85e425f4e7f80c332d906b34fa97926714594d5 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": [37, 2, 24, 7, 35, 20, 40, 25, 19, 4, 34, 38, 12, 15, 18, 10, 13, 8, 43, 14, 3, 39], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l6-s5/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-even-degree-partition-l3-s3/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s3/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbf25007c0c3cefb852b5cfc69a9f85e8a6c762f --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 2], [0, 3], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 9], [2, 3], [2, 4], [2, 6], [2, 11], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [4, 6], [4, 7], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 7], [6, 8], [6, 10], [7, 9], [8, 10], [8, 11], [9, 10], [9, 11]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s3/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..14d833023ac2493a4c071b07625c5b00effa9456 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l3-s3/tests/check.py b/tasks/construct-rlve-even-degree-partition-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s3/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-l3-s3/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbf25007c0c3cefb852b5cfc69a9f85e8a6c762f --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 2], [0, 3], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 9], [2, 3], [2, 4], [2, 6], [2, 11], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [4, 6], [4, 7], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 7], [6, 8], [6, 10], [7, 9], [8, 10], [8, 11], [9, 10], [9, 11]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s3/tests/run.py b/tasks/construct-rlve-even-degree-partition-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s3/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s4/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s4/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a6afdea85186cdda2f2aa91baab65c55102578c --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 1], [0, 4], [0, 7], [0, 8], [0, 9], [0, 11], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 11], [2, 4], [2, 7], [2, 8], [2, 10], [3, 5], [3, 6], [3, 9], [3, 10], [3, 11], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [5, 6], [5, 9], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [9, 10], [9, 11], [10, 11]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s4/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6d7f218a479b8a35ffaf861a3937a4be9d1c562a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l3-s4/tests/check.py b/tasks/construct-rlve-even-degree-partition-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s4/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-l3-s4/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a6afdea85186cdda2f2aa91baab65c55102578c --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges": [[0, 1], [0, 4], [0, 7], [0, 8], [0, 9], [0, 11], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 11], [2, 4], [2, 7], [2, 8], [2, 10], [3, 5], [3, 6], [3, 9], [3, 10], [3, 11], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [5, 6], [5, 9], [6, 8], [6, 9], [7, 8], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [9, 10], [9, 11], [10, 11]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l3-s4/tests/run.py b/tasks/construct-rlve-even-degree-partition-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l3-s4/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-graph-isomorphism-l1-s1/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s1/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..49999a4b98f2a3799930a94f0af65f680cc2028b --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[0, 4], [1, 4], [0, 3]], "edges2": [[0, 2], [3, 4], [0, 3]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s1/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..60ca1ef259eac0e1d4214a8967a2089dd6e3ad2c --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [0, 4, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s1/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-l1-s1/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..49999a4b98f2a3799930a94f0af65f680cc2028b --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[0, 4], [1, 4], [0, 3]], "edges2": [[0, 2], [3, 4], [0, 3]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s1/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s6/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s6/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..46ab35e95dc1ed21771bccba2f1cd03bf0b2ff77 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[1, 3], [2, 4], [1, 2], [0, 1], [0, 4]], "edges2": [[2, 3], [1, 2], [1, 4], [0, 1], [0, 3]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s6/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a27406dbc523ca0ecc28d02eb1dcd138437f4e2a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [2, 1, 0, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s6/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-l1-s6/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..46ab35e95dc1ed21771bccba2f1cd03bf0b2ff77 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[1, 3], [2, 4], [1, 2], [0, 1], [0, 4]], "edges2": [[2, 3], [1, 2], [1, 4], [0, 1], [0, 3]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s6/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s8/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s8/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5de11ba6dbc0812528f466c19b911c9a7acffe --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[2, 4], [1, 3], [0, 1]], "edges2": [[1, 3], [0, 4], [0, 2]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s8/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dd5bae3c0d84c5c087f9aaff28e751900c954df5 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [4, 0, 3, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s8/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-l1-s8/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5de11ba6dbc0812528f466c19b911c9a7acffe --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[2, 4], [1, 3], [0, 1]], "edges2": [[1, 3], [0, 4], [0, 2]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s8/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s0/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s0/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1defdc741a56b2cca17c693c2663d2e9364d0ac --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[14, 19], [11, 22], [3, 5], [15, 17], [1, 24], [3, 8], [17, 19], [15, 23], [3, 12], [6, 10], [4, 24], [0, 25], [2, 5], [8, 18], [2, 15], [15, 19], [3, 9], [5, 18], [0, 15], [22, 23], [15, 16], [8, 16], [1, 9], [0, 12], [12, 19], [16, 17], [5, 14], [1, 6], [20, 24], [3, 14], [3, 4], [9, 13], [6, 21], [12, 21], [13, 14], [3, 11], [4, 21], [1, 2], [7, 15], [8, 15], [20, 22], [0, 5], [1, 7], [7, 20], [3, 21], [9, 15], [5, 13], [17, 18]], "edges2": [[11, 19], [1, 22], [3, 25], [6, 10], [3, 8], [1, 23], [17, 25], [4, 24], [9, 18], [4, 22], [2, 23], [2, 12], [0, 20], [5, 12], [6, 19], [5, 11], [10, 16], [21, 25], [8, 22], [16, 21], [8, 14], [3, 23], [5, 18], [15, 21], [13, 21], [14, 16], [13, 22], [12, 21], [18, 24], [15, 24], [6, 21], [2, 21], [9, 11], [6, 17], [1, 6], [16, 22], [19, 22], [2, 20], [21, 23], [14, 22], [11, 13], [1, 7], [8, 10], [3, 22], [13, 17], [6, 25], [9, 22], [11, 20]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s0/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2d64baf731e3e5f0d0000e72a2be23e88890c1a2 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [1, 11, 19, 21, 12, 6, 20, 9, 16, 13, 0, 15, 23, 17, 25, 22, 14, 8, 10, 3, 18, 2, 24, 4, 5, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1defdc741a56b2cca17c693c2663d2e9364d0ac --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[14, 19], [11, 22], [3, 5], [15, 17], [1, 24], [3, 8], [17, 19], [15, 23], [3, 12], [6, 10], [4, 24], [0, 25], [2, 5], [8, 18], [2, 15], [15, 19], [3, 9], [5, 18], [0, 15], [22, 23], [15, 16], [8, 16], [1, 9], [0, 12], [12, 19], [16, 17], [5, 14], [1, 6], [20, 24], [3, 14], [3, 4], [9, 13], [6, 21], [12, 21], [13, 14], [3, 11], [4, 21], [1, 2], [7, 15], [8, 15], [20, 22], [0, 5], [1, 7], [7, 20], [3, 21], [9, 15], [5, 13], [17, 18]], "edges2": [[11, 19], [1, 22], [3, 25], [6, 10], [3, 8], [1, 23], [17, 25], [4, 24], [9, 18], [4, 22], [2, 23], [2, 12], [0, 20], [5, 12], [6, 19], [5, 11], [10, 16], [21, 25], [8, 22], [16, 21], [8, 14], [3, 23], [5, 18], [15, 21], [13, 21], [14, 16], [13, 22], [12, 21], [18, 24], [15, 24], [6, 21], [2, 21], [9, 11], [6, 17], [1, 6], [16, 22], [19, 22], [2, 20], [21, 23], [14, 22], [11, 13], [1, 7], [8, 10], [3, 22], [13, 17], [6, 25], [9, 22], [11, 20]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s0/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s9/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s9/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5b1dda24f442c8da747a3594496621e7c0a1d44 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[0, 16], [0, 21], [2, 19], [6, 17], [9, 14], [4, 7], [11, 24], [0, 20], [2, 8], [9, 22], [2, 20], [5, 21], [9, 17], [7, 21], [19, 23], [4, 25], [7, 8], [4, 15], [11, 18], [6, 25], [8, 12], [0, 9], [6, 23], [21, 23], [9, 13], [16, 18], [11, 13], [2, 18], [1, 3], [12, 17], [6, 11], [13, 22], [17, 25], [3, 22], [10, 18], [9, 18], [15, 25], [15, 16], [9, 19], [6, 14], [0, 23], [17, 22], [10, 19], [11, 21], [3, 18], [0, 22], [0, 1], [6, 16], [1, 14], [3, 21], [7, 24], [17, 23], [3, 13], [19, 22], [2, 17], [5, 14], [4, 17], [5, 7], [6, 7], [12, 13], [9, 16], [5, 23], [15, 23], [2, 4], [1, 18], [12, 18], [10, 24], [5, 12], [3, 17], [6, 21], [19, 24], [6, 10], [2, 22], [16, 20], [4, 11], [16, 19], [6, 18], [2, 5], [4, 20], [10, 16], [7, 16], [12, 14], [16, 24], [2, 3], [0, 15], [1, 23], [8, 13], [18, 25], [0, 17], [13, 21], [13, 19], [1, 11], [18, 20], [8, 21], [10, 14], [7, 18], [15, 24], [19, 21], [15, 20], [1, 21], [16, 17], [20, 24], [8, 10], [14, 16], [8, 24], [6, 20], [10, 12], [3, 24], [22, 23], [21, 24], [13, 14], [20, 23], [10, 13]], "edges2": [[2, 10], [2, 11], [7, 8], [9, 10], [19, 22], [1, 20], [5, 12], [12, 22], [2, 21], [14, 15], [14, 21], [4, 20], [8, 18], [5, 18], [0, 8], [2, 12], [13, 18], [7, 20], [6, 8], [22, 24], [18, 22], [4, 23], [1, 14], [2, 5], [0, 13], [7, 16], [11, 18], [14, 22], [4, 17], [4, 7], [9, 13], [10, 19], [4, 13], [3, 21], [10, 11], [18, 25], [1, 12], [3, 18], [7, 12], [9, 15], [1, 16], [18, 24], [2, 18], [2, 9], [15, 17], [20, 22], [6, 25], [0, 1], [4, 6], [1, 10], [15, 23], [15, 16], [1, 23], [19, 24], [3, 25], [8, 25], [9, 16], [2, 6], [16, 21], [7, 14], [3, 22], [2, 25], [1, 21], [6, 12], [1, 3], [3, 11], [2, 19], [2, 7], [0, 4], [11, 24], [21, 23], [5, 17], [0, 19], [12, 13], [4, 8], [4, 14], [7, 15], [6, 19], [0, 11], [3, 24], [14, 20], [3, 14], [21, 22], [5, 21], [18, 20], [8, 20], [1, 13], [17, 23], [1, 5], [2, 13], [14, 16], [10, 17], [6, 21], [20, 25], [5, 9], [14, 25], [0, 25], [1, 24], [4, 24], [9, 11], [9, 25], [0, 16], [9, 14], [8, 13], [0, 17], [10, 14], [6, 7], [6, 15], [6, 16], [16, 17], [3, 9], [4, 21], [10, 21]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s9/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4535ef9c2999ef028edb12ab42617cf899e73a8a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [7, 12, 0, 13, 17, 19, 21, 10, 11, 20, 3, 5, 24, 18, 22, 15, 14, 4, 1, 25, 16, 2, 8, 6, 9, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s9/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-l5-s9/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5b1dda24f442c8da747a3594496621e7c0a1d44 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[0, 16], [0, 21], [2, 19], [6, 17], [9, 14], [4, 7], [11, 24], [0, 20], [2, 8], [9, 22], [2, 20], [5, 21], [9, 17], [7, 21], [19, 23], [4, 25], [7, 8], [4, 15], [11, 18], [6, 25], [8, 12], [0, 9], [6, 23], [21, 23], [9, 13], [16, 18], [11, 13], [2, 18], [1, 3], [12, 17], [6, 11], [13, 22], [17, 25], [3, 22], [10, 18], [9, 18], [15, 25], [15, 16], [9, 19], [6, 14], [0, 23], [17, 22], [10, 19], [11, 21], [3, 18], [0, 22], [0, 1], [6, 16], [1, 14], [3, 21], [7, 24], [17, 23], [3, 13], [19, 22], [2, 17], [5, 14], [4, 17], [5, 7], [6, 7], [12, 13], [9, 16], [5, 23], [15, 23], [2, 4], [1, 18], [12, 18], [10, 24], [5, 12], [3, 17], [6, 21], [19, 24], [6, 10], [2, 22], [16, 20], [4, 11], [16, 19], [6, 18], [2, 5], [4, 20], [10, 16], [7, 16], [12, 14], [16, 24], [2, 3], [0, 15], [1, 23], [8, 13], [18, 25], [0, 17], [13, 21], [13, 19], [1, 11], [18, 20], [8, 21], [10, 14], [7, 18], [15, 24], [19, 21], [15, 20], [1, 21], [16, 17], [20, 24], [8, 10], [14, 16], [8, 24], [6, 20], [10, 12], [3, 24], [22, 23], [21, 24], [13, 14], [20, 23], [10, 13]], "edges2": [[2, 10], [2, 11], [7, 8], [9, 10], [19, 22], [1, 20], [5, 12], [12, 22], [2, 21], [14, 15], [14, 21], [4, 20], [8, 18], [5, 18], [0, 8], [2, 12], [13, 18], [7, 20], [6, 8], [22, 24], [18, 22], [4, 23], [1, 14], [2, 5], [0, 13], [7, 16], [11, 18], [14, 22], [4, 17], [4, 7], [9, 13], [10, 19], [4, 13], [3, 21], [10, 11], [18, 25], [1, 12], [3, 18], [7, 12], [9, 15], [1, 16], [18, 24], [2, 18], [2, 9], [15, 17], [20, 22], [6, 25], [0, 1], [4, 6], [1, 10], [15, 23], [15, 16], [1, 23], [19, 24], [3, 25], [8, 25], [9, 16], [2, 6], [16, 21], [7, 14], [3, 22], [2, 25], [1, 21], [6, 12], [1, 3], [3, 11], [2, 19], [2, 7], [0, 4], [11, 24], [21, 23], [5, 17], [0, 19], [12, 13], [4, 8], [4, 14], [7, 15], [6, 19], [0, 11], [3, 24], [14, 20], [3, 14], [21, 22], [5, 21], [18, 20], [8, 20], [1, 13], [17, 23], [1, 5], [2, 13], [14, 16], [10, 17], [6, 21], [20, 25], [5, 9], [14, 25], [0, 25], [1, 24], [4, 24], [9, 11], [9, 25], [0, 16], [9, 14], [8, 13], [0, 17], [10, 14], [6, 7], [6, 15], [6, 16], [16, 17], [3, 9], [4, 21], [10, 21]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s9/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-grid-parity-construction-l1-s1/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s1/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a9e47ce324071f1e6e0e5e9bc8f6327bab4b3a02 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["010", "010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s1/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1c2cbf8e95b027efbe6961e9a53eb892d608a31d --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["001", "001"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s1/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-l1-s1/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a9e47ce324071f1e6e0e5e9bc8f6327bab4b3a02 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["010", "010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s1/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s6/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s6/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ebe645f641f3b7266dd3c78fd02a4d468469cb2 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["001", "011"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s6/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..72a2d8f3f49acd8ba07309607879adfb7877168c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["111", "011"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s6/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-l1-s6/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ebe645f641f3b7266dd3c78fd02a4d468469cb2 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["001", "011"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s6/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s8/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s8/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db4e5543393af5b5574fe7ea17adc2c18e66d074 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["010", "110", "001"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s8/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..125d5390dbb6031f40ee05731f447c5ef12b8f32 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["000", "010", "001"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s8/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-l1-s8/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db4e5543393af5b5574fe7ea17adc2c18e66d074 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["010", "110", "001"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l1-s8/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s7/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s7/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1b59fa7b6e10739524ec68b1e38f1d4f25323f3 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["0010011100", "0010101100", "1001010100", "1110101111", "0101011111", "0101001001", "1001011010", "1011010111", "1011001011", "1011100110", "1010111101", "1100100101", "1100011110"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s7/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56ac8759e608d23eae2a22b261851fef6cfa3e46 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["0101101010", "1110010111", "0010110100", "0001000101", "1111110110", "0011111011", "1111001111", "1100010111", "0110101010", "1111110111", "1010101110", "1111101111", "0001001101"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s7/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-l5-s7/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1b59fa7b6e10739524ec68b1e38f1d4f25323f3 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["0010011100", "0010101100", "1001010100", "1110101111", "0101011111", "0101001001", "1001011010", "1011010111", "1011001011", "1011100110", "1010111101", "1100100101", "1100011110"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s7/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s9/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s9/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0fa3b3d601cbb44fdfc89cd291774346aa15b1e6 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["001101011100110110", "000011011010110001", "010011110011110111", "111000110000001000", "110110100001110001", "000110110010100000", "110000100011111100", "100001010010111101", "101100100101101110", "110000000001100010", "011100011000100111", "010111101011010010", "011011000101101010", "110001101110001111", "001010011010101110", "111010001110101111", "111010001001011100", "000101110011111100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s9/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b80431ad4c2cc2d85b045830fbc23e70f1e050a6 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["001000000100000000", "010001010010110110", "110000000000110000", "001010100000001001", "010010000000100111", "000011000000000010", "010000010010000000", "001011011100111110", "101001001011100000", "001000000000000000", "000101001010000010", "011001100011100000", "110100110100000000", "000101100000001010", "001001001010010100", "010000000001010010", "001011000111100100", "110010100011010000"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s9/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-l5-s9/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0fa3b3d601cbb44fdfc89cd291774346aa15b1e6 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["001101011100110110", "000011011010110001", "010011110011110111", "111000110000001000", "110110100001110001", "000110110010100000", "110000100011111100", "100001010010111101", "101100100101101110", "110000000001100010", "011100011000100111", "010111101011010010", "011011000101101010", "110001101110001111", "001010011010101110", "111010001110101111", "111010001001011100", "000101110011111100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s9/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-imp-party-l3-s1/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2cbc414a8fc60f54c74f02f6ba459177bbadf2bc --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [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], [0, 21], [0, 22], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 22], [1, 23], [2, 3], [2, 4], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 4], [3, 7], [3, 9], [3, 10], [3, 11], [3, 15], [3, 16], [3, 18], [3, 19], [3, 22], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 7], [5, 8], [5, 10], [5, 15], [5, 17], [5, 18], [5, 23], [6, 7], [6, 8], [6, 9], [6, 11], [6, 16], [6, 18], [6, 19], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 22], [7, 23], [8, 9], [8, 10], [8, 11], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 22], [9, 23], [10, 11], [10, 12], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 22], [10, 23], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 22], [12, 23], [13, 15], [13, 16], [13, 17], [13, 18], [13, 22], [13, 23], [14, 16], [14, 17], [14, 18], [14, 19], [14, 22], [14, 23], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [19, 20], [19, 21], [19, 22], [19, 23], [20, 22], [20, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s8/environment/Dockerfile b/tasks/construct-rlve-imp-party-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s8/environment/instance.json b/tasks/construct-rlve-imp-party-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b7c62272af9d6856f3ba6c995a3cbb088a0f6c1 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [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], [0, 21], [0, 22], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [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, 16], [3, 17], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 13], [4, 15], [4, 16], [4, 17], [4, 18], [4, 20], [4, 22], [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, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [7, 9], [7, 10], [7, 11], [7, 13], [7, 15], [7, 16], [7, 17], [7, 20], [7, 22], [8, 9], [8, 13], [8, 16], [8, 17], [8, 20], [8, 22], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [12, 13], [12, 15], [12, 16], [12, 20], [12, 22], [13, 14], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [14, 16], [14, 17], [15, 16], [15, 17], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [17, 18], [17, 19], [17, 20], [17, 22], [17, 23], [18, 20], [18, 22], [19, 20], [20, 21], [20, 22], [20, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s8/solution/solve.sh b/tasks/construct-rlve-imp-party-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..de2c7163404c415709a4b465340c0ccd53a436a8 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 2, 5, 13, 15, 17, 20, 22]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l3-s8/tests/check.py b/tasks/construct-rlve-imp-party-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s8/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-l3-s8/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b7c62272af9d6856f3ba6c995a3cbb088a0f6c1 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [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], [0, 21], [0, 22], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [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, 16], [3, 17], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 13], [4, 15], [4, 16], [4, 17], [4, 18], [4, 20], [4, 22], [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, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [7, 9], [7, 10], [7, 11], [7, 13], [7, 15], [7, 16], [7, 17], [7, 20], [7, 22], [8, 9], [8, 13], [8, 16], [8, 17], [8, 20], [8, 22], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [12, 13], [12, 15], [12, 16], [12, 20], [12, 22], [13, 14], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [14, 16], [14, 17], [15, 16], [15, 17], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [17, 18], [17, 19], [17, 20], [17, 22], [17, 23], [18, 20], [18, 22], [19, 20], [20, 21], [20, 22], [20, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s8/tests/run.py b/tasks/construct-rlve-imp-party-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l3-s8/tests/test.sh b/tasks/construct-rlve-imp-party-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l4-s8/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l4-s8/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..625620d62f6e7ab63f7cead397cba0b9bdf8aeb5 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 0, 1, 0, 2, 1, 0, 2, 1, 0, 0, 1], [0, 0, 2, 0, 1, 2, 1, 1, 1, 0, 1, 1], [0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 2], [2, 1, 0, 0, 1, 0, 0, 0, 0, 2, 0, 2], [2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 1], [0, 0, 1, 0, 0, 0, 1, 2, 2, 0, 2, 2], [0, 1, 1, 0, 0, 2, 2, 0, 2, 0, 2, 1], [0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 1, 0], [2, 0, 0, 1, 0, 2, 0, 2, 0, 0, 1, 2], [0, 2, 2, 0, 1, 0, 2, 2, 2, 2, 0, 0], [2, 1, 2, 1, 0, 0, 1, 0, 1, 2, 0, 0], [1, 0, 2, 0, 1, 0, 0, 0, 1, 1, 0, 1], [0, 0, 2, 0, 1, 0, 0, 0, 2, 2, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0], [1, 1, 0, 1, 2, 1, 1, 1, 2, 0, 1, 0], [1, 0, 2, 0, 2, 2, 1, 0, 2, 1, 1, 0], [0, 0, 2, 2, 0, 2, 1, 2, 2, 0, 1, 0], [0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 1], [0, 0, 2, 0, 0, 1, 2, 2, 2, 1, 0, 0], [1, 0, 1, 2, 0, 0, 2, 0, 1, 0, 1, 0], [2, 2, 1, 2, 2, 0, 0, 0, 0, 0, 1, 1], [0, 0, 2, 0, 2, 2, 2, 2, 0, 2, 0, 0], [0, 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0, 2, 0, 2, 1, 0, 1], [0, 1, 1, 1, 2, 0, 0, 1, 1, 2, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0, 0, 1, 0, 0, 1, 0], [0, 2, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0], [1, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2], [0, 1, 0, 2, 0, 0, 1, 0, 1, 2, 1, 0], [0, 2, 1, 2, 1, 2, 2, 0, 0, 1, 0, 2], [2, 0, 0, 2, 0, 2, 1, 0, 0, 2, 2, 0], [0, 0, 1, 0, 2, 0, 1, 0, 1, 0, 0, 0], [0, 1, 2, 0, 0, 2, 1, 0, 1, 2, 0, 2], [1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 2, 1, 0, 0, 0, 0]], "rhs": [67, 59, 12, 57, 58, 37, 66, 27, 62, 73, 73, 47, 53, 36, 80, 93, 76, 38, 55, 50, 77, 76, 45, 70, 68, 34, 28, 48, 74, 57, 86, 89, 34, 72, 32, 16], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s8/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bd9309f82a83e5c006d3e514644f3c86350aa1a9 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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": [10, 6, 4, 9, 9, 12, 3, 1, 9, 9, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l4-s8/tests/check.py b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s8/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-l4-s8/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..625620d62f6e7ab63f7cead397cba0b9bdf8aeb5 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 0, 1, 0, 2, 1, 0, 2, 1, 0, 0, 1], [0, 0, 2, 0, 1, 2, 1, 1, 1, 0, 1, 1], [0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 2], [2, 1, 0, 0, 1, 0, 0, 0, 0, 2, 0, 2], [2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 1], [0, 0, 1, 0, 0, 0, 1, 2, 2, 0, 2, 2], [0, 1, 1, 0, 0, 2, 2, 0, 2, 0, 2, 1], [0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 1, 0], [2, 0, 0, 1, 0, 2, 0, 2, 0, 0, 1, 2], [0, 2, 2, 0, 1, 0, 2, 2, 2, 2, 0, 0], [2, 1, 2, 1, 0, 0, 1, 0, 1, 2, 0, 0], [1, 0, 2, 0, 1, 0, 0, 0, 1, 1, 0, 1], [0, 0, 2, 0, 1, 0, 0, 0, 2, 2, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0], [1, 1, 0, 1, 2, 1, 1, 1, 2, 0, 1, 0], [1, 0, 2, 0, 2, 2, 1, 0, 2, 1, 1, 0], [0, 0, 2, 2, 0, 2, 1, 2, 2, 0, 1, 0], [0, 0, 0, 2, 1, 0, 0, 0, 1, 0, 0, 1], [0, 0, 2, 0, 0, 1, 2, 2, 2, 1, 0, 0], [1, 0, 1, 2, 0, 0, 2, 0, 1, 0, 1, 0], [2, 2, 1, 2, 2, 0, 0, 0, 0, 0, 1, 1], [0, 0, 2, 0, 2, 2, 2, 2, 0, 2, 0, 0], [0, 2, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0, 2, 0, 2, 1, 0, 1], [0, 1, 1, 1, 2, 0, 0, 1, 1, 2, 1, 0], [0, 0, 1, 0, 1, 0, 1, 0, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0, 0, 1, 0, 0, 1, 0], [0, 2, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0], [1, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 2], [0, 1, 0, 2, 0, 0, 1, 0, 1, 2, 1, 0], [0, 2, 1, 2, 1, 2, 2, 0, 0, 1, 0, 2], [2, 0, 0, 2, 0, 2, 1, 0, 0, 2, 2, 0], [0, 0, 1, 0, 2, 0, 1, 0, 1, 0, 0, 0], [0, 1, 2, 0, 0, 2, 1, 0, 1, 2, 0, 2], [1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0], [0, 0, 0, 1, 0, 0, 2, 1, 0, 0, 0, 0]], "rhs": [67, 59, 12, 57, 58, 37, 66, 27, 62, 73, 73, 47, 53, 36, 80, 93, 76, 38, 55, 50, 77, 76, 45, 70, 68, 34, 28, 48, 74, 57, 86, 89, 34, 72, 32, 16], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s8/tests/run.py b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l4-s8/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s1/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s1/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..537a3929960dc67a41e6dbbbe428d650adc3b462 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [2, 4], [10, 5], [8, 4], [4, 13], [7, 1], [7, 10], [9, 2], [5, 13], [2, 9], [9, 5], [1, 0], [6, 9]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s1/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e464e6ded20f34c7ab78abd051abab9db86df8a9 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [0, 9, 4, 8, 6, 10, 7, 5, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s1/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-l3-s1/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..537a3929960dc67a41e6dbbbe428d650adc3b462 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [2, 4], [10, 5], [8, 4], [4, 13], [7, 1], [7, 10], [9, 2], [5, 13], [2, 9], [9, 5], [1, 0], [6, 9]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s6/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s6/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..120f87294d6b8a149a8911b3b3c2eb11c1a54f32 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[4, 4], [4, 10], [9, 10], [13, 1], [1, 1], [0, 9], [12, 13], [9, 2], [2, 9], [7, 6], [7, 12], [3, 12], [2, 5]], "k": 8, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s6/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ddc8ee00b11fb4347e77a6fc92f2b311550b0c8 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [5, 11, 10, 2, 3, 7, 0, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/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-l3-s6/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..120f87294d6b8a149a8911b3b3c2eb11c1a54f32 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[4, 4], [4, 10], [9, 10], [13, 1], [1, 1], [0, 9], [12, 13], [9, 2], [2, 9], [7, 6], [7, 12], [3, 12], [2, 5]], "k": 8, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s8/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l3-s8/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ee70585e8f954f2016f71c9ee1cc2efb4b0b07c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 12], [6, 5], [3, 1], [6, 1], [10, 4], [13, 10], [3, 10], [13, 13], [2, 3], [8, 3], [11, 5], [9, 11], [9, 7]], "k": 8, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s8/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f52abbef631d328ff1f060efb215beaad063ad44 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [0, 11, 5, 10, 4, 9, 2, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s8/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-l3-s8/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ee70585e8f954f2016f71c9ee1cc2efb4b0b07c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 12], [6, 5], [3, 1], [6, 1], [10, 4], [13, 10], [3, 10], [13, 13], [2, 3], [8, 3], [11, 5], [9, 11], [9, 7]], "k": 8, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l1-s1/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s1/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5643c4160a97dc7cea8094e1a9ac249b6bbae7ce --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [4, 1], [5, -1], [-1, 0], [0, -1], [1, 0]], "area": 2, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s1/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7e2fab2d5af1ce09e2749e39d6c55389a358a89e --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 3, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l1-s1/tests/check.py b/tasks/construct-rlve-largest-rectangle-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s1/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-l1-s1/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5643c4160a97dc7cea8094e1a9ac249b6bbae7ce --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [4, 1], [5, -1], [-1, 0], [0, -1], [1, 0]], "area": 2, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s1/tests/run.py b/tasks/construct-rlve-largest-rectangle-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s1/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s6/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s6/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23132a0548c69fc25e7480d6b39e76400fb5e639 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-1, 4], [-3, -1], [1, 0], [-2, 1], [-6, 0], [2, 3]], "area": 10, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s6/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4c51086f38ecd6b932e7cdd7131481b09b8249a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 3, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l1-s6/tests/check.py b/tasks/construct-rlve-largest-rectangle-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s6/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-l1-s6/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23132a0548c69fc25e7480d6b39e76400fb5e639 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-1, 4], [-3, -1], [1, 0], [-2, 1], [-6, 0], [2, 3]], "area": 10, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s6/tests/run.py b/tasks/construct-rlve-largest-rectangle-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s6/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s8/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s8/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d6c9d745425c14d5a57fc9476c1ca0134d163e1 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[5, 4], [-5, -1], [8, 2], [6, -1], [3, 1], [6, 4]], "area": 13, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s8/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8706f401c6d23a1e86a5c8321cdfd09fb11cd92d --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 2, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l1-s8/tests/check.py b/tasks/construct-rlve-largest-rectangle-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s8/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-l1-s8/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d6c9d745425c14d5a57fc9476c1ca0134d163e1 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[5, 4], [-5, -1], [8, 2], [6, -1], [3, 1], [6, 4]], "area": 13, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s8/tests/run.py b/tasks/construct-rlve-largest-rectangle-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l1-s8/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s0/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s0/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1c5bfb8fbd719d9a14e8c207f0007b7a3aa0d3d4 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-25, 14], [-27, 23], [8, -5], [12, 15], [-20, -7], [-39, 22], [-29, -31], [2, -37], [-32, 39], [40, -23], [38, 19], [-16, -4], [-28, -35], [29, -14], [-9, -40], [12, 7], [18, 31], [-20, 20], [-14, -16], [-23, 34], [0, -23], [23, -29], [25, 35], [-49, -19], [33, 1], [12, 34], [23, 17], [-22, -39], [-26, 22], [-33, 0], [-10, -32], [-5, -8], [22, -33], [34, 19], [-30, 22], [12, 35], [-11, -35], [-30, 3], [-30, -35], [17, -5]], "area": 617, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s0/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..309c9e1d2f6798f922871f68e57cc3e35da60491 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [18, 29, 23, 38]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l5-s0/tests/check.py b/tasks/construct-rlve-largest-rectangle-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1c5bfb8fbd719d9a14e8c207f0007b7a3aa0d3d4 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-25, 14], [-27, 23], [8, -5], [12, 15], [-20, -7], [-39, 22], [-29, -31], [2, -37], [-32, 39], [40, -23], [38, 19], [-16, -4], [-28, -35], [29, -14], [-9, -40], [12, 7], [18, 31], [-20, 20], [-14, -16], [-23, 34], [0, -23], [23, -29], [25, 35], [-49, -19], [33, 1], [12, 34], [23, 17], [-22, -39], [-26, 22], [-33, 0], [-10, -32], [-5, -8], [22, -33], [34, 19], [-30, 22], [12, 35], [-11, -35], [-30, 3], [-30, -35], [17, -5]], "area": 617, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s0/tests/run.py b/tasks/construct-rlve-largest-rectangle-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s0/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s7/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s7/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c736fa7d3a3324b92e144894de42cbfecc933902 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-6, -3], [11, -36], [31, 4], [1, -22], [10, 16], [-23, 0], [28, -14], [2, -9], [5, 23], [30, 10], [20, -22], [-19, -2], [-17, 37], [30, -18], [-14, -1], [-13, -34], [12, 26], [39, -6], [-5, -10], [38, -8], [32, 25], [-3, -25], [-14, -20], [9, 26], [35, -22], [5, -21], [1, -2], [-32, -23], [30, -8], [-14, -29], [7, -2], [21, 36], [-18, -22], [21, 28], [2, -21], [-8, -10], [-19, 38], [-16, 10], [37, -8], [-16, -39]], "area": 50, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s7/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb726c74bb6168ae8b77317e9791733a899c7df0 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 18, 7, 26]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l5-s7/tests/check.py b/tasks/construct-rlve-largest-rectangle-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s7/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-l5-s7/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c736fa7d3a3324b92e144894de42cbfecc933902 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-6, -3], [11, -36], [31, 4], [1, -22], [10, 16], [-23, 0], [28, -14], [2, -9], [5, 23], [30, 10], [20, -22], [-19, -2], [-17, 37], [30, -18], [-14, -1], [-13, -34], [12, 26], [39, -6], [-5, -10], [38, -8], [32, 25], [-3, -25], [-14, -20], [9, 26], [35, -22], [5, -21], [1, -2], [-32, -23], [30, -8], [-14, -29], [7, -2], [21, 36], [-18, -22], [21, 28], [2, -21], [-8, -10], [-19, 38], [-16, 10], [37, -8], [-16, -39]], "area": 50, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s7/tests/run.py b/tasks/construct-rlve-largest-rectangle-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s7/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s9/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s9/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..55c05a6f8d21809e24af73ab215483b3af4d9eea --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-13, 11], [6, 19], [15, 11], [-8, 27], [3, 2], [-39, 21], [-5, 16], [-14, -19], [31, 13], [18, -40], [39, -6], [40, 5], [-5, 27], [-2, 10], [4, 35], [15, 1], [-39, -15], [33, 32], [-27, 16], [10, -5], [-28, 8], [33, -16], [-1, -15], [21, 4], [-4, 34], [0, 28], [-9, -39], [20, -36], [-31, -33], [24, -16], [9, -9], [-3, 7], [19, 15], [30, 25], [28, -4], [-32, 38], [39, -8], [8, 35], [7, 2], [24, 4]], "area": 145, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s9/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79aed88043ac405da256fe2ce28d38db06849f86 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [1, 2, 38, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l5-s9/tests/check.py b/tasks/construct-rlve-largest-rectangle-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s9/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-l5-s9/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..55c05a6f8d21809e24af73ab215483b3af4d9eea --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-13, 11], [6, 19], [15, 11], [-8, 27], [3, 2], [-39, 21], [-5, 16], [-14, -19], [31, 13], [18, -40], [39, -6], [40, 5], [-5, 27], [-2, 10], [4, 35], [15, 1], [-39, -15], [33, 32], [-27, 16], [10, -5], [-28, 8], [33, -16], [-1, -15], [21, 4], [-4, 34], [0, 28], [-9, -39], [20, -36], [-31, -33], [24, -16], [9, -9], [-3, 7], [19, 15], [30, 25], [28, -4], [-32, 38], [39, -8], [8, 35], [7, 2], [24, 4]], "area": 145, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s9/tests/run.py b/tasks/construct-rlve-largest-rectangle-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s9/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-matrix-permutation-equivalence-l6-s2/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s2/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..675f151930e7d3941d49463de6983eb044eae91a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": ["111111011111111", "101010111111110", "111111101100111", "101011111111111", "111101111111111", "101100111101111"], "B": ["111011111111000", "110111111111111", "101011111111111", "101011110111110", "011111011111011", "111111111111101"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..54c4fca85367565290d9aa3867af7dc9e0f2e79f --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [5, 0, 3, 1, 2, 4], "b": [7, 3, 6, 1, 8, 2, 11, 13, 14, 9, 12, 0, 10, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/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-l6-s2/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..675f151930e7d3941d49463de6983eb044eae91a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": ["111111011111111", "101010111111110", "111111101100111", "101011111111111", "111101111111111", "101100111101111"], "B": ["111011111111000", "110111111111111", "101011111111111", "101011110111110", "011111011111011", "111111111111101"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s2/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s5/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s5/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd6807644a1431adbca4abe8c329bb11d6befe3a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": ["10000000100000001001", "01001000000011010010", "00001000000010000011", "10011011000000100110", "11100011010011010101", "00010010010000100101", "01000001000100000001", "01000100000000001010", "11000000000100000000", "11011000000000000000", "11001000001100000110", "00000010000000000001", "00001000000000001001", "00100001001000000100", "11000110000110010010", "00101000010000000110", "00001001100000111011", "00100000101000000101", "00100000001000001100", "01010001000010000100", "10101100110001110010", "00000000000101100110", "00000001001010010000"], "B": ["10000100101110000110", "11000000000100000001", "10001010100000000000", "10000000011010111010", "00001000001101000011", "00000000101000000100", "10111000110101011001", "00001000011000100000", "00001011010100001011", "01100100100000010000", "00000000100000001000", "10001000000000110001", "11100000000000010000", "00000100110000000100", "00010000100010111000", "00001001000000000110", "00110101011111000010", "00000010000011010010", "01001010011000010010", "01100000000000010100", "00110000001000010010", "00000000101000000011", "00001010010000000000"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f062bba194595c3f03aabb75b7ecb67b80f2301 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [16, 22, 6, 3, 1, 12, 4, 9, 14, 17, 11, 19, 13, 0, 5, 7, 20, 21, 10, 18, 15, 2, 8], "b": [7, 10, 2, 9, 1, 8, 11, 5, 19, 0, 4, 15, 14, 13, 3, 17, 6, 16, 18, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd6807644a1431adbca4abe8c329bb11d6befe3a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": ["10000000100000001001", "01001000000011010010", "00001000000010000011", "10011011000000100110", "11100011010011010101", "00010010010000100101", "01000001000100000001", "01000100000000001010", "11000000000100000000", "11011000000000000000", "11001000001100000110", "00000010000000000001", "00001000000000001001", "00100001001000000100", "11000110000110010010", "00101000010000000110", "00001001100000111011", "00100000101000000101", "00100000001000001100", "01010001000010000100", "10101100110001110010", "00000000000101100110", "00000001001010010000"], "B": ["10000100101110000110", "11000000000100000001", "10001010100000000000", "10000000011010111010", "00001000001101000011", "00000000101000000100", "10111000110101011001", "00001000011000100000", "00001011010100001011", "01100100100000010000", "00000000100000001000", "10001000000000110001", "11100000000000010000", "00000100110000000100", "00010000100010111000", "00001001000000000110", "00110101011111000010", "00000010000011010010", "01001010011000010010", "01100000000000010100", "00110000001000010010", "00000000101000000011", "00001010010000000000"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s5/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-max-achromatic-coloring-l3-s0/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s0/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b56f6deb4609e2bad2d46cd3cf3891a866d41424 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "edges": [[0, 2], [0, 5], [0, 6], [0, 7], [0, 9], [1, 2], [1, 7], [1, 8], [2, 6], [3, 7], [4, 6], [6, 7], [6, 8]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s0/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3643130b715bf98d73c141c3a146710e426d86d0 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 1, 2, 2, 1, 1, 3, 4, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("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-l3-s0/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b56f6deb4609e2bad2d46cd3cf3891a866d41424 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "edges": [[0, 2], [0, 5], [0, 6], [0, 7], [0, 9], [1, 2], [1, 7], [1, 8], [2, 6], [3, 7], [4, 6], [6, 7], [6, 8]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s0/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s7/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s7/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f2b743b670f9ef35ae25ae318379e81e936b1f1 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 5], [1, 6], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 9], [3, 5], [3, 7], [4, 5], [4, 7], [4, 8], [5, 6], [5, 9], [6, 8], [7, 8], [7, 9], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s7/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1285c328008f859b08a11597d253681d06936179 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 0, 1, 2, 0, 3, 4, 4, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("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-l3-s7/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f2b743b670f9ef35ae25ae318379e81e936b1f1 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 5], [1, 6], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 9], [3, 5], [3, 7], [4, 5], [4, 7], [4, 8], [5, 6], [5, 9], [6, 8], [7, 8], [7, 9], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s7/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s9/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l3-s9/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2102fb0e2c049d40439e49c2f216cf25f56f117d --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [2, 3], [2, 6], [2, 8], [2, 9], [3, 4], [3, 5], [4, 5], [4, 7], [4, 8], [5, 7], [5, 9], [6, 7], [6, 8], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s9/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dffdd9764e713d38a40b29c7c38e82749034e494 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 2, 0, 2, 1, 3, 4, 5, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("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-l3-s9/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2102fb0e2c049d40439e49c2f216cf25f56f117d --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [2, 3], [2, 6], [2, 8], [2, 9], [3, 4], [3, 5], [4, 5], [4, 7], [4, 8], [5, 7], [5, 9], [6, 7], [6, 8], [8, 9]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-maximum-clique-l5-s3/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-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-rlve-maximum-clique-l5-s3/environment/instance.json b/tasks/construct-rlve-maximum-clique-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..965396663781dd6d695df38084808c1aaf75af0c --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 7, "edges": [[0, 2], [0, 3], [0, 4], [0, 6], [0, 7], [0, 13], [0, 20], [0, 22], [0, 25], [0, 31], [0, 32], [0, 33], [0, 34], [0, 36], [0, 38], [0, 39], [0, 40], [0, 41], [0, 42], [0, 43], [1, 3], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 17], [1, 20], [1, 21], [1, 23], [1, 29], [1, 30], [1, 32], [1, 33], [1, 35], [1, 36], [1, 39], [1, 40], [1, 42], [2, 5], [2, 9], [2, 12], [2, 13], [2, 14], [2, 17], [2, 19], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [2, 37], [2, 38], [2, 39], [2, 41], [2, 42], [2, 43], [3, 4], [3, 5], [3, 10], [3, 12], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 24], [3, 25], [3, 31], [3, 33], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [4, 7], [4, 8], [4, 10], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 30], [4, 31], [4, 36], [4, 39], [4, 40], [4, 42], [4, 43], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [5, 13], [5, 15], [5, 16], [5, 17], [5, 19], [5, 21], [5, 22], [5, 24], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 33], [5, 34], [5, 35], [5, 37], [5, 41], [5, 42], [6, 7], [6, 9], [6, 12], [6, 14], [6, 17], [6, 18], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 28], [6, 29], [6, 32], [6, 33], [6, 40], [6, 41], [6, 42], [6, 43], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 21], [7, 22], [7, 25], [7, 26], [7, 27], [7, 28], [7, 31], [7, 33], [7, 34], [7, 35], [7, 40], [8, 9], [8, 10], [8, 13], [8, 14], [8, 17], [8, 22], [8, 23], [8, 25], [8, 27], [8, 28], [8, 30], [8, 32], [8, 40], [8, 41], [8, 42], [8, 43], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 20], [9, 21], [9, 24], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 34], [9, 36], [9, 38], [9, 39], [9, 41], [9, 43], [10, 11], [10, 12], [10, 13], [10, 15], [10, 16], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 27], [10, 28], [10, 29], [10, 32], [10, 33], [10, 34], [10, 35], [10, 37], [10, 39], [10, 40], [10, 42], [10, 43], [11, 13], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 25], [11, 26], [11, 27], [11, 31], [11, 34], [11, 37], [11, 38], [11, 39], [11, 40], [11, 42], [11, 43], [12, 14], [12, 15], [12, 17], [12, 19], [12, 20], [12, 21], [12, 25], [12, 30], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 42], [12, 43], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 26], [13, 33], [13, 34], [13, 35], [13, 36], [13, 39], [13, 40], [13, 41], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 23], [14, 24], [14, 28], [14, 34], [14, 36], [14, 43], [15, 16], [15, 19], [15, 21], [15, 22], [15, 25], [15, 26], [15, 27], [15, 29], [15, 30], [15, 31], [15, 33], [15, 34], [15, 37], [15, 39], [15, 40], [15, 41], [15, 43], [16, 20], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 33], [16, 34], [16, 35], [16, 36], [16, 37], [16, 41], [16, 42], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 28], [17, 29], [17, 31], [17, 32], [17, 35], [17, 36], [17, 39], [17, 40], [17, 41], [18, 19], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 30], [18, 31], [18, 32], [18, 34], [18, 35], [18, 36], [18, 38], [18, 39], [18, 40], [18, 41], [18, 42], [19, 20], [19, 21], [19, 22], [19, 23], [19, 26], [19, 29], [19, 30], [19, 31], [19, 36], [19, 38], [19, 41], [20, 23], [20, 24], [20, 25], [20, 28], [20, 31], [20, 34], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [20, 40], [20, 42], [21, 23], [21, 24], [21, 26], [21, 27], [21, 28], [21, 31], [21, 32], [21, 33], [21, 35], [21, 36], [21, 37], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [22, 24], [22, 25], [22, 30], [22, 32], [22, 34], [22, 35], [22, 38], [22, 42], [22, 43], [23, 25], [23, 27], [23, 31], [23, 34], [23, 35], [23, 37], [23, 38], [23, 40], [23, 41], [23, 42], [23, 43], [24, 25], [24, 30], [24, 31], [24, 34], [24, 36], [24, 37], [24, 38], [24, 40], [24, 41], [24, 42], [25, 27], [25, 29], [25, 30], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 40], [25, 41], [25, 42], [26, 27], [26, 29], [26, 31], [26, 32], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 41], [26, 42], [26, 43], [27, 34], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [28, 31], [28, 34], [28, 35], [28, 37], [28, 42], [28, 43], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 37], [29, 41], [30, 31], [30, 35], [30, 36], [30, 40], [30, 41], [30, 42], [30, 43], [31, 32], [31, 34], [31, 35], [31, 37], [31, 38], [31, 39], [31, 41], [31, 42], [31, 43], [32, 34], [32, 35], [32, 36], [32, 38], [32, 40], [32, 42], [32, 43], [33, 34], [33, 35], [33, 36], [33, 38], [33, 40], [33, 41], [33, 42], [33, 43], [34, 37], [34, 40], [34, 41], [35, 38], [36, 37], [36, 39], [36, 40], [36, 43], [37, 38], [37, 40], [37, 42], [37, 43], [38, 43], [39, 43], [40, 42], [40, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s3/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5db02ab2ec97a608d95103229d8aaf15c6e9b7fc --- /dev/null +++ b/tasks/construct-rlve-maximum-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": [0, 7, 13, 25, 33, 34, 40]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l5-s3/tests/check.py b/tasks/construct-rlve-maximum-clique-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l5-s3/tests/instance.json b/tasks/construct-rlve-maximum-clique-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..965396663781dd6d695df38084808c1aaf75af0c --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 7, "edges": [[0, 2], [0, 3], [0, 4], [0, 6], [0, 7], [0, 13], [0, 20], [0, 22], [0, 25], [0, 31], [0, 32], [0, 33], [0, 34], [0, 36], [0, 38], [0, 39], [0, 40], [0, 41], [0, 42], [0, 43], [1, 3], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 17], [1, 20], [1, 21], [1, 23], [1, 29], [1, 30], [1, 32], [1, 33], [1, 35], [1, 36], [1, 39], [1, 40], [1, 42], [2, 5], [2, 9], [2, 12], [2, 13], [2, 14], [2, 17], [2, 19], [2, 23], [2, 24], [2, 25], [2, 26], [2, 28], [2, 29], [2, 37], [2, 38], [2, 39], [2, 41], [2, 42], [2, 43], [3, 4], [3, 5], [3, 10], [3, 12], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 24], [3, 25], [3, 31], [3, 33], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [4, 7], [4, 8], [4, 10], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 30], [4, 31], [4, 36], [4, 39], [4, 40], [4, 42], [4, 43], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [5, 13], [5, 15], [5, 16], [5, 17], [5, 19], [5, 21], [5, 22], [5, 24], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 33], [5, 34], [5, 35], [5, 37], [5, 41], [5, 42], [6, 7], [6, 9], [6, 12], [6, 14], [6, 17], [6, 18], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 28], [6, 29], [6, 32], [6, 33], [6, 40], [6, 41], [6, 42], [6, 43], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 21], [7, 22], [7, 25], [7, 26], [7, 27], [7, 28], [7, 31], [7, 33], [7, 34], [7, 35], [7, 40], [8, 9], [8, 10], [8, 13], [8, 14], [8, 17], [8, 22], [8, 23], [8, 25], [8, 27], [8, 28], [8, 30], [8, 32], [8, 40], [8, 41], [8, 42], [8, 43], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 20], [9, 21], [9, 24], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 34], [9, 36], [9, 38], [9, 39], [9, 41], [9, 43], [10, 11], [10, 12], [10, 13], [10, 15], [10, 16], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 27], [10, 28], [10, 29], [10, 32], [10, 33], [10, 34], [10, 35], [10, 37], [10, 39], [10, 40], [10, 42], [10, 43], [11, 13], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 25], [11, 26], [11, 27], [11, 31], [11, 34], [11, 37], [11, 38], [11, 39], [11, 40], [11, 42], [11, 43], [12, 14], [12, 15], [12, 17], [12, 19], [12, 20], [12, 21], [12, 25], [12, 30], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 42], [12, 43], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 26], [13, 33], [13, 34], [13, 35], [13, 36], [13, 39], [13, 40], [13, 41], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 23], [14, 24], [14, 28], [14, 34], [14, 36], [14, 43], [15, 16], [15, 19], [15, 21], [15, 22], [15, 25], [15, 26], [15, 27], [15, 29], [15, 30], [15, 31], [15, 33], [15, 34], [15, 37], [15, 39], [15, 40], [15, 41], [15, 43], [16, 20], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 33], [16, 34], [16, 35], [16, 36], [16, 37], [16, 41], [16, 42], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 28], [17, 29], [17, 31], [17, 32], [17, 35], [17, 36], [17, 39], [17, 40], [17, 41], [18, 19], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 30], [18, 31], [18, 32], [18, 34], [18, 35], [18, 36], [18, 38], [18, 39], [18, 40], [18, 41], [18, 42], [19, 20], [19, 21], [19, 22], [19, 23], [19, 26], [19, 29], [19, 30], [19, 31], [19, 36], [19, 38], [19, 41], [20, 23], [20, 24], [20, 25], [20, 28], [20, 31], [20, 34], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [20, 40], [20, 42], [21, 23], [21, 24], [21, 26], [21, 27], [21, 28], [21, 31], [21, 32], [21, 33], [21, 35], [21, 36], [21, 37], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [22, 24], [22, 25], [22, 30], [22, 32], [22, 34], [22, 35], [22, 38], [22, 42], [22, 43], [23, 25], [23, 27], [23, 31], [23, 34], [23, 35], [23, 37], [23, 38], [23, 40], [23, 41], [23, 42], [23, 43], [24, 25], [24, 30], [24, 31], [24, 34], [24, 36], [24, 37], [24, 38], [24, 40], [24, 41], [24, 42], [25, 27], [25, 29], [25, 30], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 40], [25, 41], [25, 42], [26, 27], [26, 29], [26, 31], [26, 32], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 41], [26, 42], [26, 43], [27, 34], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [28, 31], [28, 34], [28, 35], [28, 37], [28, 42], [28, 43], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 37], [29, 41], [30, 31], [30, 35], [30, 36], [30, 40], [30, 41], [30, 42], [30, 43], [31, 32], [31, 34], [31, 35], [31, 37], [31, 38], [31, 39], [31, 41], [31, 42], [31, 43], [32, 34], [32, 35], [32, 36], [32, 38], [32, 40], [32, 42], [32, 43], [33, 34], [33, 35], [33, 36], [33, 38], [33, 40], [33, 41], [33, 42], [33, 43], [34, 37], [34, 40], [34, 41], [35, 38], [36, 37], [36, 39], [36, 40], [36, 43], [37, 38], [37, 40], [37, 42], [37, 43], [38, 43], [39, 43], [40, 42], [40, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s3/tests/run.py b/tasks/construct-rlve-maximum-clique-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-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-rlve-maximum-clique-l5-s3/tests/test.sh b/tasks/construct-rlve-maximum-clique-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-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-rlve-maximum-clique-l5-s4/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l5-s4/environment/instance.json b/tasks/construct-rlve-maximum-clique-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9845604409fd7cb8a48a83580c01f091b02bb08 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 10, "edges": [[0, 2], [0, 4], [0, 6], [0, 7], [0, 8], [0, 10], [0, 13], [0, 14], [0, 17], [0, 19], [0, 20], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 43], [1, 2], [1, 3], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 17], [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, 37], [1, 38], [1, 40], [1, 41], [1, 42], [1, 43], [2, 4], [2, 7], [2, 10], [2, 13], [2, 16], [2, 17], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 28], [2, 29], [2, 31], [2, 32], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [2, 41], [2, 42], [2, 43], [3, 4], [3, 5], [3, 6], [3, 8], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 34], [3, 36], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 25], [4, 26], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 34], [4, 37], [4, 38], [4, 39], [4, 40], [4, 42], [4, 43], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 21], [5, 27], [5, 28], [5, 29], [5, 30], [5, 32], [5, 34], [5, 36], [5, 37], [5, 40], [5, 41], [5, 42], [6, 7], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 23], [6, 25], [6, 26], [6, 28], [6, 31], [6, 32], [6, 34], [6, 35], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [7, 8], [7, 11], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 20], [7, 21], [7, 24], [7, 26], [7, 27], [7, 28], [7, 31], [7, 32], [7, 38], [7, 39], [7, 42], [8, 9], [8, 10], [8, 11], [8, 12], [8, 15], [8, 16], [8, 18], [8, 19], [8, 20], [8, 22], [8, 24], [8, 26], [8, 27], [8, 30], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [8, 39], [8, 41], [8, 42], [8, 43], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 29], [9, 30], [9, 31], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [10, 11], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 27], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 37], [10, 42], [10, 43], [11, 12], [11, 13], [11, 15], [11, 18], [11, 19], [11, 21], [11, 22], [11, 24], [11, 25], [11, 27], [11, 28], [11, 34], [11, 35], [11, 37], [11, 40], [11, 43], [12, 13], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 27], [12, 29], [12, 30], [12, 31], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 40], [12, 41], [13, 15], [13, 16], [13, 17], [13, 21], [13, 22], [13, 23], [13, 24], [13, 26], [13, 27], [13, 28], [13, 29], [13, 31], [13, 32], [13, 34], [13, 37], [13, 39], [13, 41], [13, 42], [13, 43], [14, 15], [14, 16], [14, 17], [14, 21], [14, 22], [14, 26], [14, 28], [14, 32], [14, 34], [14, 35], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [15, 16], [15, 17], [15, 19], [15, 20], [15, 22], [15, 23], [15, 24], [15, 27], [15, 29], [15, 30], [15, 34], [15, 35], [15, 36], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [16, 18], [16, 19], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 28], [16, 30], [16, 31], [16, 32], [16, 35], [16, 37], [16, 38], [16, 41], [16, 42], [16, 43], [17, 18], [17, 19], [17, 20], [17, 21], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 42], [17, 43], [18, 19], [18, 20], [18, 27], [18, 30], [18, 32], [18, 34], [18, 35], [18, 36], [18, 41], [18, 43], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 33], [19, 34], [19, 38], [19, 39], [19, 41], [19, 42], [19, 43], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 32], [20, 33], [20, 36], [20, 37], [20, 38], [20, 39], [20, 41], [20, 42], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 32], [21, 33], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [22, 24], [22, 28], [22, 30], [22, 31], [22, 32], [22, 36], [22, 37], [22, 39], [22, 40], [22, 42], [22, 43], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 33], [23, 35], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [24, 25], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 36], [24, 38], [24, 40], [24, 41], [24, 42], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 34], [25, 35], [25, 37], [25, 39], [25, 40], [25, 41], [25, 43], [26, 27], [26, 28], [26, 29], [26, 31], [26, 32], [26, 35], [26, 36], [26, 39], [26, 40], [26, 43], [27, 28], [27, 29], [27, 30], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [28, 29], [28, 30], [28, 31], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 41], [28, 42], [28, 43], [29, 30], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [29, 41], [29, 43], [30, 31], [30, 32], [30, 33], [30, 34], [30, 37], [30, 41], [30, 42], [30, 43], [31, 32], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [31, 40], [31, 41], [31, 42], [32, 33], [32, 36], [32, 38], [32, 39], [32, 40], [32, 43], [33, 35], [33, 37], [33, 38], [33, 39], [33, 40], [33, 42], [33, 43], [34, 36], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [34, 43], [35, 37], [35, 38], [35, 39], [35, 40], [35, 42], [35, 43], [36, 37], [36, 39], [36, 40], [36, 42], [36, 43], [37, 39], [37, 41], [38, 39], [38, 40], [38, 42], [38, 43], [39, 40], [39, 41], [39, 42], [39, 43], [40, 41], [40, 42], [40, 43], [41, 42], [41, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s4/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4665b8ccd16e89282db8d37941b0bcae67fd52eb --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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' +{"clique": [3, 5, 8, 15, 19, 27, 30, 34, 41, 42]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l5-s4/tests/check.py b/tasks/construct-rlve-maximum-clique-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-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("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l5-s4/tests/instance.json b/tasks/construct-rlve-maximum-clique-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9845604409fd7cb8a48a83580c01f091b02bb08 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 10, "edges": [[0, 2], [0, 4], [0, 6], [0, 7], [0, 8], [0, 10], [0, 13], [0, 14], [0, 17], [0, 19], [0, 20], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 43], [1, 2], [1, 3], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 17], [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, 37], [1, 38], [1, 40], [1, 41], [1, 42], [1, 43], [2, 4], [2, 7], [2, 10], [2, 13], [2, 16], [2, 17], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 28], [2, 29], [2, 31], [2, 32], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [2, 41], [2, 42], [2, 43], [3, 4], [3, 5], [3, 6], [3, 8], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 34], [3, 36], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 22], [4, 23], [4, 25], [4, 26], [4, 28], [4, 29], [4, 30], [4, 31], [4, 33], [4, 34], [4, 37], [4, 38], [4, 39], [4, 40], [4, 42], [4, 43], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 21], [5, 27], [5, 28], [5, 29], [5, 30], [5, 32], [5, 34], [5, 36], [5, 37], [5, 40], [5, 41], [5, 42], [6, 7], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 20], [6, 23], [6, 25], [6, 26], [6, 28], [6, 31], [6, 32], [6, 34], [6, 35], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [7, 8], [7, 11], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 20], [7, 21], [7, 24], [7, 26], [7, 27], [7, 28], [7, 31], [7, 32], [7, 38], [7, 39], [7, 42], [8, 9], [8, 10], [8, 11], [8, 12], [8, 15], [8, 16], [8, 18], [8, 19], [8, 20], [8, 22], [8, 24], [8, 26], [8, 27], [8, 30], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [8, 39], [8, 41], [8, 42], [8, 43], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 29], [9, 30], [9, 31], [9, 34], [9, 35], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [10, 11], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 27], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 37], [10, 42], [10, 43], [11, 12], [11, 13], [11, 15], [11, 18], [11, 19], [11, 21], [11, 22], [11, 24], [11, 25], [11, 27], [11, 28], [11, 34], [11, 35], [11, 37], [11, 40], [11, 43], [12, 13], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 27], [12, 29], [12, 30], [12, 31], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 40], [12, 41], [13, 15], [13, 16], [13, 17], [13, 21], [13, 22], [13, 23], [13, 24], [13, 26], [13, 27], [13, 28], [13, 29], [13, 31], [13, 32], [13, 34], [13, 37], [13, 39], [13, 41], [13, 42], [13, 43], [14, 15], [14, 16], [14, 17], [14, 21], [14, 22], [14, 26], [14, 28], [14, 32], [14, 34], [14, 35], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [15, 16], [15, 17], [15, 19], [15, 20], [15, 22], [15, 23], [15, 24], [15, 27], [15, 29], [15, 30], [15, 34], [15, 35], [15, 36], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [16, 18], [16, 19], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 28], [16, 30], [16, 31], [16, 32], [16, 35], [16, 37], [16, 38], [16, 41], [16, 42], [16, 43], [17, 18], [17, 19], [17, 20], [17, 21], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 42], [17, 43], [18, 19], [18, 20], [18, 27], [18, 30], [18, 32], [18, 34], [18, 35], [18, 36], [18, 41], [18, 43], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 33], [19, 34], [19, 38], [19, 39], [19, 41], [19, 42], [19, 43], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 32], [20, 33], [20, 36], [20, 37], [20, 38], [20, 39], [20, 41], [20, 42], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 32], [21, 33], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [22, 24], [22, 28], [22, 30], [22, 31], [22, 32], [22, 36], [22, 37], [22, 39], [22, 40], [22, 42], [22, 43], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 33], [23, 35], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [24, 25], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 36], [24, 38], [24, 40], [24, 41], [24, 42], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 34], [25, 35], [25, 37], [25, 39], [25, 40], [25, 41], [25, 43], [26, 27], [26, 28], [26, 29], [26, 31], [26, 32], [26, 35], [26, 36], [26, 39], [26, 40], [26, 43], [27, 28], [27, 29], [27, 30], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [28, 29], [28, 30], [28, 31], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 41], [28, 42], [28, 43], [29, 30], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [29, 41], [29, 43], [30, 31], [30, 32], [30, 33], [30, 34], [30, 37], [30, 41], [30, 42], [30, 43], [31, 32], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [31, 40], [31, 41], [31, 42], [32, 33], [32, 36], [32, 38], [32, 39], [32, 40], [32, 43], [33, 35], [33, 37], [33, 38], [33, 39], [33, 40], [33, 42], [33, 43], [34, 36], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [34, 43], [35, 37], [35, 38], [35, 39], [35, 40], [35, 42], [35, 43], [36, 37], [36, 39], [36, 40], [36, 42], [36, 43], [37, 39], [37, 41], [38, 39], [38, 40], [38, 42], [38, 43], [39, 40], [39, 41], [39, 42], [39, 43], [40, 41], [40, 42], [40, 43], [41, 42], [41, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s4/tests/run.py b/tasks/construct-rlve-maximum-clique-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l5-s4/tests/test.sh b/tasks/construct-rlve-maximum-clique-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-min-chromatic-number-l2-s0/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s0/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b62218d7882417496f4cdf664d058707d008dfd --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 3, "edges": [[0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 8], [2, 8], [3, 8], [5, 8], [5, 9], [6, 7]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s0/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..884e3bc822a6fa6dab4ae11ea391c86a657e59e2 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 0, 1, 1, 0, 1, 1, 2, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s0/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-l2-s0/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b62218d7882417496f4cdf664d058707d008dfd --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 3, "edges": [[0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 8], [2, 8], [3, 8], [5, 8], [5, 9], [6, 7]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s0/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s9/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s9/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2575cd7215326e454d5a061ddb257d6b0f63ad1e --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "edges": [[0, 4], [0, 5], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [3, 4], [3, 7], [3, 8], [4, 6], [4, 7], [4, 9], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s9/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c209f347bdc23ae59a751a5b2f4bf9328a1eb63f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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": [0, 0, 1, 2, 3, 2, 1, 4, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s9/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-l2-s9/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2575cd7215326e454d5a061ddb257d6b0f63ad1e --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "edges": [[0, 4], [0, 5], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [3, 4], [3, 7], [3, 8], [4, 6], [4, 7], [4, 9], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s9/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s1/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s1/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a015d635465ad94cd1b73c393790efd08cb6d4ab --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 4, "edges": [[0, 2], [0, 6], [0, 8], [0, 11], [0, 14], [0, 16], [0, 18], [0, 28], [1, 9], [1, 10], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 22], [1, 25], [1, 26], [1, 29], [2, 8], [2, 9], [2, 13], [2, 14], [2, 20], [2, 27], [3, 5], [3, 13], [3, 21], [3, 22], [3, 29], [4, 6], [4, 9], [4, 13], [4, 17], [4, 21], [4, 24], [5, 13], [5, 16], [5, 18], [5, 22], [5, 23], [6, 10], [6, 18], [6, 20], [6, 26], [6, 27], [6, 29], [7, 10], [7, 11], [7, 13], [7, 24], [7, 27], [8, 16], [8, 19], [8, 20], [8, 21], [8, 22], [8, 28], [9, 17], [9, 29], [10, 16], [10, 26], [11, 14], [11, 15], [11, 19], [11, 21], [11, 26], [11, 28], [12, 13], [12, 28], [12, 29], [13, 14], [13, 16], [13, 17], [13, 28], [13, 29], [14, 16], [14, 22], [14, 24], [14, 25], [14, 27], [14, 28], [15, 23], [15, 27], [16, 26], [17, 18], [17, 20], [17, 22], [17, 25], [18, 19], [18, 22], [18, 25], [18, 26], [18, 28], [18, 29], [19, 23], [19, 25], [19, 29], [20, 22], [20, 23], [21, 23], [21, 27], [22, 23], [22, 24], [22, 26], [23, 28], [27, 28], [28, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s1/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e7fb4f616132af00dae9ba597a0b3b0bef1c20f0 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 1, 1, 1, 2, 3, 2, 2, 0, 0, 1, 1, 0, 2, 2, 3, 2, 1, 0, 0, 3, 3, 1, 0, 3, 2, 0, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s1/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-l6-s1/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a015d635465ad94cd1b73c393790efd08cb6d4ab --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 4, "edges": [[0, 2], [0, 6], [0, 8], [0, 11], [0, 14], [0, 16], [0, 18], [0, 28], [1, 9], [1, 10], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 22], [1, 25], [1, 26], [1, 29], [2, 8], [2, 9], [2, 13], [2, 14], [2, 20], [2, 27], [3, 5], [3, 13], [3, 21], [3, 22], [3, 29], [4, 6], [4, 9], [4, 13], [4, 17], [4, 21], [4, 24], [5, 13], [5, 16], [5, 18], [5, 22], [5, 23], [6, 10], [6, 18], [6, 20], [6, 26], [6, 27], [6, 29], [7, 10], [7, 11], [7, 13], [7, 24], [7, 27], [8, 16], [8, 19], [8, 20], [8, 21], [8, 22], [8, 28], [9, 17], [9, 29], [10, 16], [10, 26], [11, 14], [11, 15], [11, 19], [11, 21], [11, 26], [11, 28], [12, 13], [12, 28], [12, 29], [13, 14], [13, 16], [13, 17], [13, 28], [13, 29], [14, 16], [14, 22], [14, 24], [14, 25], [14, 27], [14, 28], [15, 23], [15, 27], [16, 26], [17, 18], [17, 20], [17, 22], [17, 25], [18, 19], [18, 22], [18, 25], [18, 26], [18, 28], [18, 29], [19, 23], [19, 25], [19, 29], [20, 22], [20, 23], [21, 23], [21, 27], [22, 23], [22, 24], [22, 26], [23, 28], [27, 28], [28, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s1/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s6/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s6/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6fcc0f8c759fd5bf6465295d7a1c6fb616029c36 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 6, "edges": [[0, 1], [0, 13], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 26], [0, 27], [0, 28], [0, 29], [1, 2], [1, 3], [1, 7], [1, 9], [1, 11], [1, 12], [1, 14], [1, 15], [1, 20], [1, 21], [1, 24], [1, 26], [1, 28], [2, 3], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 16], [2, 17], [2, 20], [2, 22], [2, 24], [2, 25], [2, 26], [2, 27], [3, 6], [3, 10], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [3, 18], [3, 19], [3, 21], [3, 22], [3, 23], [3, 25], [3, 29], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [4, 15], [4, 17], [4, 22], [4, 23], [4, 27], [4, 29], [5, 6], [5, 9], [5, 11], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 21], [5, 25], [5, 26], [5, 29], [6, 7], [6, 9], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 21], [6, 22], [6, 24], [6, 25], [6, 29], [7, 10], [7, 13], [7, 14], [7, 17], [7, 18], [7, 19], [7, 23], [7, 25], [7, 26], [7, 28], [8, 10], [8, 11], [8, 14], [8, 18], [8, 19], [8, 20], [8, 22], [8, 27], [9, 13], [9, 14], [9, 16], [9, 29], [10, 12], [10, 21], [10, 23], [10, 24], [10, 25], [10, 28], [11, 14], [11, 19], [11, 22], [11, 23], [11, 25], [11, 27], [11, 29], [12, 13], [12, 14], [12, 16], [12, 20], [12, 21], [12, 25], [12, 26], [12, 29], [13, 17], [13, 19], [13, 21], [13, 23], [13, 25], [13, 26], [13, 28], [13, 29], [14, 18], [14, 20], [14, 23], [14, 28], [15, 17], [15, 18], [15, 21], [15, 24], [15, 25], [15, 26], [15, 28], [16, 17], [16, 18], [16, 25], [16, 26], [17, 24], [17, 27], [17, 28], [18, 20], [18, 26], [18, 29], [19, 20], [19, 21], [19, 22], [19, 29], [20, 21], [20, 22], [20, 24], [20, 25], [20, 27], [20, 28], [20, 29], [21, 22], [21, 23], [21, 26], [21, 29], [22, 25], [22, 26], [23, 25], [23, 26], [23, 28], [23, 29], [24, 25], [24, 27], [24, 29], [25, 26], [25, 28], [25, 29], [26, 28], [26, 29], [27, 28], [27, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s6/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bdea9c4dd4e5eb48b1b59ca7194974f8a9587542 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 0, 2, 2, 1, 0, 3, 3, 4, 1, 2, 4, 1, 5, 3, 1, 5, 4, 4, 2, 5, 1, 0, 4, 5, 2, 1, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s6/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-l6-s6/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6fcc0f8c759fd5bf6465295d7a1c6fb616029c36 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 6, "edges": [[0, 1], [0, 13], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 26], [0, 27], [0, 28], [0, 29], [1, 2], [1, 3], [1, 7], [1, 9], [1, 11], [1, 12], [1, 14], [1, 15], [1, 20], [1, 21], [1, 24], [1, 26], [1, 28], [2, 3], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 16], [2, 17], [2, 20], [2, 22], [2, 24], [2, 25], [2, 26], [2, 27], [3, 6], [3, 10], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [3, 18], [3, 19], [3, 21], [3, 22], [3, 23], [3, 25], [3, 29], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [4, 15], [4, 17], [4, 22], [4, 23], [4, 27], [4, 29], [5, 6], [5, 9], [5, 11], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 21], [5, 25], [5, 26], [5, 29], [6, 7], [6, 9], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 21], [6, 22], [6, 24], [6, 25], [6, 29], [7, 10], [7, 13], [7, 14], [7, 17], [7, 18], [7, 19], [7, 23], [7, 25], [7, 26], [7, 28], [8, 10], [8, 11], [8, 14], [8, 18], [8, 19], [8, 20], [8, 22], [8, 27], [9, 13], [9, 14], [9, 16], [9, 29], [10, 12], [10, 21], [10, 23], [10, 24], [10, 25], [10, 28], [11, 14], [11, 19], [11, 22], [11, 23], [11, 25], [11, 27], [11, 29], [12, 13], [12, 14], [12, 16], [12, 20], [12, 21], [12, 25], [12, 26], [12, 29], [13, 17], [13, 19], [13, 21], [13, 23], [13, 25], [13, 26], [13, 28], [13, 29], [14, 18], [14, 20], [14, 23], [14, 28], [15, 17], [15, 18], [15, 21], [15, 24], [15, 25], [15, 26], [15, 28], [16, 17], [16, 18], [16, 25], [16, 26], [17, 24], [17, 27], [17, 28], [18, 20], [18, 26], [18, 29], [19, 20], [19, 21], [19, 22], [19, 29], [20, 21], [20, 22], [20, 24], [20, 25], [20, 27], [20, 28], [20, 29], [21, 22], [21, 23], [21, 26], [21, 29], [22, 25], [22, 26], [23, 25], [23, 26], [23, 28], [23, 29], [24, 25], [24, 27], [24, 29], [25, 26], [25, 28], [25, 29], [26, 28], [26, 29], [27, 28], [27, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s6/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-harmonious-coloring-l2-s3/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s3/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2375c5e3077b0188f74ad4108b80a57bb8bdcd07 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[2, 4], [3, 4], [3, 6], [3, 7], [5, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s3/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c6f301b5593cbf0425c9a0b2c41a4b924e70cbab --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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, 0, 0, 1, 2, 0, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/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-l2-s3/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2375c5e3077b0188f74ad4108b80a57bb8bdcd07 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[2, 4], [3, 4], [3, 6], [3, 7], [5, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s3/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s4/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s4/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ff1b54e1b68627c5ff18dc34cc3e1357f2169b8c --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [0, 6], [3, 4], [3, 7], [5, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s4/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..28b248b194b28293be84cb9ce86f1056a5e075a2 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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, 0, 1, 2, 0, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/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-l2-s4/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ff1b54e1b68627c5ff18dc34cc3e1357f2169b8c --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [0, 6], [3, 4], [3, 7], [5, 7]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l2-s4/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l6-s5/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l6-s5/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..93892855eba196e99eec2c904cefb3bcb6f4714d --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 8, "edges": [[0, 4], [0, 6], [0, 10], [0, 16], [1, 3], [1, 5], [1, 13], [1, 14], [1, 17], [2, 11], [3, 16], [4, 16], [5, 11], [6, 11], [7, 9], [7, 10], [8, 11], [8, 16], [9, 11], [10, 14], [13, 14], [14, 17]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s5/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9f66d239bb03218d9de32a59a1ed2f02920425d0 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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, 0, 2, 1, 3, 4, 4, 5, 6, 3, 2, 0, 4, 5, 0, 7, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..93892855eba196e99eec2c904cefb3bcb6f4714d --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 8, "edges": [[0, 4], [0, 6], [0, 10], [0, 16], [1, 3], [1, 5], [1, 13], [1, 14], [1, 17], [2, 11], [3, 16], [4, 16], [5, 11], [6, 11], [7, 9], [7, 10], [8, 11], [8, 16], [9, 11], [10, 14], [13, 14], [14, 17]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l6-s5/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-pairwise-sums-recovery-l4-s2/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b8a30bb278b5c358d1fee17a3b79170d5198c42 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [37, 5, 27, 21, 39, 28, 29, 24, 32, 25, 21, 12, 27, 19, 40, 45, 8, 24, 16, 39, 14, 36, 33, 22, 37, 22, 18, 19, 7, 35, 9, 31, 34, 17, 16, 42, 24, 23, 6, 17, 34, 14, 32, 43, 34, 25, 16, 20, 19, 23, 18, 20, 28, 40, 29, 37, 31, 26, 4, 30, 15, 35, 26, 20, 22, 29], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..143edc8f8f41f304569cb23df8ce56ee8ace121f --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 3, 4, 5, 11, 13, 15, 16, 18, 19, 21, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/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-l4-s2/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b8a30bb278b5c358d1fee17a3b79170d5198c42 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [37, 5, 27, 21, 39, 28, 29, 24, 32, 25, 21, 12, 27, 19, 40, 45, 8, 24, 16, 39, 14, 36, 33, 22, 37, 22, 18, 19, 7, 35, 9, 31, 34, 17, 16, 42, 24, 23, 6, 17, 34, 14, 32, 43, 34, 25, 16, 20, 19, 23, 18, 20, 28, 40, 29, 37, 31, 26, 4, 30, 15, 35, 26, 20, 22, 29], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s1/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s1/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c595fa5233d6ca15db6d6e851451865dc6be7cc --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": 21, "B": 37, "C": 15, "D": 19, "target": 18, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s1/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..73252381281393bc0b49183c78176979b077ac4b --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 36, "Y": 18} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s1/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-l1-s1/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c595fa5233d6ca15db6d6e851451865dc6be7cc --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": 21, "B": 37, "C": 15, "D": 19, "target": 18, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s1/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s6/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s6/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e66073bc4e39d2c78c448c6ef1f1ab905ef293a8 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": 8, "B": 21, "C": 46, "D": 47, "target": 2, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s6/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..30cb448ae362559097196e59d104ce6cc5f6f595 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 20, "Y": 46} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s6/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-l1-s6/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e66073bc4e39d2c78c448c6ef1f1ab905ef293a8 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": 8, "B": 21, "C": 46, "D": 47, "target": 2, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s6/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s0/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s0/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fab0f77e435aa0b76ee6777a7116d5af03936fe7 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": 405078520, "B": 527105166, "C": 93130686, "D": 247190695, "target": 247190695, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s0/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2339689bbc86ae23c12446bc20abb4e139a44011 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 494381390, "Y": 247190695} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fab0f77e435aa0b76ee6777a7116d5af03936fe7 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": 405078520, "B": 527105166, "C": 93130686, "D": 247190695, "target": 247190695, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s0/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s9/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s9/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..180467ab6586bb2357bb8bda1412f065b753b35c --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": 703491664, "B": 865253034, "C": 175676276, "D": 175943928, "target": 175943928, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s9/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f8dd762d6aa374f90946340cf542f148cead2b1 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 703775712, "Y": 175943928} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s9/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-l5-s9/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..180467ab6586bb2357bb8bda1412f065b753b35c --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": 703491664, "B": 865253034, "C": 175676276, "D": 175943928, "target": 175943928, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s9/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-global-minimum-l4-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s3/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fefe08800d67b11e549038e0f769e36f94e04c8b --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [12, -32, 66, -100, 101, -68, 30, -8, 1], "fmin": "0.554784401684218622146398324128100732256163468", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9bf8b8f765750aa17a482c23d09d0ce0aa0562b9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.576147969509968} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/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-l4-s3/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fefe08800d67b11e549038e0f769e36f94e04c8b --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [12, -32, 66, -100, 101, -68, 30, -8, 1], "fmin": "0.554784401684218622146398324128100732256163468", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s3/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s4/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..27c1f75b95dbf6800efb27b091e5dcd3d616500d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [148, -420, 505, -328, 121, -24, 2, 0, 2], "fmin": "5.98933258447042258665584624933238310752601671", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4f5cbecd62fd8a7a59951d89c79fb0d445b9dee9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.010624440939622} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/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-l4-s4/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..27c1f75b95dbf6800efb27b091e5dcd3d616500d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [148, -420, 505, -328, 121, -24, 2, 0, 2], "fmin": "5.98933258447042258665584624933238310752601671", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s4/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-integer-roots-l3-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s1/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1da867f71fca1d5054427e3da000877145cd064 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-29400, 81410, -80211, 33956, -5777, -142, 187, -24, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bce40b5532ac6b5c4a4a99f085ef75ba7d724247 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-6, 1, 1, 4, 5, 5, 7, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/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-l3-s1/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1da867f71fca1d5054427e3da000877145cd064 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-29400, 81410, -80211, 33956, -5777, -142, 187, -24, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s6/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eb63a1cf4ed7d9345dcace379806d4935ebf811b --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-1152, -3024, -2356, -96, 519, 102, -36, -6, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..299bebb6b56f22f63b0191d02930a49ef1bbf1bd --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-3, -2, -2, -1, -1, 3, 4, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/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-l3-s6/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eb63a1cf4ed7d9345dcace379806d4935ebf811b --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-1152, -3024, -2356, -96, 519, 102, -36, -6, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-rlve-polynomial-interpolation-l4-s1/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..37413919165885a375ff32323a3ede492b172158 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"X": [-9, -5, 1, 9, 0, 7, 8, -6, -7, -8], "Y": [-2142224657, -11545449, 3, 1712846899, 1, 171419151, 583278209, -58177151, -228822061, -750509439], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..34986ca8fc7a5e9d689f5846a86d3fcd3ee9ab64 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [1, 0, 2, -1, 2, 0, 1, -2, -5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s1/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-l4-s1/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..37413919165885a375ff32323a3ede492b172158 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"X": [-9, -5, 1, 9, 0, 7, 8, -6, -7, -8], "Y": [-2142224657, -11545449, 3, 1712846899, 1, 171419151, 583278209, -58177151, -228822061, -750509439], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-rlve-polynomial-interpolation-l4-s1/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-rlve-polynomial-interpolation-l4-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s8/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06b5769e2fa0866886f15aac892006626aeb02c6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"X": [9, 6, 0, -6, -9, 1, -5, -7, 4, 2], "Y": [1983630263, 52222817, 5, -49050127, -1899662413, 7, -9471365, -196993449, 1380133, 2673], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c123a430126bb5b5f3cb91d2592cc7666f6bd163 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [5, 4, 1, -4, 0, -4, -2, 1, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s8/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-l4-s8/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..06b5769e2fa0866886f15aac892006626aeb02c6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"X": [9, 6, 0, -6, -9, 1, -5, -7, 4, 2], "Y": [1983630263, 52222817, 5, -49050127, -1899662413, 7, -9471365, -196993449, 1380133, 2673], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s4/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7834fcf8a3b5d84ae4d8b617dd7aa1a2e2e4ad0a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 1487, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s4/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d2442f99e26d9d3d43e3a855711b5f8e09dabc86 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 745, 497, 373, 596, 249, 426, 187, 662, 1042, 677, 125, 573, 957, 695, 94, 176, 1075, 1175, 1265, 1134, 339, 195, 63, 120, 287, 717, 479, 924, 348, 49, 791, 722, 832, 86, 538, 845, 588, 1183, 633, 944, 1311, 416, 170, 728, 98, 1140, 32, 699, 804, 555, 144, 983, 359, 731, 240, 888, 1206, 1362, 918, 1293, 25, 1370, 396, 1305, 1105, 800, 1160, 1057, 787, 378, 1013, 551, 423, 1032, 1038, 310, 592, 321, 317, 1231, 1216, 216, 656, 36, 952, 1300, 829, 402, 1108, 720, 793, 17, 1314, 1128, 760, 47, 350, 737, 1146, 1223, 278, 232, 816, 525, 492, 543, 180, 192, 366, 778, 864, 909, 1188, 932, 1347, 395, 1425, 26, 1203, 468, 647, 811, 13, 917, 1429, 1207, 942, 635, 653, 421, 553, 806, 1144, 739, 1324, 522, 529, 1028, 394, 1372, 933, 53, 507, 483, 276, 1225, 212, 500, 1260, 454, 1263, 1177, 899, 308, 1040, 664, 161, 824, 159, 666, 616, 521, 1352, 740, 852, 838, 1072, 45, 762, 1288, 1220, 1127, 1394, 18, 415, 1446, 945, 109, 1298, 954, 1104, 1423, 397, 1062, 9, 828, 1401, 953, 1308, 110, 1124, 1149, 24, 1427, 919, 235, 369, 1219, 1317, 763, 612, 1195, 883, 487, 860, 353, 1152, 1054, 263, 149, 990, 1118, 272, 84, 834, 1070, 840, 680, 927, 472, 1133, 1468, 1176, 1336, 455, 453, 1338, 501, 1210, 104, 674, 569, 198, 1121, 713, 1099, 757, 57, 602, 291, 978, 411, 324, 438, 406, 892, 7, 1064, 459, 1097, 715, 289, 604, 1004, 1215, 1407, 318, 334, 327, 434, 211, 1341, 277, 1387, 1147, 1126, 1316, 1289, 370, 215, 1406, 1232, 1005, 147, 265, 103, 1258, 502, 941, 1361, 1430, 889, 467, 1368, 27, 773, 254, 886, 242, 512, 882, 1285, 613, 868, 850, 742, 994, 931, 1374, 910, 971, 904, 632, 1449, 589, 156, 450, 78, 898, 1335, 1264, 1469, 1076, 1167, 81, 259, 1156, 896, 80, 1173, 1077, 245, 1052, 1154, 261, 1056, 1420, 801, 1114, 895, 1170, 260, 1163, 1053, 1280, 354, 23, 1295, 1125, 1222, 1388, 738, 1354, 807, 564, 31, 1441, 99, 753, 628, 208, 338, 1467, 1266, 473, 505, 55, 759, 1393, 1315, 1221, 1148, 1296, 111, 712, 1253, 199, 271, 1275, 991, 5, 894, 1158, 802, 701, 72, 477, 719, 1398, 403, 799, 1422, 1306, 955, 575, 708, 756, 1251, 714, 1237, 460, 141, 118, 65, 185, 428, 610, 765, 659, 90, 382, 691, 1050, 247, 598, 1024, 442, 510, 244, 1166, 1174, 1470, 177, 44, 1320, 839, 1271, 835, 132, 937, 75, 458, 1239, 8, 1303, 398, 880, 514, 786, 1419, 1161, 262, 1279, 1153, 1164, 246, 1084, 692, 464, 409, 980, 1008, 567, 676, 1478, 663, 1332, 309, 1412, 1033, 228, 152, 227, 1037, 1413, 424, 251, 393, 1349, 530, 796, 441, 1081, 599, 285, 122, 843, 540, 561, 222, 357, 985, 550, 1416, 379, 771, 29, 566, 1045, 981, 146, 1214, 1233, 605, 206, 630, 906, 670, 963, 107, 947, 930, 1190, 743, 4, 1117, 1276, 150, 230, 280, 549, 1015, 358, 1435, 145, 1007, 1046, 410, 1246, 292, 608, 430, 704, 642, 903, 1186, 911, 872, 164, 138, 961, 672, 106, 998, 671, 966, 139, 462, 694, 1474, 574, 1103, 1307, 1299, 1402, 37, 645, 470, 929, 996, 108, 1310, 1447, 634, 1360, 1208, 503, 475, 74, 1067, 133, 684, 52, 1346, 1373, 1189, 995, 948, 471, 1268, 681, 347, 1459, 480, 445, 814, 234, 1292, 1428, 1363, 14, 533, 387, 782, 871, 970, 1187, 1375, 865, 669, 1000, 631, 1185, 972, 643, 39, 307, 1334, 1178, 79, 1169, 1157, 1115, 6, 1241, 407, 466, 1205, 1431, 241, 1199, 255, 486, 1284, 1196, 513, 1060, 399, 725, 203, 295, 622, 822, 163, 969, 912, 783, 849, 1193, 614, 668, 908, 1376, 779, 735, 352, 1282, 488, 584, 305, 41, 546, 130, 837, 1322, 741, 1192, 869, 784, 516, 587, 1451, 539, 1020, 123, 679, 1270, 1071, 1321, 853, 131, 1069, 1272, 85, 1454, 723, 401, 1400, 1301, 10, 448, 158, 1329, 162, 874, 623, 582, 490, 527, 524, 1384, 233, 921, 446, 12, 1365, 648, 220, 563, 1143, 1355, 554, 1438, 700, 1113, 1159, 1421, 1106, 404, 440, 1026, 531, 16, 1396, 721, 1456, 50, 686, 377, 1418, 1058, 515, 848, 870, 913, 388, 734, 863, 1377, 367, 237, 391, 253, 1201, 28, 1011, 380, 92, 697, 34, 658, 1089, 611, 1287, 1318, 46, 1392, 1129, 56, 1250, 1100, 709, 627, 1138, 100, 344, 136, 166, 638, 298, 496, 1486, 3, 993, 1191, 851, 1323, 1353, 1145, 1389, 351, 862, 780, 389, 239, 1433, 360, 97, 1443, 171, 202, 878, 400, 831, 1455, 792, 1397, 1109, 478, 1461, 288, 1236, 1098, 1252, 1122, 112, 626, 755, 1101, 576, 619, 641, 974, 431, 71, 1112, 803, 1439, 33, 768, 93, 1473, 958, 463, 1049, 1085, 383, 68, 330, 376, 789, 51, 935, 134, 346, 926, 1269, 841, 124, 1477, 1043, 568, 1256, 105, 965, 962, 999, 907, 866, 615, 1327, 160, 1331, 1041, 1479, 188, 89, 1088, 766, 35, 1404, 217, 420, 1358, 636, 168, 418, 219, 810, 1366, 469, 950, 38, 902, 973, 705, 620, 297, 748, 167, 652, 1359, 943, 1448, 1184, 905, 1001, 207, 1137, 754, 710, 113, 581, 821, 875, 296, 640, 706, 577, 520, 1326, 667, 867, 1194, 1286, 764, 1090, 429, 976, 293, 205, 1003, 1234, 290, 1248, 58, 284, 1023, 1082, 248, 1483, 374, 332, 320, 1410, 311, 155, 1182, 1450, 846, 517, 304, 858, 489, 820, 624, 114, 302, 519, 618, 707, 1102, 956, 1475, 126, 61, 197, 1255, 675, 1044, 1009, 30, 1142, 808, 221, 1018, 541, 494, 300, 116, 143, 1437, 805, 1356, 422, 1415, 1014, 986, 281, 129, 855, 42, 179, 1381, 493, 560, 1019, 844, 1452, 87, 190, 182, 386, 915, 15, 795, 1027, 1350, 523, 818, 491, 1383, 817, 528, 1351, 1325, 617, 578, 303, 586, 847, 785, 1059, 881, 1197, 243, 1079, 443, 482, 1344, 54, 1131, 474, 940, 1209, 1259, 1339, 213, 372, 1485, 746, 299, 559, 542, 1382, 526, 819, 583, 859, 1283, 884, 256, 275, 1343, 508, 444, 923, 1460, 718, 1110, 73, 939, 504, 1132, 1267, 928, 949, 646, 1367, 1204, 890, 408, 1048, 693, 959, 140, 1096, 1238, 1065, 76, 452, 1262, 1337, 1261, 456, 77, 1180, 157, 826, 11, 813, 922, 481, 509, 1080, 1025, 797, 405, 1243, 325, 336, 210, 1227, 328, 70, 703, 975, 609, 1091, 186, 1481, 250, 1031, 1414, 552, 1357, 654, 218, 650, 169, 1445, 1312, 19, 315, 323, 1245, 979, 1047, 465, 891, 1242, 439, 798, 1107, 1399, 830, 724, 879, 1061, 1304, 1424, 1371, 1348, 1029, 252, 775, 238, 733, 781, 914, 534, 183, 67, 690, 1086, 91, 770, 1012, 1417, 788, 687, 331, 595, 1484, 498, 214, 1218, 1290, 236, 777, 1378, 193, 341, 268, 174, 96, 730, 1434, 984, 1016, 223, 22, 1151, 1281, 861, 736, 1390, 48, 1458, 925, 682, 135, 751, 101, 267, 364, 194, 1466, 1135, 209, 436, 326, 1229, 319, 594, 375, 688, 69, 433, 1228, 335, 437, 1244, 412, 316, 1409, 593, 333, 1230, 1408, 322, 413, 20, 225, 154, 591, 1411, 1039, 1333, 900, 40, 857, 585, 518, 579, 115, 558, 495, 747, 639, 621, 876, 204, 607, 977, 1247, 603, 1235, 716, 1462, 121, 1022, 600, 59, 128, 548, 987, 231, 1386, 1224, 1342, 484, 257, 83, 1274, 1119, 200, 173, 363, 342, 102, 1212, 148, 1278, 1055, 1162, 1155, 1171, 82, 274, 485, 885, 1200, 774, 392, 1030, 425, 1482, 597, 1083, 1051, 1165, 1078, 511, 1198, 887, 1432, 732, 390, 776, 368, 1291, 920, 815, 1385, 279, 988, 151, 1036, 1034, 153, 313, 21, 356, 1017, 562, 809, 649, 419, 655, 1405, 1217, 371, 499, 1340, 1226, 435, 337, 1136, 629, 1002, 606, 294, 877, 726, 172, 270, 1120, 1254, 570, 62, 1465, 340, 365, 1379, 181, 536, 88, 661, 1480, 427, 1092, 66, 385, 535, 191, 1380, 544, 43, 1074, 1471, 95, 362, 269, 201, 727, 1444, 417, 651, 637, 749, 137, 968, 873, 823, 1330, 665, 1328, 825, 449, 1181, 590, 312, 226, 1035, 229, 989, 1277, 264, 1213, 1006, 982, 1436, 556, 117, 1095, 461, 960, 967, 165, 750, 345, 683, 936, 1068, 836, 854, 547, 282, 60, 572, 1476, 678, 842, 1021, 286, 1463, 64, 1094, 142, 557, 301, 580, 625, 711, 1123, 1297, 1309, 946, 997, 964, 673, 1257, 1211, 266, 343, 752, 1139, 1442, 729, 361, 175, 1472, 696, 769, 381, 1087, 660, 189, 537, 1453, 833, 1273, 273, 258, 1172, 1168, 897, 1179, 451, 457, 1066, 938, 476, 1111, 702, 432, 329, 689, 384, 184, 1093, 119, 1464, 196, 571, 127, 283, 601, 1249, 758, 1130, 506, 1345, 934, 685, 790, 1457, 349, 1391, 761, 1319, 1073, 178, 545, 856, 306, 901, 644, 951, 1403, 657, 767, 698, 1440, 1141, 565, 1010, 772, 1202, 1369, 1426, 1294, 1150, 355, 224, 314, 414, 1313, 1395, 794, 532, 916, 1364, 812, 447, 827, 1302, 1063, 1240, 893, 1116, 992, 744, 1487]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s4/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-l4-s4/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7834fcf8a3b5d84ae4d8b617dd7aa1a2e2e4ad0a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 1487, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s4/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-sum-permutation-l1-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s2/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ad17ab8c3ff6a0b8b4810e87ba75c1fb23947d1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s2/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c5a88d0fb9b719a91063ce92a3a7bec7bde104c --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [18, 1, 16, 3, 14, 5, 12, 7, 10, 9, 8, 11, 6, 13, 4, 15, 2, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/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-l1-s2/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ad17ab8c3ff6a0b8b4810e87ba75c1fb23947d1 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s2/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s5/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s5/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b581da3bbf8d6af7a85752867c87b174adf5386 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s5/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0ef2bc764b6a4b25ec8379fe1c8e574de6a1c21f --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [6, 1, 4, 3, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/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-l1-s5/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b581da3bbf8d6af7a85752867c87b174adf5386 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s5/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-recursive-sequence-sum-l2-s1/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s1/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..503e8ae29c7e3275448893ce371e4137b2bee2df --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"F0": 95, "A": 6, "B": 5264, "S": 55330174, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s1/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c414720090b22cfcf6e0fb744f57dcc5fa18d5d8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 4, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/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-l2-s1/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..503e8ae29c7e3275448893ce371e4137b2bee2df --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"F0": 95, "A": 6, "B": 5264, "S": 55330174, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s8/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-rlve-recursive-sequence-sum-l2-s8/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e188c04db5dc01a636942e86f32322d9995fc8a1 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"F0": 83, "A": 7, "B": 11023, "S": 1844224573, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s8/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..87703d2d15c27240759c0b640e902051ba850af0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 4, 5, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/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-l2-s8/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e188c04db5dc01a636942e86f32322d9995fc8a1 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"F0": 83, "A": 7, "B": 11023, "S": 1844224573, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-rlve-recursive-sequence-sum-l2-s8/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-rlve-recursive-sequence-sum-l6-s0/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s0/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5f08abbaabe826accf25059206b57f13643c690 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"F0": 87, "A": 1, "B": 5482, "S": 1118937, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s0/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5881163a88a48c87d8b0a9c5ed3b835cfc0545a1 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [9, 12, 13, 23, 41, 48, 58]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/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-l6-s0/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5f08abbaabe826accf25059206b57f13643c690 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"F0": 87, "A": 1, "B": 5482, "S": 1118937, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s7/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s7/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d6a6c67ca8b60d8b6eef405284291bb5eb81d96 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"F0": 49, "A": 5, "B": 11019, "S": 587538698265592840222051534802238378738808477, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s7/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6947584b07bd27a87841e7227f5dd3df6606803e --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 3, 6, 7, 8, 13, 15, 16, 27, 32, 34, 36, 39, 42, 44, 56, 58, 59]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/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-l6-s7/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d6a6c67ca8b60d8b6eef405284291bb5eb81d96 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"F0": 49, "A": 5, "B": 11019, "S": 587538698265592840222051534802238378738808477, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l2-s3/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s3/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5925ed96761c90bbfce29c40123e2d28689391b --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"W": [3, 4, 9, 9, 6, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s3/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d402154319a97d18b6d9619a42ef77592a50d683 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["011010", "100111", "120121", "211012", "110102", "211000"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l2-s3/tests/check.py b/tasks/construct-rlve-round-robin-scores-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s3/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l2-s3/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5925ed96761c90bbfce29c40123e2d28689391b --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"W": [3, 4, 9, 9, 6, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s3/tests/run.py b/tasks/construct-rlve-round-robin-scores-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s3/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s4/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s4/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d2df6bf6d01429f523b1aedc662af5cdf59ffcc2 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"W": [7, 5, 7, 4, 4, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s4/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bfe4b5413c023f70af80a403b178cfbf51eba8c6 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["011211", "101111", "110121", "011011", "110101", "111110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l2-s4/tests/check.py b/tasks/construct-rlve-round-robin-scores-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s4/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l2-s4/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d2df6bf6d01429f523b1aedc662af5cdf59ffcc2 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"W": [7, 5, 7, 4, 4, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s4/tests/run.py b/tasks/construct-rlve-round-robin-scores-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s4/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-shortest-path-count-l1-s9/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s9/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..383d641da7ae7c94c7fc4ef5511fc6d59cb8199e --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"K": 33, "n_max": 34, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s9/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..51ddf02155f3105307f6e9f9aa7940c9ce3a88ac --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 18, "adj": ["NNYYNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNN", "NNYYNNYYNNNNNNNNNN", "NNNNYYNNYYNNNNNNNN", "NNNNYYNNYYNNNNNNNN", "NNNNNNYYNNYYNNNNNN", "NNNNNNYYNNYYNNNNNN", "NNNNNNNNYYNNNNNNNY", "NNNNNNNNYYNNNNNNNY", "YNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNYNY", "NYNNNNNNNNYYNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l1-s9/tests/check.py b/tasks/construct-rlve-shortest-path-count-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s9/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l1-s9/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..383d641da7ae7c94c7fc4ef5511fc6d59cb8199e --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"K": 33, "n_max": 34, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s9/tests/run.py b/tasks/construct-rlve-shortest-path-count-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s9/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s1/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s1/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f721804848dd9b8c97c231beea50487eca4b02d --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"K": 5786229304640, "n_max": 261, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s1/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c345b4b2f7ae733f7ee9111311854f268c2ee422 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 129, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l5-s1/tests/check.py b/tasks/construct-rlve-shortest-path-count-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s1/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l5-s1/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f721804848dd9b8c97c231beea50487eca4b02d --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"K": 5786229304640, "n_max": 261, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s1/tests/run.py b/tasks/construct-rlve-shortest-path-count-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s1/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s6/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s6/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..00cf7d50d5c59bb5a9fa44fa2c62c8af397b82c1 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"K": 29301420376247, "n_max": 273, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s6/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..71ce21320ba25d66cf68baccf26e36f0781fc08a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 135, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l5-s6/tests/check.py b/tasks/construct-rlve-shortest-path-count-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s6/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l5-s6/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..00cf7d50d5c59bb5a9fa44fa2c62c8af397b82c1 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"K": 29301420376247, "n_max": 273, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s6/tests/run.py b/tasks/construct-rlve-shortest-path-count-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s6/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-smallest-enclosing-circle-l2-s2/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s2/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e84e79cdd28b80fad469c8b07744d36cea1559a8 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[3, 9], [3, 12], [4, 10], [9, 1], [12, 7], [15, 6], [15, 8], [16, 10]], "r_opt": 7.172049240588253, "r2_num": 1765465, "r2_den": 34322, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6d8d2e63520d3367cd36b22fff67cdb80475ec9d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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": 9.064885496183207, "y": 8.17175572519084, "r": 7.172049241588253} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/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-l2-s2/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e84e79cdd28b80fad469c8b07744d36cea1559a8 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[3, 9], [3, 12], [4, 10], [9, 1], [12, 7], [15, 6], [15, 8], [16, 10]], "r_opt": 7.172049240588253, "r2_num": 1765465, "r2_den": 34322, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s2/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s5/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s5/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ae754e78cf61d1559fd77b69c6b31bca7c485b6 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 11], [3, 9], [6, 4], [7, 5], [7, 14], [13, 10], [15, 4], [15, 10]], "r_opt": 8.276472678623424, "r2_num": 137, "r2_den": 2, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..38c90fa8e706b6d8d76330a3d8ca72577b662b9b --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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' +{"x": 7.5, "y": 7.5, "r": 8.276472679623424} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/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-l2-s5/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ae754e78cf61d1559fd77b69c6b31bca7c485b6 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 11], [3, 9], [6, 4], [7, 5], [7, 14], [13, 10], [15, 4], [15, 10]], "r_opt": 8.276472678623424, "r2_num": 137, "r2_den": 2, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s5/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-subgraph-isomorphism-l2-s1/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s1/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8db76302259e27101bf1176125e7ab817b1bb961 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n1": 5, "n2": 8, "edges1": [[0, 4], [0, 2], [0, 3], [2, 3]], "edges2": [[2, 6], [5, 6], [2, 4], [0, 6], [5, 7], [4, 6], [3, 5], [0, 1], [1, 6], [1, 5], [0, 3], [3, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s1/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7e451674cc3e2078576017307dec7df917d241d --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [6, 7, 2, 4, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/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-l2-s1/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8db76302259e27101bf1176125e7ab817b1bb961 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n1": 5, "n2": 8, "edges1": [[0, 4], [0, 2], [0, 3], [2, 3]], "edges2": [[2, 6], [5, 6], [2, 4], [0, 6], [5, 7], [4, 6], [3, 5], [0, 1], [1, 6], [1, 5], [0, 3], [3, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s6/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s6/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94446134c4cae5a9e256db35575f998f3f812ee0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 8, "edges1": [[1, 3], [0, 3]], "edges2": [[0, 6], [3, 7], [0, 7], [5, 6], [1, 4], [0, 1], [0, 2], [3, 5], [1, 3], [4, 5], [5, 7], [1, 5]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s6/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..193fb6ffc123a553cdd83e4340dfbb1730ee84d9 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [2, 6, 4, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/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-l2-s6/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94446134c4cae5a9e256db35575f998f3f812ee0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 8, "edges1": [[1, 3], [0, 3]], "edges2": [[0, 6], [3, 7], [0, 7], [5, 6], [1, 4], [0, 1], [0, 2], [3, 5], [1, 3], [4, 5], [5, 7], [1, 5]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s8/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-rlve-subgraph-isomorphism-l2-s8/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3aec8d5ad734168f7d91a9f4e038f73c8c487923 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n1": 7, "n2": 8, "edges1": [[4, 5], [0, 5], [0, 4], [1, 2], [1, 4], [0, 1], [2, 4], [2, 5], [2, 6], [1, 6]], "edges2": [[0, 1], [3, 4], [3, 5], [0, 6], [1, 4], [0, 2], [2, 4], [0, 5], [2, 3], [3, 6], [2, 5], [0, 4], [6, 7], [1, 6], [2, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s8/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7406dca8a7b88ed9b038bf8d6b371cff4eccc9fe --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [3, 4, 0, 7, 2, 5, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/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-l2-s8/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3aec8d5ad734168f7d91a9f4e038f73c8c487923 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n1": 7, "n2": 8, "edges1": [[4, 5], [0, 5], [0, 4], [1, 2], [1, 4], [0, 1], [2, 4], [2, 5], [2, 6], [1, 6]], "edges2": [[0, 1], [3, 4], [3, 5], [0, 6], [1, 4], [0, 2], [2, 4], [0, 5], [2, 3], [3, 6], [2, 5], [0, 4], [6, 7], [1, 6], [2, 6]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-rlve-subgraph-isomorphism-l2-s8/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-rlve-subgraph-isomorphism-l6-s7/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s7/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95b6c54d626b743dd8797ed018f849806089a0d1 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n1": 31, "n2": 36, "edges1": [[7, 9], [10, 13], [2, 20], [7, 17], [0, 29], [11, 24], [3, 23], [4, 20], [13, 27], [12, 17], [23, 26], [14, 18], [1, 11], [1, 5], [16, 27], [5, 20], [8, 24], [7, 24], [14, 27], [24, 30], [10, 20], [18, 27], [11, 15], [9, 15], [22, 25], [19, 28], [1, 20], [19, 26], [7, 28], [6, 25], [1, 27], [4, 10], [5, 15], [15, 30], [19, 30], [16, 23], [18, 30], [20, 23], [16, 20], [7, 21], [7, 14], [2, 18], [12, 19], [2, 16], [0, 28], [15, 26], [11, 22], [9, 18], [10, 18], [21, 22], [1, 4], [2, 19], [10, 25], [10, 26], [4, 23], [10, 17], [9, 17], [0, 7], [15, 20], [9, 20], [25, 27], [0, 14], [22, 23], [17, 27], [14, 24], [7, 29], [26, 28], [15, 25], [13, 28], [20, 27], [2, 28], [5, 14], [5, 16], [5, 24], [2, 24], [23, 27], [11, 12], [12, 28], [9, 11], [12, 24], [7, 22], [10, 30], [7, 13], [12, 14], [4, 21], [2, 3], [3, 11], [3, 29], [3, 30], [3, 24], [23, 24], [7, 19], [10, 19], [10, 22], [1, 28], [15, 17], [8, 27], [5, 7], [24, 28], [9, 14], [1, 23], [10, 15], [11, 23], [6, 19], [1, 22], [6, 22], [25, 30], [3, 5], [0, 18], [20, 25], [1, 17], [7, 30], [9, 10], [7, 18], [28, 30], [2, 22], [8, 17], [3, 25]], "edges2": [[21, 26], [13, 22], [19, 32], [17, 22], [11, 25], [23, 35], [15, 21], [12, 14], [0, 30], [17, 30], [3, 27], [11, 30], [10, 20], [23, 25], [1, 18], [9, 27], [19, 21], [10, 30], [5, 18], [24, 32], [21, 28], [3, 24], [2, 27], [5, 24], [2, 12], [6, 27], [1, 5], [13, 21], [5, 30], [7, 25], [10, 31], [6, 34], [32, 35], [0, 24], [23, 32], [11, 29], [2, 11], [27, 30], [7, 23], [4, 9], [14, 35], [14, 16], [7, 20], [12, 29], [9, 33], [19, 26], [6, 9], [18, 23], [5, 20], [15, 29], [6, 15], [8, 30], [4, 31], [12, 33], [12, 24], [18, 33], [2, 3], [23, 28], [12, 13], [17, 32], [2, 30], [0, 32], [2, 14], [15, 34], [15, 26], [23, 31], [7, 28], [1, 10], [1, 23], [12, 19], [8, 19], [14, 31], [21, 33], [10, 27], [6, 32], [28, 29], [0, 2], [2, 5], [2, 32], [0, 17], [27, 28], [9, 28], [15, 23], [26, 32], [8, 28], [31, 34], [3, 14], [23, 24], [5, 10], [2, 17], [11, 33], [5, 27], [21, 31], [13, 16], [1, 35], [32, 33], [6, 33], [19, 33], [12, 21], [8, 20], [9, 35], [19, 30], [4, 14], [3, 29], [0, 1], [15, 18], [14, 28], [17, 23], [22, 34], [21, 35], [8, 23], [20, 28], [5, 23], [9, 34], [0, 31], [20, 24], [22, 23], [2, 13], [18, 19], [8, 31], [17, 21], [9, 32], [3, 16], [3, 12], [2, 26], [0, 14], [0, 12], [10, 15], [14, 33], [11, 24], [9, 10], [17, 29], [20, 32], [18, 21], [14, 20], [4, 5], [17, 27], [1, 15], [5, 11], [19, 24], [1, 7], [17, 33], [11, 18], [5, 29], [9, 13], [8, 21], [0, 13], [16, 35], [20, 23], [8, 34], [1, 29], [8, 12], [1, 26], [18, 28], [6, 17], [13, 27], [19, 31]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s7/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4719e245fa8a6249c303ae5d079cbed0c786b4f6 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [7, 0, 29, 11, 13, 24, 6, 23, 4, 8, 21, 30, 10, 35, 20, 19, 3, 31, 28, 15, 12, 22, 17, 2, 5, 33, 26, 14, 1, 25, 18]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/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-l6-s7/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95b6c54d626b743dd8797ed018f849806089a0d1 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n1": 31, "n2": 36, "edges1": [[7, 9], [10, 13], [2, 20], [7, 17], [0, 29], [11, 24], [3, 23], [4, 20], [13, 27], [12, 17], [23, 26], [14, 18], [1, 11], [1, 5], [16, 27], [5, 20], [8, 24], [7, 24], [14, 27], [24, 30], [10, 20], [18, 27], [11, 15], [9, 15], [22, 25], [19, 28], [1, 20], [19, 26], [7, 28], [6, 25], [1, 27], [4, 10], [5, 15], [15, 30], [19, 30], [16, 23], [18, 30], [20, 23], [16, 20], [7, 21], [7, 14], [2, 18], [12, 19], [2, 16], [0, 28], [15, 26], [11, 22], [9, 18], [10, 18], [21, 22], [1, 4], [2, 19], [10, 25], [10, 26], [4, 23], [10, 17], [9, 17], [0, 7], [15, 20], [9, 20], [25, 27], [0, 14], [22, 23], [17, 27], [14, 24], [7, 29], [26, 28], [15, 25], [13, 28], [20, 27], [2, 28], [5, 14], [5, 16], [5, 24], [2, 24], [23, 27], [11, 12], [12, 28], [9, 11], [12, 24], [7, 22], [10, 30], [7, 13], [12, 14], [4, 21], [2, 3], [3, 11], [3, 29], [3, 30], [3, 24], [23, 24], [7, 19], [10, 19], [10, 22], [1, 28], [15, 17], [8, 27], [5, 7], [24, 28], [9, 14], [1, 23], [10, 15], [11, 23], [6, 19], [1, 22], [6, 22], [25, 30], [3, 5], [0, 18], [20, 25], [1, 17], [7, 30], [9, 10], [7, 18], [28, 30], [2, 22], [8, 17], [3, 25]], "edges2": [[21, 26], [13, 22], [19, 32], [17, 22], [11, 25], [23, 35], [15, 21], [12, 14], [0, 30], [17, 30], [3, 27], [11, 30], [10, 20], [23, 25], [1, 18], [9, 27], [19, 21], [10, 30], [5, 18], [24, 32], [21, 28], [3, 24], [2, 27], [5, 24], [2, 12], [6, 27], [1, 5], [13, 21], [5, 30], [7, 25], [10, 31], [6, 34], [32, 35], [0, 24], [23, 32], [11, 29], [2, 11], [27, 30], [7, 23], [4, 9], [14, 35], [14, 16], [7, 20], [12, 29], [9, 33], [19, 26], [6, 9], [18, 23], [5, 20], [15, 29], [6, 15], [8, 30], [4, 31], [12, 33], [12, 24], [18, 33], [2, 3], [23, 28], [12, 13], [17, 32], [2, 30], [0, 32], [2, 14], [15, 34], [15, 26], [23, 31], [7, 28], [1, 10], [1, 23], [12, 19], [8, 19], [14, 31], [21, 33], [10, 27], [6, 32], [28, 29], [0, 2], [2, 5], [2, 32], [0, 17], [27, 28], [9, 28], [15, 23], [26, 32], [8, 28], [31, 34], [3, 14], [23, 24], [5, 10], [2, 17], [11, 33], [5, 27], [21, 31], [13, 16], [1, 35], [32, 33], [6, 33], [19, 33], [12, 21], [8, 20], [9, 35], [19, 30], [4, 14], [3, 29], [0, 1], [15, 18], [14, 28], [17, 23], [22, 34], [21, 35], [8, 23], [20, 28], [5, 23], [9, 34], [0, 31], [20, 24], [22, 23], [2, 13], [18, 19], [8, 31], [17, 21], [9, 32], [3, 16], [3, 12], [2, 26], [0, 14], [0, 12], [10, 15], [14, 33], [11, 24], [9, 10], [17, 29], [20, 32], [18, 21], [14, 20], [4, 5], [17, 27], [1, 15], [5, 11], [19, 24], [1, 7], [17, 33], [11, 18], [5, 29], [9, 13], [8, 21], [0, 13], [16, 35], [20, 23], [8, 34], [1, 29], [8, 12], [1, 26], [18, 28], [6, 17], [13, 27], [19, 31]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s9/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s9/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f20df1e386fe4289177d0cf475beea8f4e58bf20 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n1": 31, "n2": 36, "edges1": [[3, 24], [11, 24], [4, 5], [11, 12], [0, 4], [16, 19], [23, 25], [4, 11], [7, 18], [11, 14], [1, 3], [16, 29], [2, 3], [0, 5], [0, 22], [10, 19], [0, 26], [1, 6], [13, 15], [1, 5], [9, 12], [2, 24], [1, 14], [3, 9], [7, 8], [27, 29], [18, 26], [15, 21], [5, 20], [11, 20], [5, 29], [8, 28], [7, 25], [12, 22], [17, 19], [25, 29], [10, 30], [7, 16], [13, 19], [1, 25], [15, 27], [19, 25], [1, 20], [14, 16], [14, 24], [0, 13], [5, 6], [6, 19], [10, 23], [4, 6], [12, 13], [9, 10], [15, 19], [17, 24], [14, 27], [4, 25], [18, 22], [8, 23], [28, 29], [4, 28], [14, 25], [3, 21], [7, 21], [6, 25], [8, 22], [19, 26], [10, 29], [4, 23], [1, 27], [12, 24], [8, 21], [17, 26], [24, 29], [14, 15], [1, 30], [5, 9], [10, 27], [4, 24], [14, 23], [1, 21], [3, 22], [9, 23], [1, 13], [0, 17], [5, 26], [23, 26], [3, 25], [3, 8], [20, 21], [7, 24], [2, 26], [0, 29], [11, 29], [10, 25], [0, 1], [22, 24], [8, 10], [2, 15], [13, 14], [0, 27], [19, 23], [9, 27], [15, 17], [1, 17], [26, 29], [0, 30], [24, 26], [5, 11], [3, 11], [1, 11], [25, 28], [18, 27], [21, 29], [29, 30], [3, 5], [6, 15], [11, 26], [22, 25], [12, 16], [1, 29], [11, 22], [5, 22], [8, 9], [7, 11], [12, 29], [4, 30], [19, 29], [4, 18], [21, 27], [4, 13], [9, 22], [8, 13], [17, 25], [1, 12], [9, 14], [17, 20], [7, 15], [6, 8], [2, 17], [16, 30], [12, 18], [6, 13], [2, 30], [9, 29], [9, 28], [5, 12], [20, 24], [17, 18], [7, 17], [20, 28], [14, 17], [4, 10], [14, 26], [13, 26], [5, 8], [1, 7], [14, 22], [14, 20], [7, 9], [21, 30], [13, 18], [21, 23], [6, 10], [12, 23], [3, 19], [2, 28], [4, 14], [20, 27], [9, 19], [19, 21], [3, 26], [13, 16], [7, 30], [1, 2], [3, 7], [10, 28], [23, 29], [10, 14], [14, 19], [11, 23], [13, 25], [10, 24], [3, 23], [2, 16], [7, 10], [5, 28], [0, 7], [19, 30], [0, 28], [8, 11], [18, 24], [15, 24], [20, 26], [13, 22], [20, 23], [10, 13], [0, 2], [16, 24], [22, 29], [0, 23], [10, 20], [9, 21], [26, 27], [17, 30], [18, 19], [10, 12], [17, 21], [10, 21], [21, 22], [2, 23], [22, 28], [2, 8], [17, 23], [0, 25], [8, 16], [18, 28], [21, 24], [6, 11], [9, 26], [2, 12], [2, 7], [4, 16], [6, 26], [16, 26], [24, 27], [8, 18], [4, 12], [1, 19], [12, 27], [4, 29], [15, 20], [5, 30], [1, 9], [16, 22], [18, 23], [2, 9], [8, 29], [16, 23], [15, 30], [24, 25], [20, 29], [0, 10], [2, 27], [11, 25], [16, 20], [27, 30], [25, 30], [5, 19], [3, 17], [6, 14], [5, 16], [12, 14], [8, 20], [1, 26], [19, 22], [1, 4], [6, 28], [14, 28], [23, 24]], "edges2": [[2, 22], [3, 13], [18, 24], [18, 25], [23, 24], [2, 34], [7, 16], [19, 29], [2, 15], [3, 29], [15, 16], [3, 8], [16, 18], [8, 9], [13, 14], [3, 17], [18, 29], [12, 25], [4, 14], [4, 26], [8, 19], [0, 26], [0, 21], [6, 26], [5, 29], [13, 16], [12, 29], [1, 2], [12, 16], [7, 9], [23, 27], [14, 21], [2, 17], [19, 20], [8, 27], [12, 13], [23, 35], [3, 22], [22, 26], [10, 12], [4, 6], [8, 26], [0, 29], [2, 8], [1, 27], [6, 35], [2, 20], [5, 20], [9, 10], [4, 19], [20, 21], [5, 17], [10, 14], [0, 14], [10, 26], [32, 33], [4, 25], [6, 8], [8, 29], [28, 30], [12, 18], [14, 28], [17, 20], [4, 15], [14, 29], [8, 10], [14, 35], [9, 24], [15, 17], [4, 8], [23, 28], [13, 17], [1, 28], [15, 28], [10, 31], [15, 32], [24, 28], [27, 28], [1, 20], [0, 11], [26, 35], [17, 32], [15, 24], [2, 12], [32, 35], [9, 31], [4, 29], [26, 32], [10, 22], [17, 26], [5, 14], [6, 14], [18, 28], [7, 19], [21, 24], [25, 27], [21, 34], [16, 26], [15, 23], [18, 27], [11, 28], [1, 11], [6, 20], [15, 18], [3, 26], [28, 33], [11, 34], [6, 33], [21, 31], [9, 27], [8, 20], [9, 26], [14, 18], [27, 35], [5, 23], [18, 23], [22, 25], [0, 30], [6, 28], [19, 26], [15, 20], [20, 26], [16, 35], [8, 13], [19, 22], [7, 32], [22, 31], [13, 27], [1, 14], [24, 30], [12, 19], [29, 34], [1, 22], [30, 35], [5, 24], [24, 35], [3, 5], [3, 34], [13, 19], [21, 30], [22, 34], [0, 18], [10, 25], [14, 25], [21, 32], [8, 30], [21, 26], [13, 25], [26, 30], [3, 25], [5, 25], [17, 29], [5, 12], [7, 18], [1, 6], [15, 25], [29, 35], [21, 33], [2, 9], [7, 10], [17, 28], [14, 16], [8, 11], [4, 24], [1, 24], [7, 23], [8, 16], [7, 11], [26, 27], [12, 22], [4, 33], [12, 15], [15, 26], [15, 34], [21, 27], [1, 31], [16, 23], [6, 21], [0, 5], [6, 29], [25, 32], [3, 16], [11, 15], [5, 18], [0, 6], [28, 31], [11, 27], [10, 20], [11, 21], [4, 27], [16, 34], [1, 34], [19, 33], [5, 11], [20, 28], [6, 10], [10, 28], [0, 35], [13, 20], [29, 33], [16, 27], [31, 33], [3, 30], [27, 31], [11, 30], [9, 11], [9, 35], [1, 35], [6, 15], [12, 14], [24, 27], [5, 8], [12, 23], [12, 24], [9, 25], [30, 33], [27, 32], [24, 25], [21, 35], [9, 18], [7, 15], [0, 4], [25, 30], [7, 22], [23, 31], [13, 26], [33, 34], [8, 28], [4, 32], [21, 22], [0, 32], [13, 33], [10, 30], [2, 18], [4, 12], [31, 35], [7, 8], [10, 21], [1, 4], [9, 30], [1, 3], [11, 26], [4, 31], [12, 30], [5, 35], [7, 17], [0, 19], [28, 34], [5, 33], [17, 30], [7, 28], [14, 27], [8, 25], [2, 6], [1, 9], [19, 28], [8, 32], [13, 28], [8, 15], [21, 29], [16, 25], [3, 21], [15, 19], [22, 35], [7, 33], [23, 32], [16, 19], [0, 23], [2, 30], [20, 34], [19, 35], [1, 29], [24, 34], [4, 10], [16, 22], [19, 27], [5, 15], [7, 30], [11, 20], [0, 27], [1, 23], [9, 17], [2, 27], [9, 14], [8, 18], [3, 15], [26, 29], [5, 13], [24, 31], [2, 33], [6, 32], [27, 34], [9, 29], [7, 26], [10, 34], [13, 34], [4, 18], [0, 3], [25, 34], [8, 22], [3, 14], [24, 26], [25, 35], [13, 22], [7, 21], [13, 32], [4, 34], [13, 35], [6, 19], [30, 31], [14, 26], [9, 28], [17, 35], [3, 32], [5, 9], [14, 17], [16, 17], [6, 24], [9, 13], [11, 24], [17, 23], [0, 12], [6, 11], [14, 31], [9, 15], [10, 15], [9, 21], [19, 32], [0, 17], [5, 22], [27, 30], [0, 16], [13, 21], [4, 28], [1, 19], [14, 20], [6, 31], [17, 19], [26, 34], [11, 12], [26, 33], [11, 22], [21, 25], [19, 31], [7, 14], [22, 33]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s9/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..18ac14c902e217c34415670ecd7a259befdb1eea --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [29, 14, 5, 25, 6, 21, 31, 12, 22, 13, 19, 10, 20, 1, 28, 23, 11, 18, 2, 27, 7, 16, 34, 8, 15, 4, 9, 17, 33, 26, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/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-l6-s9/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f20df1e386fe4289177d0cf475beea8f4e58bf20 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n1": 31, "n2": 36, "edges1": [[3, 24], [11, 24], [4, 5], [11, 12], [0, 4], [16, 19], [23, 25], [4, 11], [7, 18], [11, 14], [1, 3], [16, 29], [2, 3], [0, 5], [0, 22], [10, 19], [0, 26], [1, 6], [13, 15], [1, 5], [9, 12], [2, 24], [1, 14], [3, 9], [7, 8], [27, 29], [18, 26], [15, 21], [5, 20], [11, 20], [5, 29], [8, 28], [7, 25], [12, 22], [17, 19], [25, 29], [10, 30], [7, 16], [13, 19], [1, 25], [15, 27], [19, 25], [1, 20], [14, 16], [14, 24], [0, 13], [5, 6], [6, 19], [10, 23], [4, 6], [12, 13], [9, 10], [15, 19], [17, 24], [14, 27], [4, 25], [18, 22], [8, 23], [28, 29], [4, 28], [14, 25], [3, 21], [7, 21], [6, 25], [8, 22], [19, 26], [10, 29], [4, 23], [1, 27], [12, 24], [8, 21], [17, 26], [24, 29], [14, 15], [1, 30], [5, 9], [10, 27], [4, 24], [14, 23], [1, 21], [3, 22], [9, 23], [1, 13], [0, 17], [5, 26], [23, 26], [3, 25], [3, 8], [20, 21], [7, 24], [2, 26], [0, 29], [11, 29], [10, 25], [0, 1], [22, 24], [8, 10], [2, 15], [13, 14], [0, 27], [19, 23], [9, 27], [15, 17], [1, 17], [26, 29], [0, 30], [24, 26], [5, 11], [3, 11], [1, 11], [25, 28], [18, 27], [21, 29], [29, 30], [3, 5], [6, 15], [11, 26], [22, 25], [12, 16], [1, 29], [11, 22], [5, 22], [8, 9], [7, 11], [12, 29], [4, 30], [19, 29], [4, 18], [21, 27], [4, 13], [9, 22], [8, 13], [17, 25], [1, 12], [9, 14], [17, 20], [7, 15], [6, 8], [2, 17], [16, 30], [12, 18], [6, 13], [2, 30], [9, 29], [9, 28], [5, 12], [20, 24], [17, 18], [7, 17], [20, 28], [14, 17], [4, 10], [14, 26], [13, 26], [5, 8], [1, 7], [14, 22], [14, 20], [7, 9], [21, 30], [13, 18], [21, 23], [6, 10], [12, 23], [3, 19], [2, 28], [4, 14], [20, 27], [9, 19], [19, 21], [3, 26], [13, 16], [7, 30], [1, 2], [3, 7], [10, 28], [23, 29], [10, 14], [14, 19], [11, 23], [13, 25], [10, 24], [3, 23], [2, 16], [7, 10], [5, 28], [0, 7], [19, 30], [0, 28], [8, 11], [18, 24], [15, 24], [20, 26], [13, 22], [20, 23], [10, 13], [0, 2], [16, 24], [22, 29], [0, 23], [10, 20], [9, 21], [26, 27], [17, 30], [18, 19], [10, 12], [17, 21], [10, 21], [21, 22], [2, 23], [22, 28], [2, 8], [17, 23], [0, 25], [8, 16], [18, 28], [21, 24], [6, 11], [9, 26], [2, 12], [2, 7], [4, 16], [6, 26], [16, 26], [24, 27], [8, 18], [4, 12], [1, 19], [12, 27], [4, 29], [15, 20], [5, 30], [1, 9], [16, 22], [18, 23], [2, 9], [8, 29], [16, 23], [15, 30], [24, 25], [20, 29], [0, 10], [2, 27], [11, 25], [16, 20], [27, 30], [25, 30], [5, 19], [3, 17], [6, 14], [5, 16], [12, 14], [8, 20], [1, 26], [19, 22], [1, 4], [6, 28], [14, 28], [23, 24]], "edges2": [[2, 22], [3, 13], [18, 24], [18, 25], [23, 24], [2, 34], [7, 16], [19, 29], [2, 15], [3, 29], [15, 16], [3, 8], [16, 18], [8, 9], [13, 14], [3, 17], [18, 29], [12, 25], [4, 14], [4, 26], [8, 19], [0, 26], [0, 21], [6, 26], [5, 29], [13, 16], [12, 29], [1, 2], [12, 16], [7, 9], [23, 27], [14, 21], [2, 17], [19, 20], [8, 27], [12, 13], [23, 35], [3, 22], [22, 26], [10, 12], [4, 6], [8, 26], [0, 29], [2, 8], [1, 27], [6, 35], [2, 20], [5, 20], [9, 10], [4, 19], [20, 21], [5, 17], [10, 14], [0, 14], [10, 26], [32, 33], [4, 25], [6, 8], [8, 29], [28, 30], [12, 18], [14, 28], [17, 20], [4, 15], [14, 29], [8, 10], [14, 35], [9, 24], [15, 17], [4, 8], [23, 28], [13, 17], [1, 28], [15, 28], [10, 31], [15, 32], [24, 28], [27, 28], [1, 20], [0, 11], [26, 35], [17, 32], [15, 24], [2, 12], [32, 35], [9, 31], [4, 29], [26, 32], [10, 22], [17, 26], [5, 14], [6, 14], [18, 28], [7, 19], [21, 24], [25, 27], [21, 34], [16, 26], [15, 23], [18, 27], [11, 28], [1, 11], [6, 20], [15, 18], [3, 26], [28, 33], [11, 34], [6, 33], [21, 31], [9, 27], [8, 20], [9, 26], [14, 18], [27, 35], [5, 23], [18, 23], [22, 25], [0, 30], [6, 28], [19, 26], [15, 20], [20, 26], [16, 35], [8, 13], [19, 22], [7, 32], [22, 31], [13, 27], [1, 14], [24, 30], [12, 19], [29, 34], [1, 22], [30, 35], [5, 24], [24, 35], [3, 5], [3, 34], [13, 19], [21, 30], [22, 34], [0, 18], [10, 25], [14, 25], [21, 32], [8, 30], [21, 26], [13, 25], [26, 30], [3, 25], [5, 25], [17, 29], [5, 12], [7, 18], [1, 6], [15, 25], [29, 35], [21, 33], [2, 9], [7, 10], [17, 28], [14, 16], [8, 11], [4, 24], [1, 24], [7, 23], [8, 16], [7, 11], [26, 27], [12, 22], [4, 33], [12, 15], [15, 26], [15, 34], [21, 27], [1, 31], [16, 23], [6, 21], [0, 5], [6, 29], [25, 32], [3, 16], [11, 15], [5, 18], [0, 6], [28, 31], [11, 27], [10, 20], [11, 21], [4, 27], [16, 34], [1, 34], [19, 33], [5, 11], [20, 28], [6, 10], [10, 28], [0, 35], [13, 20], [29, 33], [16, 27], [31, 33], [3, 30], [27, 31], [11, 30], [9, 11], [9, 35], [1, 35], [6, 15], [12, 14], [24, 27], [5, 8], [12, 23], [12, 24], [9, 25], [30, 33], [27, 32], [24, 25], [21, 35], [9, 18], [7, 15], [0, 4], [25, 30], [7, 22], [23, 31], [13, 26], [33, 34], [8, 28], [4, 32], [21, 22], [0, 32], [13, 33], [10, 30], [2, 18], [4, 12], [31, 35], [7, 8], [10, 21], [1, 4], [9, 30], [1, 3], [11, 26], [4, 31], [12, 30], [5, 35], [7, 17], [0, 19], [28, 34], [5, 33], [17, 30], [7, 28], [14, 27], [8, 25], [2, 6], [1, 9], [19, 28], [8, 32], [13, 28], [8, 15], [21, 29], [16, 25], [3, 21], [15, 19], [22, 35], [7, 33], [23, 32], [16, 19], [0, 23], [2, 30], [20, 34], [19, 35], [1, 29], [24, 34], [4, 10], [16, 22], [19, 27], [5, 15], [7, 30], [11, 20], [0, 27], [1, 23], [9, 17], [2, 27], [9, 14], [8, 18], [3, 15], [26, 29], [5, 13], [24, 31], [2, 33], [6, 32], [27, 34], [9, 29], [7, 26], [10, 34], [13, 34], [4, 18], [0, 3], [25, 34], [8, 22], [3, 14], [24, 26], [25, 35], [13, 22], [7, 21], [13, 32], [4, 34], [13, 35], [6, 19], [30, 31], [14, 26], [9, 28], [17, 35], [3, 32], [5, 9], [14, 17], [16, 17], [6, 24], [9, 13], [11, 24], [17, 23], [0, 12], [6, 11], [14, 31], [9, 15], [10, 15], [9, 21], [19, 32], [0, 17], [5, 22], [27, 30], [0, 16], [13, 21], [4, 28], [1, 19], [14, 20], [6, 31], [17, 19], [26, 34], [11, 12], [26, 33], [11, 22], [21, 25], [19, 31], [7, 14], [22, 33]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p40-erdos-discrepancy-c2/environment/Dockerfile b/tasks/optimize-ae-p40-erdos-discrepancy-c2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p40-erdos-discrepancy-c2/environment/instance.json b/tasks/optimize-ae-p40-erdos-discrepancy-c2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..876b52da55f097fc09490c846e7a1ae479c704e6 --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/environment/instance.json @@ -0,0 +1 @@ +{"C": 2, "max_length": 5000, "direction": "maximize", "family": "ae_p40_erdos_discrepancy", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p40-erdos-discrepancy-c2/solution/solve.sh b/tasks/optimize-ae-p40-erdos-discrepancy-c2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f793d979ac1c8b50179d4b0b3553b1f2a31174a2 --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"sequence": [1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1, 1, -1, -1, -1, 1, -1, -1]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/check.py b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..6681bdc6534e00aecae90a5ea822b730e135caac --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/check.py @@ -0,0 +1,25 @@ +"""Erdos discrepancy problem, C = 2 (AlphaEvolve problem 40): longest +-1 sequence with discrepancy <= 2. + +Upstream scored the longest good prefix (plus a fractional bonus); we require the whole submitted sequence to +have discrepancy <= C and score its length (exact integer check).""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + x = ans.get("sequence") + if not isinstance(x, list) or not (1 <= len(x) <= inst["max_length"]): + raise Invalid(f"sequence must be a list of 1..{inst['max_length']} entries") + int_list(x, None, -1, 1, "sequence") + if 0 in x: + raise Invalid("entries must be +1 or -1") + a = np.array(x, dtype=np.int64) + n, c = len(x), inst["C"] + for d in range(1, n + 1): + ps = np.cumsum(a[d - 1::d]) + m = int(np.abs(ps).max()) + if m > c: + k = int(np.argmax(np.abs(ps) > c)) + 1 + raise Invalid(f"|x_{d} + x_{2*d} + ... + x_{k*d}| = {abs(int(ps[k-1]))} > {c}") + return float(n), {"length": n} diff --git a/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/instance.json b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5f21993fe6a75446c038b977e7d71ffb5cd5b8a --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/instance.json @@ -0,0 +1 @@ +{"C": 2, "max_length": 5000, "direction": "maximize", "best_known": 1160, "baseline": 12.0, "family": "ae_p40_erdos_discrepancy", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/run.py b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p40-erdos-discrepancy-c2/tests/test.sh b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p40-erdos-discrepancy-c2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-p41-sphere-max-volume-n32/environment/Dockerfile b/tasks/optimize-ae-p41-sphere-max-volume-n32/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p41-sphere-max-volume-n32/environment/instance.json b/tasks/optimize-ae-p41-sphere-max-volume-n32/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9506d17cc5e37560043721f665fe1d8afe4c0284 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "direction": "maximize", "family": "ae_p41_sphere_max_volume", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n32/solution/solve.sh b/tasks/optimize-ae-p41-sphere-max-volume-n32/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..365d75552f262a5cbf418b66fdcef75a065dd032 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"points": [[0.133690086740639, -0.396093474658593, 0.908425517056937], [-0.270978518515841, 0.135394670599493, 0.953015700645176], [0.471357136176526, 0.145566333454924, 0.86984647653477], [-0.436324471603384, -0.477743925419532, 0.762483899636422], [0.051369561382384, 0.651356378865607, 0.757031066650811], [0.645126790638617, -0.49679350573836, 0.580523588372177], [-0.84013543414063, -0.01713138254512, 0.542106048696589], [0.573082445546043, 0.689205276683516, 0.443365083422867], [0.019439344439282, -0.893389934648231, 0.448861377885201], [-0.54032442712654, 0.633478968913057, 0.553853689520279], [0.929459430856181, 0.079251385180415, 0.360311510140171], [-0.725800421855955, -0.637262768859376, 0.259055806843621], [0.006782215337359, 0.984866851135627, 0.17317992692374], [0.533477493572747, -0.844937963174074, 0.038491586594838], [-0.916860359111367, 0.392354639584389, 0.073654047321103], [0.870912044572941, 0.491420005829378, -0.004311436933672], [-0.336807963469119, -0.94156349082542, 0.004311436933672], [-0.541979992572735, 0.83715755325033, -0.073654047321102], [0.923088232859612, -0.382657173090392, -0.038491586594839], [-0.969488233296218, -0.173497200008725, -0.173179926923739], [0.505121965104194, 0.823250805836155, -0.259055806843621], [0.07932196124266, -0.929453410411263, -0.360311510140172], [-0.715844216314214, 0.425221293651039, -0.553853689520279], [0.883774330648303, 0.132160493076194, -0.448861377885202], [-0.582180766666339, -0.68153720201118, -0.443365083422867], [-0.125415064863356, 0.830898365308232, -0.542106048696589], [0.598884679511951, -0.551660678306292, -0.580523588372178], [-0.633244461015937, -0.160951597439018, -0.75703106665081], [0.396938261960244, 0.5109386646039, -0.762483899636421], [-0.063626447209726, -0.489202189769746, -0.86984647653477], [-0.179335721772343, 0.24413064785106, -0.953015700645176], [0.413014423846339, -0.064669665645592, -0.908425517056937]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/check.py b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..58b6521809868700c39ccbae7ef07cd7c99c8d83 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/check.py @@ -0,0 +1,23 @@ +"""n points on the unit sphere maximizing the volume of their convex hull (AlphaEvolve problem 41). + +Upstream bug fixed: the notebook summed |det|/6 of origin-pyramids over (QJ-joggled) hull facets, which +over-counts whenever the origin lies outside the hull (e.g. all points in one hemisphere). We use the exact +hull volume (scipy ConvexHull.volume) of the normalized points, without joggling.""" +import numpy as np +from scipy.spatial import ConvexHull + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + p = np.array(float_matrix(ans.get("points"), n, 3, "points")) + nr = np.linalg.norm(p, axis=1) + if (nr < 1e-9).any() or (nr > 1e9).any(): + raise Invalid("every point needs a non-zero, finite norm (it is projected to the unit sphere)") + p = p / nr[:, None] + try: + v = ConvexHull(p).volume + except Exception as e: # degenerate (coplanar) input + raise Invalid(f"degenerate hull: {type(e).__name__}") + return float(v), {} diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/instance.json b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..faa99cbd527f6d0a6fa1f585aa914ce2f5e38bbf --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "direction": "maximize", "best_known": 3.504874080794, "baseline": 2.079116908177594, "family": "ae_p41_sphere_max_volume", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/run.py b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p41-sphere-max-volume-n32/tests/test.sh b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p41-sphere-max-volume-n32/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-edges-vs-triangles/environment/Dockerfile b/tasks/optimize-ea-edges-vs-triangles/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-edges-vs-triangles/environment/instance.json b/tasks/optimize-ea-edges-vs-triangles/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ec510924285a4e465245bd32c68cd0ff70029ba --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/environment/instance.json @@ -0,0 +1 @@ +{"parts": 20, "max_rows": 500, "direction": "maximize", "family": "ea_edges_vs_triangles", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-edges-vs-triangles/solution/solve.sh b/tasks/optimize-ea-edges-vs-triangles/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d34c7a1ed5b68089d0d7437cc62a82d3a67a741d --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/solution/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": [[0.1616699982783082, 0.1543057328542216, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1840242688674702, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1219183693958312, 0.1603741196724814, 0.1501643966383713, 0.06754311429331619], [0.3221469073106969, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3351852954060235, 0.0, 0.0, 0.0, 0.0, 0.3295911808464399, 0.0, 0.0, 0.01307661643683977], [0.4266801412961053, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4216023483569766, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.151717510346918], [0.2053195825093272, 0.1845528962862067, 0.0, 0.0, 0.0, 0.1941606352151726, 0.1942880609465776, 0.0, 0.0, 0.0, 0.01567656367662728, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2060022613660887, 0.0], [0.1718088080506412, 0.1467120074624758, 0.0, 0.0, 0.0, 0.1543497671173445, 0.1544510653642592, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1222890203633533, 0.0, 0.129344810434962, 0.0, 0.0, 0.0, 0.121044521206964, 0.0], [0.1480797165346565, 0.1413345050043918, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.131427424344911, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1519168694251984, 0.1211924649160464, 0.1115407700174985, 0.09618347066297028, 0.0, 0.09832477909432724], [0.0, 0.0, 0.0, 0.0, 0.1307935302040479, 0.0, 0.1334582443519229, 0.0, 0.1077491511726836, 0.102686766555347, 0.06738870824208981, 0.09218620123354912, 0.0, 0.05360433146327811, 0.0961670133975766, 0.000651453861022078, 0.002842658943585438, 0.0, 0.09039913428728157, 0.122072806287616], [0.7589377580308538, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2410622419691462], [0.06910483485793051, 0.04974070105974455, 0.04950520487090557, 0.04935929395351854, 0.04956311075289233, 0.07202522241865301, 0.09586143695169781, 0.0577995754956558, 0.05158551452351586, 0.0, 0.07358958794719671, 0.1006688618933506, 0.0, 0.05853681970570529, 0.1050159748517053, 0.0007113984293481744, 0.00310423075007408, 0.0, 0.06419239335808694, 0.04963583818001899], [0.2457535004247804, 0.2345591290182132, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2472979470453056, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2538096476935505, 0.0123811486374769, 0.006198627180673493], [0.3233399965566163, 0.3086114657084432, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3680485377349404, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.003684880370257584, 0.071904791869621, 0.07900873530038552, 0.08297383110107345, 0.08195528029530881, 0.0885822314768875, 0.08409628032582404, 0.0809750529780427, 0.0846789809371207, 0.09013451753026902, 0.08356594517568533, 0.0833456922986981, 0.08278084149299907, 0.002312938847827223, 0.0, 0.0], [0.4171863917444897, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2633839426768047, 0.0, 0.3194296655787057], [0.4897552822254472, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4879849129419983, 0.0, 0.0, 0.0, 0.0, 0.0, 0.02225980483255457, 0.0, 0.0], [0.2293662684801766, 0.2189183554573003, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2308077289582751, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1204096231478373, 0.2004980239564107, 0.0, 0.0], [0.3989023553575372, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4216370184882347, 0.0, 0.0, 0.1794606261542281], [0.2344739181045496, 0.2237933454173714, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.235947477788509, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2429763783231698, 0.0, 0.06280888036640025, 0.0], [0.2482678040126902, 0.2369589030138964, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2251766140361838, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2495886203789349, 0.0, 0.0, 0.04000805855829479], [0.2108942219134782, 0.2043116792555483, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1899901072799307, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2196094343595973, 0.1751945571914455, 0.0, 0.0, 0.0, 0.0], [0.333626878167512, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3359903361069463, 0.0, 0.0, 0.0, 0.0, 0.3303827857255417, 0.0, 0.0, 0.0], [0.4837819837332583, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4762676204798203, 0.0, 0.0, 0.03995039578692149], [0.2732799648167456, 0.280627974963697, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1749359573056871, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2711561029138704, 0.0], [0.3008321124813432, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3130078178662338, 0.0, 0.0, 0.0, 0.0, 0.3077838369363188, 0.0, 0.0, 0.07837623271610407], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.05588041373183431, 0.9441195862681657, 0.0], [0.2456164644415056, 0.2344283351909614, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2471600498545163, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.09312041151793315, 0.0, 0.1796747389950836, 0.0], [0.9777655325420783, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.02223446745792172], [0.4668331966882094, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4635497414593863, 0.0, 0.0, 0.06961706185240428], [0.1154569744772111, 0.1037792828905834, 0.0, 0.0, 0.0, 0.1091819846433738, 0.1092536397151344, 0.0, 0.0, 0.0, 0.0, 0.09597703900047773, 0.07478618280191714, 0.04567446376735678, 0.06250552687630881, 0.0, 0.115053607903646, 0.07851656546355659, 0.0898147324604344, 0.0], [0.1533482474405494, 0.1309480548647081, 0.0, 0.0, 0.0, 0.1377651503951132, 0.137855564319809, 0.0, 0.0, 0.0, 0.01397500989713012, 0.0, 0.01100103110672923, 0.0, 0.0, 0.0, 0.0, 0.1450311413057912, 0.1663020259984476, 0.1037737746717222], [0.2458184792370227, 0.2346211479663781, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2473633342192062, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.272197038577393, 0.0, 0.0], [0.1338194119923476, 0.127723774710838, 0.0, 0.0, 0.0, 0.1560032871448503, 0.1374880320410287, 0.0, 0.0, 0.0, 0.0, 0.1583547535733077, 0.1144228031272007, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1091328096791357, 0.06305512773129131], [0.1007029974872034, 0.1022376930126454, 0.02206641983786378, 0.07344876380679712, 0.0, 0.02739465965591325, 0.08935755043248939, 0.0006644698665248878, 0.03715247508377899, 0.0, 0.08157806881467004, 0.112416319119299, 0.0, 0.0, 0.04425320395833497, 0.1267605174716687, 0.0, 0.0, 0.1171441677558138, 0.06482269369699734], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.7877428459245156, 0.0, 0.2122571540754844, 0.0], [0.2890106151555579, 0.2758458294621715, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2908269126532593, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1443166427290113, 0.0], [0.3678621241219278, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.6321378758780721, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.38588751600881, 0.0, 0.4090014635380119, 0.0, 0.205111020453178], [0.1783790323342217, 0.1532245387055562, 0.0, 0.0, 0.0, 0.1612013377426799, 0.1613071326085783, 0.0, 0.0, 0.0, 0.01301542422891263, 0.0, 0.01024565190747729, 0.0, 0.0, 0.0, 0.1343530992856723, 0.00901176877951138, 0.1792620144073903, 0.0], [0.4863689911712528, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.486288825012563, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0273421838161843, 0.0], [0.4400884405839033, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.440015902654048, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1198956567620488], [0.07096249501493478, 0.05107781905923201, 0.05083599231641613, 0.05068615905555981, 0.05089545481090395, 0.07396138775732392, 0.09843836188588581, 0.0593533302902484, 0.05297222437103824, 0.0, 0.0, 0.07230213129827154, 0.02922976155074553, 0.0, 0.05966447180162376, 0.07674014267395218, 0.08639178059423415, 0.0827468170267535, 0.03374167049287634, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.4288056618463641, 0.37791284821176, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1932814899418759, 0.0, 0.0], [0.04996794793098901, 0.05006107315247825, 0.04998559611653128, 0.049950806881649, 0.05000232344969021, 0.05001359391413348, 0.04996512587007753, 0.05000080997672408, 0.04999761047483434, 0.05007995390213629, 0.04988896735425338, 0.05002780947603458, 0.0500171845260553, 0.0500185481160632, 0.04999048267048197, 0.05000978445807944, 0.05002139418198893, 0.04995709350779211, 0.04994915182233473, 0.05009474221767291], [0.3180497946975858, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.320505220647913, 0.0, 0.0, 0.0, 0.0, 0.3381903669181699, 0.0, 0.0, 0.02325461773633131], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1749175184303061, 0.1986584432619842, 0.1794138872404755, 0.1799679335842623, 0.0, 0.0, 0.09606470016974732, 0.1709775173132245], [0.1119676004258696, 0.09199975458653258, 0.1163604474409536, 0.0, 0.09201666252171538, 0.0313220252457953, 0.04070394282549022, 0.0, 0.03309112565766113, 0.07188299802588975, 0.0, 0.0, 0.0, 0.001792075735244447, 0.0, 0.1051955747503673, 0.07507228618386126, 0.06521621337341629, 0.09737499257874743, 0.06600430064845574], [0.4443540125643341, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4601221144668068, 0.0, 0.0, 0.0955238729688591], [0.4398332869741099, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4298638286943248, 0.0, 0.0, 0.1303028843315653], [0.3277905046013257, 0.3366042058014851, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3267364366054823, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.008868852991706828, 0.0, 0.0], [0.3965596055463514, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2262094812447538, 0.3772309132088948, 0.0, 0.0], [0.429381867673194, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4087661645929135, 0.0, 0.1618519677338925, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.9254227158789841, 0.0, 0.0, 0.0, 0.0, 0.07457728412101597, 0.0, 0.0, 0.0], [0.2539019968546615, 0.2423364515063865, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2554976529910298, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2403877877810967, 0.0, 0.0, 0.007876110866825487], [0.1090601948338732, 0.1040923700642047, 0.0, 0.0, 0.0, 0.1271396177687207, 0.112050048184174, 0.0, 0.0, 0.0, 0.0, 0.1290560167650602, 0.09325233922866161, 0.0, 0.07768115925127772, 0.0, 0.05155386045788234, 0.02648153717148393, 0.07922286261498744, 0.09040999365967411], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1735459690875908, 0.8264540309124092, 0.0], [0.490157110449924, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.01202906855563425, 0.0, 0.0, 0.0, 0.0, 0.4978138209944417, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.68200380205959, 0.31799619794041, 0.0], [0.0, 0.0823185004964443, 0.00118191182117239, 0.03769184747124002, 0.05606067420024995, 0.05432808520882509, 0.0596801219142534, 0.07072184229261103, 0.06197536540345174, 0.041066974403659, 0.07981684430597571, 0.06345483631714988, 0.09446996825204705, 0.001642313761457333, 0.0390659641195272, 0.04096878518601892, 0.04712392313732853, 0.04203861742758905, 0.06804721007617394, 0.05834621420482554], [0.1274940155168384, 0.1216865077525819, 0.0, 0.0, 0.0, 0.1194065951027556, 0.1194849604866486, 0.0, 0.111195174699312, 0.0, 0.0901775122110441, 0.0, 0.0702301722754204, 0.0, 0.0, 0.1403601051441368, 0.0, 0.0, 0.09996495681126229, 0.0], [0.2258533603529428, 0.2155654645759061, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2272727438348807, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.162487918604431, 0.0, 0.1688205126318394, 0.0, 0.0], [0.2102281634986257, 0.1889650075283933, 0.0, 0.0, 0.0, 0.1988024389400756, 0.189414197283208, 0.0, 0.0, 0.0, 0.01747543843352771, 0.0, 0.01375654423332105, 0.0, 0.0, 0.0, 0.0, 0.1813582100828486, 0.0, 0.0], [0.4629886401715345, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4566650477087713, 0.0, 0.07886084019478028, 0.001485471924913691], [0.3090339505766482, 0.3173433215402768, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3080401975778294, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06558253030524547], [0.3171942075008773, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2490019739574258, 0.0, 0.2633688046871145, 0.0, 0.0, 0.0, 0.0, 0.1704350138545823], [0.3202169134032709, 0.3189084448041599, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3239170612631116, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.00262654809616672, 0.0, 0.0, 0.0, 0.03433103243329091], [0.4593297486393575, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4534772921611107, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.08719295919953181], [0.1967609920983341, 0.1877982891457161, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.197997543556491, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1831535816328902, 0.06188972726977526, 0.001584175288507823, 0.1708156910082854], [0.2477743108917333, 0.2440818712400762, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2268977102692738, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.163366980254127, 0.0, 0.0, 0.1178791273447897], [0.3178858410306973, 0.326433223518221, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3259883982833098, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.002982090617993399, 0.0, 0.0, 0.0, 0.02671044654977867], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.8615149304724637, 0.1384850695275363, 0.0], [0.3811252414609911, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3592735453261077, 0.2596012132129012, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.901526558618339, 0.0, 0.0, 0.0, 0.0, 0.0, 0.09847344138166109, 0.0, 0.0], [0.2478031050496696, 0.2365153716548989, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2286790964418568, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.256951724801011, 0.0, 0.03005070205256384], [0.1700817185443257, 0.1527397956128646, 0.0, 0.0, 0.0, 0.1865581427372076, 0.1644164836241702, 0.0, 0.0, 0.0, 0.0, 0.1893701681607141, 0.1368336913207177, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.485603724510129, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4805697662569086, 0.0, 0.0, 0.0338265092329624], [0.4891928049671583, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5017711320150706, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.00903606301777108, 0.0], [0.3192555945537156, 0.3182358995637005, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3178022446885781, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.002907204971875758, 0.0, 0.0, 0.04179905622213005, 0.0], [0.477449416235485, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4773707202528812, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0331781774931928, 0.01200168601844099], [0.247274298646481, 0.2360106530277511, 0.0, 0.0, 0.0, 0.2348231992350713, 0.2349773114106946, 0.0, 0.0, 0.0, 0.01895966621389722, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.004617026036099474, 0.02333784543000524], [0.295053136129021, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2972068374526513, 0.0, 0.0, 0.0, 0.0, 0.313606403057995, 0.0, 0.09413362336033282, 0.0], [0.4613796256202699, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4638141179188116, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.07480625646091851], [0.4905843322268349, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4928398216555963, 0.0, 0.01657584611756886, 0.0], [0.4427844350909252, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4530103620677742, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1042052028413006, 0.0], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0764158880903946, 0.07608643688443481, 0.07673866420285846, 0.07616882940536532, 0.07660472730159493, 0.07586291331000192, 0.07627799616639805, 0.07610957774588682, 0.0769654216124561, 0.07630514656550555, 0.0766307391370021, 0.07665403848915041, 0.08317962108895101, 0.0, 0.0], [0.1501074655212832, 0.1281806669378709, 0.0, 0.0, 0.0, 0.1348536935251639, 0.134942196689109, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1372621726667977, 0.03597546317473341, 0.0, 0.06867007572641241, 0.0, 0.1273809397606583, 0.08262732599797112], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.8744076310849419, 0.0, 0.1255923689150581], [0.4066984160211644, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4231588931063109, 0.0, 0.0, 0.0, 0.0, 0.1701426908725247, 0.0, 0.0, 0.0], [0.4725516482971623, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4704503247391861, 0.0, 0.0, 0.0, 0.0, 0.0, 0.05699802696365158, 0.0, 0.0], [0.1130078776906513, 0.107860231156419, 0.0, 0.0, 0.0, 0.1304271213380153, 0.1305127193858026, 0.0, 0.0, 0.0, 0.0, 0.0, 0.103335464608199, 0.0, 0.1092976789023458, 0.0, 0.109497449524614, 0.0976180530707459, 0.0697540995788014, 0.02868930474440559], [0.3170310669769288, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3160512224066144, 0.0, 0.0, 0.0, 0.0, 0.310776448217319, 0.0, 0.05614126239913791, 0.0], [0.4432029609447692, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4445428429477704, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1122541961074603, 0.0], [0.96706261519031, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.03293738480969004, 0.0], [0.1578936052874791, 0.1661210550589605, 0.0, 0.0, 0.0, 0.1747692408080245, 0.1748839401563882, 0.0, 0.0, 0.0, 0.01571495973985966, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1828419921109487, 0.0, 0.1277752068383394], [0.4955948648402598, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5044051351597403, 0.0, 0.0, 0.0], [0.3015318352904618, 0.3002997175552783, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2854518610864963, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.1127165860677638, 0.0, 0.0, 0.0], [0.2840822498080262, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2955800309132728, 0.0, 0.0, 0.0, 0.0, 0.2906469130912301, 0.0, 0.1296908061874708, 0.0], [0.4877808142032851, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4614526299504636, 0.0, 0.0192420092923631, 0.0315245465538882], [0.06931190374343914, 0.05769524717632195, 0.05264595968848474, 0.04210521070632976, 0.05274138577627915, 0.05125320134886215, 0.04829250631668593, 0.04680084611478574, 0.05666664889796764, 0.05432479854269069, 0.04979650704927225, 0.04832239906574707, 0.04446313883499555, 0.0572808149658464, 0.06337661782351206, 0.06189761615006221, 0.04824365647586837, 0.08359523653381509, 0.002043424711695171, 0.009142880077339023], [0.433987192718982, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.4241502446299947, 0.0, 0.1418625626510232, 0.0], [0.4668061820338874, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.46926930782438, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.06392451014173264], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.2851315924802448, 0.0, 0.7148684075197551]]} +RLMATH_EOF diff --git a/tasks/optimize-ea-edges-vs-triangles/tests/check.py b/tasks/optimize-ea-edges-vs-triangles/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d666f7e136894b7e7831bc4abe8ddf4e24160fea --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/tests/check.py @@ -0,0 +1,68 @@ +"""Edges vs triangles (Razborov) upper-bound curve (EinsteinArena edges-vs-triangles, MIT). + +Each row is a probability vector over 20 parts (a complete 20-partite graphon); edge density +1 - sum w^2 ... (upstream uses S1^2 - S2 and S1^3 - 3 S1 S2 + 2 S3). Score = -(area under the slope-3 +envelope + 10 * max gap) (maximize). Ported verbatim from the upstream verifier. Changes: at most +inst["max_rows"] rows (the description says m <= 500 but upstream did not enforce it); NaN/inf rejected.""" +import numpy as np + +from run import Invalid, float_matrix + + +def _densities(A): + S1 = A.sum(1) + S2 = (A ** 2).sum(1) + S3 = (A ** 3).sum(1) + return S1 ** 2 - S2, S1 ** 3 - 3 * S1 * S2 + 2 * S3 + + +def _curve(ex, ty): + slope = 3.0 + o = np.argsort(ex) + fx = np.concatenate(([0.0], ex[o], [1.0])) + fy = np.concatenate(([0.0], ty[o], [1.0])) + ux, inv = np.unique(fx, return_inverse=True) + my = np.full(len(ux), np.inf) + np.minimum.at(my, inv, fy) + fx, fy = ux, my + if len(fx) < 2: + return 5.0 / 6.0, 1.0 + left = np.minimum.accumulate(fy - slope * fx) + right = np.minimum.accumulate(fy[::-1])[::-1] + area = 0.0 + for i in range(len(fx) - 1): + x0, x1 = fx[i], fx[i + 1] + w = x1 - x0 + if w <= 0: + continue + cap = min(float(right[i + 1]), 1.0) + yl, yr = slope * x0 + left[i], slope * x1 + left[i] + if yl >= cap: + area += cap * w + elif yr <= cap: + area += (yl + yr) * w / 2.0 + else: + xh = (cap - left[i]) / slope + area += (yl + cap) * (xh - x0) / 2.0 + cap * (x1 - xh) + gaps = np.diff(fx) + idx = np.where((fx[:-1] >= 0.0) & (fx[:-1] < 1.0))[0] + return area, float(np.max(gaps[idx])) if idx.size else 0.0 + + +def check(inst, ans): + w = ans.get("weights") + if not isinstance(w, list) or not 1 <= len(w) <= inst["max_rows"]: + raise Invalid(f"weights must be a list of 1..{inst['max_rows']} rows") + A = np.array(float_matrix(w, None, inst["parts"], "weights")) + if np.any(A < 0): + raise Invalid("weights must be non-negative") + s = A.sum(1) + if np.any(s < 1e-7): + raise Invalid("a row sums to (nearly) zero") + A = A / s[:, None] + e, t = _densities(A) + area, gap = _curve(e, t) + val = -(area + 10 * gap) + if not np.isfinite(val): + raise Invalid("non-finite score") + return float(val), {"area": float(area), "max_gap": gap} diff --git a/tasks/optimize-ea-edges-vs-triangles/tests/instance.json b/tasks/optimize-ea-edges-vs-triangles/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..af3fa32c2518457ab68edd93ff3dd0dae9a9ae04 --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/tests/instance.json @@ -0,0 +1 @@ +{"parts": 20, "max_rows": 500, "direction": "maximize", "best_known": -0.712256, "baseline": -5.224465062515447, "family": "ea_edges_vs_triangles", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-edges-vs-triangles/tests/run.py b/tasks/optimize-ea-edges-vs-triangles/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ea-edges-vs-triangles/tests/test.sh b/tasks/optimize-ea-edges-vs-triangles/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-edges-vs-triangles/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-third-autocorrelation/environment/Dockerfile b/tasks/optimize-ea-third-autocorrelation/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-third-autocorrelation/environment/instance.json b/tasks/optimize-ea-third-autocorrelation/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..19a3495d395f8a45f5e3ed5390fe5aaae981f104 --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/environment/instance.json @@ -0,0 +1 @@ +{"max_len": 30000, "direction": "minimize", "family": "ea_third_autocorrelation", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-third-autocorrelation/solution/solve.sh b/tasks/optimize-ea-third-autocorrelation/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9a942c81bfa5c382fd0f23488175624f222a8d89 --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"values": [29.822474586952435, 13.35577542848344, 15.34090251357998, 7.41973780909517, 9.941172227087801, 9.397527742756054, 6.223753972127697, 7.56329589706775, 2.1067211015108285, 9.974340772016436, 8.520985201036822, 5.555614238031824, 6.4207807868982885, 6.08650501068607, -1.086292705443019, 0.4543446540875604, 3.0749360916629365, 9.651448385117874, 6.91111005215068, 2.6293616012576764, 2.494180660949903, -1.1237107164061881, 3.7748358284726047, 5.0563109221202245, 6.496190604000092, 1.940945279091857, 3.4561176861604053, -2.0682191942766597, 5.231322841482674, 2.0166752624479787, 1.2750083043923754, -3.656830137590605, -0.890034667694402, -5.079430968650838, 0.4498555225173546, -0.40999059122271486, -2.076004236539431, -3.7727681320100492, -3.8824114464719237, -3.0668005357529653, -3.3386683675046065, -1.8846459332731227, -0.6700102311003655, 0.5503863166220995, 6.574990562901413, 4.355509565730535, 4.4765131503876265, 1.9876459461571483, 6.458267158207537, 3.2963361399041498, -4.201623863332442, 0.29501097277314137, -0.8990505777993056, 2.388289283056365, 1.8118339696124244, -1.8691041641774606, 5.406232899781979, 4.609433332155248, 1.87302502730677, 1.3285429786171348, 2.068144198379287, 1.0349391254175302, 0.13132312300251625, 0.6496105778173946, -2.2278900042506464, -1.0809890657528691, 2.7932844974524267, -2.378429845770511, -0.07565198130685413, 0.7794633738581462, -1.1907683219066243, -2.363630702941169, 2.5176951930644575, 0.4840665774759294, -1.42138428299282, 1.7818712641636345, 1.864625344637249, 1.1879483587830364, 2.016139734272687, 3.0459925202130576, 1.0241806911210596, 2.1277448622380994, 2.7686696629482905, 1.465562774596172, 0.4289310952287715, 2.6913756617644915, 1.6993584856814976, 1.4237709656694764, 1.0402220486803755, 0.7917540255810867, 0.050848137432480955, 0.4885282315104751, 1.370118457442015, 0.7701459879179864, 3.6416714982302074, 1.649723584464175, 2.50679063247599, 1.2011439367360945, 2.9058343470033354, 1.6211812557477063, -2.17547168171485, -0.06503461393033572, -1.2524047144093329, 1.0822123515717086, 0.8621808070445565, 0.6599539919288464, 3.2331824689736055, 5.639989914625983, 1.4195241653933572, 3.750535878076202, 3.9350664030297096, 4.695027744381525, 3.8067728347868073, 5.065598673785374, 2.4084588752201097, 3.76366698404769, 5.067444075331292, 3.5278712068757607, 4.683674221898379, 3.9876483626441277, 2.8368632206638242, 1.6659582629676766, 0.8515341390100906, 1.6328750176878848, 1.875954421505874, 6.06597307924434, 3.900104419988838, 3.837424450092794, -1.8019133878742912, 0.8979487403238753, -1.2310679091351293, 7.119179032067094, 5.424215164915786, 2.487640761641165, 2.2303729891888273, 1.5212201288649638, 1.3977787459644677, -0.1466076886389951, 3.1586409109876055, -7.231684261037122, -1.090145717968722, 3.4890129890745074, 2.3126213344498026, -3.6328929589333816, -21.762632344840398, -19.019334243046966, -21.637701518936307, -8.812492360654893, -12.836401450094137, -5.222698451943903, 0.5883462331499247, 0.7682181256007814, 1.5269870021833525, -1.3885358222096231, 1.9658218740816278, 12.477202593035521, -8.84524549232242, -4.357365411065137, 0.9735572978386937, 0.2911214772688304, 1.8923681177368157, 1.1445510564328163, 1.1578150378158332, 1.3109279837091976, 1.6407516610844102, 1.5951674856865352, 0.7114460293000304, 1.5086337546878081, 1.4483937116941614, 1.9031884002219446, 0.2747913999120719, 2.175941627135083, 1.3500787810265242, 0.7097505538331568, 1.5057645156045185, 2.3537269869412834, 0.6007363252187083, 0.7109246177898854, 1.8463754661186629, 1.6516518214399176, 0.6017171929135086, 1.8015916878632094, 1.9295565444315985, 1.0685387309076726, 1.467086529268155, 2.341295965018609, 1.2168546447536486, 2.09293999559367, 1.971302043942939, 2.3436776994693806, 1.6381147232531392, 2.027123073556922, 1.545528493731711, 3.047820316051929, 1.5448775462942759, 2.0360675820988785, 1.5269924917930546, 2.8248180294493532, 0.8815767124192126, 2.505684877677395, 2.93338369440571, 2.137106424241189, 1.9563093389803845, 3.198543195219207, 2.616970935168015, 1.6380720093391878, 2.5666491140445813, 2.3584167649892063, 2.704648397792848, 1.3610957493372688, 4.114847418677698, 0.3109131924574857, 3.1397332586816438, 2.7077176076368525, 3.5307053502082275, 2.0068346957127394, 2.901581180557342, 2.0769286952867296, 4.251908659172121, 2.4943271630034873, 3.4146266577962194, 3.502701062689788, 4.172450872725465, 3.1120768647902057, 3.230585976144584, 3.424276809035965, 2.8660991452307774, 2.9503388513783246, 4.935727847671723, 4.125592046922797, 0.6731370125501104, 3.772397397363904, 2.83576281189473, 3.3011524894409767, 1.6026039291308185, 3.0092344436836105, 1.1458441858417208, 2.282902678255513, 2.9786716450918447, 5.164603558764292, 3.3577441937463983, 2.9545347513501183, 4.7954706923652966, 4.202167490778789, -2.292091923212606, 0.9018477903517135, 1.196917619905997, 1.0562112054857598, 0.3172061467442169, 3.2649555235002237, 5.409384954448099, 6.744031165255508, 6.815518738138658, 8.414234925339695, 7.791000653999829, 9.436455841758512, 3.449307941797402, 5.248164285951556, 4.044349681791928, 4.565448208116523, 5.621386452472719, 4.116198238446057, 4.097835386574838, 4.6199313415569945, 4.940203419659278, 1.5174569180478144, 0.6907692500258615, -0.6552725084513416, 2.707755673001066, 4.9582207333704655, 5.305251746860825, 4.924644218068229, 0.2359462486107582, -0.8272509324363728, 0.21444751162136644, 4.651723432890657, 4.0940636862009745, 5.015449482221029, 2.1410659505033234, 1.2973602939757827, 1.0668526035799943, -0.13308760696169353, 1.9061167705112947, -0.6223720562263475, -0.9933002293760356, 0.12421425505907857, -0.07958798079815788, -1.5633644554368802, -3.4353353936261577, -3.9816669909263904, -4.99132422153432, -3.467242665932913, -5.197616875527715, -0.9176166796738485, 4.952122278920942, 3.2983895100050775, 4.13087177764586, 5.959347405172698, 5.611672573164332, 7.257980664521631, 0.6889186817911817, 1.4445830317665764, -0.5008588756737584, 1.2474504233466799, -0.24724237186531584, 0.20307101440923536, 2.523166166678627, 4.338106510688674, 4.084139242595694, 2.4773554368320916, 0.45349133668483477, 5.465230192602899, 1.0951271798603641, 0.6116464550552352, 2.2729359139821605, 1.0355323436603185, -0.7525137712582959, 1.0545731217992163, 1.1695717448987444, 0.5259830757826429, 0.13633030539784885, 0.15603785592606734, 0.5195661087152532, -1.0980847488303498, 0.09794928980739703, 2.4206615651752417, 2.0969438234581315, 2.1636746440881467, 2.8301773593665294, 1.639877889058949, 2.6774872135740364, 1.8072835457837424, 4.724804083315695, 3.4289959137543065, 3.247603209132396, 2.657589825320717, 3.7341104189729015, 1.4239767844833158, 2.435890118197348, 1.2762491900614972, 1.3211208652913746, 0.4213279300161554, -1.2321732010111992, -0.31355802671098143, 3.731507835870336, 2.1242697218899496, 3.8144584027803963, 3.2587591017016675, 2.4993998110383813, 2.9868093779754568, -0.838757284697139, 0.24152988079536009, 0.5059765718377291, -0.30926647862786316, -0.8381478937957536, -1.68948704779611, 0.011067527655095333, 2.6181473230812684, 3.325082296690492, 3.497349779449698, 2.9346701569231457, 4.579690699759554, 1.7548416403515203, 2.7844365878834236, 2.801749190699653, 3.4660050977781283, 5.127777800005223, 2.5094361397138054, 2.372623368009197, 2.0680627433538206, 1.2263168882719833, 2.423995490782778, 3.9846108161397105, 0.4964419505408235, -0.6785875773626491, 1.1483132453802452, 0.004589538404844662, 2.4390990338797613, 1.5878808886028206, 2.365916815625474, -1.0364998357131916, -0.8127888373467984, 1.726930482957257, 0.26226670900951277, 1.9074855880971588, 7.013803336708728, 1.6883949623693713, 1.4769123390400731, -2.312691748741072, -3.3984244182269165, -1.0028699978817217, 1.5891293624111782, -2.2535310480920483, 1.2917935820518966, 5.681586620739426, 7.10954012229358, 13.095605279381697, 15.282877009294417, 19.483769209707113, 21.688985380825365]} +RLMATH_EOF diff --git a/tasks/optimize-ea-third-autocorrelation/tests/check.py b/tasks/optimize-ea-third-autocorrelation/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1998a6ffaf74a7aaf2af5e3a3a1df28903e415a0 --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/tests/check.py @@ -0,0 +1,23 @@ +"""Third autocorrelation inequality, upper bound (EinsteinArena third-autocorrelation-inequality, MIT). + +C = |max(conv(f, f) * dx)| / (sum(f) * dx)^2, dx = 0.5 / n, f may be negative (minimize). Ported from the +upstream verifier (np.convolve; the squared integral must be >= 1e-9). Change: length capped at +inst["max_len"]; NaN/inf rejected.""" +import numpy as np + +from run import Invalid, float_list + + +def check(inst, ans): + v = ans.get("values") + if not isinstance(v, list) or not 1 <= len(v) <= inst["max_len"]: + raise Invalid(f"values must be a list of 1..{inst['max_len']} numbers") + f = np.array(float_list(v, None, "values")) + dx = 0.5 / len(f) + i2 = (np.sum(f) * dx) ** 2 + if not i2 >= 1e-9: + raise Invalid("(integral of f)^2 must be at least 1e-9") + c = float(abs(np.max(np.convolve(f, f) * dx)) / i2) + if not np.isfinite(c): + raise Invalid("non-finite score") + return c, {} diff --git a/tasks/optimize-ea-third-autocorrelation/tests/instance.json b/tasks/optimize-ea-third-autocorrelation/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab030426665debf735ed581a9c8b0869b7b48a1c --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/tests/instance.json @@ -0,0 +1 @@ +{"max_len": 30000, "direction": "minimize", "best_known": 1.4545548626983331, "baseline": 2.0, "family": "ea_third_autocorrelation", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-third-autocorrelation/tests/run.py b/tasks/optimize-ea-third-autocorrelation/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ea-third-autocorrelation/tests/test.sh b/tasks/optimize-ea-third-autocorrelation/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-third-autocorrelation/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/environment/Dockerfile b/tasks/optimize-fs-cycle-indep-c9-n5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/environment/instance.json b/tasks/optimize-fs-cycle-indep-c9-n5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2468bf17b74701fcdc0807e2637eb158044eb3cf --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/environment/instance.json @@ -0,0 +1 @@ +{"m": 9, "n": 5, "direction": "maximize", "family": "fs_cycle_independent_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/solution/solve.sh b/tasks/optimize-fs-cycle-indep-c9-n5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3d7df244e47bbcb8f55b6dc6260157f8dc32a441 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"vertices": [[0, 0, 4, 0, 4], [0, 0, 4, 1, 8], [0, 0, 4, 2, 3], [0, 0, 4, 3, 7], [0, 0, 4, 4, 2], [0, 0, 4, 5, 6], [0, 0, 4, 6, 1], [0, 0, 4, 7, 5], [0, 0, 4, 8, 0], [0, 1, 8, 0, 4], [0, 1, 8, 1, 8], [0, 1, 8, 2, 3], [0, 1, 8, 3, 7], [0, 1, 8, 4, 2], [0, 1, 8, 5, 6], [0, 1, 8, 6, 1], [0, 1, 8, 7, 5], [0, 1, 8, 8, 0], [0, 2, 3, 0, 4], [0, 2, 3, 1, 8], [0, 2, 3, 2, 3], [0, 2, 3, 3, 7], [0, 2, 3, 4, 2], [0, 2, 3, 5, 6], [0, 2, 3, 6, 1], [0, 2, 3, 7, 5], [0, 2, 3, 8, 0], [0, 3, 7, 0, 4], [0, 3, 7, 1, 8], [0, 3, 7, 2, 3], [0, 3, 7, 3, 7], [0, 3, 7, 4, 2], [0, 3, 7, 5, 6], [0, 3, 7, 6, 1], [0, 3, 7, 7, 5], [0, 3, 7, 8, 0], [0, 4, 2, 0, 4], [0, 4, 2, 1, 8], [0, 4, 2, 2, 3], [0, 4, 2, 3, 7], [0, 4, 2, 4, 2], [0, 4, 2, 5, 6], [0, 4, 2, 6, 1], [0, 4, 2, 7, 5], [0, 4, 2, 8, 0], [0, 5, 6, 0, 4], [0, 5, 6, 1, 8], [0, 5, 6, 2, 3], [0, 5, 6, 3, 7], [0, 5, 6, 4, 2], [0, 5, 6, 5, 6], [0, 5, 6, 6, 1], [0, 5, 6, 7, 5], [0, 5, 6, 8, 0], [0, 6, 1, 0, 4], [0, 6, 1, 1, 8], [0, 6, 1, 2, 3], [0, 6, 1, 3, 7], [0, 6, 1, 4, 2], [0, 6, 1, 5, 6], [0, 6, 1, 6, 1], [0, 6, 1, 7, 5], [0, 6, 1, 8, 0], [0, 7, 5, 0, 4], [0, 7, 5, 1, 8], [0, 7, 5, 2, 3], [0, 7, 5, 3, 7], [0, 7, 5, 4, 2], [0, 7, 5, 5, 6], [0, 7, 5, 6, 1], [0, 7, 5, 7, 5], [0, 7, 5, 8, 0], [0, 8, 0, 0, 4], [0, 8, 0, 1, 8], [0, 8, 0, 2, 3], [0, 8, 0, 3, 7], [0, 8, 0, 4, 2], [0, 8, 0, 5, 6], [0, 8, 0, 6, 1], [0, 8, 0, 7, 5], [0, 8, 0, 8, 0], [1, 0, 6, 0, 4], [1, 0, 6, 1, 8], [1, 0, 6, 2, 3], [1, 0, 6, 3, 7], [1, 0, 6, 4, 2], [1, 0, 6, 5, 6], [1, 0, 6, 6, 1], [1, 0, 6, 7, 5], [1, 0, 6, 8, 0], [1, 1, 1, 0, 4], [1, 1, 1, 1, 8], [1, 1, 1, 2, 3], [1, 1, 1, 3, 7], [1, 1, 1, 4, 2], [1, 1, 1, 5, 6], [1, 1, 1, 6, 1], [1, 1, 1, 7, 5], [1, 1, 1, 8, 0], [1, 2, 5, 0, 4], [1, 2, 5, 1, 8], [1, 2, 5, 2, 3], [1, 2, 5, 3, 7], [1, 2, 5, 4, 2], [1, 2, 5, 5, 6], [1, 2, 5, 6, 1], [1, 2, 5, 7, 5], [1, 2, 5, 8, 0], [1, 3, 0, 0, 4], [1, 3, 0, 1, 8], [1, 3, 0, 2, 3], [1, 3, 0, 3, 7], [1, 3, 0, 4, 2], [1, 3, 0, 5, 6], [1, 3, 0, 6, 1], [1, 3, 0, 7, 5], [1, 3, 0, 8, 0], [1, 4, 4, 0, 4], [1, 4, 4, 1, 8], [1, 4, 4, 2, 3], [1, 4, 4, 3, 7], [1, 4, 4, 4, 2], [1, 4, 4, 5, 6], [1, 4, 4, 6, 1], [1, 4, 4, 7, 5], [1, 4, 4, 8, 0], [1, 5, 8, 0, 4], [1, 5, 8, 1, 8], [1, 5, 8, 2, 3], [1, 5, 8, 3, 7], [1, 5, 8, 4, 2], [1, 5, 8, 5, 6], [1, 5, 8, 6, 1], [1, 5, 8, 7, 5], [1, 5, 8, 8, 0], [1, 6, 3, 0, 4], [1, 6, 3, 1, 8], [1, 6, 3, 2, 3], [1, 6, 3, 3, 7], [1, 6, 3, 4, 2], [1, 6, 3, 5, 6], [1, 6, 3, 6, 1], [1, 6, 3, 7, 5], [1, 6, 3, 8, 0], [1, 7, 7, 0, 4], [1, 7, 7, 1, 8], [1, 7, 7, 2, 3], [1, 7, 7, 3, 7], [1, 7, 7, 4, 2], [1, 7, 7, 5, 6], [1, 7, 7, 6, 1], [1, 7, 7, 7, 5], [1, 7, 7, 8, 0], [1, 8, 2, 0, 4], [1, 8, 2, 1, 8], [1, 8, 2, 2, 3], [1, 8, 2, 3, 7], [1, 8, 2, 4, 2], [1, 8, 2, 5, 6], [1, 8, 2, 6, 1], [1, 8, 2, 7, 5], [1, 8, 2, 8, 0], [2, 0, 8, 0, 4], [2, 0, 8, 1, 8], [2, 0, 8, 2, 3], [2, 0, 8, 3, 7], [2, 0, 8, 4, 2], [2, 0, 8, 5, 6], [2, 0, 8, 6, 1], [2, 0, 8, 7, 5], [2, 0, 8, 8, 0], [2, 1, 3, 0, 4], [2, 1, 3, 1, 8], [2, 1, 3, 2, 3], [2, 1, 3, 3, 7], [2, 1, 3, 4, 2], [2, 1, 3, 5, 6], [2, 1, 3, 6, 1], [2, 1, 3, 7, 5], [2, 1, 3, 8, 0], [2, 2, 7, 0, 4], [2, 2, 7, 1, 8], [2, 2, 7, 2, 3], [2, 2, 7, 3, 7], [2, 2, 7, 4, 2], [2, 2, 7, 5, 6], [2, 2, 7, 6, 1], [2, 2, 7, 7, 5], [2, 2, 7, 8, 0], [2, 3, 2, 0, 4], [2, 3, 2, 1, 8], [2, 3, 2, 2, 3], [2, 3, 2, 3, 7], [2, 3, 2, 4, 2], [2, 3, 2, 5, 6], [2, 3, 2, 6, 1], [2, 3, 2, 7, 5], [2, 3, 2, 8, 0], [2, 4, 6, 0, 4], [2, 4, 6, 1, 8], [2, 4, 6, 2, 3], [2, 4, 6, 3, 7], [2, 4, 6, 4, 2], [2, 4, 6, 5, 6], [2, 4, 6, 6, 1], [2, 4, 6, 7, 5], [2, 4, 6, 8, 0], [2, 5, 1, 0, 4], [2, 5, 1, 1, 8], [2, 5, 1, 2, 3], [2, 5, 1, 3, 7], [2, 5, 1, 4, 2], [2, 5, 1, 5, 6], [2, 5, 1, 6, 1], [2, 5, 1, 7, 5], [2, 5, 1, 8, 0], [2, 6, 5, 0, 4], [2, 6, 5, 1, 8], [2, 6, 5, 2, 3], [2, 6, 5, 3, 7], [2, 6, 5, 4, 2], [2, 6, 5, 5, 6], [2, 6, 5, 6, 1], [2, 6, 5, 7, 5], [2, 6, 5, 8, 0], [2, 7, 0, 0, 4], [2, 7, 0, 1, 8], [2, 7, 0, 2, 3], [2, 7, 0, 3, 7], [2, 7, 0, 4, 2], [2, 7, 0, 5, 6], [2, 7, 0, 6, 1], [2, 7, 0, 7, 5], [2, 7, 0, 8, 0], [2, 8, 4, 0, 4], [2, 8, 4, 1, 8], [2, 8, 4, 2, 3], [2, 8, 4, 3, 7], [2, 8, 4, 4, 2], [2, 8, 4, 5, 6], [2, 8, 4, 6, 1], [2, 8, 4, 7, 5], [2, 8, 4, 8, 0], [3, 0, 1, 0, 4], [3, 0, 1, 1, 8], [3, 0, 1, 2, 3], [3, 0, 1, 3, 7], [3, 0, 1, 4, 2], [3, 0, 1, 5, 6], [3, 0, 1, 6, 1], [3, 0, 1, 7, 5], [3, 0, 1, 8, 0], [3, 1, 5, 0, 4], [3, 1, 5, 1, 8], [3, 1, 5, 2, 3], [3, 1, 5, 3, 7], [3, 1, 5, 4, 2], [3, 1, 5, 5, 6], [3, 1, 5, 6, 1], [3, 1, 5, 7, 5], [3, 1, 5, 8, 0], [3, 2, 0, 0, 4], [3, 2, 0, 1, 8], [3, 2, 0, 2, 3], [3, 2, 0, 3, 7], [3, 2, 0, 4, 2], [3, 2, 0, 5, 6], [3, 2, 0, 6, 1], [3, 2, 0, 7, 5], [3, 2, 0, 8, 0], [3, 3, 4, 0, 4], [3, 3, 4, 1, 8], [3, 3, 4, 2, 3], [3, 3, 4, 3, 7], [3, 3, 4, 4, 2], [3, 3, 4, 5, 6], [3, 3, 4, 6, 1], [3, 3, 4, 7, 5], [3, 3, 4, 8, 0], [3, 4, 8, 0, 4], [3, 4, 8, 1, 8], [3, 4, 8, 2, 3], [3, 4, 8, 3, 7], [3, 4, 8, 4, 2], [3, 4, 8, 5, 6], [3, 4, 8, 6, 1], [3, 4, 8, 7, 5], [3, 4, 8, 8, 0], [3, 5, 3, 0, 4], [3, 5, 3, 1, 8], [3, 5, 3, 2, 3], [3, 5, 3, 3, 7], [3, 5, 3, 4, 2], [3, 5, 3, 5, 6], [3, 5, 3, 6, 1], [3, 5, 3, 7, 5], [3, 5, 3, 8, 0], [3, 6, 7, 0, 4], [3, 6, 7, 1, 8], [3, 6, 7, 2, 3], [3, 6, 7, 3, 7], [3, 6, 7, 4, 2], [3, 6, 7, 5, 6], [3, 6, 7, 6, 1], [3, 6, 7, 7, 5], [3, 6, 7, 8, 0], [3, 7, 2, 0, 4], [3, 7, 2, 1, 8], [3, 7, 2, 2, 3], [3, 7, 2, 3, 7], [3, 7, 2, 4, 2], [3, 7, 2, 5, 6], [3, 7, 2, 6, 1], [3, 7, 2, 7, 5], [3, 7, 2, 8, 0], [3, 8, 6, 0, 4], [3, 8, 6, 1, 8], [3, 8, 6, 2, 3], [3, 8, 6, 3, 7], [3, 8, 6, 4, 2], [3, 8, 6, 5, 6], [3, 8, 6, 6, 1], [3, 8, 6, 7, 5], [3, 8, 6, 8, 0], [4, 0, 3, 0, 4], [4, 0, 3, 1, 8], [4, 0, 3, 2, 3], [4, 0, 3, 3, 7], [4, 0, 3, 4, 2], [4, 0, 3, 5, 6], [4, 0, 3, 6, 1], [4, 0, 3, 7, 5], [4, 0, 3, 8, 0], [4, 1, 7, 0, 4], [4, 1, 7, 1, 8], [4, 1, 7, 2, 3], [4, 1, 7, 3, 7], [4, 1, 7, 4, 2], [4, 1, 7, 5, 6], [4, 1, 7, 6, 1], [4, 1, 7, 7, 5], [4, 1, 7, 8, 0], [4, 2, 2, 0, 4], [4, 2, 2, 1, 8], [4, 2, 2, 2, 3], [4, 2, 2, 3, 7], [4, 2, 2, 4, 2], [4, 2, 2, 5, 6], [4, 2, 2, 6, 1], [4, 2, 2, 7, 5], [4, 2, 2, 8, 0], [4, 3, 6, 0, 4], [4, 3, 6, 1, 8], [4, 3, 6, 2, 3], [4, 3, 6, 3, 7], [4, 3, 6, 4, 2], [4, 3, 6, 5, 6], [4, 3, 6, 6, 1], [4, 3, 6, 7, 5], [4, 3, 6, 8, 0], [4, 4, 1, 0, 4], [4, 4, 1, 1, 8], [4, 4, 1, 2, 3], [4, 4, 1, 3, 7], [4, 4, 1, 4, 2], [4, 4, 1, 5, 6], [4, 4, 1, 6, 1], [4, 4, 1, 7, 5], [4, 4, 1, 8, 0], [4, 5, 5, 0, 4], [4, 5, 5, 1, 8], [4, 5, 5, 2, 3], [4, 5, 5, 3, 7], [4, 5, 5, 4, 2], [4, 5, 5, 5, 6], [4, 5, 5, 6, 1], [4, 5, 5, 7, 5], [4, 5, 5, 8, 0], [4, 6, 0, 0, 4], [4, 6, 0, 1, 8], [4, 6, 0, 2, 3], [4, 6, 0, 3, 7], [4, 6, 0, 4, 2], [4, 6, 0, 5, 6], [4, 6, 0, 6, 1], [4, 6, 0, 7, 5], [4, 6, 0, 8, 0], [4, 7, 4, 0, 4], [4, 7, 4, 1, 8], [4, 7, 4, 2, 3], [4, 7, 4, 3, 7], [4, 7, 4, 4, 2], [4, 7, 4, 5, 6], [4, 7, 4, 6, 1], [4, 7, 4, 7, 5], [4, 7, 4, 8, 0], [4, 8, 8, 0, 4], [4, 8, 8, 1, 8], [4, 8, 8, 2, 3], [4, 8, 8, 3, 7], [4, 8, 8, 4, 2], [4, 8, 8, 5, 6], [4, 8, 8, 6, 1], [4, 8, 8, 7, 5], [4, 8, 8, 8, 0], [5, 0, 5, 0, 4], [5, 0, 5, 1, 8], [5, 0, 5, 2, 3], [5, 0, 5, 3, 7], [5, 0, 5, 4, 2], [5, 0, 5, 5, 6], [5, 0, 5, 6, 1], [5, 0, 5, 7, 5], [5, 0, 5, 8, 0], [5, 1, 0, 0, 4], [5, 1, 0, 1, 8], [5, 1, 0, 2, 3], [5, 1, 0, 3, 7], [5, 1, 0, 4, 2], [5, 1, 0, 5, 6], [5, 1, 0, 6, 1], [5, 1, 0, 7, 5], [5, 1, 0, 8, 0], [5, 2, 4, 0, 4], [5, 2, 4, 1, 8], [5, 2, 4, 2, 3], [5, 2, 4, 3, 7], [5, 2, 4, 4, 2], [5, 2, 4, 5, 6], [5, 2, 4, 6, 1], [5, 2, 4, 7, 5], [5, 2, 4, 8, 0], [5, 3, 8, 0, 4], [5, 3, 8, 1, 8], [5, 3, 8, 2, 3], [5, 3, 8, 3, 7], [5, 3, 8, 4, 2], [5, 3, 8, 5, 6], [5, 3, 8, 6, 1], [5, 3, 8, 7, 5], [5, 3, 8, 8, 0], [5, 4, 3, 0, 4], [5, 4, 3, 1, 8], [5, 4, 3, 2, 3], [5, 4, 3, 3, 7], [5, 4, 3, 4, 2], [5, 4, 3, 5, 6], [5, 4, 3, 6, 1], [5, 4, 3, 7, 5], [5, 4, 3, 8, 0], [5, 5, 7, 0, 4], [5, 5, 7, 1, 8], [5, 5, 7, 2, 3], [5, 5, 7, 3, 7], [5, 5, 7, 4, 2], [5, 5, 7, 5, 6], [5, 5, 7, 6, 1], [5, 5, 7, 7, 5], [5, 5, 7, 8, 0], [5, 6, 2, 0, 4], [5, 6, 2, 1, 8], [5, 6, 2, 2, 3], [5, 6, 2, 3, 7], [5, 6, 2, 4, 2], [5, 6, 2, 5, 6], [5, 6, 2, 6, 1], [5, 6, 2, 7, 5], [5, 6, 2, 8, 0], [5, 7, 6, 0, 4], [5, 7, 6, 1, 8], [5, 7, 6, 2, 3], [5, 7, 6, 3, 7], [5, 7, 6, 4, 2], [5, 7, 6, 5, 6], [5, 7, 6, 6, 1], [5, 7, 6, 7, 5], [5, 7, 6, 8, 0], [5, 8, 1, 0, 4], [5, 8, 1, 1, 8], [5, 8, 1, 2, 3], [5, 8, 1, 3, 7], [5, 8, 1, 4, 2], [5, 8, 1, 5, 6], [5, 8, 1, 6, 1], [5, 8, 1, 7, 5], [5, 8, 1, 8, 0], [6, 0, 7, 0, 4], [6, 0, 7, 1, 8], [6, 0, 7, 2, 3], [6, 0, 7, 3, 7], [6, 0, 7, 4, 2], [6, 0, 7, 5, 6], [6, 0, 7, 6, 1], [6, 0, 7, 7, 5], [6, 0, 7, 8, 0], [6, 1, 2, 0, 4], [6, 1, 2, 1, 8], [6, 1, 2, 2, 3], [6, 1, 2, 3, 7], [6, 1, 2, 4, 2], [6, 1, 2, 5, 6], [6, 1, 2, 6, 1], [6, 1, 2, 7, 5], [6, 1, 2, 8, 0], [6, 2, 6, 0, 4], [6, 2, 6, 1, 8], [6, 2, 6, 2, 3], [6, 2, 6, 3, 7], [6, 2, 6, 4, 2], [6, 2, 6, 5, 6], [6, 2, 6, 6, 1], [6, 2, 6, 7, 5], [6, 2, 6, 8, 0], [6, 3, 1, 0, 4], [6, 3, 1, 1, 8], [6, 3, 1, 2, 3], [6, 3, 1, 3, 7], [6, 3, 1, 4, 2], [6, 3, 1, 5, 6], [6, 3, 1, 6, 1], [6, 3, 1, 7, 5], [6, 3, 1, 8, 0], [6, 4, 5, 0, 4], [6, 4, 5, 1, 8], [6, 4, 5, 2, 3], [6, 4, 5, 3, 7], [6, 4, 5, 4, 2], [6, 4, 5, 5, 6], [6, 4, 5, 6, 1], [6, 4, 5, 7, 5], [6, 4, 5, 8, 0], [6, 5, 0, 0, 4], [6, 5, 0, 1, 8], [6, 5, 0, 2, 3], [6, 5, 0, 3, 7], [6, 5, 0, 4, 2], [6, 5, 0, 5, 6], [6, 5, 0, 6, 1], [6, 5, 0, 7, 5], [6, 5, 0, 8, 0], [6, 6, 4, 0, 4], [6, 6, 4, 1, 8], [6, 6, 4, 2, 3], [6, 6, 4, 3, 7], [6, 6, 4, 4, 2], [6, 6, 4, 5, 6], [6, 6, 4, 6, 1], [6, 6, 4, 7, 5], [6, 6, 4, 8, 0], [6, 7, 8, 0, 4], [6, 7, 8, 1, 8], [6, 7, 8, 2, 3], [6, 7, 8, 3, 7], [6, 7, 8, 4, 2], [6, 7, 8, 5, 6], [6, 7, 8, 6, 1], [6, 7, 8, 7, 5], [6, 7, 8, 8, 0], [6, 8, 3, 0, 4], [6, 8, 3, 1, 8], [6, 8, 3, 2, 3], [6, 8, 3, 3, 7], [6, 8, 3, 4, 2], [6, 8, 3, 5, 6], [6, 8, 3, 6, 1], [6, 8, 3, 7, 5], [6, 8, 3, 8, 0], [7, 0, 0, 0, 4], [7, 0, 0, 1, 8], [7, 0, 0, 2, 3], [7, 0, 0, 3, 7], [7, 0, 0, 4, 2], [7, 0, 0, 5, 6], [7, 0, 0, 6, 1], [7, 0, 0, 7, 5], [7, 0, 0, 8, 0], [7, 1, 4, 0, 4], [7, 1, 4, 1, 8], [7, 1, 4, 2, 3], [7, 1, 4, 3, 7], [7, 1, 4, 4, 2], [7, 1, 4, 5, 6], [7, 1, 4, 6, 1], [7, 1, 4, 7, 5], [7, 1, 4, 8, 0], [7, 2, 8, 0, 4], [7, 2, 8, 1, 8], [7, 2, 8, 2, 3], [7, 2, 8, 3, 7], [7, 2, 8, 4, 2], [7, 2, 8, 5, 6], [7, 2, 8, 6, 1], [7, 2, 8, 7, 5], [7, 2, 8, 8, 0], [7, 3, 3, 0, 4], [7, 3, 3, 1, 8], [7, 3, 3, 2, 3], [7, 3, 3, 3, 7], [7, 3, 3, 4, 2], [7, 3, 3, 5, 6], [7, 3, 3, 6, 1], [7, 3, 3, 7, 5], [7, 3, 3, 8, 0], [7, 4, 7, 0, 4], [7, 4, 7, 1, 8], [7, 4, 7, 2, 3], [7, 4, 7, 3, 7], [7, 4, 7, 4, 2], [7, 4, 7, 5, 6], [7, 4, 7, 6, 1], [7, 4, 7, 7, 5], [7, 4, 7, 8, 0], [7, 5, 2, 0, 4], [7, 5, 2, 1, 8], [7, 5, 2, 2, 3], [7, 5, 2, 3, 7], [7, 5, 2, 4, 2], [7, 5, 2, 5, 6], [7, 5, 2, 6, 1], [7, 5, 2, 7, 5], [7, 5, 2, 8, 0], [7, 6, 6, 0, 4], [7, 6, 6, 1, 8], [7, 6, 6, 2, 3], [7, 6, 6, 3, 7], [7, 6, 6, 4, 2], [7, 6, 6, 5, 6], [7, 6, 6, 6, 1], [7, 6, 6, 7, 5], [7, 6, 6, 8, 0], [7, 7, 1, 0, 4], [7, 7, 1, 1, 8], [7, 7, 1, 2, 3], [7, 7, 1, 3, 7], [7, 7, 1, 4, 2], [7, 7, 1, 5, 6], [7, 7, 1, 6, 1], [7, 7, 1, 7, 5], [7, 7, 1, 8, 0], [7, 8, 5, 0, 4], [7, 8, 5, 1, 8], [7, 8, 5, 2, 3], [7, 8, 5, 3, 7], [7, 8, 5, 4, 2], [7, 8, 5, 5, 6], [7, 8, 5, 6, 1], [7, 8, 5, 7, 5], [7, 8, 5, 8, 0], [8, 0, 2, 0, 4], [8, 0, 2, 1, 8], [8, 0, 2, 2, 3], [8, 0, 2, 3, 7], [8, 0, 2, 4, 2], [8, 0, 2, 5, 6], [8, 0, 2, 6, 1], [8, 0, 2, 7, 5], [8, 0, 2, 8, 0], [8, 1, 6, 0, 4], [8, 1, 6, 1, 8], [8, 1, 6, 2, 3], [8, 1, 6, 3, 7], [8, 1, 6, 4, 2], [8, 1, 6, 5, 6], [8, 1, 6, 6, 1], [8, 1, 6, 7, 5], [8, 1, 6, 8, 0], [8, 2, 1, 0, 4], [8, 2, 1, 1, 8], [8, 2, 1, 2, 3], [8, 2, 1, 3, 7], [8, 2, 1, 4, 2], [8, 2, 1, 5, 6], [8, 2, 1, 6, 1], [8, 2, 1, 7, 5], [8, 2, 1, 8, 0], [8, 3, 5, 0, 4], [8, 3, 5, 1, 8], [8, 3, 5, 2, 3], [8, 3, 5, 3, 7], [8, 3, 5, 4, 2], [8, 3, 5, 5, 6], [8, 3, 5, 6, 1], [8, 3, 5, 7, 5], [8, 3, 5, 8, 0], [8, 4, 0, 0, 4], [8, 4, 0, 1, 8], [8, 4, 0, 2, 3], [8, 4, 0, 3, 7], [8, 4, 0, 4, 2], [8, 4, 0, 5, 6], [8, 4, 0, 6, 1], [8, 4, 0, 7, 5], [8, 4, 0, 8, 0], [8, 5, 4, 0, 4], [8, 5, 4, 1, 8], [8, 5, 4, 2, 3], [8, 5, 4, 3, 7], [8, 5, 4, 4, 2], [8, 5, 4, 5, 6], [8, 5, 4, 6, 1], [8, 5, 4, 7, 5], [8, 5, 4, 8, 0], [8, 6, 8, 0, 4], [8, 6, 8, 1, 8], [8, 6, 8, 2, 3], [8, 6, 8, 3, 7], [8, 6, 8, 4, 2], [8, 6, 8, 5, 6], [8, 6, 8, 6, 1], [8, 6, 8, 7, 5], [8, 6, 8, 8, 0], [8, 7, 3, 0, 4], [8, 7, 3, 1, 8], [8, 7, 3, 2, 3], [8, 7, 3, 3, 7], [8, 7, 3, 4, 2], [8, 7, 3, 5, 6], [8, 7, 3, 6, 1], [8, 7, 3, 7, 5], [8, 7, 3, 8, 0], [8, 8, 7, 0, 4], [8, 8, 7, 1, 8], [8, 8, 7, 2, 3], [8, 8, 7, 3, 7], [8, 8, 7, 4, 2], [8, 8, 7, 5, 6], [8, 8, 7, 6, 1], [8, 8, 7, 7, 5], [8, 8, 7, 8, 0], [0, 0, 3, 0, 2], [0, 0, 3, 1, 6], [0, 0, 3, 2, 1], [0, 0, 3, 3, 5], [0, 0, 3, 4, 0], [0, 0, 3, 5, 4], [0, 0, 3, 6, 8], [0, 0, 3, 7, 3], [0, 0, 3, 8, 7], [0, 1, 7, 0, 2], [0, 1, 7, 1, 6], [0, 1, 7, 2, 1], [0, 1, 7, 3, 5], [0, 1, 7, 4, 0], [0, 1, 7, 5, 4], [0, 1, 7, 6, 8], [0, 1, 7, 7, 3], [0, 1, 7, 8, 7], [0, 2, 2, 0, 2], [0, 2, 2, 1, 6], [0, 2, 2, 2, 1], [0, 2, 2, 3, 5], [0, 2, 2, 4, 0], [0, 2, 2, 5, 4], [0, 2, 2, 6, 8], [0, 2, 2, 7, 3], [0, 2, 2, 8, 7], [0, 3, 6, 0, 2], [0, 3, 6, 1, 6], [0, 3, 6, 2, 1], [0, 3, 6, 3, 5], [0, 3, 6, 4, 0], [0, 3, 6, 5, 4], [0, 3, 6, 6, 8], [0, 3, 6, 7, 3], [0, 3, 6, 8, 7], [0, 4, 1, 0, 2], [0, 4, 1, 1, 6], [0, 4, 1, 2, 1], [0, 4, 1, 3, 5], [0, 4, 1, 4, 0], [0, 4, 1, 5, 4], [0, 4, 1, 6, 8], [0, 4, 1, 7, 3], [0, 4, 1, 8, 7], [0, 5, 5, 0, 2], [0, 5, 5, 1, 6], [0, 5, 5, 2, 1], [0, 5, 5, 3, 5], [0, 5, 5, 4, 0], [0, 5, 5, 5, 4], [0, 5, 5, 6, 8], [0, 5, 5, 7, 3], [0, 5, 5, 8, 7], [0, 6, 0, 0, 2], [0, 6, 0, 1, 6], [0, 6, 0, 2, 1], [0, 6, 0, 3, 5], [0, 6, 0, 4, 0], [0, 6, 0, 5, 4], [0, 6, 0, 6, 8], [0, 6, 0, 7, 3], [0, 6, 0, 8, 7], [0, 7, 4, 0, 2], [0, 7, 4, 1, 6], [0, 7, 4, 2, 1], [0, 7, 4, 3, 5], [0, 7, 4, 4, 0], [0, 7, 4, 5, 4], [0, 7, 4, 6, 8], [0, 7, 4, 7, 3], [0, 7, 4, 8, 7], [0, 8, 8, 0, 2], [0, 8, 8, 1, 6], [0, 8, 8, 2, 1], [0, 8, 8, 3, 5], [0, 8, 8, 4, 0], [0, 8, 8, 5, 4], [0, 8, 8, 6, 8], [0, 8, 8, 7, 3], [0, 8, 8, 8, 7], [1, 0, 5, 0, 2], [1, 0, 5, 1, 6], [1, 0, 5, 2, 1], [1, 0, 5, 3, 5], [1, 0, 5, 4, 0], [1, 0, 5, 5, 4], [1, 0, 5, 6, 8], [1, 0, 5, 7, 3], [1, 0, 5, 8, 7], [1, 1, 0, 0, 2], [1, 1, 0, 1, 6], [1, 1, 0, 2, 1], [1, 1, 0, 3, 5], [1, 1, 0, 4, 0], [1, 1, 0, 5, 4], [1, 1, 0, 6, 8], [1, 1, 0, 7, 3], [1, 1, 0, 8, 7], [1, 2, 4, 0, 2], [1, 2, 4, 1, 6], [1, 2, 4, 2, 1], [1, 2, 4, 3, 5], [1, 2, 4, 4, 0], [1, 2, 4, 5, 4], [1, 2, 4, 6, 8], [1, 2, 4, 7, 3], [1, 2, 4, 8, 7], [1, 3, 8, 0, 2], [1, 3, 8, 1, 6], [1, 3, 8, 2, 1], [1, 3, 8, 3, 5], [1, 3, 8, 4, 0], [1, 3, 8, 5, 4], [1, 3, 8, 6, 8], [1, 3, 8, 7, 3], [1, 3, 8, 8, 7], [1, 4, 3, 0, 2], [1, 4, 3, 1, 6], [1, 4, 3, 2, 1], [1, 4, 3, 3, 5], [1, 4, 3, 4, 0], [1, 4, 3, 5, 4], [1, 4, 3, 6, 8], [1, 4, 3, 7, 3], [1, 4, 3, 8, 7], [1, 5, 7, 0, 2], [1, 5, 7, 1, 6], [1, 5, 7, 2, 1], [1, 5, 7, 3, 5], [1, 5, 7, 4, 0], [1, 5, 7, 5, 4], [1, 5, 7, 6, 8], [1, 5, 7, 7, 3], [1, 5, 7, 8, 7], [1, 6, 2, 0, 2], [1, 6, 2, 1, 6], [1, 6, 2, 2, 1], [1, 6, 2, 3, 5], [1, 6, 2, 4, 0], [1, 6, 2, 5, 4], [1, 6, 2, 6, 8], [1, 6, 2, 7, 3], [1, 6, 2, 8, 7], [1, 7, 6, 0, 2], [1, 7, 6, 1, 6], [1, 7, 6, 2, 1], [1, 7, 6, 3, 5], [1, 7, 6, 4, 0], [1, 7, 6, 5, 4], [1, 7, 6, 6, 8], [1, 7, 6, 7, 3], [1, 7, 6, 8, 7], [1, 8, 1, 0, 2], [1, 8, 1, 1, 6], [1, 8, 1, 2, 1], [1, 8, 1, 3, 5], [1, 8, 1, 4, 0], [1, 8, 1, 5, 4], [1, 8, 1, 6, 8], [1, 8, 1, 7, 3], [1, 8, 1, 8, 7], [2, 0, 7, 0, 2], [2, 0, 7, 1, 6], [2, 0, 7, 2, 1], [2, 0, 7, 3, 5], [2, 0, 7, 4, 0], [2, 0, 7, 5, 4], [2, 0, 7, 6, 8], [2, 0, 7, 7, 3], [2, 0, 7, 8, 7], [2, 1, 2, 0, 2], [2, 1, 2, 1, 6], [2, 1, 2, 2, 1], [2, 1, 2, 3, 5], [2, 1, 2, 4, 0], [2, 1, 2, 5, 4], [2, 1, 2, 6, 8], [2, 1, 2, 7, 3], [2, 1, 2, 8, 7], [2, 2, 6, 0, 2], [2, 2, 6, 1, 6], [2, 2, 6, 2, 1], [2, 2, 6, 3, 5], [2, 2, 6, 4, 0], [2, 2, 6, 5, 4], [2, 2, 6, 6, 8], [2, 2, 6, 7, 3], [2, 2, 6, 8, 7], [2, 3, 1, 0, 2], [2, 3, 1, 1, 6], [2, 3, 1, 2, 1], [2, 3, 1, 3, 5], [2, 3, 1, 4, 0], [2, 3, 1, 5, 4], [2, 3, 1, 6, 8], [2, 3, 1, 7, 3], [2, 3, 1, 8, 7], [2, 4, 5, 0, 2], [2, 4, 5, 1, 6], [2, 4, 5, 2, 1], [2, 4, 5, 3, 5], [2, 4, 5, 4, 0], [2, 4, 5, 5, 4], [2, 4, 5, 6, 8], [2, 4, 5, 7, 3], [2, 4, 5, 8, 7], [2, 5, 0, 0, 2], [2, 5, 0, 1, 6], [2, 5, 0, 2, 1], [2, 5, 0, 3, 5], [2, 5, 0, 4, 0], [2, 5, 0, 5, 4], [2, 5, 0, 6, 8], [2, 5, 0, 7, 3], [2, 5, 0, 8, 7], [2, 6, 4, 0, 2], [2, 6, 4, 1, 6], [2, 6, 4, 2, 1], [2, 6, 4, 3, 5], [2, 6, 4, 4, 0], [2, 6, 4, 5, 4], [2, 6, 4, 6, 8], [2, 6, 4, 7, 3], [2, 6, 4, 8, 7], [2, 7, 8, 0, 2], [2, 7, 8, 1, 6], [2, 7, 8, 2, 1], [2, 7, 8, 3, 5], [2, 7, 8, 4, 0], [2, 7, 8, 5, 4], [2, 7, 8, 6, 8], [2, 7, 8, 7, 3], [2, 7, 8, 8, 7], [2, 8, 3, 0, 2], [2, 8, 3, 1, 6], [2, 8, 3, 2, 1], [2, 8, 3, 3, 5], [2, 8, 3, 4, 0], [2, 8, 3, 5, 4], [2, 8, 3, 6, 8], [2, 8, 3, 7, 3], [2, 8, 3, 8, 7], [3, 0, 0, 0, 2], [3, 0, 0, 1, 6], [3, 0, 0, 2, 1], [3, 0, 0, 3, 5], [3, 0, 0, 4, 0], [3, 0, 0, 5, 4], [3, 0, 0, 6, 8], [3, 0, 0, 7, 3], [3, 0, 0, 8, 7], [3, 1, 4, 0, 2], [3, 1, 4, 1, 6], [3, 1, 4, 2, 1], [3, 1, 4, 3, 5], [3, 1, 4, 4, 0], [3, 1, 4, 5, 4], [3, 1, 4, 6, 8], [3, 1, 4, 7, 3], [3, 1, 4, 8, 7], [3, 2, 8, 0, 2], [3, 2, 8, 1, 6], [3, 2, 8, 2, 1], [3, 2, 8, 3, 5], [3, 2, 8, 4, 0], [3, 2, 8, 5, 4], [3, 2, 8, 6, 8], [3, 2, 8, 7, 3], [3, 2, 8, 8, 7], [3, 3, 3, 0, 2], [3, 3, 3, 1, 6], [3, 3, 3, 2, 1], [3, 3, 3, 3, 5], [3, 3, 3, 4, 0], [3, 3, 3, 5, 4], [3, 3, 3, 6, 8], [3, 3, 3, 7, 3], [3, 3, 3, 8, 7], [3, 4, 7, 0, 2], [3, 4, 7, 1, 6], [3, 4, 7, 2, 1], [3, 4, 7, 3, 5], [3, 4, 7, 4, 0], [3, 4, 7, 5, 4], [3, 4, 7, 6, 8], [3, 4, 7, 7, 3], [3, 4, 7, 8, 7], [3, 5, 2, 0, 2], [3, 5, 2, 1, 6], [3, 5, 2, 2, 1], [3, 5, 2, 3, 5], [3, 5, 2, 4, 0], [3, 5, 2, 5, 4], [3, 5, 2, 6, 8], [3, 5, 2, 7, 3], [3, 5, 2, 8, 7], [3, 6, 6, 0, 2], [3, 6, 6, 1, 6], [3, 6, 6, 2, 1], [3, 6, 6, 3, 5], [3, 6, 6, 4, 0], [3, 6, 6, 5, 4], [3, 6, 6, 6, 8], [3, 6, 6, 7, 3], [3, 6, 6, 8, 7], [3, 7, 1, 0, 2], [3, 7, 1, 1, 6], [3, 7, 1, 2, 1], [3, 7, 1, 3, 5], [3, 7, 1, 4, 0], [3, 7, 1, 5, 4], [3, 7, 1, 6, 8], [3, 7, 1, 7, 3], [3, 7, 1, 8, 7], [3, 8, 5, 0, 2], [3, 8, 5, 1, 6], [3, 8, 5, 2, 1], [3, 8, 5, 3, 5], [3, 8, 5, 4, 0], [3, 8, 5, 5, 4], [3, 8, 5, 6, 8], [3, 8, 5, 7, 3], [3, 8, 5, 8, 7], [4, 0, 2, 0, 2], [4, 0, 2, 1, 6], [4, 0, 2, 2, 1], [4, 0, 2, 3, 5], [4, 0, 2, 4, 0], [4, 0, 2, 5, 4], [4, 0, 2, 6, 8], [4, 0, 2, 7, 3], [4, 0, 2, 8, 7], [4, 1, 6, 0, 2], [4, 1, 6, 1, 6], [4, 1, 6, 2, 1], [4, 1, 6, 3, 5], [4, 1, 6, 4, 0], [4, 1, 6, 5, 4], [4, 1, 6, 6, 8], [4, 1, 6, 7, 3], [4, 1, 6, 8, 7], [4, 2, 1, 0, 2], [4, 2, 1, 1, 6], [4, 2, 1, 2, 1], [4, 2, 1, 3, 5], [4, 2, 1, 4, 0], [4, 2, 1, 5, 4], [4, 2, 1, 6, 8], [4, 2, 1, 7, 3], [4, 2, 1, 8, 7], [4, 3, 5, 0, 2], [4, 3, 5, 1, 6], [4, 3, 5, 2, 1], [4, 3, 5, 3, 5], [4, 3, 5, 4, 0], [4, 3, 5, 5, 4], [4, 3, 5, 6, 8], [4, 3, 5, 7, 3], [4, 3, 5, 8, 7], [4, 4, 0, 0, 2], [4, 4, 0, 1, 6], [4, 4, 0, 2, 1], [4, 4, 0, 3, 5], [4, 4, 0, 4, 0], [4, 4, 0, 5, 4], [4, 4, 0, 6, 8], [4, 4, 0, 7, 3], [4, 4, 0, 8, 7], [4, 5, 4, 0, 2], [4, 5, 4, 1, 6], [4, 5, 4, 2, 1], [4, 5, 4, 3, 5], [4, 5, 4, 4, 0], [4, 5, 4, 5, 4], [4, 5, 4, 6, 8], [4, 5, 4, 7, 3], [4, 5, 4, 8, 7], [4, 6, 8, 0, 2], [4, 6, 8, 1, 6], [4, 6, 8, 2, 1], [4, 6, 8, 3, 5], [4, 6, 8, 4, 0], [4, 6, 8, 5, 4], [4, 6, 8, 6, 8], [4, 6, 8, 7, 3], [4, 6, 8, 8, 7], [4, 7, 3, 0, 2], [4, 7, 3, 1, 6], [4, 7, 3, 2, 1], [4, 7, 3, 3, 5], [4, 7, 3, 4, 0], [4, 7, 3, 5, 4], [4, 7, 3, 6, 8], [4, 7, 3, 7, 3], [4, 7, 3, 8, 7], [4, 8, 7, 0, 2], [4, 8, 7, 1, 6], [4, 8, 7, 2, 1], [4, 8, 7, 3, 5], [4, 8, 7, 4, 0], [4, 8, 7, 5, 4], [4, 8, 7, 6, 8], [4, 8, 7, 7, 3], [4, 8, 7, 8, 7], [5, 0, 4, 0, 2], [5, 0, 4, 1, 6], [5, 0, 4, 2, 1], [5, 0, 4, 3, 5], [5, 0, 4, 4, 0], [5, 0, 4, 5, 4], [5, 0, 4, 6, 8], [5, 0, 4, 7, 3], [5, 0, 4, 8, 7], [5, 1, 8, 0, 2], [5, 1, 8, 1, 6], [5, 1, 8, 2, 1], [5, 1, 8, 3, 5], [5, 1, 8, 4, 0], [5, 1, 8, 5, 4], [5, 1, 8, 6, 8], [5, 1, 8, 7, 3], [5, 1, 8, 8, 7], [5, 2, 3, 0, 2], [5, 2, 3, 1, 6], [5, 2, 3, 2, 1], [5, 2, 3, 3, 5], [5, 2, 3, 4, 0], [5, 2, 3, 5, 4], [5, 2, 3, 6, 8], [5, 2, 3, 7, 3], [5, 2, 3, 8, 7], [5, 3, 7, 0, 2], [5, 3, 7, 1, 6], [5, 3, 7, 2, 1], [5, 3, 7, 3, 5], [5, 3, 7, 4, 0], [5, 3, 7, 5, 4], [5, 3, 7, 6, 8], [5, 3, 7, 7, 3], [5, 3, 7, 8, 7], [5, 4, 2, 0, 2], [5, 4, 2, 1, 6], [5, 4, 2, 2, 1], [5, 4, 2, 3, 5], [5, 4, 2, 4, 0], [5, 4, 2, 5, 4], [5, 4, 2, 6, 8], [5, 4, 2, 7, 3], [5, 4, 2, 8, 7], [5, 5, 6, 0, 2], [5, 5, 6, 1, 6], [5, 5, 6, 2, 1], [5, 5, 6, 3, 5], [5, 5, 6, 4, 0], [5, 5, 6, 5, 4], [5, 5, 6, 6, 8], [5, 5, 6, 7, 3], [5, 5, 6, 8, 7], [5, 6, 1, 0, 2], [5, 6, 1, 1, 6], [5, 6, 1, 2, 1], [5, 6, 1, 3, 5], [5, 6, 1, 4, 0], [5, 6, 1, 5, 4], [5, 6, 1, 6, 8], [5, 6, 1, 7, 3], [5, 6, 1, 8, 7], [5, 7, 5, 0, 2], [5, 7, 5, 1, 6], [5, 7, 5, 2, 1], [5, 7, 5, 3, 5], [5, 7, 5, 4, 0], [5, 7, 5, 5, 4], [5, 7, 5, 6, 8], [5, 7, 5, 7, 3], [5, 7, 5, 8, 7], [5, 8, 0, 0, 2], [5, 8, 0, 1, 6], [5, 8, 0, 2, 1], [5, 8, 0, 3, 5], [5, 8, 0, 4, 0], [5, 8, 0, 5, 4], [5, 8, 0, 6, 8], [5, 8, 0, 7, 3], [5, 8, 0, 8, 7], [6, 0, 6, 0, 2], [6, 0, 6, 1, 6], [6, 0, 6, 2, 1], [6, 0, 6, 3, 5], [6, 0, 6, 4, 0], [6, 0, 6, 5, 4], [6, 0, 6, 6, 8], [6, 0, 6, 7, 3], [6, 0, 6, 8, 7], [6, 1, 1, 0, 2], [6, 1, 1, 1, 6], [6, 1, 1, 2, 1], [6, 1, 1, 3, 5], [6, 1, 1, 4, 0], [6, 1, 1, 5, 4], [6, 1, 1, 6, 8], [6, 1, 1, 7, 3], [6, 1, 1, 8, 7], [6, 2, 5, 0, 2], [6, 2, 5, 1, 6], [6, 2, 5, 2, 1], [6, 2, 5, 3, 5], [6, 2, 5, 4, 0], [6, 2, 5, 5, 4], [6, 2, 5, 6, 8], [6, 2, 5, 7, 3], [6, 2, 5, 8, 7], [6, 3, 0, 0, 2], [6, 3, 0, 1, 6], [6, 3, 0, 2, 1], [6, 3, 0, 3, 5], [6, 3, 0, 4, 0], [6, 3, 0, 5, 4], [6, 3, 0, 6, 8], [6, 3, 0, 7, 3], [6, 3, 0, 8, 7], [6, 4, 4, 0, 2], [6, 4, 4, 1, 6], [6, 4, 4, 2, 1], [6, 4, 4, 3, 5], [6, 4, 4, 4, 0], [6, 4, 4, 5, 4], [6, 4, 4, 6, 8], [6, 4, 4, 7, 3], [6, 4, 4, 8, 7], [6, 5, 8, 0, 2], [6, 5, 8, 1, 6], [6, 5, 8, 2, 1], [6, 5, 8, 3, 5], [6, 5, 8, 4, 0], [6, 5, 8, 5, 4], [6, 5, 8, 6, 8], [6, 5, 8, 7, 3], [6, 5, 8, 8, 7], [6, 6, 3, 0, 2], [6, 6, 3, 1, 6], [6, 6, 3, 2, 1], [6, 6, 3, 3, 5], [6, 6, 3, 4, 0], [6, 6, 3, 5, 4], [6, 6, 3, 6, 8], [6, 6, 3, 7, 3], [6, 6, 3, 8, 7], [6, 7, 7, 0, 2], [6, 7, 7, 1, 6], [6, 7, 7, 2, 1], [6, 7, 7, 3, 5], [6, 7, 7, 4, 0], [6, 7, 7, 5, 4], [6, 7, 7, 6, 8], [6, 7, 7, 7, 3], [6, 7, 7, 8, 7], [6, 8, 2, 0, 2], [6, 8, 2, 1, 6], [6, 8, 2, 2, 1], [6, 8, 2, 3, 5], [6, 8, 2, 4, 0], [6, 8, 2, 5, 4], [6, 8, 2, 6, 8], [6, 8, 2, 7, 3], [6, 8, 2, 8, 7], [7, 0, 8, 0, 2], [7, 0, 8, 1, 6], [7, 0, 8, 2, 1], [7, 0, 8, 3, 5], [7, 0, 8, 4, 0], [7, 0, 8, 5, 4], [7, 0, 8, 6, 8], [7, 0, 8, 7, 3], [7, 0, 8, 8, 7], [7, 1, 3, 0, 2], [7, 1, 3, 1, 6], [7, 1, 3, 2, 1], [7, 1, 3, 3, 5], [7, 1, 3, 4, 0], [7, 1, 3, 5, 4], [7, 1, 3, 6, 8], [7, 1, 3, 7, 3], [7, 1, 3, 8, 7], [7, 2, 7, 0, 2], [7, 2, 7, 1, 6], [7, 2, 7, 2, 1], [7, 2, 7, 3, 5], [7, 2, 7, 4, 0], [7, 2, 7, 5, 4], [7, 2, 7, 6, 8], [7, 2, 7, 7, 3], [7, 2, 7, 8, 7], [7, 3, 2, 0, 2], [7, 3, 2, 1, 6], [7, 3, 2, 2, 1], [7, 3, 2, 3, 5], [7, 3, 2, 4, 0], [7, 3, 2, 5, 4], [7, 3, 2, 6, 8], [7, 3, 2, 7, 3], [7, 3, 2, 8, 7], [7, 4, 6, 0, 2], [7, 4, 6, 1, 6], [7, 4, 6, 2, 1], [7, 4, 6, 3, 5], [7, 4, 6, 4, 0], [7, 4, 6, 5, 4], [7, 4, 6, 6, 8], [7, 4, 6, 7, 3], [7, 4, 6, 8, 7], [7, 5, 1, 0, 2], [7, 5, 1, 1, 6], [7, 5, 1, 2, 1], [7, 5, 1, 3, 5], [7, 5, 1, 4, 0], [7, 5, 1, 5, 4], [7, 5, 1, 6, 8], [7, 5, 1, 7, 3], [7, 5, 1, 8, 7], [7, 6, 5, 0, 2], [7, 6, 5, 1, 6], [7, 6, 5, 2, 1], [7, 6, 5, 3, 5], [7, 6, 5, 4, 0], [7, 6, 5, 5, 4], [7, 6, 5, 6, 8], [7, 6, 5, 7, 3], [7, 6, 5, 8, 7], [7, 7, 0, 0, 2], [7, 7, 0, 1, 6], [7, 7, 0, 2, 1], [7, 7, 0, 3, 5], [7, 7, 0, 4, 0], [7, 7, 0, 5, 4], [7, 7, 0, 6, 8], [7, 7, 0, 7, 3], [7, 7, 0, 8, 7], [7, 8, 4, 0, 2], [7, 8, 4, 1, 6], [7, 8, 4, 2, 1], [7, 8, 4, 3, 5], [7, 8, 4, 4, 0], [7, 8, 4, 5, 4], [7, 8, 4, 6, 8], [7, 8, 4, 7, 3], [7, 8, 4, 8, 7], [8, 0, 1, 0, 2], [8, 0, 1, 1, 6], [8, 0, 1, 2, 1], [8, 0, 1, 3, 5], [8, 0, 1, 4, 0], [8, 0, 1, 5, 4], [8, 0, 1, 6, 8], [8, 0, 1, 7, 3], [8, 0, 1, 8, 7], [8, 1, 5, 0, 2], [8, 1, 5, 1, 6], [8, 1, 5, 2, 1], [8, 1, 5, 3, 5], [8, 1, 5, 4, 0], [8, 1, 5, 5, 4], [8, 1, 5, 6, 8], [8, 1, 5, 7, 3], [8, 1, 5, 8, 7], [8, 2, 0, 0, 2], [8, 2, 0, 1, 6], [8, 2, 0, 2, 1], [8, 2, 0, 3, 5], [8, 2, 0, 4, 0], [8, 2, 0, 5, 4], [8, 2, 0, 6, 8], [8, 2, 0, 7, 3], [8, 2, 0, 8, 7], [8, 3, 4, 0, 2], [8, 3, 4, 1, 6], [8, 3, 4, 2, 1], [8, 3, 4, 3, 5], [8, 3, 4, 4, 0], [8, 3, 4, 5, 4], [8, 3, 4, 6, 8], [8, 3, 4, 7, 3], [8, 3, 4, 8, 7], [8, 4, 8, 0, 2], [8, 4, 8, 1, 6], [8, 4, 8, 2, 1], [8, 4, 8, 3, 5], [8, 4, 8, 4, 0], [8, 4, 8, 5, 4], [8, 4, 8, 6, 8], [8, 4, 8, 7, 3], [8, 4, 8, 8, 7], [8, 5, 3, 0, 2], [8, 5, 3, 1, 6], [8, 5, 3, 2, 1], [8, 5, 3, 3, 5], [8, 5, 3, 4, 0], [8, 5, 3, 5, 4], [8, 5, 3, 6, 8], [8, 5, 3, 7, 3], [8, 5, 3, 8, 7], [8, 6, 7, 0, 2], [8, 6, 7, 1, 6], [8, 6, 7, 2, 1], [8, 6, 7, 3, 5], [8, 6, 7, 4, 0], [8, 6, 7, 5, 4], [8, 6, 7, 6, 8], [8, 6, 7, 7, 3], [8, 6, 7, 8, 7], [8, 7, 2, 0, 2], [8, 7, 2, 1, 6], [8, 7, 2, 2, 1], [8, 7, 2, 3, 5], [8, 7, 2, 4, 0], [8, 7, 2, 5, 4], [8, 7, 2, 6, 8], [8, 7, 2, 7, 3], [8, 7, 2, 8, 7], [8, 8, 6, 0, 2], [8, 8, 6, 1, 6], [8, 8, 6, 2, 1], [8, 8, 6, 3, 5], [8, 8, 6, 4, 0], [8, 8, 6, 5, 4], [8, 8, 6, 6, 8], [8, 8, 6, 7, 3], [8, 8, 6, 8, 7]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/tests/check.py b/tasks/optimize-fs-cycle-indep-c9-n5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..18467766f4b39df02d00aad7ae384bd83e857320 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/tests/check.py @@ -0,0 +1,38 @@ +"""Independent set in the strong product C_m^{⊠n}. Score = size. + +Two distinct vertices x, y of C_m^{⊠n} (n-tuples over Z_m) are adjacent iff x_i - y_i ∈ {-1, 0, 1} (mod m) +for every i. Check: mark the answer in a boolean table of size m^n and look up all 3^n - 1 neighbours of +every answer vertex (vectorised; 26244 vertices of C_9^7 take ~1 s). +""" +import itertools + +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + m, n = inst["m"], inst["n"] + vecs = ans.get("vertices") + # alpha(C_m^{⊠n}) <= (m/2)^n (fractional independence number is multiplicative under strong products), + # so longer lists are invalid; rejecting them early also bounds grading time + if not isinstance(vecs, list) or not vecs or 2 ** n * len(vecs) > m ** n: + raise Invalid(f"vertices must be a non-empty list of at most ({m}/2)^{n} tuples") + for v in vecs: + int_list(v, n, 0, m - 1, "vertex") + A = np.array(vecs, dtype=np.int64) + pw = m ** np.arange(n - 1, -1, -1, dtype=np.int64) + codes = A @ pw + if len(np.unique(codes)) != len(codes): + raise Invalid("duplicate vertices") + table = np.zeros(m ** n, bool) + table[codes] = True + for off in itertools.product((-1, 0, 1), repeat=n): + if not any(off): + continue + nb = ((A + np.array(off)) % m) @ pw + hit = table[nb] + if hit.any(): + k = int(np.nonzero(hit)[0][0]) + raise Invalid(f"vertices {vecs[k]} and {[(x + o) % m for x, o in zip(vecs[k], off)]} are adjacent") + return float(len(vecs)), {"size": len(vecs)} diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/tests/instance.json b/tasks/optimize-fs-cycle-indep-c9-n5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ca9c4e108a384f32a6d3e3883dc7a96dd5081b2 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/tests/instance.json @@ -0,0 +1 @@ +{"m": 9, "n": 5, "direction": "maximize", "best_known": 1458, "baseline": 1024, "family": "fs_cycle_independent_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/tests/run.py b/tasks/optimize-fs-cycle-indep-c9-n5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-fs-cycle-indep-c9-n5/tests/test.sh b/tasks/optimize-fs-cycle-indep-c9-n5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cycle-indep-c9-n5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt