diff --git a/tasks/construct-mc-bibd-l2-s1/environment/Dockerfile b/tasks/construct-mc-bibd-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-bibd-l2-s1/environment/instance.json b/tasks/construct-mc-bibd-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6493a3f75037ff5f5d77bee72c04168e94420d31 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 3, "lambda": 1, "b": 26, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s1/solution/solve.sh b/tasks/construct-mc-bibd-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6965db83eb0ddc81850fd5ce253055c33f18a0f8 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[0, 1, 4], [1, 2, 5], [2, 3, 6], [3, 4, 7], [4, 5, 8], [5, 6, 9], [6, 7, 10], [7, 8, 11], [8, 9, 12], [0, 9, 10], [1, 10, 11], [2, 11, 12], [0, 3, 12], [0, 2, 7], [1, 3, 8], [2, 4, 9], [3, 5, 10], [4, 6, 11], [5, 7, 12], [0, 6, 8], [1, 7, 9], [2, 8, 10], [3, 9, 11], [4, 10, 12], [0, 5, 11], [1, 6, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l2-s1/tests/check.py b/tasks/construct-mc-bibd-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-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-l2-s1/tests/instance.json b/tasks/construct-mc-bibd-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6493a3f75037ff5f5d77bee72c04168e94420d31 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 3, "lambda": 1, "b": 26, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l2-s1/tests/run.py b/tasks/construct-mc-bibd-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-bibd-l2-s1/tests/test.sh b/tasks/construct-mc-bibd-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-bibd-l5-s2/environment/Dockerfile b/tasks/construct-mc-bibd-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l5-s2/environment/instance.json b/tasks/construct-mc-bibd-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5c3706dbc9d450a5404d6cd426ce30a0eb87c2f --- /dev/null +++ b/tasks/construct-mc-bibd-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 3, "lambda": 4, "b": 104, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l5-s2/solution/solve.sh b/tasks/construct-mc-bibd-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..151694081bb881724e068d4ae0b7673f30cf5127 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[3, 4, 12], [3, 11, 12], [4, 6, 12], [4, 11, 12], [3, 4, 7], [4, 6, 11], [4, 7, 11], [4, 7, 12], [4, 6, 11], [4, 9, 10], [4, 9, 10], [4, 9, 10], [4, 9, 10], [1, 4, 8], [1, 4, 8], [1, 4, 5], [1, 4, 5], [4, 5, 8], [0, 3, 4], [3, 4, 8], [0, 3, 7], [3, 7, 12], [2, 5, 7], [0, 3, 11], [1, 3, 11], [1, 5, 6], [1, 6, 7], [1, 6, 7], [5, 6, 12], [1, 3, 10], [5, 7, 12], [1, 6, 7], [5, 7, 10], [7, 10, 11], [5, 7, 10], [7, 10, 11], [1, 7, 9], [7, 9, 12], [1, 3, 10], [1, 11, 12], [7, 9, 11], [1, 2, 12], [0, 7, 9], [4, 6, 7], [0, 7, 8], [0, 2, 7], [2, 7, 8], [2, 7, 8], [0, 6, 12], [3, 7, 8], [0, 6, 10], [6, 10, 11], [0, 3, 10], [0, 1, 12], [1, 10, 12], [6, 10, 11], [0, 1, 11], [0, 9, 12], [0, 1, 9], [0, 5, 12], [0, 1, 9], [2, 9, 11], [1, 2, 9], [1, 2, 10], [1, 8, 11], [1, 2, 8], [1, 3, 5], [2, 10, 12], [0, 5, 6], [6, 9, 12], [6, 8, 9], [0, 2, 4], [0, 8, 11], [0, 6, 8], [6, 8, 10], [3, 11, 12], [0, 8, 10], [0, 5, 11], [0, 5, 10], [3, 5, 9], [5, 6, 9], [3, 5, 9], [8, 10, 12], [8, 9, 12], [6, 8, 9], [5, 8, 12], [3, 5, 9], [2, 10, 12], [5, 8, 11], [2, 3, 6], [3, 8, 10], [5, 8, 11], [2, 3, 6], [2, 8, 12], [3, 8, 9], [2, 9, 11], [2, 9, 11], [0, 2, 4], [2, 3, 6], [2, 3, 6], [0, 2, 4], [2, 5, 11], [2, 4, 5], [2, 5, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l5-s2/tests/check.py b/tasks/construct-mc-bibd-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l5-s2/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-l5-s2/tests/instance.json b/tasks/construct-mc-bibd-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5c3706dbc9d450a5404d6cd426ce30a0eb87c2f --- /dev/null +++ b/tasks/construct-mc-bibd-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 3, "lambda": 4, "b": 104, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l5-s2/tests/run.py b/tasks/construct-mc-bibd-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l5-s2/tests/test.sh b/tasks/construct-mc-bibd-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-golomb-l4-s0/environment/Dockerfile b/tasks/construct-mc-golomb-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l4-s0/environment/instance.json b/tasks/construct-mc-golomb-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..30f04d134f9268ebaab1995334f765114f1a2ece --- /dev/null +++ b/tasks/construct-mc-golomb-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "max_length": 106, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l4-s0/solution/solve.sh b/tasks/construct-mc-golomb-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8eb7bf77146a43ff41b8f176bb45e5c88f1d59af --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 2, 5, 25, 37, 43, 59, 70, 85, 89, 98, 99, 106]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l4-s0/tests/check.py b/tasks/construct-mc-golomb-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l4-s0/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-s0/tests/instance.json b/tasks/construct-mc-golomb-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..30f04d134f9268ebaab1995334f765114f1a2ece --- /dev/null +++ b/tasks/construct-mc-golomb-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "max_length": 106, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l4-s0/tests/run.py b/tasks/construct-mc-golomb-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l4-s0/tests/test.sh b/tasks/construct-mc-golomb-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-graph-k-coloring-l1-s0/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l1-s0/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fe60c8abeb2755395bd01ba028c8bff02be9937e --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "edges": [[0, 2], [0, 8], [0, 12], [0, 13], [0, 16], [0, 17], [1, 11], [2, 4], [2, 13], [3, 5], [3, 9], [3, 15], [3, 16], [4, 13], [4, 16], [4, 17], [5, 14], [5, 15], [7, 16], [9, 14], [9, 19], [10, 13], [10, 17], [11, 16], [13, 17], [13, 19], [14, 18], [14, 19], [15, 17], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l1-s0/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c5d2c38a336e584597cbb020d813dc8939a29a43 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 0, 0, 1, 1, 0, 2, 1, 2, 2, 1, 1, 2, 2, 1, 2, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l1-s0/tests/check.py b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l1-s0/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fe60c8abeb2755395bd01ba028c8bff02be9937e --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "edges": [[0, 2], [0, 8], [0, 12], [0, 13], [0, 16], [0, 17], [1, 11], [2, 4], [2, 13], [3, 5], [3, 9], [3, 15], [3, 16], [4, 13], [4, 16], [4, 17], [5, 14], [5, 15], [7, 16], [9, 14], [9, 19], [10, 13], [10, 17], [11, 16], [13, 17], [13, 19], [14, 18], [14, 19], [15, 17], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l1-s0/tests/run.py b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l1-s0/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l1-s7/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l1-s7/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..651da86b28ae364354b42c65134f8e94113e3048 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "edges": [[0, 5], [0, 12], [0, 14], [0, 15], [1, 5], [1, 7], [1, 14], [1, 16], [1, 17], [1, 19], [2, 10], [2, 18], [3, 8], [3, 13], [4, 16], [6, 11], [6, 17], [7, 11], [7, 18], [9, 11], [9, 19], [11, 13], [11, 14], [11, 17], [11, 19], [12, 13], [12, 16], [13, 15], [14, 15], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l1-s7/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f82c05d7d083831f30fdb09affcc42397379f5b2 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 0, 0, 2, 0, 1, 0, 1, 1, 1, 2, 2, 1, 0, 2, 1, 0, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l1-s7/tests/check.py b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/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-l1-s7/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..651da86b28ae364354b42c65134f8e94113e3048 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "edges": [[0, 5], [0, 12], [0, 14], [0, 15], [1, 5], [1, 7], [1, 14], [1, 16], [1, 17], [1, 19], [2, 10], [2, 18], [3, 8], [3, 13], [4, 16], [6, 11], [6, 17], [7, 11], [7, 18], [9, 11], [9, 19], [11, 13], [11, 14], [11, 17], [11, 19], [12, 13], [12, 16], [13, 15], [14, 15], [15, 19]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l1-s7/tests/run.py b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l1-s7/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l1-s9/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l1-s9/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99c511fc17fa6d476276b028bd3c4bd091f9e09a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "edges": [[1, 7], [1, 8], [2, 5], [2, 7], [2, 8], [3, 6], [3, 15], [3, 16], [4, 5], [4, 7], [4, 11], [5, 7], [6, 9], [6, 14], [6, 19], [7, 9], [7, 10], [9, 11], [10, 14], [11, 15], [12, 14], [12, 15], [13, 14], [13, 17], [13, 18], [15, 17], [15, 18], [16, 18], [16, 19], [17, 19]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l1-s9/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb3fede792f5d342b8914b234ada174ab81ec696 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 1, 1, 0, 1, 0, 1, 2, 2, 0, 1, 2, 2, 1, 0, 1, 2, 2, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l1-s9/tests/check.py b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/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-l1-s9/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99c511fc17fa6d476276b028bd3c4bd091f9e09a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "k": 3, "edges": [[1, 7], [1, 8], [2, 5], [2, 7], [2, 8], [3, 6], [3, 15], [3, 16], [4, 5], [4, 7], [4, 11], [5, 7], [6, 9], [6, 14], [6, 19], [7, 9], [7, 10], [9, 11], [10, 14], [11, 15], [12, 14], [12, 15], [13, 14], [13, 17], [13, 18], [15, 17], [15, 18], [16, 18], [16, 19], [17, 19]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l1-s9/tests/run.py b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l1-s9/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6f86e57b059004d74643e558d2a58b3f758e9c2 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 100, "k": 4, "edges": [[0, 1], [0, 10], [0, 17], [0, 23], [0, 44], [0, 48], [0, 51], [0, 68], [0, 85], [1, 17], [1, 37], [1, 80], [1, 83], [1, 92], [2, 7], [2, 10], [2, 13], [2, 63], [2, 64], [2, 92], [3, 25], [3, 27], [3, 42], [3, 53], [3, 92], [3, 94], [4, 8], [4, 19], [4, 25], [4, 26], [4, 48], [4, 54], [4, 63], [4, 73], [4, 74], [4, 77], [4, 94], [5, 6], [5, 9], [5, 43], [5, 44], [5, 77], [5, 85], [6, 23], [6, 28], [6, 30], [6, 40], [6, 42], [6, 47], [6, 54], [6, 64], [6, 69], [6, 81], [6, 82], [6, 93], [7, 24], [7, 25], [7, 48], [7, 49], [7, 83], [7, 99], [8, 19], [8, 60], [8, 61], [8, 73], [8, 89], [8, 94], [9, 36], [9, 43], [9, 73], [9, 74], [9, 81], [9, 82], [10, 17], [10, 30], [10, 60], [10, 63], [10, 70], [10, 76], [11, 54], [11, 56], [11, 73], [11, 92], [11, 93], [12, 26], [12, 31], [12, 43], [12, 57], [12, 60], [12, 64], [12, 68], [12, 73], [12, 78], [12, 88], [13, 16], [13, 23], [13, 47], [13, 51], [13, 58], [13, 65], [13, 76], [13, 83], [13, 93], [13, 99], [14, 32], [14, 34], [14, 42], [14, 56], [14, 84], [14, 95], [15, 43], [15, 59], [15, 66], [16, 22], [16, 49], [16, 55], [16, 84], [16, 87], [16, 89], [16, 93], [16, 97], [17, 40], [17, 41], [17, 45], [17, 49], [17, 73], [17, 90], [18, 30], [18, 32], [18, 67], [18, 70], [18, 76], [18, 94], [20, 21], [20, 22], [20, 33], [20, 35], [20, 81], [20, 93], [20, 98], [21, 52], [21, 54], [21, 59], [21, 66], [21, 77], [21, 82], [22, 61], [22, 65], [22, 80], [22, 82], [23, 27], [23, 40], [23, 53], [23, 84], [23, 93], [24, 36], [24, 59], [24, 70], [24, 97], [25, 32], [25, 41], [25, 52], [25, 79], [25, 94], [26, 52], [26, 67], [26, 80], [26, 85], [27, 32], [27, 66], [28, 29], [28, 52], [28, 57], [28, 97], [28, 99], [29, 38], [29, 74], [29, 77], [29, 87], [29, 90], [30, 36], [30, 37], [30, 43], [30, 44], [30, 57], [30, 62], [30, 77], [30, 85], [31, 32], [31, 44], [31, 58], [31, 64], [31, 81], [31, 84], [31, 94], [32, 46], [32, 51], [32, 62], [32, 63], [33, 55], [33, 61], [33, 65], [33, 81], [33, 86], [34, 49], [34, 55], [34, 61], [34, 68], [34, 73], [34, 87], [34, 91], [34, 92], [35, 52], [35, 62], [35, 92], [35, 97], [36, 52], [36, 55], [36, 62], [36, 66], [36, 87], [36, 94], [36, 96], [36, 97], [37, 38], [37, 42], [37, 52], [37, 58], [37, 64], [37, 73], [37, 74], [37, 77], [37, 84], [37, 85], [38, 39], [38, 54], [38, 83], [38, 86], [38, 89], [38, 98], [39, 60], [39, 67], [39, 85], [40, 42], [40, 56], [40, 70], [40, 82], [40, 83], [40, 95], [41, 45], [41, 53], [41, 63], [41, 74], [41, 77], [41, 92], [42, 59], [42, 66], [42, 72], [42, 74], [42, 81], [42, 89], [42, 96], [42, 98], [43, 46], [43, 47], [43, 50], [43, 61], [43, 66], [43, 67], [43, 82], [43, 84], [44, 59], [44, 90], [44, 91], [45, 71], [45, 86], [46, 56], [47, 53], [47, 55], [47, 91], [47, 92], [48, 62], [48, 80], [48, 85], [48, 87], [49, 69], [49, 71], [49, 81], [49, 83], [49, 93], [49, 95], [50, 60], [50, 63], [50, 88], [51, 53], [51, 56], [51, 66], [51, 82], [51, 85], [51, 88], [52, 71], [53, 60], [53, 71], [53, 81], [53, 87], [53, 99], [54, 64], [54, 70], [54, 71], [54, 73], [54, 83], [54, 89], [54, 90], [54, 95], [54, 96], [55, 59], [55, 66], [55, 71], [55, 76], [55, 81], [55, 90], [55, 93], [56, 68], [56, 85], [56, 91], [57, 61], [57, 94], [58, 68], [58, 74], [58, 75], [58, 76], [58, 77], [59, 60], [60, 66], [60, 84], [60, 85], [60, 98], [61, 64], [61, 74], [62, 64], [62, 68], [62, 71], [62, 73], [62, 80], [62, 84], [62, 97], [63, 69], [63, 77], [63, 83], [63, 97], [64, 92], [64, 97], [66, 73], [66, 77], [67, 70], [67, 90], [68, 70], [68, 77], [68, 86], [68, 99], [69, 97], [70, 85], [71, 86], [71, 97], [71, 98], [72, 74], [73, 87], [73, 89], [73, 92], [73, 93], [73, 94], [74, 83], [74, 92], [75, 84], [75, 88], [75, 90], [75, 91], [75, 96], [76, 86], [76, 87], [76, 92], [76, 97], [77, 98], [78, 82], [78, 84], [79, 86], [79, 88], [80, 97], [81, 98], [82, 88], [83, 96], [84, 96], [85, 90], [86, 92], [87, 95], [89, 94], [92, 93], [93, 95], [93, 97], [95, 99]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..98eb7718c6c207ac7b9c570262ca0b1b1e367a65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 2, 0, 2, 0, 2, 3, 2, 3, 1, 1, 3, 0, 3, 2, 1, 2, 3, 3, 2, 1, 2, 3, 1, 1, 3, 2, 3, 2, 3, 0, 3, 0, 3, 3, 2, 2, 3, 2, 0, 2, 0, 1, 3, 1, 1, 1, 0, 3, 1, 1, 2, 0, 3, 1, 1, 0, 3, 0, 3, 2, 1, 1, 2, 2, 1, 0, 1, 2, 0, 0, 2, 3, 2, 2, 1, 2, 1, 1, 1, 0, 2, 0, 0, 0, 1, 0, 0, 3, 0, 0, 2, 1, 0, 1, 3, 3, 3, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/tests/check.py b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6f86e57b059004d74643e558d2a58b3f758e9c2 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 100, "k": 4, "edges": [[0, 1], [0, 10], [0, 17], [0, 23], [0, 44], [0, 48], [0, 51], [0, 68], [0, 85], [1, 17], [1, 37], [1, 80], [1, 83], [1, 92], [2, 7], [2, 10], [2, 13], [2, 63], [2, 64], [2, 92], [3, 25], [3, 27], [3, 42], [3, 53], [3, 92], [3, 94], [4, 8], [4, 19], [4, 25], [4, 26], [4, 48], [4, 54], [4, 63], [4, 73], [4, 74], [4, 77], [4, 94], [5, 6], [5, 9], [5, 43], [5, 44], [5, 77], [5, 85], [6, 23], [6, 28], [6, 30], [6, 40], [6, 42], [6, 47], [6, 54], [6, 64], [6, 69], [6, 81], [6, 82], [6, 93], [7, 24], [7, 25], [7, 48], [7, 49], [7, 83], [7, 99], [8, 19], [8, 60], [8, 61], [8, 73], [8, 89], [8, 94], [9, 36], [9, 43], [9, 73], [9, 74], [9, 81], [9, 82], [10, 17], [10, 30], [10, 60], [10, 63], [10, 70], [10, 76], [11, 54], [11, 56], [11, 73], [11, 92], [11, 93], [12, 26], [12, 31], [12, 43], [12, 57], [12, 60], [12, 64], [12, 68], [12, 73], [12, 78], [12, 88], [13, 16], [13, 23], [13, 47], [13, 51], [13, 58], [13, 65], [13, 76], [13, 83], [13, 93], [13, 99], [14, 32], [14, 34], [14, 42], [14, 56], [14, 84], [14, 95], [15, 43], [15, 59], [15, 66], [16, 22], [16, 49], [16, 55], [16, 84], [16, 87], [16, 89], [16, 93], [16, 97], [17, 40], [17, 41], [17, 45], [17, 49], [17, 73], [17, 90], [18, 30], [18, 32], [18, 67], [18, 70], [18, 76], [18, 94], [20, 21], [20, 22], [20, 33], [20, 35], [20, 81], [20, 93], [20, 98], [21, 52], [21, 54], [21, 59], [21, 66], [21, 77], [21, 82], [22, 61], [22, 65], [22, 80], [22, 82], [23, 27], [23, 40], [23, 53], [23, 84], [23, 93], [24, 36], [24, 59], [24, 70], [24, 97], [25, 32], [25, 41], [25, 52], [25, 79], [25, 94], [26, 52], [26, 67], [26, 80], [26, 85], [27, 32], [27, 66], [28, 29], [28, 52], [28, 57], [28, 97], [28, 99], [29, 38], [29, 74], [29, 77], [29, 87], [29, 90], [30, 36], [30, 37], [30, 43], [30, 44], [30, 57], [30, 62], [30, 77], [30, 85], [31, 32], [31, 44], [31, 58], [31, 64], [31, 81], [31, 84], [31, 94], [32, 46], [32, 51], [32, 62], [32, 63], [33, 55], [33, 61], [33, 65], [33, 81], [33, 86], [34, 49], [34, 55], [34, 61], [34, 68], [34, 73], [34, 87], [34, 91], [34, 92], [35, 52], [35, 62], [35, 92], [35, 97], [36, 52], [36, 55], [36, 62], [36, 66], [36, 87], [36, 94], [36, 96], [36, 97], [37, 38], [37, 42], [37, 52], [37, 58], [37, 64], [37, 73], [37, 74], [37, 77], [37, 84], [37, 85], [38, 39], [38, 54], [38, 83], [38, 86], [38, 89], [38, 98], [39, 60], [39, 67], [39, 85], [40, 42], [40, 56], [40, 70], [40, 82], [40, 83], [40, 95], [41, 45], [41, 53], [41, 63], [41, 74], [41, 77], [41, 92], [42, 59], [42, 66], [42, 72], [42, 74], [42, 81], [42, 89], [42, 96], [42, 98], [43, 46], [43, 47], [43, 50], [43, 61], [43, 66], [43, 67], [43, 82], [43, 84], [44, 59], [44, 90], [44, 91], [45, 71], [45, 86], [46, 56], [47, 53], [47, 55], [47, 91], [47, 92], [48, 62], [48, 80], [48, 85], [48, 87], [49, 69], [49, 71], [49, 81], [49, 83], [49, 93], [49, 95], [50, 60], [50, 63], [50, 88], [51, 53], [51, 56], [51, 66], [51, 82], [51, 85], [51, 88], [52, 71], [53, 60], [53, 71], [53, 81], [53, 87], [53, 99], [54, 64], [54, 70], [54, 71], [54, 73], [54, 83], [54, 89], [54, 90], [54, 95], [54, 96], [55, 59], [55, 66], [55, 71], [55, 76], [55, 81], [55, 90], [55, 93], [56, 68], [56, 85], [56, 91], [57, 61], [57, 94], [58, 68], [58, 74], [58, 75], [58, 76], [58, 77], [59, 60], [60, 66], [60, 84], [60, 85], [60, 98], [61, 64], [61, 74], [62, 64], [62, 68], [62, 71], [62, 73], [62, 80], [62, 84], [62, 97], [63, 69], [63, 77], [63, 83], [63, 97], [64, 92], [64, 97], [66, 73], [66, 77], [67, 70], [67, 90], [68, 70], [68, 77], [68, 86], [68, 99], [69, 97], [70, 85], [71, 86], [71, 97], [71, 98], [72, 74], [73, 87], [73, 89], [73, 92], [73, 93], [73, 94], [74, 83], [74, 92], [75, 84], [75, 88], [75, 90], [75, 91], [75, 96], [76, 86], [76, 87], [76, 92], [76, 97], [77, 98], [78, 82], [78, 84], [79, 86], [79, 88], [80, 97], [81, 98], [82, 88], [83, 96], [84, 96], [85, 90], [86, 92], [87, 95], [89, 94], [92, 93], [93, 95], [93, 97], [95, 99]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/tests/run.py b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l5-s1/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l5-s6/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l5-s6/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e97c87d33c180481dff45469d7adf5829bdf1bb --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 100, "k": 4, "edges": [[0, 9], [0, 17], [0, 36], [0, 37], [0, 39], [0, 47], [0, 59], [0, 68], [0, 69], [0, 73], [0, 78], [0, 80], [0, 90], [0, 96], [1, 6], [1, 13], [1, 27], [1, 38], [1, 41], [1, 52], [1, 79], [1, 91], [2, 45], [2, 63], [2, 92], [2, 98], [3, 11], [3, 15], [3, 17], [3, 18], [3, 24], [3, 52], [3, 62], [3, 63], [3, 77], [4, 10], [4, 12], [4, 14], [4, 49], [4, 56], [4, 61], [4, 77], [4, 83], [5, 35], [5, 41], [5, 50], [5, 67], [5, 68], [5, 74], [5, 85], [6, 9], [6, 15], [6, 57], [6, 66], [6, 71], [6, 80], [7, 9], [7, 16], [7, 17], [7, 28], [7, 51], [7, 55], [7, 60], [7, 68], [7, 73], [7, 74], [7, 93], [8, 9], [8, 12], [8, 29], [8, 31], [8, 42], [8, 59], [8, 73], [8, 74], [8, 77], [8, 85], [8, 96], [8, 97], [9, 18], [9, 26], [9, 27], [9, 36], [9, 41], [9, 60], [10, 18], [10, 28], [10, 37], [10, 41], [10, 44], [10, 53], [10, 65], [10, 71], [10, 82], [10, 91], [11, 23], [11, 44], [11, 56], [11, 98], [12, 29], [12, 34], [12, 38], [12, 42], [12, 61], [12, 74], [12, 79], [12, 86], [13, 37], [13, 49], [13, 52], [13, 56], [13, 67], [14, 23], [14, 27], [14, 31], [14, 34], [14, 60], [14, 61], [15, 27], [15, 31], [15, 42], [15, 43], [15, 72], [15, 84], [16, 29], [16, 44], [16, 46], [16, 54], [16, 61], [16, 65], [16, 69], [16, 74], [16, 86], [16, 97], [17, 21], [17, 56], [17, 64], [17, 79], [17, 90], [18, 41], [18, 50], [18, 60], [18, 83], [18, 91], [19, 43], [19, 46], [19, 53], [19, 78], [19, 79], [19, 80], [19, 89], [19, 90], [19, 96], [19, 99], [20, 44], [20, 57], [20, 73], [20, 90], [20, 98], [21, 32], [21, 48], [21, 58], [21, 77], [21, 93], [22, 24], [22, 37], [22, 38], [22, 54], [22, 55], [22, 56], [22, 67], [22, 73], [22, 80], [22, 83], [23, 74], [23, 79], [24, 35], [24, 38], [24, 40], [24, 56], [24, 63], [24, 66], [24, 74], [24, 80], [24, 87], [25, 37], [25, 40], [25, 41], [25, 47], [25, 60], [26, 40], [26, 47], [26, 62], [26, 68], [26, 79], [26, 85], [27, 31], [27, 58], [27, 59], [27, 70], [27, 81], [27, 94], [27, 99], [28, 57], [28, 62], [28, 75], [28, 84], [29, 68], [29, 86], [30, 61], [30, 65], [31, 69], [31, 72], [31, 74], [31, 75], [31, 81], [32, 38], [32, 42], [32, 53], [32, 62], [32, 76], [32, 81], [32, 99], [33, 36], [33, 38], [33, 39], [33, 60], [33, 74], [33, 88], [33, 97], [34, 55], [34, 59], [34, 62], [34, 76], [35, 55], [35, 64], [35, 90], [36, 55], [36, 64], [36, 66], [36, 93], [37, 39], [37, 53], [37, 78], [37, 86], [37, 97], [38, 45], [38, 53], [38, 91], [39, 40], [39, 54], [39, 55], [39, 59], [39, 62], [39, 68], [39, 70], [39, 79], [39, 84], [39, 96], [40, 63], [40, 70], [40, 76], [40, 93], [41, 43], [41, 45], [41, 50], [41, 67], [41, 70], [41, 96], [41, 97], [42, 54], [42, 68], [42, 73], [42, 91], [42, 93], [43, 55], [43, 58], [43, 64], [43, 67], [43, 83], [43, 91], [43, 92], [44, 51], [44, 55], [44, 56], [44, 75], [44, 78], [45, 47], [45, 52], [45, 76], [45, 88], [46, 54], [46, 56], [46, 80], [46, 95], [46, 98], [47, 77], [47, 91], [47, 99], [48, 49], [48, 60], [48, 96], [49, 54], [49, 64], [49, 66], [49, 73], [49, 80], [50, 96], [51, 59], [51, 61], [51, 68], [51, 74], [51, 78], [51, 96], [52, 73], [52, 96], [53, 71], [53, 87], [53, 93], [54, 64], [54, 91], [55, 74], [56, 82], [57, 86], [58, 70], [58, 79], [59, 66], [59, 67], [59, 69], [59, 84], [59, 88], [59, 91], [60, 76], [60, 88], [60, 93], [60, 96], [60, 98], [61, 86], [61, 91], [62, 69], [62, 72], [62, 83], [62, 90], [62, 94], [63, 64], [63, 81], [63, 86], [63, 97], [64, 79], [64, 80], [64, 81], [64, 90], [65, 74], [65, 97], [66, 67], [66, 72], [66, 96], [67, 90], [67, 92], [68, 77], [68, 91], [68, 93], [69, 75], [69, 76], [69, 79], [69, 97], [70, 81], [70, 83], [70, 94], [71, 80], [71, 93], [71, 97], [72, 79], [72, 85], [72, 86], [72, 90], [73, 86], [74, 82], [74, 90], [74, 97], [75, 98], [76, 94], [76, 96], [77, 86], [77, 94], [77, 97], [77, 98], [78, 91], [81, 86], [82, 97], [83, 91], [84, 86], [84, 98], [85, 89], [85, 92], [87, 88], [88, 90], [88, 98], [90, 95], [92, 96]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l5-s6/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee6844837d2213c77028df4c5f8b03e139f5bd4d --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 3, 2, 1, 1, 2, 2, 1, 2, 3, 0, 0, 3, 1, 2, 3, 2, 0, 2, 1, 2, 3, 1, 3, 2, 3, 0, 0, 3, 0, 2, 1, 1, 1, 1, 0, 0, 2, 0, 0, 1, 1, 0, 2, 1, 3, 0, 2, 1, 2, 0, 2, 0, 3, 3, 3, 3, 0, 1, 3, 0, 0, 2, 0, 1, 1, 1, 0, 3, 0, 2, 1, 0, 3, 0, 2, 2, 0, 0, 2, 3, 3, 2, 0, 2, 3, 1, 1, 2, 2, 3, 1, 1, 2, 3, 1, 3, 3, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l5-s6/tests/check.py b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/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-l5-s6/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e97c87d33c180481dff45469d7adf5829bdf1bb --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 100, "k": 4, "edges": [[0, 9], [0, 17], [0, 36], [0, 37], [0, 39], [0, 47], [0, 59], [0, 68], [0, 69], [0, 73], [0, 78], [0, 80], [0, 90], [0, 96], [1, 6], [1, 13], [1, 27], [1, 38], [1, 41], [1, 52], [1, 79], [1, 91], [2, 45], [2, 63], [2, 92], [2, 98], [3, 11], [3, 15], [3, 17], [3, 18], [3, 24], [3, 52], [3, 62], [3, 63], [3, 77], [4, 10], [4, 12], [4, 14], [4, 49], [4, 56], [4, 61], [4, 77], [4, 83], [5, 35], [5, 41], [5, 50], [5, 67], [5, 68], [5, 74], [5, 85], [6, 9], [6, 15], [6, 57], [6, 66], [6, 71], [6, 80], [7, 9], [7, 16], [7, 17], [7, 28], [7, 51], [7, 55], [7, 60], [7, 68], [7, 73], [7, 74], [7, 93], [8, 9], [8, 12], [8, 29], [8, 31], [8, 42], [8, 59], [8, 73], [8, 74], [8, 77], [8, 85], [8, 96], [8, 97], [9, 18], [9, 26], [9, 27], [9, 36], [9, 41], [9, 60], [10, 18], [10, 28], [10, 37], [10, 41], [10, 44], [10, 53], [10, 65], [10, 71], [10, 82], [10, 91], [11, 23], [11, 44], [11, 56], [11, 98], [12, 29], [12, 34], [12, 38], [12, 42], [12, 61], [12, 74], [12, 79], [12, 86], [13, 37], [13, 49], [13, 52], [13, 56], [13, 67], [14, 23], [14, 27], [14, 31], [14, 34], [14, 60], [14, 61], [15, 27], [15, 31], [15, 42], [15, 43], [15, 72], [15, 84], [16, 29], [16, 44], [16, 46], [16, 54], [16, 61], [16, 65], [16, 69], [16, 74], [16, 86], [16, 97], [17, 21], [17, 56], [17, 64], [17, 79], [17, 90], [18, 41], [18, 50], [18, 60], [18, 83], [18, 91], [19, 43], [19, 46], [19, 53], [19, 78], [19, 79], [19, 80], [19, 89], [19, 90], [19, 96], [19, 99], [20, 44], [20, 57], [20, 73], [20, 90], [20, 98], [21, 32], [21, 48], [21, 58], [21, 77], [21, 93], [22, 24], [22, 37], [22, 38], [22, 54], [22, 55], [22, 56], [22, 67], [22, 73], [22, 80], [22, 83], [23, 74], [23, 79], [24, 35], [24, 38], [24, 40], [24, 56], [24, 63], [24, 66], [24, 74], [24, 80], [24, 87], [25, 37], [25, 40], [25, 41], [25, 47], [25, 60], [26, 40], [26, 47], [26, 62], [26, 68], [26, 79], [26, 85], [27, 31], [27, 58], [27, 59], [27, 70], [27, 81], [27, 94], [27, 99], [28, 57], [28, 62], [28, 75], [28, 84], [29, 68], [29, 86], [30, 61], [30, 65], [31, 69], [31, 72], [31, 74], [31, 75], [31, 81], [32, 38], [32, 42], [32, 53], [32, 62], [32, 76], [32, 81], [32, 99], [33, 36], [33, 38], [33, 39], [33, 60], [33, 74], [33, 88], [33, 97], [34, 55], [34, 59], [34, 62], [34, 76], [35, 55], [35, 64], [35, 90], [36, 55], [36, 64], [36, 66], [36, 93], [37, 39], [37, 53], [37, 78], [37, 86], [37, 97], [38, 45], [38, 53], [38, 91], [39, 40], [39, 54], [39, 55], [39, 59], [39, 62], [39, 68], [39, 70], [39, 79], [39, 84], [39, 96], [40, 63], [40, 70], [40, 76], [40, 93], [41, 43], [41, 45], [41, 50], [41, 67], [41, 70], [41, 96], [41, 97], [42, 54], [42, 68], [42, 73], [42, 91], [42, 93], [43, 55], [43, 58], [43, 64], [43, 67], [43, 83], [43, 91], [43, 92], [44, 51], [44, 55], [44, 56], [44, 75], [44, 78], [45, 47], [45, 52], [45, 76], [45, 88], [46, 54], [46, 56], [46, 80], [46, 95], [46, 98], [47, 77], [47, 91], [47, 99], [48, 49], [48, 60], [48, 96], [49, 54], [49, 64], [49, 66], [49, 73], [49, 80], [50, 96], [51, 59], [51, 61], [51, 68], [51, 74], [51, 78], [51, 96], [52, 73], [52, 96], [53, 71], [53, 87], [53, 93], [54, 64], [54, 91], [55, 74], [56, 82], [57, 86], [58, 70], [58, 79], [59, 66], [59, 67], [59, 69], [59, 84], [59, 88], [59, 91], [60, 76], [60, 88], [60, 93], [60, 96], [60, 98], [61, 86], [61, 91], [62, 69], [62, 72], [62, 83], [62, 90], [62, 94], [63, 64], [63, 81], [63, 86], [63, 97], [64, 79], [64, 80], [64, 81], [64, 90], [65, 74], [65, 97], [66, 67], [66, 72], [66, 96], [67, 90], [67, 92], [68, 77], [68, 91], [68, 93], [69, 75], [69, 76], [69, 79], [69, 97], [70, 81], [70, 83], [70, 94], [71, 80], [71, 93], [71, 97], [72, 79], [72, 85], [72, 86], [72, 90], [73, 86], [74, 82], [74, 90], [74, 97], [75, 98], [76, 94], [76, 96], [77, 86], [77, 94], [77, 97], [77, 98], [78, 91], [81, 86], [82, 97], [83, 91], [84, 86], [84, 98], [85, 89], [85, 92], [87, 88], [88, 90], [88, 98], [90, 95], [92, 96]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l5-s6/tests/run.py b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l5-s6/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l5-s8/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l5-s8/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1a988c902f05890b1b75a6bb1c18ed33ca74122 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 100, "k": 4, "edges": [[0, 1], [0, 2], [0, 7], [0, 26], [0, 29], [0, 40], [0, 49], [0, 84], [0, 87], [0, 91], [1, 15], [1, 55], [1, 69], [1, 72], [1, 79], [1, 81], [1, 86], [2, 4], [2, 31], [2, 39], [2, 43], [2, 86], [3, 25], [3, 29], [3, 45], [3, 48], [3, 56], [3, 57], [3, 63], [3, 70], [3, 71], [3, 75], [4, 24], [4, 29], [4, 42], [4, 46], [4, 47], [5, 38], [5, 39], [5, 65], [6, 18], [6, 29], [6, 42], [6, 44], [6, 45], [7, 24], [7, 31], [7, 36], [7, 41], [7, 80], [8, 11], [8, 13], [8, 36], [8, 43], [8, 55], [8, 58], [8, 79], [8, 88], [8, 93], [9, 19], [9, 22], [9, 37], [9, 60], [9, 79], [10, 36], [10, 42], [10, 44], [10, 48], [10, 56], [10, 65], [10, 87], [11, 13], [11, 19], [11, 25], [11, 38], [11, 54], [11, 59], [11, 62], [11, 67], [11, 69], [11, 79], [12, 23], [12, 27], [12, 35], [12, 64], [12, 74], [12, 86], [12, 89], [12, 91], [12, 95], [13, 14], [13, 20], [13, 25], [13, 31], [13, 36], [13, 38], [13, 53], [13, 69], [13, 73], [13, 83], [13, 93], [13, 95], [14, 37], [14, 53], [14, 58], [14, 85], [14, 88], [14, 89], [14, 92], [15, 28], [15, 47], [15, 65], [15, 74], [15, 83], [16, 39], [16, 64], [16, 72], [16, 90], [17, 24], [17, 46], [17, 58], [17, 59], [17, 76], [17, 77], [17, 93], [17, 97], [18, 25], [18, 33], [18, 34], [18, 50], [18, 61], [18, 70], [18, 78], [19, 26], [19, 27], [19, 31], [19, 55], [19, 70], [19, 72], [19, 82], [20, 44], [20, 48], [20, 55], [20, 73], [21, 53], [21, 56], [21, 95], [22, 26], [22, 51], [22, 57], [22, 66], [22, 78], [22, 80], [22, 96], [23, 27], [23, 66], [23, 90], [23, 91], [24, 54], [24, 99], [25, 27], [25, 41], [25, 42], [25, 48], [25, 55], [25, 68], [25, 88], [25, 96], [26, 64], [26, 73], [26, 87], [26, 91], [26, 99], [27, 43], [27, 45], [27, 59], [27, 83], [27, 95], [28, 36], [28, 42], [28, 65], [28, 83], [28, 92], [29, 38], [29, 49], [29, 51], [29, 57], [29, 69], [29, 75], [29, 80], [29, 83], [30, 77], [30, 90], [30, 91], [31, 35], [31, 52], [31, 54], [31, 58], [31, 61], [31, 77], [31, 99], [32, 52], [32, 66], [32, 70], [32, 74], [32, 78], [32, 86], [33, 42], [33, 43], [33, 47], [33, 48], [33, 63], [34, 50], [34, 60], [34, 87], [34, 88], [35, 66], [35, 84], [36, 41], [36, 42], [36, 48], [36, 49], [36, 55], [36, 56], [36, 59], [36, 65], [37, 54], [37, 83], [37, 86], [37, 90], [38, 45], [38, 50], [38, 52], [38, 78], [39, 40], [39, 46], [39, 50], [39, 53], [39, 56], [39, 65], [39, 66], [39, 84], [39, 95], [40, 43], [40, 46], [40, 51], [40, 58], [40, 60], [40, 61], [40, 71], [40, 72], [40, 75], [41, 44], [41, 53], [41, 54], [41, 68], [41, 69], [41, 72], [41, 98], [42, 69], [42, 72], [42, 96], [43, 52], [43, 63], [43, 79], [44, 57], [44, 71], [44, 76], [44, 82], [44, 91], [45, 49], [45, 63], [45, 94], [45, 99], [46, 68], [46, 70], [46, 72], [46, 87], [46, 90], [46, 93], [46, 94], [47, 63], [47, 65], [47, 73], [47, 74], [47, 80], [47, 81], [48, 49], [48, 69], [48, 86], [48, 92], [49, 71], [49, 88], [49, 92], [49, 94], [49, 98], [50, 73], [50, 78], [50, 79], [50, 81], [50, 89], [50, 97], [51, 52], [51, 78], [52, 53], [52, 67], [52, 72], [52, 90], [52, 97], [53, 59], [53, 60], [53, 76], [53, 80], [53, 82], [53, 85], [53, 93], [54, 64], [54, 65], [54, 76], [54, 80], [54, 88], [54, 96], [55, 56], [55, 65], [55, 74], [55, 81], [55, 86], [56, 71], [56, 90], [57, 64], [57, 65], [57, 74], [57, 76], [58, 69], [58, 70], [58, 77], [58, 81], [58, 99], [59, 63], [59, 68], [59, 86], [59, 98], [60, 71], [60, 81], [61, 65], [61, 75], [61, 82], [61, 90], [61, 93], [62, 79], [62, 92], [63, 71], [63, 77], [63, 82], [63, 92], [63, 93], [64, 73], [64, 74], [64, 81], [64, 83], [64, 95], [65, 97], [66, 71], [66, 72], [66, 73], [66, 94], [67, 72], [67, 78], [67, 90], [69, 85], [69, 88], [69, 97], [70, 84], [70, 86], [70, 94], [71, 72], [71, 82], [71, 91], [74, 85], [74, 97], [75, 88], [75, 93], [76, 94], [78, 92], [79, 82], [79, 94], [79, 98], [80, 87], [80, 99], [82, 99], [83, 96], [84, 89], [85, 86], [85, 90], [85, 96], [86, 87], [88, 91], [90, 98], [92, 97], [96, 97]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l5-s8/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..58696936cfa2ef7fb83286d1f72f8f565f77c497 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [2, 1, 1, 3, 0, 0, 0, 3, 0, 0, 0, 3, 1, 1, 0, 0, 1, 0, 3, 2, 0, 0, 2, 3, 1, 2, 1, 0, 3, 1, 3, 0, 3, 2, 2, 2, 2, 3, 2, 3, 1, 1, 1, 3, 3, 1, 2, 3, 1, 0, 0, 3, 1, 2, 2, 3, 1, 0, 3, 1, 3, 2, 0, 0, 3, 1, 1, 2, 3, 2, 1, 2, 3, 2, 2, 0, 1, 1, 1, 2, 0, 2, 1, 2, 0, 1, 0, 3, 1, 2, 0, 0, 2, 3, 3, 2, 0, 3, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l5-s8/tests/check.py b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/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-l5-s8/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1a988c902f05890b1b75a6bb1c18ed33ca74122 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 100, "k": 4, "edges": [[0, 1], [0, 2], [0, 7], [0, 26], [0, 29], [0, 40], [0, 49], [0, 84], [0, 87], [0, 91], [1, 15], [1, 55], [1, 69], [1, 72], [1, 79], [1, 81], [1, 86], [2, 4], [2, 31], [2, 39], [2, 43], [2, 86], [3, 25], [3, 29], [3, 45], [3, 48], [3, 56], [3, 57], [3, 63], [3, 70], [3, 71], [3, 75], [4, 24], [4, 29], [4, 42], [4, 46], [4, 47], [5, 38], [5, 39], [5, 65], [6, 18], [6, 29], [6, 42], [6, 44], [6, 45], [7, 24], [7, 31], [7, 36], [7, 41], [7, 80], [8, 11], [8, 13], [8, 36], [8, 43], [8, 55], [8, 58], [8, 79], [8, 88], [8, 93], [9, 19], [9, 22], [9, 37], [9, 60], [9, 79], [10, 36], [10, 42], [10, 44], [10, 48], [10, 56], [10, 65], [10, 87], [11, 13], [11, 19], [11, 25], [11, 38], [11, 54], [11, 59], [11, 62], [11, 67], [11, 69], [11, 79], [12, 23], [12, 27], [12, 35], [12, 64], [12, 74], [12, 86], [12, 89], [12, 91], [12, 95], [13, 14], [13, 20], [13, 25], [13, 31], [13, 36], [13, 38], [13, 53], [13, 69], [13, 73], [13, 83], [13, 93], [13, 95], [14, 37], [14, 53], [14, 58], [14, 85], [14, 88], [14, 89], [14, 92], [15, 28], [15, 47], [15, 65], [15, 74], [15, 83], [16, 39], [16, 64], [16, 72], [16, 90], [17, 24], [17, 46], [17, 58], [17, 59], [17, 76], [17, 77], [17, 93], [17, 97], [18, 25], [18, 33], [18, 34], [18, 50], [18, 61], [18, 70], [18, 78], [19, 26], [19, 27], [19, 31], [19, 55], [19, 70], [19, 72], [19, 82], [20, 44], [20, 48], [20, 55], [20, 73], [21, 53], [21, 56], [21, 95], [22, 26], [22, 51], [22, 57], [22, 66], [22, 78], [22, 80], [22, 96], [23, 27], [23, 66], [23, 90], [23, 91], [24, 54], [24, 99], [25, 27], [25, 41], [25, 42], [25, 48], [25, 55], [25, 68], [25, 88], [25, 96], [26, 64], [26, 73], [26, 87], [26, 91], [26, 99], [27, 43], [27, 45], [27, 59], [27, 83], [27, 95], [28, 36], [28, 42], [28, 65], [28, 83], [28, 92], [29, 38], [29, 49], [29, 51], [29, 57], [29, 69], [29, 75], [29, 80], [29, 83], [30, 77], [30, 90], [30, 91], [31, 35], [31, 52], [31, 54], [31, 58], [31, 61], [31, 77], [31, 99], [32, 52], [32, 66], [32, 70], [32, 74], [32, 78], [32, 86], [33, 42], [33, 43], [33, 47], [33, 48], [33, 63], [34, 50], [34, 60], [34, 87], [34, 88], [35, 66], [35, 84], [36, 41], [36, 42], [36, 48], [36, 49], [36, 55], [36, 56], [36, 59], [36, 65], [37, 54], [37, 83], [37, 86], [37, 90], [38, 45], [38, 50], [38, 52], [38, 78], [39, 40], [39, 46], [39, 50], [39, 53], [39, 56], [39, 65], [39, 66], [39, 84], [39, 95], [40, 43], [40, 46], [40, 51], [40, 58], [40, 60], [40, 61], [40, 71], [40, 72], [40, 75], [41, 44], [41, 53], [41, 54], [41, 68], [41, 69], [41, 72], [41, 98], [42, 69], [42, 72], [42, 96], [43, 52], [43, 63], [43, 79], [44, 57], [44, 71], [44, 76], [44, 82], [44, 91], [45, 49], [45, 63], [45, 94], [45, 99], [46, 68], [46, 70], [46, 72], [46, 87], [46, 90], [46, 93], [46, 94], [47, 63], [47, 65], [47, 73], [47, 74], [47, 80], [47, 81], [48, 49], [48, 69], [48, 86], [48, 92], [49, 71], [49, 88], [49, 92], [49, 94], [49, 98], [50, 73], [50, 78], [50, 79], [50, 81], [50, 89], [50, 97], [51, 52], [51, 78], [52, 53], [52, 67], [52, 72], [52, 90], [52, 97], [53, 59], [53, 60], [53, 76], [53, 80], [53, 82], [53, 85], [53, 93], [54, 64], [54, 65], [54, 76], [54, 80], [54, 88], [54, 96], [55, 56], [55, 65], [55, 74], [55, 81], [55, 86], [56, 71], [56, 90], [57, 64], [57, 65], [57, 74], [57, 76], [58, 69], [58, 70], [58, 77], [58, 81], [58, 99], [59, 63], [59, 68], [59, 86], [59, 98], [60, 71], [60, 81], [61, 65], [61, 75], [61, 82], [61, 90], [61, 93], [62, 79], [62, 92], [63, 71], [63, 77], [63, 82], [63, 92], [63, 93], [64, 73], [64, 74], [64, 81], [64, 83], [64, 95], [65, 97], [66, 71], [66, 72], [66, 73], [66, 94], [67, 72], [67, 78], [67, 90], [69, 85], [69, 88], [69, 97], [70, 84], [70, 86], [70, 94], [71, 72], [71, 82], [71, 91], [74, 85], [74, 97], [75, 88], [75, 93], [76, 94], [78, 92], [79, 82], [79, 94], [79, 98], [80, 87], [80, 99], [82, 99], [83, 96], [84, 89], [85, 86], [85, 90], [85, 96], [86, 87], [88, 91], [90, 98], [92, 97], [96, 97]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l5-s8/tests/run.py b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l5-s8/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l6-s4/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l6-s4/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..21e99b22ac53ac4330d82b14fbe2d5ef85d9684c --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 6], [0, 17], [0, 47], [0, 54], [0, 56], [0, 95], [0, 137], [0, 148], [0, 163], [0, 184], [0, 191], [0, 211], [0, 216], [1, 28], [1, 36], [1, 79], [1, 85], [1, 94], [1, 149], [1, 204], [1, 206], [1, 207], [1, 220], [1, 231], [2, 6], [2, 14], [2, 46], [2, 57], [2, 67], [2, 85], [2, 177], [3, 36], [3, 48], [3, 53], [3, 62], [3, 66], [3, 71], [3, 134], [3, 163], [3, 173], [3, 241], [3, 246], [4, 6], [4, 65], [4, 74], [4, 121], [4, 141], [4, 194], [5, 6], [5, 8], [5, 37], [5, 54], [5, 132], [5, 213], [6, 46], [6, 64], [6, 122], [6, 148], [6, 162], [6, 165], [6, 195], [7, 149], [7, 151], [7, 204], [7, 211], [7, 217], [7, 241], [8, 65], [8, 118], [8, 124], [8, 125], [8, 152], [8, 157], [8, 189], [8, 221], [9, 21], [9, 47], [9, 64], [9, 101], [9, 137], [9, 154], [9, 171], [9, 240], [9, 244], [10, 29], [10, 91], [10, 115], [10, 138], [10, 171], [10, 195], [10, 224], [10, 236], [10, 241], [11, 13], [11, 37], [11, 48], [11, 51], [11, 56], [11, 85], [11, 122], [11, 130], [11, 215], [12, 28], [12, 34], [12, 163], [12, 187], [12, 216], [12, 221], [12, 225], [13, 16], [13, 66], [13, 97], [13, 113], [13, 117], [13, 122], [13, 123], [13, 146], [13, 212], [13, 242], [14, 17], [14, 21], [14, 52], [14, 113], [14, 152], [14, 214], [14, 247], [15, 26], [15, 59], [15, 86], [15, 130], [15, 131], [15, 213], [16, 76], [16, 113], [16, 117], [16, 139], [16, 150], [16, 152], [16, 154], [16, 161], [16, 180], [16, 184], [16, 229], [17, 110], [17, 164], [17, 211], [17, 230], [18, 19], [18, 41], [18, 46], [18, 102], [18, 127], [18, 130], [18, 139], [18, 143], [18, 158], [18, 164], [18, 191], [18, 225], [18, 241], [19, 20], [19, 64], [19, 86], [19, 97], [19, 111], [19, 112], [19, 140], [19, 180], [19, 205], [19, 224], [19, 241], [20, 61], [20, 69], [20, 80], [20, 83], [20, 108], [20, 122], [20, 125], [20, 244], [21, 32], [21, 41], [21, 206], [21, 228], [22, 46], [22, 59], [22, 64], [22, 96], [22, 100], [22, 120], [22, 168], [23, 142], [23, 158], [23, 167], [23, 168], [23, 233], [23, 243], [24, 46], [24, 96], [24, 108], [24, 115], [24, 119], [24, 140], [24, 143], [24, 151], [24, 161], [25, 48], [25, 66], [25, 98], [25, 125], [25, 164], [25, 229], [26, 43], [26, 75], [26, 89], [26, 106], [26, 143], [26, 175], [26, 185], [26, 240], [27, 28], [27, 45], [27, 61], [27, 170], [27, 202], [27, 210], [27, 211], [27, 237], [27, 238], [28, 60], [28, 71], [28, 115], [28, 183], [28, 212], [28, 224], [29, 65], [29, 83], [29, 99], [29, 124], [29, 187], [29, 189], [29, 195], [29, 228], [30, 42], [30, 149], [30, 157], [30, 203], [31, 59], [31, 73], [31, 81], [31, 82], [31, 94], [31, 149], [31, 245], [32, 35], [32, 52], [32, 62], [32, 115], [32, 123], [32, 195], [33, 38], [33, 68], [33, 78], [33, 113], [33, 128], [33, 211], [34, 68], [34, 74], [34, 76], [34, 112], [34, 144], [34, 149], [34, 156], [34, 171], [35, 47], [35, 134], [35, 153], [35, 192], [35, 215], [35, 230], [35, 240], [35, 246], [35, 248], [36, 92], [36, 149], [36, 230], [36, 249], [37, 38], [37, 75], [37, 90], [37, 92], [37, 128], [37, 213], [37, 214], [37, 224], [37, 232], [37, 242], [38, 45], [38, 55], [38, 102], [38, 104], [38, 112], [38, 138], [38, 152], [38, 156], [38, 214], [38, 247], [39, 86], [39, 98], [39, 102], [39, 147], [39, 151], [39, 185], [39, 232], [39, 236], [39, 240], [40, 41], [40, 68], [40, 72], [40, 90], [40, 114], [40, 199], [40, 207], [40, 219], [41, 113], [41, 144], [41, 149], [41, 167], [41, 180], [41, 181], [41, 229], [42, 57], [42, 88], [42, 189], [43, 103], [43, 117], [43, 119], [43, 158], [43, 206], [43, 216], [44, 63], [44, 85], [44, 95], [44, 129], [44, 139], [44, 167], [44, 178], [44, 183], [44, 186], [44, 221], [44, 236], [44, 245], [45, 66], [45, 98], [45, 163], [45, 173], [45, 181], [45, 205], [45, 248], [46, 181], [46, 219], [47, 52], [47, 82], [47, 108], [47, 116], [47, 241], [47, 242], [48, 77], [48, 80], [48, 113], [48, 114], [48, 122], [48, 138], [48, 159], [48, 172], [48, 194], [48, 210], [49, 124], [49, 211], [50, 66], [50, 103], [50, 131], [50, 149], [50, 163], [51, 74], [51, 82], [51, 160], [51, 185], [51, 189], [52, 70], [52, 96], [52, 143], [52, 151], [52, 161], [52, 191], [52, 206], [52, 225], [52, 242], [53, 69], [53, 108], [53, 111], [53, 225], [53, 237], [53, 246], [54, 78], [54, 79], [54, 101], [54, 122], [54, 166], [54, 178], [54, 228], [55, 68], [55, 97], [55, 99], [55, 136], [55, 139], [55, 182], [55, 183], [55, 217], [55, 228], [55, 230], [56, 81], [56, 83], [56, 137], [56, 146], [56, 152], [56, 162], [57, 117], [57, 172], [57, 184], [57, 211], [57, 237], [58, 94], [58, 106], [58, 113], [58, 119], [58, 173], [58, 178], [58, 179], [58, 192], [58, 219], [59, 94], [59, 141], [59, 229], [60, 62], [60, 214], [60, 228], [60, 243], [61, 74], [61, 122], [61, 127], [61, 144], [61, 190], [61, 239], [62, 129], [62, 141], [62, 246], [63, 73], [63, 94], [63, 148], [63, 219], [63, 230], [64, 67], [64, 76], [64, 84], [64, 100], [64, 131], [64, 231], [65, 78], [65, 81], [65, 111], [65, 120], [65, 130], [65, 132], [65, 142], [65, 144], [65, 151], [65, 167], [66, 81], [66, 90], [66, 102], [66, 114], [66, 151], [66, 209], [66, 237], [66, 246], [67, 93], [67, 97], [67, 98], [67, 152], [67, 158], [67, 164], [67, 180], [67, 182], [67, 191], [67, 201], [67, 244], [68, 92], [68, 142], [68, 183], [68, 202], [69, 110], [69, 133], [69, 139], [69, 191], [69, 215], [70, 82], [70, 84], [70, 100], [70, 129], [70, 158], [70, 190], [70, 228], [71, 80], [71, 161], [71, 176], [71, 177], [71, 215], [71, 232], [72, 97], [72, 124], [72, 143], [72, 158], [72, 219], [72, 232], [73, 115], [73, 122], [73, 148], [73, 149], [73, 154], [73, 237], [74, 106], [74, 113], [74, 151], [74, 167], [74, 188], [74, 203], [74, 244], [75, 105], [75, 139], [75, 150], [75, 164], [75, 180], [75, 184], [75, 192], [75, 196], [75, 199], [75, 235], [76, 108], [76, 116], [76, 134], [76, 184], [76, 202], [76, 240], [76, 244], [76, 247], [77, 148], [77, 157], [77, 192], [77, 223], [77, 233], [77, 243], [77, 244], [78, 82], [78, 96], [78, 100], [78, 158], [78, 171], [78, 204], [79, 94], [79, 112], [79, 143], [79, 156], [79, 165], [79, 175], [80, 104], [80, 118], [80, 141], [80, 190], [81, 85], [81, 217], [81, 227], [82, 86], [82, 134], [82, 140], [82, 158], [82, 161], [82, 180], [82, 217], [83, 138], [83, 176], [83, 216], [83, 219], [83, 235], [84, 92], [84, 98], [84, 127], [84, 143], [84, 144], [84, 157], [84, 246], [85, 135], [85, 136], [85, 138], [85, 144], [85, 168], [85, 182], [85, 192], [85, 220], [86, 158], [86, 194], [86, 216], [86, 217], [86, 225], [86, 236], [87, 177], [87, 193], [87, 215], [88, 116], [88, 133], [88, 148], [88, 154], [88, 170], [88, 178], [88, 195], [88, 217], [89, 229], [90, 93], [90, 152], [90, 164], [90, 228], [90, 230], [90, 241], [91, 119], [91, 166], [91, 173], [91, 177], [91, 237], [91, 241], [91, 245], [92, 126], [92, 169], [92, 170], [92, 185], [92, 199], [92, 235], [93, 106], [93, 176], [93, 198], [93, 211], [94, 111], [94, 123], [94, 144], [94, 183], [94, 186], [94, 208], [94, 226], [94, 243], [95, 102], [95, 213], [95, 248], [96, 154], [96, 157], [96, 162], [96, 181], [96, 218], [97, 138], [97, 141], [98, 105], [98, 107], [98, 151], [98, 174], [98, 229], [98, 235], [99, 147], [99, 150], [99, 165], [99, 200], [99, 207], [99, 229], [99, 235], [100, 113], [100, 148], [100, 160], [100, 230], [100, 240], [101, 182], [102, 128], [102, 138], [102, 149], [102, 178], [102, 185], [102, 225], [102, 248], [103, 161], [103, 163], [103, 170], [103, 210], [104, 120], [104, 127], [104, 154], [104, 177], [104, 182], [104, 223], [104, 237], [105, 143], [105, 149], [105, 178], [105, 217], [105, 219], [106, 111], [106, 112], [106, 166], [106, 170], [106, 232], [106, 233], [106, 241], [106, 245], [107, 146], [107, 181], [107, 211], [107, 240], [108, 117], [108, 119], [108, 131], [108, 145], [108, 156], [108, 164], [108, 200], [108, 214], [108, 222], [108, 231], [109, 154], [109, 175], [110, 119], [110, 140], [111, 127], [111, 160], [112, 144], [112, 155], [112, 175], [112, 204], [112, 217], [112, 239], [112, 245], [113, 120], [113, 127], [113, 185], [113, 203], [113, 221], [114, 119], [114, 130], [114, 134], [114, 141], [114, 189], [114, 214], [114, 215], [114, 219], [114, 230], [114, 247], [115, 215], [115, 220], [116, 154], [116, 167], [116, 168], [116, 180], [116, 207], [116, 220], [117, 189], [117, 210], [117, 224], [117, 242], [117, 249], [118, 123], [118, 129], [118, 134], [118, 148], [118, 189], [119, 132], [119, 151], [119, 158], [119, 237], [120, 154], [120, 193], [120, 195], [121, 158], [121, 162], [121, 178], [121, 179], [121, 180], [121, 209], [121, 249], [122, 138], [122, 186], [122, 192], [122, 208], [123, 126], [123, 127], [123, 135], [123, 148], [123, 182], [123, 219], [123, 244], [124, 149], [124, 175], [124, 198], [124, 211], [124, 230], [125, 226], [125, 241], [126, 128], [126, 137], [126, 178], [126, 182], [126, 205], [127, 134], [127, 135], [127, 141], [127, 235], [128, 149], [128, 155], [128, 190], [128, 195], [128, 216], [128, 219], [128, 230], [129, 152], [129, 167], [129, 181], [129, 187], [129, 190], [129, 216], [129, 244], [130, 157], [130, 173], [130, 213], [130, 232], [130, 249], [131, 154], [131, 210], [131, 216], [131, 232], [131, 238], [131, 242], [132, 135], [132, 142], [132, 201], [132, 246], [133, 153], [133, 220], [133, 221], [133, 245], [133, 247], [134, 201], [135, 200], [135, 207], [135, 208], [135, 211], [135, 230], [136, 141], [136, 142], [136, 144], [136, 154], [136, 180], [136, 183], [136, 187], [136, 188], [137, 139], [137, 190], [137, 206], [137, 233], [138, 144], [138, 145], [138, 199], [139, 231], [140, 220], [140, 227], [140, 237], [141, 225], [142, 151], [142, 159], [142, 234], [142, 235], [143, 169], [143, 248], [144, 145], [144, 185], [144, 189], [144, 191], [144, 201], [144, 209], [144, 211], [145, 180], [145, 228], [146, 148], [146, 183], [146, 190], [146, 192], [146, 222], [146, 231], [146, 248], [147, 220], [147, 235], [148, 153], [148, 171], [148, 174], [148, 237], [149, 166], [149, 197], [150, 154], [150, 178], [150, 188], [150, 240], [151, 184], [151, 197], [151, 206], [151, 216], [152, 186], [152, 218], [152, 226], [152, 248], [153, 200], [153, 214], [153, 224], [154, 161], [154, 172], [154, 215], [155, 180], [155, 185], [155, 209], [155, 248], [156, 158], [156, 181], [156, 224], [156, 228], [156, 238], [156, 244], [157, 192], [158, 211], [158, 222], [158, 242], [159, 168], [159, 172], [160, 182], [160, 191], [160, 204], [160, 215], [161, 195], [161, 233], [163, 170], [163, 185], [164, 176], [164, 183], [165, 199], [165, 204], [165, 217], [165, 221], [165, 223], [166, 212], [167, 205], [167, 220], [168, 176], [168, 230], [168, 249], [169, 231], [170, 182], [170, 205], [170, 224], [171, 190], [171, 197], [171, 219], [171, 226], [171, 239], [172, 218], [172, 240], [173, 208], [173, 228], [173, 237], [174, 175], [174, 179], [174, 226], [175, 201], [175, 229], [175, 245], [176, 178], [178, 188], [178, 196], [178, 214], [178, 244], [179, 189], [180, 243], [181, 191], [181, 227], [182, 211], [183, 187], [183, 204], [183, 216], [184, 195], [184, 196], [184, 201], [184, 214], [184, 238], [185, 190], [185, 202], [185, 214], [185, 230], [185, 235], [186, 218], [187, 214], [187, 242], [187, 247], [188, 217], [189, 211], [189, 217], [189, 218], [189, 231], [189, 237], [190, 207], [190, 219], [190, 242], [191, 199], [191, 214], [192, 236], [192, 244], [193, 200], [193, 221], [193, 222], [193, 233], [195, 237], [196, 227], [196, 234], [197, 243], [198, 224], [199, 207], [199, 212], [199, 243], [200, 208], [200, 241], [201, 207], [201, 231], [203, 212], [203, 227], [204, 244], [205, 216], [207, 223], [207, 236], [208, 217], [208, 224], [209, 233], [211, 231], [212, 214], [212, 218], [213, 229], [213, 242], [214, 218], [214, 220], [214, 221], [214, 248], [215, 219], [219, 237], [222, 228], [222, 234], [223, 225], [223, 227], [224, 226], [227, 242], [227, 243], [228, 229], [228, 233], [230, 241], [233, 239], [233, 245], [235, 238], [237, 240], [245, 247], [248, 249]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s4/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ddb13b6d6d2a194994002f36e21a58f4c1bd2d6f --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [2, 0, 0, 0, 1, 2, 3, 3, 0, 2, 3, 0, 0, 3, 2, 3, 0, 3, 1, 3, 2, 1, 3, 3, 1, 0, 2, 2, 3, 0, 0, 1, 3, 3, 1, 0, 3, 3, 2, 2, 2, 0, 2, 1, 3, 0, 2, 3, 2, 2, 3, 2, 1, 1, 0, 3, 3, 1, 0, 0, 0, 0, 1, 2, 1, 3, 1, 3, 0, 3, 3, 1, 1, 3, 3, 1, 2, 3, 1, 2, 0, 0, 0, 1, 0, 1, 1, 1, 3, 1, 0, 1, 2, 2, 3, 0, 2, 2, 1, 2, 2, 1, 3, 2, 3, 0, 1, 3, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 2, 3, 2, 0, 1, 0, 3, 1, 3, 2, 0, 0, 2, 2, 1, 1, 1, 3, 0, 1, 0, 2, 2, 3, 2, 3, 2, 3, 0, 0, 1, 2, 3, 0, 1, 2, 1, 1, 3, 1, 2, 1, 3, 3, 1, 1, 2, 1, 3, 1, 2, 0, 0, 0, 0, 3, 3, 1, 3, 2, 2, 2, 2, 1, 2, 1, 3, 0, 0, 2, 1, 1, 2, 0, 2, 3, 0, 1, 0, 3, 0, 3, 1, 0, 3, 2, 2, 2, 2, 1, 0, 3, 1, 0, 0, 1, 1, 2, 3, 2, 3, 3, 3, 2, 1, 0, 1, 2, 2, 3, 2, 3, 1, 3, 0, 0, 3, 3, 0, 0, 1, 1, 1, 2, 0, 1, 1, 2, 2, 3, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l6-s4/tests/check.py b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/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-s4/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..21e99b22ac53ac4330d82b14fbe2d5ef85d9684c --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 250, "k": 4, "edges": [[0, 6], [0, 17], [0, 47], [0, 54], [0, 56], [0, 95], [0, 137], [0, 148], [0, 163], [0, 184], [0, 191], [0, 211], [0, 216], [1, 28], [1, 36], [1, 79], [1, 85], [1, 94], [1, 149], [1, 204], [1, 206], [1, 207], [1, 220], [1, 231], [2, 6], [2, 14], [2, 46], [2, 57], [2, 67], [2, 85], [2, 177], [3, 36], [3, 48], [3, 53], [3, 62], [3, 66], [3, 71], [3, 134], [3, 163], [3, 173], [3, 241], [3, 246], [4, 6], [4, 65], [4, 74], [4, 121], [4, 141], [4, 194], [5, 6], [5, 8], [5, 37], [5, 54], [5, 132], [5, 213], [6, 46], [6, 64], [6, 122], [6, 148], [6, 162], [6, 165], [6, 195], [7, 149], [7, 151], [7, 204], [7, 211], [7, 217], [7, 241], [8, 65], [8, 118], [8, 124], [8, 125], [8, 152], [8, 157], [8, 189], [8, 221], [9, 21], [9, 47], [9, 64], [9, 101], [9, 137], [9, 154], [9, 171], [9, 240], [9, 244], [10, 29], [10, 91], [10, 115], [10, 138], [10, 171], [10, 195], [10, 224], [10, 236], [10, 241], [11, 13], [11, 37], [11, 48], [11, 51], [11, 56], [11, 85], [11, 122], [11, 130], [11, 215], [12, 28], [12, 34], [12, 163], [12, 187], [12, 216], [12, 221], [12, 225], [13, 16], [13, 66], [13, 97], [13, 113], [13, 117], [13, 122], [13, 123], [13, 146], [13, 212], [13, 242], [14, 17], [14, 21], [14, 52], [14, 113], [14, 152], [14, 214], [14, 247], [15, 26], [15, 59], [15, 86], [15, 130], [15, 131], [15, 213], [16, 76], [16, 113], [16, 117], [16, 139], [16, 150], [16, 152], [16, 154], [16, 161], [16, 180], [16, 184], [16, 229], [17, 110], [17, 164], [17, 211], [17, 230], [18, 19], [18, 41], [18, 46], [18, 102], [18, 127], [18, 130], [18, 139], [18, 143], [18, 158], [18, 164], [18, 191], [18, 225], [18, 241], [19, 20], [19, 64], [19, 86], [19, 97], [19, 111], [19, 112], [19, 140], [19, 180], [19, 205], [19, 224], [19, 241], [20, 61], [20, 69], [20, 80], [20, 83], [20, 108], [20, 122], [20, 125], [20, 244], [21, 32], [21, 41], [21, 206], [21, 228], [22, 46], [22, 59], [22, 64], [22, 96], [22, 100], [22, 120], [22, 168], [23, 142], [23, 158], [23, 167], [23, 168], [23, 233], [23, 243], [24, 46], [24, 96], [24, 108], [24, 115], [24, 119], [24, 140], [24, 143], [24, 151], [24, 161], [25, 48], [25, 66], [25, 98], [25, 125], [25, 164], [25, 229], [26, 43], [26, 75], [26, 89], [26, 106], [26, 143], [26, 175], [26, 185], [26, 240], [27, 28], [27, 45], [27, 61], [27, 170], [27, 202], [27, 210], [27, 211], [27, 237], [27, 238], [28, 60], [28, 71], [28, 115], [28, 183], [28, 212], [28, 224], [29, 65], [29, 83], [29, 99], [29, 124], [29, 187], [29, 189], [29, 195], [29, 228], [30, 42], [30, 149], [30, 157], [30, 203], [31, 59], [31, 73], [31, 81], [31, 82], [31, 94], [31, 149], [31, 245], [32, 35], [32, 52], [32, 62], [32, 115], [32, 123], [32, 195], [33, 38], [33, 68], [33, 78], [33, 113], [33, 128], [33, 211], [34, 68], [34, 74], [34, 76], [34, 112], [34, 144], [34, 149], [34, 156], [34, 171], [35, 47], [35, 134], [35, 153], [35, 192], [35, 215], [35, 230], [35, 240], [35, 246], [35, 248], [36, 92], [36, 149], [36, 230], [36, 249], [37, 38], [37, 75], [37, 90], [37, 92], [37, 128], [37, 213], [37, 214], [37, 224], [37, 232], [37, 242], [38, 45], [38, 55], [38, 102], [38, 104], [38, 112], [38, 138], [38, 152], [38, 156], [38, 214], [38, 247], [39, 86], [39, 98], [39, 102], [39, 147], [39, 151], [39, 185], [39, 232], [39, 236], [39, 240], [40, 41], [40, 68], [40, 72], [40, 90], [40, 114], [40, 199], [40, 207], [40, 219], [41, 113], [41, 144], [41, 149], [41, 167], [41, 180], [41, 181], [41, 229], [42, 57], [42, 88], [42, 189], [43, 103], [43, 117], [43, 119], [43, 158], [43, 206], [43, 216], [44, 63], [44, 85], [44, 95], [44, 129], [44, 139], [44, 167], [44, 178], [44, 183], [44, 186], [44, 221], [44, 236], [44, 245], [45, 66], [45, 98], [45, 163], [45, 173], [45, 181], [45, 205], [45, 248], [46, 181], [46, 219], [47, 52], [47, 82], [47, 108], [47, 116], [47, 241], [47, 242], [48, 77], [48, 80], [48, 113], [48, 114], [48, 122], [48, 138], [48, 159], [48, 172], [48, 194], [48, 210], [49, 124], [49, 211], [50, 66], [50, 103], [50, 131], [50, 149], [50, 163], [51, 74], [51, 82], [51, 160], [51, 185], [51, 189], [52, 70], [52, 96], [52, 143], [52, 151], [52, 161], [52, 191], [52, 206], [52, 225], [52, 242], [53, 69], [53, 108], [53, 111], [53, 225], [53, 237], [53, 246], [54, 78], [54, 79], [54, 101], [54, 122], [54, 166], [54, 178], [54, 228], [55, 68], [55, 97], [55, 99], [55, 136], [55, 139], [55, 182], [55, 183], [55, 217], [55, 228], [55, 230], [56, 81], [56, 83], [56, 137], [56, 146], [56, 152], [56, 162], [57, 117], [57, 172], [57, 184], [57, 211], [57, 237], [58, 94], [58, 106], [58, 113], [58, 119], [58, 173], [58, 178], [58, 179], [58, 192], [58, 219], [59, 94], [59, 141], [59, 229], [60, 62], [60, 214], [60, 228], [60, 243], [61, 74], [61, 122], [61, 127], [61, 144], [61, 190], [61, 239], [62, 129], [62, 141], [62, 246], [63, 73], [63, 94], [63, 148], [63, 219], [63, 230], [64, 67], [64, 76], [64, 84], [64, 100], [64, 131], [64, 231], [65, 78], [65, 81], [65, 111], [65, 120], [65, 130], [65, 132], [65, 142], [65, 144], [65, 151], [65, 167], [66, 81], [66, 90], [66, 102], [66, 114], [66, 151], [66, 209], [66, 237], [66, 246], [67, 93], [67, 97], [67, 98], [67, 152], [67, 158], [67, 164], [67, 180], [67, 182], [67, 191], [67, 201], [67, 244], [68, 92], [68, 142], [68, 183], [68, 202], [69, 110], [69, 133], [69, 139], [69, 191], [69, 215], [70, 82], [70, 84], [70, 100], [70, 129], [70, 158], [70, 190], [70, 228], [71, 80], [71, 161], [71, 176], [71, 177], [71, 215], [71, 232], [72, 97], [72, 124], [72, 143], [72, 158], [72, 219], [72, 232], [73, 115], [73, 122], [73, 148], [73, 149], [73, 154], [73, 237], [74, 106], [74, 113], [74, 151], [74, 167], [74, 188], [74, 203], [74, 244], [75, 105], [75, 139], [75, 150], [75, 164], [75, 180], [75, 184], [75, 192], [75, 196], [75, 199], [75, 235], [76, 108], [76, 116], [76, 134], [76, 184], [76, 202], [76, 240], [76, 244], [76, 247], [77, 148], [77, 157], [77, 192], [77, 223], [77, 233], [77, 243], [77, 244], [78, 82], [78, 96], [78, 100], [78, 158], [78, 171], [78, 204], [79, 94], [79, 112], [79, 143], [79, 156], [79, 165], [79, 175], [80, 104], [80, 118], [80, 141], [80, 190], [81, 85], [81, 217], [81, 227], [82, 86], [82, 134], [82, 140], [82, 158], [82, 161], [82, 180], [82, 217], [83, 138], [83, 176], [83, 216], [83, 219], [83, 235], [84, 92], [84, 98], [84, 127], [84, 143], [84, 144], [84, 157], [84, 246], [85, 135], [85, 136], [85, 138], [85, 144], [85, 168], [85, 182], [85, 192], [85, 220], [86, 158], [86, 194], [86, 216], [86, 217], [86, 225], [86, 236], [87, 177], [87, 193], [87, 215], [88, 116], [88, 133], [88, 148], [88, 154], [88, 170], [88, 178], [88, 195], [88, 217], [89, 229], [90, 93], [90, 152], [90, 164], [90, 228], [90, 230], [90, 241], [91, 119], [91, 166], [91, 173], [91, 177], [91, 237], [91, 241], [91, 245], [92, 126], [92, 169], [92, 170], [92, 185], [92, 199], [92, 235], [93, 106], [93, 176], [93, 198], [93, 211], [94, 111], [94, 123], [94, 144], [94, 183], [94, 186], [94, 208], [94, 226], [94, 243], [95, 102], [95, 213], [95, 248], [96, 154], [96, 157], [96, 162], [96, 181], [96, 218], [97, 138], [97, 141], [98, 105], [98, 107], [98, 151], [98, 174], [98, 229], [98, 235], [99, 147], [99, 150], [99, 165], [99, 200], [99, 207], [99, 229], [99, 235], [100, 113], [100, 148], [100, 160], [100, 230], [100, 240], [101, 182], [102, 128], [102, 138], [102, 149], [102, 178], [102, 185], [102, 225], [102, 248], [103, 161], [103, 163], [103, 170], [103, 210], [104, 120], [104, 127], [104, 154], [104, 177], [104, 182], [104, 223], [104, 237], [105, 143], [105, 149], [105, 178], [105, 217], [105, 219], [106, 111], [106, 112], [106, 166], [106, 170], [106, 232], [106, 233], [106, 241], [106, 245], [107, 146], [107, 181], [107, 211], [107, 240], [108, 117], [108, 119], [108, 131], [108, 145], [108, 156], [108, 164], [108, 200], [108, 214], [108, 222], [108, 231], [109, 154], [109, 175], [110, 119], [110, 140], [111, 127], [111, 160], [112, 144], [112, 155], [112, 175], [112, 204], [112, 217], [112, 239], [112, 245], [113, 120], [113, 127], [113, 185], [113, 203], [113, 221], [114, 119], [114, 130], [114, 134], [114, 141], [114, 189], [114, 214], [114, 215], [114, 219], [114, 230], [114, 247], [115, 215], [115, 220], [116, 154], [116, 167], [116, 168], [116, 180], [116, 207], [116, 220], [117, 189], [117, 210], [117, 224], [117, 242], [117, 249], [118, 123], [118, 129], [118, 134], [118, 148], [118, 189], [119, 132], [119, 151], [119, 158], [119, 237], [120, 154], [120, 193], [120, 195], [121, 158], [121, 162], [121, 178], [121, 179], [121, 180], [121, 209], [121, 249], [122, 138], [122, 186], [122, 192], [122, 208], [123, 126], [123, 127], [123, 135], [123, 148], [123, 182], [123, 219], [123, 244], [124, 149], [124, 175], [124, 198], [124, 211], [124, 230], [125, 226], [125, 241], [126, 128], [126, 137], [126, 178], [126, 182], [126, 205], [127, 134], [127, 135], [127, 141], [127, 235], [128, 149], [128, 155], [128, 190], [128, 195], [128, 216], [128, 219], [128, 230], [129, 152], [129, 167], [129, 181], [129, 187], [129, 190], [129, 216], [129, 244], [130, 157], [130, 173], [130, 213], [130, 232], [130, 249], [131, 154], [131, 210], [131, 216], [131, 232], [131, 238], [131, 242], [132, 135], [132, 142], [132, 201], [132, 246], [133, 153], [133, 220], [133, 221], [133, 245], [133, 247], [134, 201], [135, 200], [135, 207], [135, 208], [135, 211], [135, 230], [136, 141], [136, 142], [136, 144], [136, 154], [136, 180], [136, 183], [136, 187], [136, 188], [137, 139], [137, 190], [137, 206], [137, 233], [138, 144], [138, 145], [138, 199], [139, 231], [140, 220], [140, 227], [140, 237], [141, 225], [142, 151], [142, 159], [142, 234], [142, 235], [143, 169], [143, 248], [144, 145], [144, 185], [144, 189], [144, 191], [144, 201], [144, 209], [144, 211], [145, 180], [145, 228], [146, 148], [146, 183], [146, 190], [146, 192], [146, 222], [146, 231], [146, 248], [147, 220], [147, 235], [148, 153], [148, 171], [148, 174], [148, 237], [149, 166], [149, 197], [150, 154], [150, 178], [150, 188], [150, 240], [151, 184], [151, 197], [151, 206], [151, 216], [152, 186], [152, 218], [152, 226], [152, 248], [153, 200], [153, 214], [153, 224], [154, 161], [154, 172], [154, 215], [155, 180], [155, 185], [155, 209], [155, 248], [156, 158], [156, 181], [156, 224], [156, 228], [156, 238], [156, 244], [157, 192], [158, 211], [158, 222], [158, 242], [159, 168], [159, 172], [160, 182], [160, 191], [160, 204], [160, 215], [161, 195], [161, 233], [163, 170], [163, 185], [164, 176], [164, 183], [165, 199], [165, 204], [165, 217], [165, 221], [165, 223], [166, 212], [167, 205], [167, 220], [168, 176], [168, 230], [168, 249], [169, 231], [170, 182], [170, 205], [170, 224], [171, 190], [171, 197], [171, 219], [171, 226], [171, 239], [172, 218], [172, 240], [173, 208], [173, 228], [173, 237], [174, 175], [174, 179], [174, 226], [175, 201], [175, 229], [175, 245], [176, 178], [178, 188], [178, 196], [178, 214], [178, 244], [179, 189], [180, 243], [181, 191], [181, 227], [182, 211], [183, 187], [183, 204], [183, 216], [184, 195], [184, 196], [184, 201], [184, 214], [184, 238], [185, 190], [185, 202], [185, 214], [185, 230], [185, 235], [186, 218], [187, 214], [187, 242], [187, 247], [188, 217], [189, 211], [189, 217], [189, 218], [189, 231], [189, 237], [190, 207], [190, 219], [190, 242], [191, 199], [191, 214], [192, 236], [192, 244], [193, 200], [193, 221], [193, 222], [193, 233], [195, 237], [196, 227], [196, 234], [197, 243], [198, 224], [199, 207], [199, 212], [199, 243], [200, 208], [200, 241], [201, 207], [201, 231], [203, 212], [203, 227], [204, 244], [205, 216], [207, 223], [207, 236], [208, 217], [208, 224], [209, 233], [211, 231], [212, 214], [212, 218], [213, 229], [213, 242], [214, 218], [214, 220], [214, 221], [214, 248], [215, 219], [219, 237], [222, 228], [222, 234], [223, 225], [223, 227], [224, 226], [227, 242], [227, 243], [228, 229], [228, 233], [230, 241], [233, 239], [233, 245], [235, 238], [237, 240], [245, 247], [248, 249]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l6-s4/tests/run.py b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l6-s4/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-low-autocorrelation-l3-s2/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l3-s2/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b44cfd3ca9656d8aaf310bb0dff4c20752bacdf3 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "bound": 62, "fixed": [["seq", 9, -1], ["seq", 14, 1], ["seq", 15, -1], ["seq", 22, -1], ["c", 3, 0], ["c", 9, -2], ["c", 14, -1], ["c", 19, 0]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l3-s2/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..658511af53320fae87738a1e2a0df8bc287aa9c0 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l3-s2/tests/check.py b/tasks/construct-mc-low-autocorrelation-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l3-s2/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l3-s2/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b44cfd3ca9656d8aaf310bb0dff4c20752bacdf3 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "bound": 62, "fixed": [["seq", 9, -1], ["seq", 14, 1], ["seq", 15, -1], ["seq", 22, -1], ["c", 3, 0], ["c", 9, -2], ["c", 14, -1], ["c", 19, 0]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l3-s2/tests/run.py b/tasks/construct-mc-low-autocorrelation-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l3-s2/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l3-s5/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l3-s5/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ee275ee2591ad002198a57a2c6837cc9ccf1451 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "bound": 90, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l3-s5/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f00774a147367b6a9eb1a51aab41713d718e10b7 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, 1, 1, -1, 1, 1, -1, -1, 1, -1, -1, -1, -1, -1, 1, 1, 1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l3-s5/tests/check.py b/tasks/construct-mc-low-autocorrelation-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l3-s5/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-l3-s5/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ee275ee2591ad002198a57a2c6837cc9ccf1451 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "bound": 90, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l3-s5/tests/run.py b/tasks/construct-mc-low-autocorrelation-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l3-s5/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l4-s1/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l4-s1/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f17f22096b80fd1e54d8c412fed9925aa401ac7 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "bound": 160, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s1/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a0aadb8ad8c4e7f0d8a048ca01b6650f9b396787 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-1, -1, -1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l4-s1/tests/check.py b/tasks/construct-mc-low-autocorrelation-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s1/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-s1/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f17f22096b80fd1e54d8c412fed9925aa401ac7 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "bound": 160, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l4-s1/tests/run.py b/tasks/construct-mc-low-autocorrelation-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l4-s1/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-magic-sequence-l3-s7/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s7/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94e718be8edde963f674f54496906b17fd673eea --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s7/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..046ed8d1ef7d12b500516b52eb271a4dd2cc2723 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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": [11, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s7/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s7/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-s7/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94e718be8edde963f674f54496906b17fd673eea --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s7/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s7/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s9/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s9/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75c6c6fc894d4841e01a60dc8ae15ddfa8c68adf --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s9/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..039900bc73f4d37fd703b6f4e80ea36e43b95452 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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": [9, 2, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s9/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s9/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-s9/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75c6c6fc894d4841e01a60dc8ae15ddfa8c68adf --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s9/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l3-s9/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l4-s3/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l4-s3/environment/instance.json b/tasks/construct-mc-magic-sequence-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a32cb427b2b413c4e834eb39e2f59cc4fd618bff --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l4-s3/solution/solve.sh b/tasks/construct-mc-magic-sequence-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bedfa2c46c7a43d9de7b3df343c6f2a607b05915 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [36, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l4-s3/tests/check.py b/tasks/construct-mc-magic-sequence-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l4-s3/tests/instance.json b/tasks/construct-mc-magic-sequence-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a32cb427b2b413c4e834eb39e2f59cc4fd618bff --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l4-s3/tests/run.py b/tasks/construct-mc-magic-sequence-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l4-s3/tests/test.sh b/tasks/construct-mc-magic-sequence-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l4-s4/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l4-s4/environment/instance.json b/tasks/construct-mc-magic-sequence-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2ccfbbab157861ad1364bc3fdc049278c89f8a6 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 36, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l4-s4/solution/solve.sh b/tasks/construct-mc-magic-sequence-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..06ef5b1346f996087eef9ad68cd15cde64d2a022 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [32, 2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l4-s4/tests/check.py b/tasks/construct-mc-magic-sequence-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s4/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-l4-s4/tests/instance.json b/tasks/construct-mc-magic-sequence-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2ccfbbab157861ad1364bc3fdc049278c89f8a6 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 36, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l4-s4/tests/run.py b/tasks/construct-mc-magic-sequence-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l4-s4/tests/test.sh b/tasks/construct-mc-magic-sequence-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-non-transitive-dice-l4-s1/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l4-s1/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..785805e225bdec070f334831762a2b25c45e5d64 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "m": 6, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l4-s1/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bfc58cf4658455af883ed3e9424840dfaf291027 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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' +{"dice": [[0, 2, 2, 2, 2, 2], [1, 1, 1, 1, 6, 7], [0, 0, 1, 5, 5, 6], [0, 0, 1, 4, 4, 4], [0, 1, 1, 3, 3, 3]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l4-s1/tests/check.py b/tasks/construct-mc-non-transitive-dice-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l4-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Cyclically intransitive dice (MathConstraint non_transitive_dice, CC-BY-4.0): n dice with m faces in +0..2m-1; die i beats die (i+1) mod n, i.e. #{(a, b): face_i(a) > face_{i+1}(b)} > floor(m^2 / 2). +Face order is irrelevant (upstream additionally demanded sorted faces as a symmetry break; not required).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, m = inst["n"], inst["m"] + D = ans.get("dice") + if not isinstance(D, list) or len(D) != n: + raise Invalid(f"dice must be a list of {n} dice") + D = [int_list(d, m, 0, 2 * m - 1, "die") for d in D] + for i in range(n): + A, B = D[i], D[(i + 1) % n] + w = sum(1 for a in A for b in B if a > b) + if w <= m * m // 2: + raise Invalid(f"die {i} wins only {w} of {m * m} face pairs against die {(i + 1) % n}") + return None, {} diff --git a/tasks/construct-mc-non-transitive-dice-l4-s1/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..785805e225bdec070f334831762a2b25c45e5d64 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "m": 6, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l4-s1/tests/run.py b/tasks/construct-mc-non-transitive-dice-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l4-s1/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-number-partitioning-l3-s6/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l3-s6/environment/instance.json b/tasks/construct-mc-number-partitioning-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a92c74cdfc09d428e69a5b6b6b2cfd4e3aae34b1 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s6/solution/solve.sh b/tasks/construct-mc-number-partitioning-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c249e3f39334b70a71de3d812f890548d3c1d276 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 1, 3, 3, 3, 0, 3, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l3-s6/tests/check.py b/tasks/construct-mc-number-partitioning-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s6/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-s6/tests/instance.json b/tasks/construct-mc-number-partitioning-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a92c74cdfc09d428e69a5b6b6b2cfd4e3aae34b1 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l3-s6/tests/run.py b/tasks/construct-mc-number-partitioning-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l3-s6/tests/test.sh b/tasks/construct-mc-number-partitioning-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-l4-s2/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l4-s2/environment/instance.json b/tasks/construct-mc-number-partitioning-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c4aae44bb7dff03b1a2490bd6c16e0ca9a667cd0 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 27, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l4-s2/solution/solve.sh b/tasks/construct-mc-number-partitioning-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6936a7e67074ab8599ad5b82f16195cea4707575 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [5, 4, 2, 2, 0, 1, 4, 3, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l4-s2/tests/check.py b/tasks/construct-mc-number-partitioning-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l4-s2/tests/instance.json b/tasks/construct-mc-number-partitioning-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c4aae44bb7dff03b1a2490bd6c16e0ca9a667cd0 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 27, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l4-s2/tests/run.py b/tasks/construct-mc-number-partitioning-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l4-s2/tests/test.sh b/tasks/construct-mc-number-partitioning-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l4-s5/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l4-s5/environment/instance.json b/tasks/construct-mc-number-partitioning-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..14506f8b0db3f6fae495ea09afe0b178af9fa1dc --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 39, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l4-s5/solution/solve.sh b/tasks/construct-mc-number-partitioning-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..30f99907b0cce846bbd0b9a87d94702e260a8ce1 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 2, 1, 1, 0, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l4-s5/tests/check.py b/tasks/construct-mc-number-partitioning-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s5/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l4-s5/tests/instance.json b/tasks/construct-mc-number-partitioning-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..14506f8b0db3f6fae495ea09afe0b178af9fa1dc --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 39, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l4-s5/tests/run.py b/tasks/construct-mc-number-partitioning-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l4-s5/tests/test.sh b/tasks/construct-mc-number-partitioning-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ortholatin-l1-s1/environment/Dockerfile b/tasks/construct-mc-ortholatin-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l1-s1/environment/instance.json b/tasks/construct-mc-ortholatin-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a50e94866bf6d8dc7d61a60f5877ed750f07331 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 4, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l1-s1/solution/solve.sh b/tasks/construct-mc-ortholatin-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..87bbff71da709d30aa75fb510611591227ed6f54 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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": [[0, 1, 2, 3], [1, 0, 3, 2], [2, 3, 0, 1], [3, 2, 1, 0]], "Y": [[0, 1, 2, 3], [2, 3, 0, 1], [3, 2, 1, 0], [1, 0, 3, 2]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l1-s1/tests/check.py b/tasks/construct-mc-ortholatin-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l1-s1/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-s1/tests/instance.json b/tasks/construct-mc-ortholatin-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a50e94866bf6d8dc7d61a60f5877ed750f07331 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 4, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l1-s1/tests/run.py b/tasks/construct-mc-ortholatin-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l1-s1/tests/test.sh b/tasks/construct-mc-ortholatin-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l6-s2/environment/Dockerfile b/tasks/construct-mc-ortholatin-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l6-s2/environment/instance.json b/tasks/construct-mc-ortholatin-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5e0020d6795ea023733de381adef9e8d0009130 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l6-s2/solution/solve.sh b/tasks/construct-mc-ortholatin-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b5bcf659aca5bafc2886cc6aa1e5c5c6edf4d14b --- /dev/null +++ b/tasks/construct-mc-ortholatin-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4], [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7], [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8], [10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [17, 18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [18, 19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], [19, 20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], [20, 21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], [21, 22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], [22, 23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21], [23, 24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], [24, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23]], "Y": [[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23], [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24], [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0], [3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1], [4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2], [5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3], [6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4], [7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5], [8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6], [9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7], [10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8], [11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9], [12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10], [13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11], [14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12], [15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13], [16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14], [17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15], [18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16], [19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17], [20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18], [21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19], [22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20], [23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21], [24, 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l6-s2/tests/check.py b/tasks/construct-mc-ortholatin-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l6-s2/tests/check.py @@ -0,0 +1,25 @@ +"""Pair of orthogonal Latin squares of order n (MathConstraint ortholatin, CC-BY-4.0).""" +from run import Invalid, int_list + + +def _square(v, n, name): + if not isinstance(v, list) or len(v) != n: + raise Invalid(f"{name} must be a list of {n} rows") + S = [int_list(r, n, 0, n - 1, f"{name} row") for r in v] + full = list(range(n)) + for i in range(n): + if sorted(S[i]) != full: + raise Invalid(f"{name}: row {i} is not a permutation of 0..{n - 1}") + if sorted(S[r][i] for r in range(n)) != full: + raise Invalid(f"{name}: column {i} is not a permutation of 0..{n - 1}") + return S + + +def check(inst, ans): + n = inst["n"] + X = _square(ans.get("X"), n, "X") + Y = _square(ans.get("Y"), n, "Y") + pairs = {(X[i][j], Y[i][j]) for i in range(n) for j in range(n)} + if len(pairs) != n * n: + raise Invalid("X and Y are not orthogonal (some ordered pair repeats)") + return None, {} diff --git a/tasks/construct-mc-ortholatin-l6-s2/tests/instance.json b/tasks/construct-mc-ortholatin-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5e0020d6795ea023733de381adef9e8d0009130 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l6-s2/tests/run.py b/tasks/construct-mc-ortholatin-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l6-s2/tests/test.sh b/tasks/construct-mc-ortholatin-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-pysms-chromatic-girth-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b935a944d0d7f7a2582271cc3b98c610066d2500 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 13, "required_edges": [[0, 1], [0, 8]], "max_chromatic_number": 2, "min_edges": 8, "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-s1/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..df49457c89004518544130ef76cdb82b6fe8cf69 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12]], "coloring": [0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l1-s1/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b935a944d0d7f7a2582271cc3b98c610066d2500 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 13, "required_edges": [[0, 1], [0, 8]], "max_chromatic_number": 2, "min_edges": 8, "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-s1/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l2-s3/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l2-s3/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f15e6b7c72f078c530c57546ba222bd98c451a2c --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_chromatic_number": 5, "min_edges": 16, "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-l2-s3/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..35d6ca2ba036e4cee7df2af9b005f4e691bfbf9d --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 11], [0, 12], [0, 13], [1, 9], [1, 10], [1, 13], [2, 8], [2, 10], [2, 12], [3, 6], [3, 7], [3, 13], [4, 5], [4, 7], [4, 12], [5, 6], [5, 11], [6, 8], [7, 10], [8, 9], [9, 11]], "coloring": [0, 0, 0, 0, 0, 1, 2, 1, 1, 2, 2, 3, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l2-s3/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/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-l2-s3/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f15e6b7c72f078c530c57546ba222bd98c451a2c --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "max_chromatic_number": 5, "min_edges": 16, "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-l2-s3/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l2-s3/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l6-s2/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l6-s2/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..956afe7104996d1ac4215fb687ea039917e4c11a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 25, "required_edges": [], "max_chromatic_number": 5, "min_edges": 34, "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-l6-s2/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..742db41cfe523c936b9cb1faaa0358d5ab0f0038 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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' +{"edges": [[0, 23], [0, 24], [1, 21], [1, 22], [2, 19], [2, 20], [3, 17], [3, 18], [4, 15], [4, 16], [5, 13], [5, 14], [5, 24], [6, 12], [6, 14], [6, 22], [7, 11], [7, 13], [7, 20], [8, 10], [8, 12], [8, 18], [9, 10], [9, 11], [9, 16], [10, 21], [11, 17], [12, 23], [13, 15], [14, 19], [15, 18], [16, 19], [17, 22], [20, 23], [21, 24]], "coloring": [2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..956afe7104996d1ac4215fb687ea039917e4c11a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 25, "required_edges": [], "max_chromatic_number": 5, "min_edges": 34, "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-l6-s2/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-chromatic-girth-l6-s2/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-pysms-clique-coloring-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-clique-coloring-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d25ee0164d42f47992b109e6f00874db9807551b --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_chromatic_number": 4, "max_clique": 5, "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-l1-s1/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f35cee0be4715acada3f239b105bf4da3eb06bfa --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [7, 9], [7, 10], [8, 9], [8, 10]], "coloring": [0, 3, 3, 0, 0, 3, 1, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l1-s1/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-clique-coloring-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d25ee0164d42f47992b109e6f00874db9807551b --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_chromatic_number": 4, "max_clique": 5, "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-l1-s1/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-clique-coloring-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-clique-coloring-l5-s0/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-mc-pysms-clique-coloring-l5-s0/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cc5a3ad538e3a1b14262332f66fb8fb5530c75e --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[0, 10], [0, 11], [0, 7], [3, 10], [2, 9], [1, 9], [3, 6]], "max_chromatic_number": 5, "max_clique": 4, "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-l5-s0/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5be358b6abeeb34a59761477a8dff3a099377793 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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' +{"edges": [[0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [2, 3], [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, 1, 0, 1, 2, 2, 2, 2, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cc5a3ad538e3a1b14262332f66fb8fb5530c75e --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[0, 10], [0, 11], [0, 7], [3, 10], [2, 9], [1, 9], [3, 6]], "max_chromatic_number": 5, "max_clique": 4, "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-l5-s0/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-mc-pysms-clique-coloring-l5-s0/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-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-mc-pysms-girth-degree-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-girth-degree-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12efe55e3948d2fdf0632eefc2b530dc5d9518b --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 8, "required_edges": [[0, 4], [0, 7], [2, 4]], "max_degree": 4, "min_degree": 4, "min_girth": 4, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l1-s1/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c787192a83d8aa912bc6cd12be86635cbb652b6 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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, 4], [0, 5], [0, 6], [0, 7], [1, 4], [1, 5], [1, 6], [1, 7], [2, 4], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 7]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-girth-degree-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12efe55e3948d2fdf0632eefc2b530dc5d9518b --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 8, "required_edges": [[0, 4], [0, 7], [2, 4]], "max_degree": 4, "min_degree": 4, "min_girth": 4, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-girth-degree-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-l5-s0/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l5-s0/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..365cfb89e5782a97577e68be1ec838d148e762f7 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_degree": 4, "min_degree": 3, "min_girth": 7, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l5-s0/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bfe00871b8706710dc5fbe22ce43aad419c5b2b3 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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' +{"edges": [[0, 21], [0, 22], [0, 23], [1, 19], [1, 20], [1, 23], [2, 17], [2, 18], [2, 23], [3, 15], [3, 16], [3, 22], [4, 14], [4, 16], [4, 20], [5, 13], [5, 16], [5, 18], [6, 12], [6, 15], [6, 19], [7, 11], [7, 14], [7, 17], [8, 10], [8, 12], [8, 18], [9, 10], [9, 11], [9, 22], [10, 20], [11, 13], [12, 21], [13, 19], [14, 21], [15, 17]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l5-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-girth-degree-l5-s0/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..365cfb89e5782a97577e68be1ec838d148e762f7 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_degree": 4, "min_degree": 3, "min_girth": 7, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-girth-degree-l5-s0/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-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-mc-pysms-min-connectivity-l2-s0/environment/Dockerfile b/tasks/construct-mc-pysms-min-connectivity-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-connectivity-l2-s0/environment/instance.json b/tasks/construct-mc-pysms-min-connectivity-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d735023357f8bc6604bc714e5548ac7579151da5 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "min_connectivity": 1, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l2-s0/solution/solve.sh b/tasks/construct-mc-pysms-min-connectivity-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..752031b11da6795a502d7f36701ee4e3b999221c --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/check.py b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/instance.json b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d735023357f8bc6604bc714e5548ac7579151da5 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "min_connectivity": 1, "family": "mc_pysms_min_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/run.py b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/test.sh b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-connectivity-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l4-s3/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l4-s3/environment/instance.json b/tasks/construct-mc-van-der-waerden-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d1f032fa6eb96caed9a28a8ba3ffab2ec0d7eb6 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 60, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l4-s3/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a46698733b99964fa6a19d07036105d28fec074a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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' +{"colors": [0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l4-s3/tests/check.py b/tasks/construct-mc-van-der-waerden-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l4-s3/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l4-s3/tests/instance.json b/tasks/construct-mc-van-der-waerden-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d1f032fa6eb96caed9a28a8ba3ffab2ec0d7eb6 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 60, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l4-s3/tests/run.py b/tasks/construct-mc-van-der-waerden-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l4-s3/tests/test.sh b/tasks/construct-mc-van-der-waerden-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l4-s4/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l4-s4/environment/instance.json b/tasks/construct-mc-van-der-waerden-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31ec3e1bf6cf7c2a9c6ef205b23f3c09827072aa --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 50, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l4-s4/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c041358c42d29212f9b70da53796677370eaeb8e --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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' +{"colors": [0, 2, 0, 2, 1, 1, 0, 2, 0, 3, 3, 0, 3, 3, 1, 2, 1, 2, 3, 3, 2, 3, 3, 0, 0, 1, 1, 0, 2, 0, 1, 1, 0, 0, 2, 2, 3, 3, 2, 3, 3, 1, 1, 2, 2, 3, 3, 2, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l4-s4/tests/check.py b/tasks/construct-mc-van-der-waerden-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l4-s4/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l4-s4/tests/instance.json b/tasks/construct-mc-van-der-waerden-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31ec3e1bf6cf7c2a9c6ef205b23f3c09827072aa --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 50, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l4-s4/tests/run.py b/tasks/construct-mc-van-der-waerden-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l4-s4/tests/test.sh b/tasks/construct-mc-van-der-waerden-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-nppc-3col-l1-s2/environment/Dockerfile b/tasks/construct-nppc-3col-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l1-s2/environment/instance.json b/tasks/construct-nppc-3col-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..af60b85dc7ae6e59553d8da0c5f3f1835fb7c09a --- /dev/null +++ b/tasks/construct-nppc-3col-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "edges": [[0, 2], [0, 3], [0, 9], [1, 2], [1, 5], [1, 6], [1, 8], [1, 9], [2, 4], [2, 6], [3, 4], [3, 5], [3, 7], [4, 6], [4, 7], [4, 8], [4, 9], [5, 8], [7, 8], [7, 9]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l1-s2/solution/solve.sh b/tasks/construct-nppc-3col-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6c58aa5300b02c22a452168414e2a50d8c7210d2 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [2, 2, 0, 0, 2, 1, 1, 1, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l1-s2/tests/check.py b/tasks/construct-nppc-3col-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l1-s2/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l1-s2/tests/instance.json b/tasks/construct-nppc-3col-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..af60b85dc7ae6e59553d8da0c5f3f1835fb7c09a --- /dev/null +++ b/tasks/construct-nppc-3col-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "edges": [[0, 2], [0, 3], [0, 9], [1, 2], [1, 5], [1, 6], [1, 8], [1, 9], [2, 4], [2, 6], [3, 4], [3, 5], [3, 7], [4, 6], [4, 7], [4, 8], [4, 9], [5, 8], [7, 8], [7, 9]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l1-s2/tests/run.py b/tasks/construct-nppc-3col-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l1-s2/tests/test.sh b/tasks/construct-nppc-3col-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l1-s5/environment/Dockerfile b/tasks/construct-nppc-3col-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l1-s5/environment/instance.json b/tasks/construct-nppc-3col-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4894a99e22171faa97b79c497d3cf02ba72c882c --- /dev/null +++ b/tasks/construct-nppc-3col-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 8], [0, 9], [1, 2], [1, 6], [1, 7], [1, 9], [2, 3], [2, 4], [2, 7], [3, 5], [3, 6], [3, 9], [4, 7], [4, 9], [5, 7], [7, 9]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l1-s5/solution/solve.sh b/tasks/construct-nppc-3col-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..54a4d2b3e57925d4877ded4165d1a02181a668c4 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [1, 2, 0, 1, 2, 0, 0, 1, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l1-s5/tests/check.py b/tasks/construct-nppc-3col-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l1-s5/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l1-s5/tests/instance.json b/tasks/construct-nppc-3col-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4894a99e22171faa97b79c497d3cf02ba72c882c --- /dev/null +++ b/tasks/construct-nppc-3col-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 10, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 8], [0, 9], [1, 2], [1, 6], [1, 7], [1, 9], [2, 3], [2, 4], [2, 7], [3, 5], [3, 6], [3, 9], [4, 7], [4, 9], [5, 7], [7, 9]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l1-s5/tests/run.py b/tasks/construct-nppc-3col-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l1-s5/tests/test.sh b/tasks/construct-nppc-3col-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l5-s3/environment/Dockerfile b/tasks/construct-nppc-3col-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l5-s3/environment/instance.json b/tasks/construct-nppc-3col-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc21db9d6b2dab07da7cea0cee445f193f337ae8 --- /dev/null +++ b/tasks/construct-nppc-3col-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 60, "edges": [[0, 7], [0, 10], [0, 18], [0, 36], [0, 37], [0, 41], [0, 43], [1, 2], [1, 10], [1, 13], [1, 17], [1, 18], [1, 21], [1, 30], [1, 31], [1, 35], [1, 43], [2, 17], [2, 37], [2, 58], [3, 6], [3, 11], [3, 16], [3, 21], [3, 28], [3, 39], [3, 43], [3, 45], [3, 47], [3, 52], [3, 59], [4, 7], [4, 24], [4, 30], [4, 41], [4, 46], [4, 55], [4, 58], [5, 10], [5, 20], [5, 28], [5, 58], [6, 23], [6, 33], [6, 42], [7, 14], [7, 17], [7, 30], [8, 11], [8, 31], [8, 36], [8, 46], [8, 47], [8, 58], [8, 59], [9, 19], [9, 48], [9, 56], [10, 21], [10, 33], [10, 34], [10, 41], [11, 17], [11, 41], [11, 46], [12, 14], [12, 15], [12, 16], [12, 17], [12, 20], [12, 23], [12, 25], [12, 30], [12, 34], [12, 46], [13, 16], [13, 31], [13, 39], [13, 50], [13, 52], [14, 17], [14, 29], [14, 40], [14, 43], [14, 45], [14, 47], [14, 59], [15, 48], [16, 41], [16, 49], [17, 24], [17, 27], [17, 28], [17, 31], [17, 34], [17, 38], [17, 50], [17, 51], [17, 56], [18, 25], [18, 48], [19, 37], [19, 38], [19, 40], [19, 55], [19, 56], [20, 22], [20, 31], [20, 39], [20, 41], [20, 50], [20, 52], [21, 22], [21, 45], [21, 46], [21, 50], [21, 57], [22, 23], [22, 26], [22, 44], [22, 59], [23, 24], [23, 29], [23, 32], [23, 37], [24, 30], [24, 45], [24, 54], [24, 58], [25, 29], [25, 33], [25, 37], [25, 38], [25, 50], [25, 54], [25, 56], [26, 33], [26, 38], [26, 40], [27, 31], [27, 35], [27, 36], [27, 39], [27, 59], [28, 33], [28, 38], [28, 43], [28, 45], [28, 54], [28, 57], [29, 39], [29, 47], [29, 53], [30, 32], [30, 38], [30, 50], [30, 57], [31, 44], [31, 54], [31, 55], [31, 57], [32, 45], [32, 54], [32, 59], [34, 35], [34, 45], [34, 49], [35, 38], [35, 39], [35, 41], [35, 51], [35, 53], [35, 56], [37, 49], [37, 50], [37, 55], [38, 47], [38, 52], [39, 41], [39, 46], [39, 55], [40, 56], [41, 44], [41, 47], [41, 52], [42, 54], [43, 52], [44, 53], [45, 50], [45, 57], [47, 48], [47, 55], [47, 56], [49, 51], [49, 52], [50, 53], [52, 56], [54, 55], [56, 58], [56, 59]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l5-s3/solution/solve.sh b/tasks/construct-nppc-3col-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..18817ff03f1882a4deafe4b9c55d48d0c4877085 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [1, 0, 1, 0, 1, 0, 2, 0, 0, 2, 2, 1, 0, 2, 1, 1, 1, 2, 2, 1, 2, 1, 0, 1, 0, 1, 1, 0, 1, 0, 2, 1, 0, 0, 1, 2, 2, 2, 0, 1, 2, 0, 1, 2, 2, 2, 2, 2, 0, 0, 0, 1, 1, 1, 2, 0, 0, 0, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l5-s3/tests/check.py b/tasks/construct-nppc-3col-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l5-s3/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-l5-s3/tests/instance.json b/tasks/construct-nppc-3col-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fc21db9d6b2dab07da7cea0cee445f193f337ae8 --- /dev/null +++ b/tasks/construct-nppc-3col-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 60, "edges": [[0, 7], [0, 10], [0, 18], [0, 36], [0, 37], [0, 41], [0, 43], [1, 2], [1, 10], [1, 13], [1, 17], [1, 18], [1, 21], [1, 30], [1, 31], [1, 35], [1, 43], [2, 17], [2, 37], [2, 58], [3, 6], [3, 11], [3, 16], [3, 21], [3, 28], [3, 39], [3, 43], [3, 45], [3, 47], [3, 52], [3, 59], [4, 7], [4, 24], [4, 30], [4, 41], [4, 46], [4, 55], [4, 58], [5, 10], [5, 20], [5, 28], [5, 58], [6, 23], [6, 33], [6, 42], [7, 14], [7, 17], [7, 30], [8, 11], [8, 31], [8, 36], [8, 46], [8, 47], [8, 58], [8, 59], [9, 19], [9, 48], [9, 56], [10, 21], [10, 33], [10, 34], [10, 41], [11, 17], [11, 41], [11, 46], [12, 14], [12, 15], [12, 16], [12, 17], [12, 20], [12, 23], [12, 25], [12, 30], [12, 34], [12, 46], [13, 16], [13, 31], [13, 39], [13, 50], [13, 52], [14, 17], [14, 29], [14, 40], [14, 43], [14, 45], [14, 47], [14, 59], [15, 48], [16, 41], [16, 49], [17, 24], [17, 27], [17, 28], [17, 31], [17, 34], [17, 38], [17, 50], [17, 51], [17, 56], [18, 25], [18, 48], [19, 37], [19, 38], [19, 40], [19, 55], [19, 56], [20, 22], [20, 31], [20, 39], [20, 41], [20, 50], [20, 52], [21, 22], [21, 45], [21, 46], [21, 50], [21, 57], [22, 23], [22, 26], [22, 44], [22, 59], [23, 24], [23, 29], [23, 32], [23, 37], [24, 30], [24, 45], [24, 54], [24, 58], [25, 29], [25, 33], [25, 37], [25, 38], [25, 50], [25, 54], [25, 56], [26, 33], [26, 38], [26, 40], [27, 31], [27, 35], [27, 36], [27, 39], [27, 59], [28, 33], [28, 38], [28, 43], [28, 45], [28, 54], [28, 57], [29, 39], [29, 47], [29, 53], [30, 32], [30, 38], [30, 50], [30, 57], [31, 44], [31, 54], [31, 55], [31, 57], [32, 45], [32, 54], [32, 59], [34, 35], [34, 45], [34, 49], [35, 38], [35, 39], [35, 41], [35, 51], [35, 53], [35, 56], [37, 49], [37, 50], [37, 55], [38, 47], [38, 52], [39, 41], [39, 46], [39, 55], [40, 56], [41, 44], [41, 47], [41, 52], [42, 54], [43, 52], [44, 53], [45, 50], [45, 57], [47, 48], [47, 55], [47, 56], [49, 51], [49, 52], [50, 53], [52, 56], [54, 55], [56, 58], [56, 59]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l5-s3/tests/run.py b/tasks/construct-nppc-3col-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l5-s3/tests/test.sh b/tasks/construct-nppc-3col-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l5-s4/environment/Dockerfile b/tasks/construct-nppc-3col-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l5-s4/environment/instance.json b/tasks/construct-nppc-3col-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..138b2a721b0f038613fd55e4c88e4b3261a2a78e --- /dev/null +++ b/tasks/construct-nppc-3col-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 60, "edges": [[0, 9], [0, 19], [0, 40], [0, 57], [1, 4], [1, 18], [1, 20], [1, 37], [1, 43], [1, 46], [1, 50], [1, 51], [2, 17], [2, 25], [2, 40], [2, 54], [3, 9], [3, 17], [3, 25], [3, 27], [3, 55], [4, 14], [4, 16], [4, 29], [4, 32], [4, 33], [4, 34], [5, 6], [5, 14], [5, 21], [5, 46], [5, 54], [6, 13], [6, 26], [6, 29], [6, 37], [6, 44], [6, 49], [7, 10], [7, 15], [7, 18], [7, 39], [7, 44], [8, 26], [8, 32], [8, 34], [8, 36], [8, 47], [9, 40], [9, 41], [9, 42], [9, 51], [10, 14], [10, 37], [10, 47], [10, 53], [10, 55], [10, 56], [10, 57], [11, 30], [11, 31], [11, 37], [11, 38], [12, 19], [12, 21], [12, 25], [12, 26], [12, 29], [12, 35], [12, 55], [12, 57], [12, 58], [13, 20], [13, 21], [13, 23], [13, 49], [13, 51], [13, 54], [13, 55], [14, 17], [14, 21], [14, 33], [14, 35], [15, 21], [15, 24], [15, 34], [15, 41], [15, 45], [15, 47], [16, 36], [16, 55], [16, 58], [17, 18], [17, 26], [17, 27], [17, 40], [17, 42], [18, 34], [18, 47], [18, 53], [19, 20], [19, 21], [19, 25], [19, 49], [19, 51], [20, 21], [20, 25], [20, 38], [20, 59], [21, 31], [21, 45], [21, 46], [21, 50], [22, 43], [22, 44], [22, 49], [23, 28], [23, 33], [23, 39], [23, 46], [23, 55], [24, 49], [25, 29], [25, 46], [26, 33], [26, 41], [26, 43], [26, 45], [26, 48], [26, 49], [26, 51], [26, 54], [26, 55], [27, 38], [27, 44], [27, 53], [27, 54], [27, 59], [28, 29], [28, 38], [28, 40], [28, 56], [29, 35], [29, 42], [29, 43], [29, 45], [29, 58], [30, 31], [30, 40], [30, 41], [30, 44], [30, 46], [31, 41], [31, 49], [32, 35], [32, 41], [32, 47], [32, 49], [33, 45], [34, 39], [34, 40], [34, 41], [34, 43], [34, 46], [34, 52], [35, 43], [35, 50], [35, 51], [35, 52], [36, 44], [36, 49], [37, 47], [37, 54], [37, 55], [38, 48], [39, 45], [39, 47], [39, 48], [39, 49], [39, 50], [40, 51], [40, 54], [41, 44], [41, 55], [42, 52], [42, 57], [42, 59], [43, 52], [43, 58], [44, 47], [44, 48], [44, 49], [46, 51], [46, 53], [48, 59], [49, 52], [50, 54], [51, 53], [51, 57], [55, 59]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l5-s4/solution/solve.sh b/tasks/construct-nppc-3col-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..15f36152c109e1b4aa0615861c59ed8eceb0194d --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [1, 2, 1, 0, 1, 1, 2, 2, 1, 2, 1, 1, 1, 0, 0, 0, 0, 2, 1, 0, 1, 2, 2, 1, 2, 2, 0, 1, 2, 0, 2, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 2, 1, 1, 1, 1, 0, 2, 2, 2, 0, 0, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l5-s4/tests/check.py b/tasks/construct-nppc-3col-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l5-s4/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l5-s4/tests/instance.json b/tasks/construct-nppc-3col-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..138b2a721b0f038613fd55e4c88e4b3261a2a78e --- /dev/null +++ b/tasks/construct-nppc-3col-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 60, "edges": [[0, 9], [0, 19], [0, 40], [0, 57], [1, 4], [1, 18], [1, 20], [1, 37], [1, 43], [1, 46], [1, 50], [1, 51], [2, 17], [2, 25], [2, 40], [2, 54], [3, 9], [3, 17], [3, 25], [3, 27], [3, 55], [4, 14], [4, 16], [4, 29], [4, 32], [4, 33], [4, 34], [5, 6], [5, 14], [5, 21], [5, 46], [5, 54], [6, 13], [6, 26], [6, 29], [6, 37], [6, 44], [6, 49], [7, 10], [7, 15], [7, 18], [7, 39], [7, 44], [8, 26], [8, 32], [8, 34], [8, 36], [8, 47], [9, 40], [9, 41], [9, 42], [9, 51], [10, 14], [10, 37], [10, 47], [10, 53], [10, 55], [10, 56], [10, 57], [11, 30], [11, 31], [11, 37], [11, 38], [12, 19], [12, 21], [12, 25], [12, 26], [12, 29], [12, 35], [12, 55], [12, 57], [12, 58], [13, 20], [13, 21], [13, 23], [13, 49], [13, 51], [13, 54], [13, 55], [14, 17], [14, 21], [14, 33], [14, 35], [15, 21], [15, 24], [15, 34], [15, 41], [15, 45], [15, 47], [16, 36], [16, 55], [16, 58], [17, 18], [17, 26], [17, 27], [17, 40], [17, 42], [18, 34], [18, 47], [18, 53], [19, 20], [19, 21], [19, 25], [19, 49], [19, 51], [20, 21], [20, 25], [20, 38], [20, 59], [21, 31], [21, 45], [21, 46], [21, 50], [22, 43], [22, 44], [22, 49], [23, 28], [23, 33], [23, 39], [23, 46], [23, 55], [24, 49], [25, 29], [25, 46], [26, 33], [26, 41], [26, 43], [26, 45], [26, 48], [26, 49], [26, 51], [26, 54], [26, 55], [27, 38], [27, 44], [27, 53], [27, 54], [27, 59], [28, 29], [28, 38], [28, 40], [28, 56], [29, 35], [29, 42], [29, 43], [29, 45], [29, 58], [30, 31], [30, 40], [30, 41], [30, 44], [30, 46], [31, 41], [31, 49], [32, 35], [32, 41], [32, 47], [32, 49], [33, 45], [34, 39], [34, 40], [34, 41], [34, 43], [34, 46], [34, 52], [35, 43], [35, 50], [35, 51], [35, 52], [36, 44], [36, 49], [37, 47], [37, 54], [37, 55], [38, 48], [39, 45], [39, 47], [39, 48], [39, 49], [39, 50], [40, 51], [40, 54], [41, 44], [41, 55], [42, 52], [42, 57], [42, 59], [43, 52], [43, 58], [44, 47], [44, 48], [44, 49], [46, 51], [46, 53], [48, 59], [49, 52], [50, 54], [51, 53], [51, 57], [55, 59]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l5-s4/tests/run.py b/tasks/construct-nppc-3col-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l5-s4/tests/test.sh b/tasks/construct-nppc-3col-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-3col-l6-s1/environment/Dockerfile b/tasks/construct-nppc-3col-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s1/environment/instance.json b/tasks/construct-nppc-3col-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ac851ffec1e278f6a1b3cd9cf0eff3acaf4705e --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 10], [0, 23], [0, 29], [0, 45], [0, 46], [0, 54], [0, 73], [0, 78], [0, 100], [0, 101], [1, 3], [1, 7], [1, 33], [1, 44], [1, 72], [1, 112], [2, 7], [2, 10], [2, 14], [2, 27], [2, 28], [2, 53], [2, 54], [2, 70], [2, 79], [2, 104], [2, 108], [3, 4], [3, 6], [3, 25], [3, 30], [3, 31], [3, 61], [3, 65], [3, 68], [3, 76], [3, 106], [4, 44], [4, 49], [4, 51], [4, 66], [4, 68], [4, 77], [4, 98], [4, 105], [5, 22], [5, 43], [5, 45], [5, 50], [5, 58], [5, 67], [5, 81], [6, 24], [6, 38], [6, 56], [6, 57], [6, 64], [6, 92], [6, 105], [6, 108], [6, 114], [6, 118], [7, 15], [7, 24], [7, 67], [7, 78], [7, 107], [8, 21], [8, 34], [8, 49], [8, 94], [8, 107], [8, 114], [9, 11], [9, 13], [9, 27], [9, 63], [9, 97], [9, 108], [10, 17], [10, 19], [10, 58], [10, 77], [10, 85], [10, 88], [10, 99], [11, 29], [11, 65], [11, 77], [11, 80], [11, 84], [12, 26], [12, 36], [12, 39], [12, 43], [12, 53], [12, 54], [12, 58], [12, 70], [12, 103], [12, 107], [12, 116], [12, 118], [13, 19], [13, 21], [13, 25], [13, 29], [13, 39], [13, 65], [13, 68], [13, 74], [13, 78], [13, 81], [14, 19], [14, 21], [14, 51], [14, 76], [14, 87], [14, 88], [14, 92], [14, 99], [14, 100], [14, 107], [14, 109], [14, 112], [15, 19], [15, 26], [15, 49], [15, 67], [15, 72], [15, 83], [15, 93], [15, 99], [15, 115], [16, 22], [16, 41], [16, 62], [16, 64], [16, 80], [16, 82], [16, 97], [17, 42], [17, 81], [17, 83], [18, 28], [18, 47], [18, 49], [18, 60], [18, 67], [18, 69], [18, 76], [18, 82], [18, 94], [18, 96], [18, 104], [18, 115], [19, 41], [19, 46], [19, 57], [19, 65], [19, 83], [19, 96], [19, 115], [20, 25], [20, 44], [20, 66], [20, 70], [20, 73], [21, 43], [21, 64], [21, 70], [21, 101], [22, 57], [22, 86], [22, 105], [23, 42], [23, 88], [23, 97], [24, 26], [24, 28], [24, 30], [24, 50], [24, 55], [24, 64], [24, 68], [24, 75], [24, 88], [24, 94], [24, 113], [25, 30], [25, 42], [25, 51], [25, 97], [25, 111], [25, 114], [26, 31], [26, 73], [26, 75], [26, 92], [26, 97], [26, 110], [27, 86], [27, 103], [28, 34], [28, 44], [28, 54], [28, 62], [28, 69], [28, 85], [28, 95], [28, 99], [28, 102], [29, 49], [29, 66], [29, 85], [29, 110], [29, 113], [30, 103], [30, 104], [30, 116], [31, 39], [31, 44], [31, 49], [31, 50], [31, 63], [31, 68], [31, 79], [31, 98], [31, 109], [32, 49], [32, 86], [32, 92], [32, 109], [33, 44], [33, 73], [33, 78], [33, 88], [33, 90], [34, 60], [34, 65], [34, 100], [34, 104], [34, 109], [35, 39], [35, 46], [35, 54], [35, 69], [35, 77], [35, 85], [36, 42], [36, 60], [36, 99], [36, 100], [36, 110], [37, 64], [37, 65], [37, 70], [37, 80], [37, 83], [37, 97], [37, 100], [37, 103], [38, 44], [38, 47], [38, 57], [38, 59], [38, 67], [38, 69], [38, 72], [38, 88], [38, 89], [38, 93], [38, 94], [38, 104], [38, 105], [39, 52], [39, 61], [39, 75], [39, 102], [39, 108], [40, 96], [40, 98], [40, 113], [40, 115], [40, 116], [41, 45], [41, 47], [41, 58], [41, 68], [41, 71], [41, 81], [42, 43], [42, 62], [42, 91], [42, 116], [43, 47], [43, 51], [43, 59], [43, 60], [43, 68], [43, 72], [43, 87], [43, 94], [43, 113], [44, 83], [45, 68], [45, 86], [45, 88], [45, 101], [46, 57], [46, 77], [46, 98], [46, 104], [46, 112], [46, 114], [47, 53], [47, 62], [47, 79], [47, 98], [47, 103], [47, 116], [47, 118], [48, 52], [48, 54], [48, 61], [48, 87], [48, 113], [48, 118], [48, 119], [49, 52], [49, 73], [49, 80], [49, 103], [49, 113], [50, 62], [50, 73], [50, 78], [50, 92], [50, 100], [51, 84], [51, 85], [52, 63], [52, 89], [52, 92], [52, 98], [52, 99], [52, 109], [53, 86], [53, 88], [53, 110], [54, 68], [54, 89], [54, 97], [54, 100], [54, 113], [55, 58], [55, 74], [55, 92], [55, 100], [55, 102], [55, 115], [56, 77], [56, 101], [56, 104], [56, 117], [57, 58], [57, 61], [57, 72], [57, 103], [58, 68], [58, 75], [58, 76], [58, 84], [58, 86], [58, 94], [59, 116], [60, 62], [60, 63], [61, 64], [61, 84], [61, 85], [61, 92], [61, 93], [61, 94], [61, 111], [62, 84], [62, 93], [63, 73], [63, 81], [63, 92], [63, 116], [64, 72], [64, 91], [64, 95], [64, 102], [64, 112], [65, 79], [65, 82], [65, 95], [65, 97], [65, 110], [66, 83], [66, 98], [66, 104], [66, 113], [67, 79], [67, 98], [68, 81], [68, 113], [69, 73], [69, 78], [69, 82], [69, 96], [70, 93], [70, 115], [71, 84], [71, 87], [71, 95], [71, 117], [72, 78], [72, 79], [72, 96], [72, 114], [72, 119], [73, 84], [73, 85], [73, 88], [73, 95], [73, 96], [73, 110], [73, 111], [73, 115], [73, 117], [74, 75], [74, 85], [74, 95], [74, 98], [74, 107], [74, 111], [75, 106], [75, 107], [76, 82], [76, 106], [76, 111], [76, 115], [77, 119], [78, 85], [78, 86], [78, 95], [78, 108], [78, 109], [78, 113], [79, 84], [79, 88], [79, 91], [80, 112], [81, 84], [81, 117], [84, 96], [84, 103], [84, 113], [85, 92], [85, 103], [86, 97], [86, 114], [86, 115], [87, 93], [88, 92], [88, 106], [88, 115], [88, 117], [88, 118], [88, 119], [89, 98], [89, 114], [90, 98], [90, 116], [91, 96], [91, 115], [91, 116], [91, 119], [92, 93], [93, 97], [93, 101], [93, 108], [94, 99], [94, 106], [94, 107], [95, 97], [96, 112], [98, 116], [99, 105], [99, 118], [101, 107], [102, 108], [102, 110], [103, 105], [107, 110], [110, 119], [112, 114]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s1/solution/solve.sh b/tasks/construct-nppc-3col-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6e23b14609c009b7486af739de912eb2f2c48bd1 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [2, 0, 2, 1, 0, 1, 2, 1, 0, 0, 1, 1, 1, 1, 0, 0, 2, 2, 0, 2, 1, 2, 0, 0, 0, 0, 2, 1, 1, 0, 2, 0, 0, 1, 2, 1, 0, 2, 0, 2, 2, 1, 1, 0, 2, 0, 0, 2, 2, 2, 2, 1, 0, 0, 0, 2, 0, 1, 0, 2, 1, 0, 0, 2, 1, 0, 2, 2, 2, 2, 0, 0, 2, 0, 0, 1, 2, 2, 0, 1, 0, 0, 1, 1, 2, 2, 2, 1, 2, 2, 2, 2, 1, 2, 1, 2, 1, 1, 1, 2, 1, 1, 0, 0, 1, 1, 0, 2, 1, 1, 1, 1, 2, 1, 1, 1, 0, 1, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l6-s1/tests/check.py b/tasks/construct-nppc-3col-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-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-l6-s1/tests/instance.json b/tasks/construct-nppc-3col-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ac851ffec1e278f6a1b3cd9cf0eff3acaf4705e --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 10], [0, 23], [0, 29], [0, 45], [0, 46], [0, 54], [0, 73], [0, 78], [0, 100], [0, 101], [1, 3], [1, 7], [1, 33], [1, 44], [1, 72], [1, 112], [2, 7], [2, 10], [2, 14], [2, 27], [2, 28], [2, 53], [2, 54], [2, 70], [2, 79], [2, 104], [2, 108], [3, 4], [3, 6], [3, 25], [3, 30], [3, 31], [3, 61], [3, 65], [3, 68], [3, 76], [3, 106], [4, 44], [4, 49], [4, 51], [4, 66], [4, 68], [4, 77], [4, 98], [4, 105], [5, 22], [5, 43], [5, 45], [5, 50], [5, 58], [5, 67], [5, 81], [6, 24], [6, 38], [6, 56], [6, 57], [6, 64], [6, 92], [6, 105], [6, 108], [6, 114], [6, 118], [7, 15], [7, 24], [7, 67], [7, 78], [7, 107], [8, 21], [8, 34], [8, 49], [8, 94], [8, 107], [8, 114], [9, 11], [9, 13], [9, 27], [9, 63], [9, 97], [9, 108], [10, 17], [10, 19], [10, 58], [10, 77], [10, 85], [10, 88], [10, 99], [11, 29], [11, 65], [11, 77], [11, 80], [11, 84], [12, 26], [12, 36], [12, 39], [12, 43], [12, 53], [12, 54], [12, 58], [12, 70], [12, 103], [12, 107], [12, 116], [12, 118], [13, 19], [13, 21], [13, 25], [13, 29], [13, 39], [13, 65], [13, 68], [13, 74], [13, 78], [13, 81], [14, 19], [14, 21], [14, 51], [14, 76], [14, 87], [14, 88], [14, 92], [14, 99], [14, 100], [14, 107], [14, 109], [14, 112], [15, 19], [15, 26], [15, 49], [15, 67], [15, 72], [15, 83], [15, 93], [15, 99], [15, 115], [16, 22], [16, 41], [16, 62], [16, 64], [16, 80], [16, 82], [16, 97], [17, 42], [17, 81], [17, 83], [18, 28], [18, 47], [18, 49], [18, 60], [18, 67], [18, 69], [18, 76], [18, 82], [18, 94], [18, 96], [18, 104], [18, 115], [19, 41], [19, 46], [19, 57], [19, 65], [19, 83], [19, 96], [19, 115], [20, 25], [20, 44], [20, 66], [20, 70], [20, 73], [21, 43], [21, 64], [21, 70], [21, 101], [22, 57], [22, 86], [22, 105], [23, 42], [23, 88], [23, 97], [24, 26], [24, 28], [24, 30], [24, 50], [24, 55], [24, 64], [24, 68], [24, 75], [24, 88], [24, 94], [24, 113], [25, 30], [25, 42], [25, 51], [25, 97], [25, 111], [25, 114], [26, 31], [26, 73], [26, 75], [26, 92], [26, 97], [26, 110], [27, 86], [27, 103], [28, 34], [28, 44], [28, 54], [28, 62], [28, 69], [28, 85], [28, 95], [28, 99], [28, 102], [29, 49], [29, 66], [29, 85], [29, 110], [29, 113], [30, 103], [30, 104], [30, 116], [31, 39], [31, 44], [31, 49], [31, 50], [31, 63], [31, 68], [31, 79], [31, 98], [31, 109], [32, 49], [32, 86], [32, 92], [32, 109], [33, 44], [33, 73], [33, 78], [33, 88], [33, 90], [34, 60], [34, 65], [34, 100], [34, 104], [34, 109], [35, 39], [35, 46], [35, 54], [35, 69], [35, 77], [35, 85], [36, 42], [36, 60], [36, 99], [36, 100], [36, 110], [37, 64], [37, 65], [37, 70], [37, 80], [37, 83], [37, 97], [37, 100], [37, 103], [38, 44], [38, 47], [38, 57], [38, 59], [38, 67], [38, 69], [38, 72], [38, 88], [38, 89], [38, 93], [38, 94], [38, 104], [38, 105], [39, 52], [39, 61], [39, 75], [39, 102], [39, 108], [40, 96], [40, 98], [40, 113], [40, 115], [40, 116], [41, 45], [41, 47], [41, 58], [41, 68], [41, 71], [41, 81], [42, 43], [42, 62], [42, 91], [42, 116], [43, 47], [43, 51], [43, 59], [43, 60], [43, 68], [43, 72], [43, 87], [43, 94], [43, 113], [44, 83], [45, 68], [45, 86], [45, 88], [45, 101], [46, 57], [46, 77], [46, 98], [46, 104], [46, 112], [46, 114], [47, 53], [47, 62], [47, 79], [47, 98], [47, 103], [47, 116], [47, 118], [48, 52], [48, 54], [48, 61], [48, 87], [48, 113], [48, 118], [48, 119], [49, 52], [49, 73], [49, 80], [49, 103], [49, 113], [50, 62], [50, 73], [50, 78], [50, 92], [50, 100], [51, 84], [51, 85], [52, 63], [52, 89], [52, 92], [52, 98], [52, 99], [52, 109], [53, 86], [53, 88], [53, 110], [54, 68], [54, 89], [54, 97], [54, 100], [54, 113], [55, 58], [55, 74], [55, 92], [55, 100], [55, 102], [55, 115], [56, 77], [56, 101], [56, 104], [56, 117], [57, 58], [57, 61], [57, 72], [57, 103], [58, 68], [58, 75], [58, 76], [58, 84], [58, 86], [58, 94], [59, 116], [60, 62], [60, 63], [61, 64], [61, 84], [61, 85], [61, 92], [61, 93], [61, 94], [61, 111], [62, 84], [62, 93], [63, 73], [63, 81], [63, 92], [63, 116], [64, 72], [64, 91], [64, 95], [64, 102], [64, 112], [65, 79], [65, 82], [65, 95], [65, 97], [65, 110], [66, 83], [66, 98], [66, 104], [66, 113], [67, 79], [67, 98], [68, 81], [68, 113], [69, 73], [69, 78], [69, 82], [69, 96], [70, 93], [70, 115], [71, 84], [71, 87], [71, 95], [71, 117], [72, 78], [72, 79], [72, 96], [72, 114], [72, 119], [73, 84], [73, 85], [73, 88], [73, 95], [73, 96], [73, 110], [73, 111], [73, 115], [73, 117], [74, 75], [74, 85], [74, 95], [74, 98], [74, 107], [74, 111], [75, 106], [75, 107], [76, 82], [76, 106], [76, 111], [76, 115], [77, 119], [78, 85], [78, 86], [78, 95], [78, 108], [78, 109], [78, 113], [79, 84], [79, 88], [79, 91], [80, 112], [81, 84], [81, 117], [84, 96], [84, 103], [84, 113], [85, 92], [85, 103], [86, 97], [86, 114], [86, 115], [87, 93], [88, 92], [88, 106], [88, 115], [88, 117], [88, 118], [88, 119], [89, 98], [89, 114], [90, 98], [90, 116], [91, 96], [91, 115], [91, 116], [91, 119], [92, 93], [93, 97], [93, 101], [93, 108], [94, 99], [94, 106], [94, 107], [95, 97], [96, 112], [98, 116], [99, 105], [99, 118], [101, 107], [102, 108], [102, 110], [103, 105], [107, 110], [110, 119], [112, 114]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l6-s1/tests/run.py b/tasks/construct-nppc-3col-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s1/tests/test.sh b/tasks/construct-nppc-3col-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-dominating-set-l2-s1/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l2-s1/environment/instance.json b/tasks/construct-nppc-dominating-set-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..59d992466196cc14033f460d1cd815a50d6b588e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 13], [0, 17], [0, 20], [0, 22], [0, 23], [0, 24], [0, 25], [1, 4], [1, 8], [1, 10], [1, 12], [1, 13], [1, 19], [1, 23], [1, 28], [1, 29], [2, 11], [2, 23], [2, 25], [2, 27], [2, 29], [3, 4], [3, 6], [3, 10], [3, 12], [3, 17], [3, 21], [3, 24], [3, 28], [4, 7], [4, 8], [4, 10], [4, 13], [4, 29], [5, 7], [5, 11], [5, 14], [5, 15], [5, 16], [5, 20], [5, 22], [5, 23], [6, 13], [6, 18], [6, 19], [6, 22], [6, 23], [6, 26], [6, 29], [7, 8], [7, 10], [7, 11], [7, 13], [7, 14], [7, 16], [7, 20], [7, 29], [8, 9], [8, 13], [8, 14], [8, 19], [8, 22], [8, 24], [9, 15], [9, 16], [9, 24], [9, 28], [9, 29], [10, 12], [10, 15], [10, 18], [10, 20], [10, 28], [10, 29], [11, 12], [11, 13], [11, 16], [11, 17], [11, 19], [11, 23], [11, 24], [11, 26], [12, 15], [12, 18], [12, 26], [12, 28], [13, 17], [13, 19], [13, 20], [13, 21], [13, 24], [13, 26], [13, 29], [14, 15], [14, 16], [14, 18], [14, 23], [14, 24], [14, 27], [15, 18], [15, 19], [15, 24], [15, 26], [16, 18], [16, 19], [16, 22], [16, 27], [16, 28], [16, 29], [17, 21], [17, 25], [17, 27], [18, 26], [18, 28], [19, 20], [19, 21], [19, 26], [19, 29], [20, 22], [21, 22], [22, 23], [22, 26], [23, 24], [24, 27], [24, 29], [25, 27], [25, 29], [27, 29], [28, 29]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l2-s1/solution/solve.sh b/tasks/construct-nppc-dominating-set-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fccd062e1ad38c134e26178657978c06b20d17bf --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [0, 2, 5, 7, 8, 9, 12, 13, 17, 19, 22, 23, 26, 28, 29]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l2-s1/tests/check.py b/tasks/construct-nppc-dominating-set-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l2-s1/tests/instance.json b/tasks/construct-nppc-dominating-set-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..59d992466196cc14033f460d1cd815a50d6b588e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 13], [0, 17], [0, 20], [0, 22], [0, 23], [0, 24], [0, 25], [1, 4], [1, 8], [1, 10], [1, 12], [1, 13], [1, 19], [1, 23], [1, 28], [1, 29], [2, 11], [2, 23], [2, 25], [2, 27], [2, 29], [3, 4], [3, 6], [3, 10], [3, 12], [3, 17], [3, 21], [3, 24], [3, 28], [4, 7], [4, 8], [4, 10], [4, 13], [4, 29], [5, 7], [5, 11], [5, 14], [5, 15], [5, 16], [5, 20], [5, 22], [5, 23], [6, 13], [6, 18], [6, 19], [6, 22], [6, 23], [6, 26], [6, 29], [7, 8], [7, 10], [7, 11], [7, 13], [7, 14], [7, 16], [7, 20], [7, 29], [8, 9], [8, 13], [8, 14], [8, 19], [8, 22], [8, 24], [9, 15], [9, 16], [9, 24], [9, 28], [9, 29], [10, 12], [10, 15], [10, 18], [10, 20], [10, 28], [10, 29], [11, 12], [11, 13], [11, 16], [11, 17], [11, 19], [11, 23], [11, 24], [11, 26], [12, 15], [12, 18], [12, 26], [12, 28], [13, 17], [13, 19], [13, 20], [13, 21], [13, 24], [13, 26], [13, 29], [14, 15], [14, 16], [14, 18], [14, 23], [14, 24], [14, 27], [15, 18], [15, 19], [15, 24], [15, 26], [16, 18], [16, 19], [16, 22], [16, 27], [16, 28], [16, 29], [17, 21], [17, 25], [17, 27], [18, 26], [18, 28], [19, 20], [19, 21], [19, 26], [19, 29], [20, 22], [21, 22], [22, 23], [22, 26], [23, 24], [24, 27], [24, 29], [25, 27], [25, 29], [27, 29], [28, 29]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l2-s1/tests/run.py b/tasks/construct-nppc-dominating-set-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l2-s1/tests/test.sh b/tasks/construct-nppc-dominating-set-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l2-s6/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l2-s6/environment/instance.json b/tasks/construct-nppc-dominating-set-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..656bd96ada35a19b58e529de89b918bff1363521 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 4], [0, 5], [0, 10], [0, 11], [0, 22], [1, 2], [1, 4], [1, 6], [1, 10], [1, 13], [1, 14], [1, 16], [1, 18], [1, 20], [1, 26], [2, 8], [2, 10], [2, 13], [2, 25], [2, 27], [2, 28], [2, 29], [3, 4], [3, 5], [3, 13], [3, 14], [3, 15], [3, 16], [3, 18], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [4, 7], [4, 12], [4, 14], [4, 15], [4, 18], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 29], [5, 12], [5, 14], [5, 15], [5, 21], [5, 22], [5, 24], [5, 28], [6, 16], [6, 17], [6, 19], [6, 20], [6, 23], [6, 24], [6, 26], [6, 27], [7, 10], [7, 15], [7, 16], [7, 19], [7, 24], [7, 27], [7, 28], [8, 10], [8, 18], [8, 23], [8, 28], [8, 29], [9, 12], [9, 17], [9, 18], [9, 23], [9, 29], [10, 13], [10, 15], [10, 19], [10, 20], [10, 23], [10, 24], [10, 26], [10, 28], [11, 12], [11, 13], [11, 14], [11, 16], [11, 17], [11, 19], [11, 21], [11, 24], [11, 25], [12, 23], [12, 27], [13, 16], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [13, 29], [14, 15], [14, 17], [14, 19], [14, 22], [14, 23], [14, 26], [14, 27], [15, 18], [15, 20], [15, 21], [15, 22], [15, 26], [15, 27], [15, 28], [16, 17], [16, 19], [16, 21], [16, 25], [16, 26], [16, 27], [16, 28], [17, 27], [17, 28], [18, 19], [18, 22], [18, 29], [19, 22], [19, 24], [19, 26], [19, 28], [20, 25], [20, 26], [20, 27], [20, 28], [21, 22], [21, 23], [21, 25], [21, 26], [21, 27], [21, 28], [22, 25], [22, 26], [22, 28], [24, 26], [24, 28], [25, 26], [25, 28], [26, 27], [26, 29], [27, 29], [28, 29]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l2-s6/solution/solve.sh b/tasks/construct-nppc-dominating-set-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b26e18e5c2c91dd63b55f2c53294745bc286523e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [1, 4, 5, 11, 13, 14, 15, 16, 19, 20, 23, 24, 26, 28, 29]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l2-s6/tests/check.py b/tasks/construct-nppc-dominating-set-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l2-s6/tests/instance.json b/tasks/construct-nppc-dominating-set-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..656bd96ada35a19b58e529de89b918bff1363521 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 4], [0, 5], [0, 10], [0, 11], [0, 22], [1, 2], [1, 4], [1, 6], [1, 10], [1, 13], [1, 14], [1, 16], [1, 18], [1, 20], [1, 26], [2, 8], [2, 10], [2, 13], [2, 25], [2, 27], [2, 28], [2, 29], [3, 4], [3, 5], [3, 13], [3, 14], [3, 15], [3, 16], [3, 18], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [4, 7], [4, 12], [4, 14], [4, 15], [4, 18], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 29], [5, 12], [5, 14], [5, 15], [5, 21], [5, 22], [5, 24], [5, 28], [6, 16], [6, 17], [6, 19], [6, 20], [6, 23], [6, 24], [6, 26], [6, 27], [7, 10], [7, 15], [7, 16], [7, 19], [7, 24], [7, 27], [7, 28], [8, 10], [8, 18], [8, 23], [8, 28], [8, 29], [9, 12], [9, 17], [9, 18], [9, 23], [9, 29], [10, 13], [10, 15], [10, 19], [10, 20], [10, 23], [10, 24], [10, 26], [10, 28], [11, 12], [11, 13], [11, 14], [11, 16], [11, 17], [11, 19], [11, 21], [11, 24], [11, 25], [12, 23], [12, 27], [13, 16], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [13, 25], [13, 26], [13, 29], [14, 15], [14, 17], [14, 19], [14, 22], [14, 23], [14, 26], [14, 27], [15, 18], [15, 20], [15, 21], [15, 22], [15, 26], [15, 27], [15, 28], [16, 17], [16, 19], [16, 21], [16, 25], [16, 26], [16, 27], [16, 28], [17, 27], [17, 28], [18, 19], [18, 22], [18, 29], [19, 22], [19, 24], [19, 26], [19, 28], [20, 25], [20, 26], [20, 27], [20, 28], [21, 22], [21, 23], [21, 25], [21, 26], [21, 27], [21, 28], [22, 25], [22, 26], [22, 28], [24, 26], [24, 28], [25, 26], [25, 28], [26, 27], [26, 29], [27, 29], [28, 29]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l2-s6/tests/run.py b/tasks/construct-nppc-dominating-set-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l2-s6/tests/test.sh b/tasks/construct-nppc-dominating-set-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l2-s8/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l2-s8/environment/instance.json b/tasks/construct-nppc-dominating-set-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23f917ca410959bf059fe9723536919c26a9db1f --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 4], [0, 5], [0, 10], [0, 13], [0, 17], [0, 18], [0, 19], [0, 26], [1, 2], [1, 3], [1, 4], [1, 6], [1, 15], [1, 18], [1, 26], [1, 29], [2, 4], [2, 5], [2, 6], [2, 7], [2, 13], [2, 16], [2, 19], [2, 23], [2, 24], [2, 28], [2, 29], [3, 9], [3, 10], [3, 14], [3, 15], [3, 16], [3, 17], [3, 20], [3, 22], [3, 23], [3, 28], [4, 9], [4, 10], [4, 13], [4, 14], [4, 17], [4, 21], [4, 23], [4, 25], [4, 27], [5, 8], [5, 12], [5, 13], [5, 15], [5, 16], [5, 19], [5, 24], [5, 29], [6, 7], [6, 9], [6, 11], [6, 12], [6, 17], [6, 18], [6, 19], [6, 21], [6, 23], [6, 25], [6, 26], [6, 29], [7, 13], [7, 14], [8, 23], [8, 29], [9, 12], [9, 13], [9, 14], [9, 16], [9, 18], [9, 21], [9, 23], [9, 24], [9, 28], [10, 19], [10, 24], [11, 16], [11, 19], [11, 20], [11, 22], [11, 23], [11, 25], [11, 26], [12, 18], [12, 20], [12, 21], [12, 26], [12, 29], [13, 14], [13, 15], [13, 18], [13, 24], [13, 25], [14, 20], [14, 21], [14, 22], [14, 23], [14, 27], [14, 29], [15, 16], [15, 28], [15, 29], [16, 26], [17, 18], [17, 19], [17, 25], [17, 28], [18, 28], [19, 24], [19, 25], [19, 27], [20, 22], [20, 23], [20, 29], [21, 22], [21, 23], [21, 25], [21, 26], [21, 28], [23, 27], [24, 25], [24, 27], [25, 26], [25, 28], [26, 27]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l2-s8/solution/solve.sh b/tasks/construct-nppc-dominating-set-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..51076c280774b9fc5a26b595ed59b5e081a43553 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [1, 2, 4, 6, 7, 8, 10, 15, 18, 19, 20, 22, 23, 24, 27]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l2-s8/tests/check.py b/tasks/construct-nppc-dominating-set-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/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-l2-s8/tests/instance.json b/tasks/construct-nppc-dominating-set-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23f917ca410959bf059fe9723536919c26a9db1f --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 4], [0, 5], [0, 10], [0, 13], [0, 17], [0, 18], [0, 19], [0, 26], [1, 2], [1, 3], [1, 4], [1, 6], [1, 15], [1, 18], [1, 26], [1, 29], [2, 4], [2, 5], [2, 6], [2, 7], [2, 13], [2, 16], [2, 19], [2, 23], [2, 24], [2, 28], [2, 29], [3, 9], [3, 10], [3, 14], [3, 15], [3, 16], [3, 17], [3, 20], [3, 22], [3, 23], [3, 28], [4, 9], [4, 10], [4, 13], [4, 14], [4, 17], [4, 21], [4, 23], [4, 25], [4, 27], [5, 8], [5, 12], [5, 13], [5, 15], [5, 16], [5, 19], [5, 24], [5, 29], [6, 7], [6, 9], [6, 11], [6, 12], [6, 17], [6, 18], [6, 19], [6, 21], [6, 23], [6, 25], [6, 26], [6, 29], [7, 13], [7, 14], [8, 23], [8, 29], [9, 12], [9, 13], [9, 14], [9, 16], [9, 18], [9, 21], [9, 23], [9, 24], [9, 28], [10, 19], [10, 24], [11, 16], [11, 19], [11, 20], [11, 22], [11, 23], [11, 25], [11, 26], [12, 18], [12, 20], [12, 21], [12, 26], [12, 29], [13, 14], [13, 15], [13, 18], [13, 24], [13, 25], [14, 20], [14, 21], [14, 22], [14, 23], [14, 27], [14, 29], [15, 16], [15, 28], [15, 29], [16, 26], [17, 18], [17, 19], [17, 25], [17, 28], [18, 28], [19, 24], [19, 25], [19, 27], [20, 22], [20, 23], [20, 29], [21, 22], [21, 23], [21, 25], [21, 26], [21, 28], [23, 27], [24, 25], [24, 27], [25, 26], [25, 28], [26, 27]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l2-s8/tests/run.py b/tasks/construct-nppc-dominating-set-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l2-s8/tests/test.sh b/tasks/construct-nppc-dominating-set-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l5-s5/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l5-s5/environment/instance.json b/tasks/construct-nppc-dominating-set-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dc28d3f02fb769fd2409d9dce104d5f812938cf7 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 1], [0, 9], [0, 16], [0, 18], [0, 21], [0, 32], [0, 33], [0, 36], [0, 39], [0, 40], [0, 44], [0, 47], [0, 52], [0, 58], [0, 63], [0, 72], [0, 73], [0, 75], [0, 76], [0, 77], [0, 80], [0, 86], [0, 93], [0, 97], [0, 103], [0, 105], [0, 108], [0, 111], [0, 112], [0, 113], [0, 119], [0, 125], [0, 133], [0, 137], [0, 139], [0, 145], [0, 152], [0, 157], [0, 158], [0, 163], [0, 165], [0, 169], [0, 174], [0, 177], [1, 5], [1, 6], [1, 11], [1, 20], [1, 22], [1, 30], [1, 37], [1, 55], [1, 62], [1, 64], [1, 76], [1, 77], [1, 81], [1, 83], [1, 91], [1, 104], [1, 117], [1, 120], [1, 123], [1, 125], [1, 126], [1, 128], [1, 129], [1, 133], [1, 144], [1, 145], [1, 152], [1, 157], [1, 160], [1, 163], [1, 164], [1, 169], [2, 8], [2, 9], [2, 12], [2, 24], [2, 25], [2, 27], [2, 34], [2, 35], [2, 37], [2, 41], [2, 42], [2, 50], [2, 52], [2, 55], [2, 56], [2, 68], [2, 77], [2, 79], [2, 81], [2, 91], [2, 96], [2, 104], [2, 105], [2, 109], [2, 111], [2, 112], [2, 113], [2, 114], [2, 128], [2, 129], [2, 130], [2, 132], [2, 137], [2, 139], [2, 140], [2, 143], [2, 150], [2, 152], [2, 157], [2, 159], [2, 170], [3, 6], [3, 20], [3, 21], [3, 26], [3, 38], [3, 42], [3, 43], [3, 52], [3, 59], [3, 61], [3, 65], [3, 68], [3, 76], [3, 78], [3, 87], [3, 88], [3, 97], [3, 99], [3, 104], [3, 111], [3, 115], [3, 118], [3, 126], [3, 130], [3, 132], [3, 146], [3, 153], [3, 156], [3, 161], [3, 177], [4, 8], [4, 9], [4, 15], [4, 21], [4, 37], [4, 40], [4, 41], [4, 42], [4, 48], [4, 55], [4, 58], [4, 63], [4, 65], [4, 68], [4, 69], [4, 71], [4, 73], [4, 79], [4, 81], [4, 86], [4, 87], [4, 88], [4, 89], [4, 95], [4, 100], [4, 101], [4, 102], [4, 108], [4, 111], [4, 130], [4, 131], [4, 145], [4, 148], [4, 150], [4, 152], [4, 157], [4, 159], [4, 164], [4, 175], [4, 178], [5, 11], [5, 12], [5, 19], [5, 22], [5, 23], [5, 27], [5, 34], [5, 36], [5, 44], [5, 45], [5, 51], [5, 54], [5, 56], [5, 60], [5, 67], [5, 70], [5, 72], [5, 79], [5, 86], [5, 88], [5, 96], [5, 105], [5, 106], [5, 108], [5, 113], [5, 124], [5, 127], [5, 134], [5, 135], [5, 142], [5, 147], [5, 159], [5, 162], [5, 166], [5, 169], [5, 174], [6, 7], [6, 9], [6, 19], [6, 21], [6, 27], [6, 28], [6, 29], [6, 37], [6, 38], [6, 39], [6, 45], [6, 47], [6, 54], [6, 55], [6, 61], [6, 63], [6, 68], [6, 69], [6, 74], [6, 77], [6, 78], [6, 100], [6, 103], [6, 105], [6, 108], [6, 111], [6, 113], [6, 115], [6, 126], [6, 129], [6, 134], [6, 135], [6, 140], [6, 151], [6, 155], [6, 168], [6, 171], [7, 25], [7, 31], [7, 34], [7, 37], [7, 39], [7, 42], [7, 49], [7, 50], [7, 62], [7, 63], [7, 67], [7, 75], [7, 80], [7, 88], [7, 89], [7, 91], [7, 92], [7, 93], [7, 99], [7, 107], [7, 112], [7, 115], [7, 126], [7, 132], [7, 137], [7, 140], [7, 145], [7, 147], [7, 162], [7, 163], [7, 165], [7, 176], [7, 178], [8, 10], [8, 12], [8, 14], [8, 16], [8, 18], [8, 19], [8, 22], [8, 24], [8, 28], [8, 37], [8, 42], [8, 49], [8, 50], [8, 51], [8, 52], [8, 56], [8, 64], [8, 67], [8, 68], [8, 69], [8, 70], [8, 74], [8, 76], [8, 78], [8, 82], [8, 86], [8, 89], [8, 102], [8, 110], [8, 116], [8, 118], [8, 121], [8, 124], [8, 126], [8, 127], [8, 129], [8, 143], [8, 145], [8, 159], [8, 163], [8, 170], [8, 171], [8, 176], [8, 178], [9, 12], [9, 13], [9, 23], [9, 27], [9, 38], [9, 43], [9, 46], [9, 47], [9, 50], [9, 57], [9, 65], [9, 72], [9, 73], [9, 78], [9, 82], [9, 83], [9, 97], [9, 107], [9, 115], [9, 124], [9, 125], [9, 129], [9, 130], [9, 139], [9, 146], [9, 147], [9, 161], [9, 164], [9, 172], [9, 176], [10, 11], [10, 16], [10, 17], [10, 28], [10, 34], [10, 35], [10, 38], [10, 52], [10, 54], [10, 64], [10, 69], [10, 78], [10, 91], [10, 106], [10, 111], [10, 115], [10, 117], [10, 121], [10, 134], [10, 135], [10, 140], [10, 152], [10, 157], [10, 167], [10, 170], [10, 174], [10, 177], [10, 178], [11, 22], [11, 27], [11, 34], [11, 36], [11, 44], [11, 46], [11, 50], [11, 57], [11, 59], [11, 64], [11, 73], [11, 74], [11, 83], [11, 95], [11, 111], [11, 113], [11, 114], [11, 119], [11, 137], [11, 143], [11, 145], [11, 148], [11, 151], [11, 152], [11, 154], [11, 162], [11, 165], [11, 174], [11, 178], [12, 15], [12, 22], [12, 35], [12, 41], [12, 43], [12, 45], [12, 49], [12, 50], [12, 51], [12, 54], [12, 56], [12, 59], [12, 62], [12, 67], [12, 75], [12, 79], [12, 85], [12, 86], [12, 87], [12, 93], [12, 98], [12, 101], [12, 102], [12, 103], [12, 108], [12, 113], [12, 118], [12, 122], [12, 124], [12, 126], [12, 138], [12, 143], [12, 164], [12, 165], [12, 167], [12, 176], [13, 22], [13, 27], [13, 32], [13, 40], [13, 44], [13, 50], [13, 56], [13, 65], [13, 83], [13, 87], [13, 94], [13, 102], [13, 106], [13, 113], [13, 115], [13, 117], [13, 123], [13, 130], [13, 137], [13, 141], [13, 143], [13, 164], [13, 165], [13, 169], [13, 170], [13, 172], [13, 179], [14, 21], [14, 25], [14, 31], [14, 32], [14, 37], [14, 47], [14, 57], [14, 58], [14, 60], [14, 66], [14, 67], [14, 69], [14, 92], [14, 93], [14, 103], [14, 108], [14, 111], [14, 114], [14, 125], [14, 127], [14, 129], [14, 131], [14, 153], [14, 163], [14, 166], [14, 172], [14, 174], [15, 18], [15, 25], [15, 30], [15, 31], [15, 34], [15, 35], [15, 40], [15, 50], [15, 56], [15, 63], [15, 65], [15, 66], [15, 71], [15, 78], [15, 81], [15, 85], [15, 92], [15, 104], [15, 110], [15, 111], [15, 115], [15, 117], [15, 129], [15, 130], [15, 137], [15, 145], [15, 151], [15, 152], [15, 154], [15, 161], [15, 163], [15, 170], [15, 174], [15, 178], [16, 20], [16, 21], [16, 23], [16, 27], [16, 29], [16, 33], [16, 37], [16, 47], [16, 50], [16, 57], [16, 59], [16, 67], [16, 68], [16, 84], [16, 95], [16, 105], [16, 112], [16, 113], [16, 117], [16, 124], [16, 126], [16, 127], [16, 130], [16, 135], [16, 136], [16, 137], [16, 145], [16, 146], [16, 149], [16, 150], [16, 154], [16, 155], [16, 167], [16, 169], [16, 170], [16, 178], [16, 179], [17, 23], [17, 24], [17, 25], [17, 33], [17, 42], [17, 60], [17, 78], [17, 79], [17, 82], [17, 93], [17, 94], [17, 99], [17, 100], [17, 104], [17, 112], [17, 119], [17, 123], [17, 127], [17, 133], [17, 136], [17, 137], [17, 138], [17, 139], [17, 142], [17, 150], [17, 157], [17, 159], [17, 165], [17, 170], [17, 172], [17, 173], [17, 174], [17, 177], [18, 45], [18, 46], [18, 51], [18, 52], [18, 53], [18, 54], [18, 56], [18, 60], [18, 67], [18, 73], [18, 75], [18, 78], [18, 79], [18, 83], [18, 86], [18, 89], [18, 90], [18, 95], [18, 97], [18, 98], [18, 104], [18, 106], [18, 108], [18, 113], [18, 116], [18, 124], [18, 134], [18, 141], [18, 145], [18, 151], [18, 153], [18, 164], [18, 165], [18, 166], [18, 174], [18, 179], [19, 24], [19, 25], [19, 26], [19, 30], [19, 32], [19, 40], [19, 47], [19, 54], [19, 58], [19, 62], [19, 64], [19, 65], [19, 69], [19, 75], [19, 77], [19, 79], [19, 83], [19, 87], [19, 94], [19, 104], [19, 105], [19, 109], [19, 115], [19, 116], [19, 133], [19, 139], [19, 152], [19, 153], [19, 154], [19, 161], [19, 162], [19, 164], [19, 167], [19, 169], [19, 172], [20, 27], [20, 46], [20, 51], [20, 59], [20, 65], [20, 76], [20, 83], [20, 90], [20, 92], [20, 94], [20, 102], [20, 105], [20, 111], [20, 123], [20, 133], [20, 134], [20, 148], [20, 150], [21, 24], [21, 25], [21, 36], [21, 38], [21, 43], [21, 54], [21, 58], [21, 61], [21, 62], [21, 67], [21, 69], [21, 72], [21, 75], [21, 81], [21, 87], [21, 88], [21, 92], [21, 94], [21, 98], [21, 104], [21, 106], [21, 114], [21, 122], [21, 124], [21, 125], [21, 127], [21, 128], [21, 136], [21, 138], [21, 148], [21, 155], [21, 176], [21, 177], [22, 23], [22, 30], [22, 39], [22, 40], [22, 41], [22, 57], [22, 62], [22, 68], [22, 69], [22, 70], [22, 72], [22, 75], [22, 77], [22, 81], [22, 88], [22, 89], [22, 94], [22, 95], [22, 97], [22, 109], [22, 110], [22, 116], [22, 119], [22, 121], [22, 125], [22, 126], [22, 144], [22, 145], [22, 146], [22, 149], [22, 152], [22, 154], [22, 157], [22, 167], [22, 174], [23, 28], [23, 29], [23, 31], [23, 32], [23, 37], [23, 39], [23, 41], [23, 47], [23, 49], [23, 54], [23, 55], [23, 64], [23, 65], [23, 73], [23, 75], [23, 78], [23, 79], [23, 86], [23, 88], [23, 90], [23, 94], [23, 99], [23, 100], [23, 102], [23, 111], [23, 113], [23, 115], [23, 124], [23, 131], [23, 133], [23, 136], [23, 137], [23, 138], [23, 139], [23, 140], [23, 142], [23, 144], [23, 147], [23, 150], [23, 157], [23, 159], [23, 167], [23, 168], [23, 173], [23, 175], [23, 179], [24, 26], [24, 27], [24, 34], [24, 43], [24, 49], [24, 53], [24, 70], [24, 72], [24, 76], [24, 78], [24, 90], [24, 94], [24, 95], [24, 99], [24, 100], [24, 105], [24, 113], [24, 114], [24, 116], [24, 118], [24, 124], [24, 127], [24, 128], [24, 129], [24, 134], [24, 135], [24, 136], [24, 139], [24, 144], [24, 151], [24, 155], [24, 156], [24, 158], [24, 161], [24, 167], [24, 172], [25, 32], [25, 37], [25, 39], [25, 43], [25, 46], [25, 60], [25, 65], [25, 74], [25, 76], [25, 77], [25, 79], [25, 86], [25, 91], [25, 102], [25, 106], [25, 107], [25, 108], [25, 110], [25, 111], [25, 113], [25, 126], [25, 127], [25, 129], [25, 133], [25, 137], [25, 140], [25, 153], [25, 168], [25, 173], [26, 34], [26, 48], [26, 52], [26, 54], [26, 58], [26, 60], [26, 62], [26, 64], [26, 69], [26, 76], [26, 77], [26, 82], [26, 85], [26, 86], [26, 89], [26, 90], [26, 91], [26, 97], [26, 98], [26, 99], [26, 101], [26, 104], [26, 108], [26, 112], [26, 115], [26, 117], [26, 118], [26, 125], [26, 131], [26, 132], [26, 138], [26, 139], [26, 146], [26, 150], [26, 166], [26, 168], [26, 173], [27, 30], [27, 36], [27, 49], [27, 56], [27, 57], [27, 58], [27, 72], [27, 76], [27, 78], [27, 89], [27, 90], [27, 93], [27, 95], [27, 103], [27, 104], [27, 105], [27, 116], [27, 121], [27, 126], [27, 127], [27, 131], [27, 137], [27, 145], [27, 149], [27, 162], [27, 165], [27, 166], [27, 170], [27, 172], [27, 173], [27, 179], [28, 36], [28, 43], [28, 47], [28, 51], [28, 58], [28, 59], [28, 62], [28, 66], [28, 68], [28, 70], [28, 71], [28, 73], [28, 74], [28, 75], [28, 76], [28, 95], [28, 97], [28, 107], [28, 110], [28, 121], [28, 135], [28, 138], [28, 141], [28, 146], [28, 164], [28, 167], [29, 31], [29, 53], [29, 60], [29, 69], [29, 72], [29, 75], [29, 76], [29, 77], [29, 82], [29, 83], [29, 91], [29, 98], [29, 113], [29, 120], [29, 121], [29, 123], [29, 126], [29, 133], [29, 148], [29, 150], [29, 167], [29, 169], [30, 33], [30, 38], [30, 41], [30, 42], [30, 43], [30, 52], [30, 57], [30, 63], [30, 72], [30, 81], [30, 83], [30, 84], [30, 89], [30, 90], [30, 96], [30, 97], [30, 102], [30, 105], [30, 108], [30, 115], [30, 126], [30, 127], [30, 134], [30, 136], [30, 137], [30, 138], [30, 139], [30, 140], [30, 141], [30, 151], [30, 163], [30, 165], [30, 168], [30, 169], [30, 171], [31, 35], [31, 39], [31, 43], [31, 52], [31, 69], [31, 70], [31, 85], [31, 86], [31, 90], [31, 91], [31, 120], [31, 123], [31, 126], [31, 132], [31, 135], [31, 151], [31, 157], [31, 172], [31, 177], [32, 33], [32, 36], [32, 37], [32, 41], [32, 48], [32, 52], [32, 54], [32, 61], [32, 68], [32, 71], [32, 75], [32, 77], [32, 87], [32, 92], [32, 94], [32, 98], [32, 100], [32, 105], [32, 107], [32, 112], [32, 115], [32, 116], [32, 121], [32, 138], [32, 140], [32, 141], [32, 152], [32, 156], [32, 162], [32, 166], [32, 167], [32, 168], [32, 169], [32, 178], [33, 35], [33, 42], [33, 50], [33, 53], [33, 59], [33, 66], [33, 67], [33, 68], [33, 79], [33, 80], [33, 90], [33, 96], [33, 100], [33, 102], [33, 104], [33, 108], [33, 109], [33, 121], [33, 122], [33, 125], [33, 131], [33, 148], [33, 151], [33, 153], [33, 178], [34, 39], [34, 45], [34, 46], [34, 50], [34, 57], [34, 65], [34, 68], [34, 70], [34, 71], [34, 78], [34, 84], [34, 85], [34, 89], [34, 92], [34, 104], [34, 112], [34, 115], [34, 121], [34, 123], [34, 124], [34, 129], [34, 131], [34, 132], [34, 134], [34, 139], [34, 148], [34, 150], [34, 151], [34, 155], [34, 161], [34, 163], [34, 173], [34, 179], [35, 39], [35, 42], [35, 43], [35, 54], [35, 55], [35, 56], [35, 67], [35, 74], [35, 85], [35, 90], [35, 92], [35, 93], [35, 99], [35, 109], [35, 112], [35, 113], [35, 115], [35, 120], [35, 121], [35, 123], [35, 126], [35, 133], [35, 134], [35, 137], [35, 138], [35, 140], [35, 141], [35, 144], [35, 149], [35, 150], [35, 151], [35, 153], [35, 157], [35, 163], [35, 168], [35, 171], [35, 174], [35, 178], [35, 179], [36, 39], [36, 43], [36, 50], [36, 60], [36, 63], [36, 72], [36, 84], [36, 97], [36, 99], [36, 100], [36, 102], [36, 110], [36, 127], [36, 140], [36, 141], [36, 144], [36, 146], [36, 147], [36, 150], [36, 171], [36, 173], [36, 175], [37, 38], [37, 46], [37, 47], [37, 48], [37, 55], [37, 59], [37, 63], [37, 67], [37, 70], [37, 81], [37, 82], [37, 84], [37, 85], [37, 86], [37, 91], [37, 92], [37, 94], [37, 96], [37, 102], [37, 106], [37, 110], [37, 117], [37, 119], [37, 120], [37, 124], [37, 127], [37, 128], [37, 131], [37, 132], [37, 135], [37, 137], [37, 138], [37, 148], [37, 153], [37, 154], [37, 158], [37, 162], [37, 163], [37, 169], [37, 171], [37, 178], [38, 42], [38, 49], [38, 50], [38, 52], [38, 54], [38, 55], [38, 56], [38, 60], [38, 61], [38, 71], [38, 72], [38, 75], [38, 79], [38, 84], [38, 87], [38, 105], [38, 115], [38, 119], [38, 123], [38, 126], [38, 133], [38, 136], [38, 137], [38, 138], [38, 142], [38, 144], [38, 148], [38, 151], [38, 153], [38, 156], [38, 157], [38, 162], [38, 164], [38, 171], [39, 43], [39, 45], [39, 52], [39, 58], [39, 65], [39, 68], [39, 71], [39, 72], [39, 74], [39, 76], [39, 78], [39, 80], [39, 95], [39, 96], [39, 97], [39, 111], [39, 113], [39, 121], [39, 124], [39, 129], [39, 132], [39, 135], [39, 150], [39, 154], [39, 160], [39, 162], [39, 167], [39, 169], [39, 170], [39, 171], [39, 174], [39, 176], [39, 177], [39, 178], [40, 42], [40, 44], [40, 47], [40, 51], [40, 69], [40, 86], [40, 87], [40, 89], [40, 90], [40, 96], [40, 100], [40, 107], [40, 120], [40, 130], [40, 131], [40, 132], [40, 138], [40, 143], [40, 150], [40, 151], [40, 161], [40, 165], [40, 166], [41, 46], [41, 50], [41, 55], [41, 56], [41, 73], [41, 88], [41, 90], [41, 92], [41, 97], [41, 103], [41, 104], [41, 105], [41, 106], [41, 107], [41, 108], [41, 110], [41, 129], [41, 133], [41, 142], [41, 159], [41, 162], [41, 164], [41, 173], [41, 177], [41, 178], [42, 50], [42, 53], [42, 70], [42, 75], [42, 80], [42, 87], [42, 90], [42, 91], [42, 92], [42, 94], [42, 105], [42, 117], [42, 121], [42, 128], [42, 131], [42, 137], [42, 139], [42, 140], [42, 172], [42, 173], [43, 52], [43, 56], [43, 59], [43, 61], [43, 64], [43, 65], [43, 73], [43, 82], [43, 83], [43, 85], [43, 88], [43, 103], [43, 104], [43, 121], [43, 122], [43, 125], [43, 133], [43, 137], [43, 139], [43, 148], [43, 154], [43, 158], [43, 168], [43, 169], [43, 176], [44, 52], [44, 54], [44, 61], [44, 67], [44, 75], [44, 76], [44, 79], [44, 81], [44, 83], [44, 85], [44, 87], [44, 88], [44, 91], [44, 98], [44, 103], [44, 105], [44, 108], [44, 115], [44, 116], [44, 120], [44, 125], [44, 132], [44, 136], [44, 140], [44, 158], [44, 160], [44, 161], [44, 170], [44, 172], [45, 67], [45, 70], [45, 73], [45, 85], [45, 88], [45, 89], [45, 95], [45, 98], [45, 102], [45, 105], [45, 107], [45, 108], [45, 111], [45, 118], [45, 125], [45, 132], [45, 141], [45, 142], [45, 145], [45, 152], [45, 162], [45, 166], [46, 61], [46, 67], [46, 71], [46, 77], [46, 79], [46, 83], [46, 86], [46, 87], [46, 88], [46, 94], [46, 97], [46, 98], [46, 102], [46, 108], [46, 115], [46, 116], [46, 118], [46, 128], [46, 132], [46, 136], [46, 141], [46, 144], [46, 157], [46, 159], [46, 161], [46, 168], [46, 169], [46, 173], [46, 175], [47, 52], [47, 53], [47, 57], [47, 59], [47, 60], [47, 71], [47, 77], [47, 89], [47, 91], [47, 99], [47, 101], [47, 108], [47, 109], [47, 116], [47, 119], [47, 123], [47, 127], [47, 130], [47, 134], [47, 149], [47, 152], [47, 158], [47, 162], [47, 167], [47, 174], [47, 175], [47, 179], [48, 63], [48, 64], [48, 66], [48, 73], [48, 74], [48, 77], [48, 78], [48, 81], [48, 87], [48, 93], [48, 94], [48, 96], [48, 102], [48, 104], [48, 108], [48, 111], [48, 113], [48, 125], [48, 130], [48, 134], [48, 142], [48, 145], [48, 147], [48, 149], [48, 151], [48, 155], [48, 156], [48, 164], [48, 165], [48, 170], [49, 52], [49, 59], [49, 63], [49, 65], [49, 68], [49, 70], [49, 77], [49, 78], [49, 89], [49, 92], [49, 96], [49, 100], [49, 102], [49, 112], [49, 116], [49, 122], [49, 125], [49, 138], [49, 139], [49, 142], [49, 144], [49, 148], [49, 149], [49, 151], [49, 154], [49, 158], [49, 160], [49, 164], [49, 173], [49, 178], [50, 60], [50, 62], [50, 65], [50, 66], [50, 75], [50, 87], [50, 92], [50, 99], [50, 101], [50, 113], [50, 114], [50, 117], [50, 127], [50, 129], [50, 135], [50, 144], [50, 157], [50, 161], [50, 170], [50, 179], [51, 57], [51, 62], [51, 75], [51, 80], [51, 89], [51, 95], [51, 103], [51, 104], [51, 111], [51, 116], [51, 117], [51, 118], [51, 123], [51, 124], [51, 132], [51, 143], [51, 159], [51, 161], [51, 167], [51, 172], [51, 176], [51, 177], [52, 56], [52, 63], [52, 65], [52, 70], [52, 73], [52, 74], [52, 78], [52, 80], [52, 82], [52, 89], [52, 91], [52, 93], [52, 94], [52, 95], [52, 98], [52, 101], [52, 112], [52, 115], [52, 120], [52, 128], [52, 133], [52, 136], [52, 141], [52, 143], [52, 144], [52, 145], [52, 150], [52, 152], [52, 158], [52, 159], [52, 166], [52, 168], [52, 169], [52, 172], [52, 175], [52, 176], [53, 55], [53, 61], [53, 62], [53, 63], [53, 76], [53, 79], [53, 83], [53, 92], [53, 94], [53, 103], [53, 107], [53, 109], [53, 115], [53, 116], [53, 118], [53, 121], [53, 133], [53, 134], [53, 141], [53, 144], [53, 154], [53, 162], [53, 167], [53, 172], [53, 177], [54, 55], [54, 70], [54, 72], [54, 74], [54, 77], [54, 79], [54, 80], [54, 83], [54, 94], [54, 97], [54, 100], [54, 103], [54, 105], [54, 111], [54, 114], [54, 115], [54, 130], [54, 144], [54, 145], [54, 148], [54, 150], [54, 168], [54, 175], [54, 178], [55, 60], [55, 63], [55, 70], [55, 71], [55, 73], [55, 74], [55, 77], [55, 78], [55, 94], [55, 99], [55, 103], [55, 108], [55, 111], [55, 112], [55, 117], [55, 126], [55, 137], [55, 144], [55, 149], [55, 152], [55, 154], [55, 171], [55, 176], [56, 58], [56, 62], [56, 81], [56, 83], [56, 92], [56, 94], [56, 96], [56, 120], [56, 121], [56, 122], [56, 124], [56, 129], [56, 135], [56, 141], [56, 147], [56, 150], [56, 151], [56, 155], [56, 164], [56, 169], [56, 173], [56, 177], [56, 179], [57, 59], [57, 64], [57, 67], [57, 68], [57, 69], [57, 75], [57, 82], [57, 85], [57, 88], [57, 89], [57, 97], [57, 108], [57, 125], [57, 135], [57, 139], [57, 145], [57, 157], [57, 158], [57, 160], [57, 170], [57, 174], [57, 176], [58, 60], [58, 63], [58, 68], [58, 72], [58, 87], [58, 88], [58, 99], [58, 103], [58, 104], [58, 106], [58, 111], [58, 113], [58, 123], [58, 125], [58, 129], [58, 131], [58, 132], [58, 137], [58, 138], [58, 139], [58, 140], [58, 146], [58, 150], [58, 155], [58, 158], [58, 174], [59, 60], [59, 64], [59, 65], [59, 66], [59, 69], [59, 76], [59, 81], [59, 85], [59, 88], [59, 98], [59, 101], [59, 108], [59, 111], [59, 120], [59, 128], [59, 129], [59, 130], [59, 153], [59, 155], [59, 158], [59, 160], [59, 161], [59, 162], [59, 164], [59, 172], [59, 178], [60, 71], [60, 73], [60, 74], [60, 81], [60, 84], [60, 88], [60, 90], [60, 97], [60, 106], [60, 107], [60, 115], [60, 116], [60, 123], [60, 126], [60, 136], [60, 143], [60, 144], [60, 163], [60, 165], [60, 166], [60, 177], [61, 62], [61, 67], [61, 77], [61, 78], [61, 80], [61, 83], [61, 87], [61, 91], [61, 97], [61, 99], [61, 101], [61, 116], [61, 122], [61, 125], [61, 126], [61, 131], [61, 135], [61, 136], [61, 138], [61, 143], [61, 151], [61, 156], [61, 160], [61, 164], [61, 167], [61, 170], [61, 172], [61, 174], [61, 175], [61, 177], [62, 81], [62, 92], [62, 95], [62, 100], [62, 101], [62, 105], [62, 108], [62, 115], [62, 116], [62, 118], [62, 120], [62, 127], [62, 134], [62, 144], [62, 145], [62, 149], [62, 154], [62, 162], [62, 168], [62, 173], [62, 179], [63, 64], [63, 67], [63, 74], [63, 75], [63, 78], [63, 85], [63, 88], [63, 92], [63, 97], [63, 101], [63, 103], [63, 107], [63, 110], [63, 117], [63, 124], [63, 125], [63, 129], [63, 130], [63, 131], [63, 138], [63, 147], [63, 153], [63, 162], [63, 173], [64, 65], [64, 68], [64, 69], [64, 83], [64, 91], [64, 95], [64, 97], [64, 117], [64, 119], [64, 121], [64, 127], [64, 135], [64, 138], [64, 139], [64, 143], [64, 166], [64, 178], [64, 179], [65, 70], [65, 75], [65, 77], [65, 81], [65, 82], [65, 87], [65, 93], [65, 97], [65, 101], [65, 102], [65, 114], [65, 121], [65, 125], [65, 128], [65, 134], [65, 148], [65, 152], [65, 157], [65, 158], [65, 159], [65, 166], [65, 167], [65, 170], [65, 171], [65, 175], [66, 84], [66, 109], [66, 112], [66, 113], [66, 134], [66, 137], [66, 148], [66, 151], [66, 157], [66, 168], [66, 173], [66, 177], [67, 70], [67, 73], [67, 79], [67, 80], [67, 84], [67, 88], [67, 93], [67, 95], [67, 97], [67, 98], [67, 99], [67, 102], [67, 103], [67, 106], [67, 107], [67, 116], [67, 122], [67, 124], [67, 126], [67, 133], [67, 141], [67, 143], [67, 144], [67, 146], [67, 149], [67, 154], [67, 167], [67, 168], [67, 172], [67, 174], [67, 175], [67, 176], [67, 177], [68, 80], [68, 81], [68, 85], [68, 89], [68, 91], [68, 96], [68, 106], [68, 107], [68, 112], [68, 120], [68, 121], [68, 130], [68, 136], [68, 139], [68, 148], [68, 150], [68, 154], [68, 156], [68, 159], [68, 164], [68, 165], [68, 175], [68, 177], [69, 71], [69, 79], [69, 85], [69, 86], [69, 87], [69, 88], [69, 89], [69, 90], [69, 101], [69, 104], [69, 106], [69, 114], [69, 126], [69, 127], [69, 128], [69, 135], [69, 138], [69, 140], [69, 144], [69, 159], [69, 161], [69, 164], [69, 167], [69, 170], [69, 174], [69, 177], [69, 179], [70, 71], [70, 74], [70, 75], [70, 77], [70, 86], [70, 92], [70, 93], [70, 96], [70, 111], [70, 115], [70, 123], [70, 128], [70, 143], [70, 145], [70, 146], [70, 153], [70, 158], [70, 164], [70, 167], [70, 172], [70, 175], [70, 177], [70, 178], [70, 179], [71, 72], [71, 74], [71, 76], [71, 85], [71, 87], [71, 97], [71, 101], [71, 106], [71, 116], [71, 119], [71, 135], [71, 142], [71, 148], [71, 159], [71, 163], [71, 165], [71, 172], [72, 74], [72, 75], [72, 83], [72, 85], [72, 90], [72, 94], [72, 95], [72, 97], [72, 98], [72, 101], [72, 103], [72, 106], [72, 108], [72, 111], [72, 125], [72, 134], [72, 135], [72, 139], [72, 152], [72, 156], [72, 160], [72, 162], [72, 165], [72, 168], [72, 169], [72, 175], [73, 92], [73, 98], [73, 99], [73, 113], [73, 116], [73, 123], [73, 124], [73, 130], [73, 140], [73, 141], [73, 147], [73, 154], [73, 156], [73, 161], [73, 171], [73, 174], [74, 79], [74, 85], [74, 88], [74, 92], [74, 93], [74, 95], [74, 118], [74, 122], [74, 123], [74, 124], [74, 127], [74, 130], [74, 134], [74, 145], [74, 150], [74, 153], [74, 155], [74, 159], [74, 161], [74, 167], [74, 171], [74, 172], [74, 176], [74, 177], [75, 106], [75, 107], [75, 116], [75, 121], [75, 127], [75, 128], [75, 148], [75, 149], [75, 150], [75, 154], [75, 161], [75, 162], [75, 166], [75, 169], [76, 79], [76, 80], [76, 81], [76, 82], [76, 85], [76, 88], [76, 92], [76, 116], [76, 129], [76, 130], [76, 134], [76, 143], [76, 144], [76, 148], [76, 150], [76, 161], [76, 162], [76, 166], [76, 169], [76, 179], [77, 78], [77, 83], [77, 84], [77, 91], [77, 107], [77, 111], [77, 119], [77, 121], [77, 123], [77, 128], [77, 130], [77, 131], [77, 133], [77, 136], [77, 139], [77, 140], [77, 144], [77, 149], [77, 152], [77, 157], [77, 158], [77, 159], [77, 162], [77, 163], [77, 167], [77, 169], [78, 80], [78, 83], [78, 85], [78, 86], [78, 88], [78, 96], [78, 103], [78, 119], [78, 123], [78, 125], [78, 139], [78, 140], [78, 141], [78, 143], [78, 149], [78, 151], [78, 155], [78, 156], [78, 157], [78, 158], [78, 167], [78, 178], [79, 83], [79, 89], [79, 102], [79, 103], [79, 110], [79, 111], [79, 113], [79, 114], [79, 118], [79, 128], [79, 129], [79, 130], [79, 131], [79, 137], [79, 143], [79, 151], [79, 164], [79, 169], [79, 173], [79, 174], [80, 82], [80, 86], [80, 92], [80, 105], [80, 116], [80, 117], [80, 118], [80, 125], [80, 126], [80, 132], [80, 140], [80, 142], [80, 153], [80, 162], [80, 164], [80, 168], [80, 178], [80, 179], [81, 83], [81, 86], [81, 93], [81, 111], [81, 122], [81, 123], [81, 124], [81, 126], [81, 129], [81, 131], [81, 139], [81, 148], [81, 160], [81, 162], [81, 168], [81, 170], [81, 171], [81, 174], [82, 84], [82, 90], [82, 91], [82, 100], [82, 106], [82, 109], [82, 110], [82, 111], [82, 124], [82, 128], [82, 133], [82, 147], [82, 155], [82, 159], [82, 174], [82, 176], [83, 111], [83, 115], [83, 118], [83, 119], [83, 123], [83, 126], [83, 129], [83, 135], [83, 139], [83, 140], [83, 146], [83, 155], [83, 159], [83, 165], [83, 167], [83, 171], [83, 173], [83, 179], [84, 96], [84, 97], [84, 98], [84, 99], [84, 100], [84, 102], [84, 105], [84, 113], [84, 116], [84, 117], [84, 123], [84, 128], [84, 130], [84, 135], [84, 137], [84, 139], [84, 143], [84, 147], [84, 156], [84, 157], [84, 160], [84, 174], [84, 179], [85, 88], [85, 92], [85, 109], [85, 112], [85, 113], [85, 116], [85, 123], [85, 124], [85, 125], [85, 128], [85, 129], [85, 135], [85, 152], [85, 156], [85, 158], [85, 161], [85, 163], [85, 164], [85, 165], [85, 169], [85, 174], [85, 176], [85, 178], [86, 92], [86, 95], [86, 99], [86, 102], [86, 105], [86, 108], [86, 112], [86, 116], [86, 119], [86, 123], [86, 132], [86, 136], [86, 137], [86, 139], [86, 142], [86, 145], [86, 146], [86, 151], [86, 173], [87, 97], [87, 103], [87, 115], [87, 124], [87, 127], [87, 128], [87, 129], [87, 139], [87, 140], [87, 147], [87, 149], [87, 156], [87, 157], [87, 162], [87, 163], [87, 169], [87, 171], [87, 174], [87, 178], [88, 93], [88, 102], [88, 105], [88, 106], [88, 111], [88, 118], [88, 127], [88, 133], [88, 140], [88, 141], [88, 144], [88, 158], [88, 164], [88, 166], [88, 175], [88, 176], [88, 178], [89, 92], [89, 102], [89, 104], [89, 105], [89, 107], [89, 110], [89, 115], [89, 130], [89, 131], [89, 145], [89, 156], [89, 157], [89, 160], [89, 170], [89, 171], [89, 172], [89, 177], [90, 91], [90, 93], [90, 103], [90, 109], [90, 114], [90, 115], [90, 118], [90, 122], [90, 134], [90, 146], [90, 148], [90, 149], [90, 155], [90, 158], [90, 160], [90, 163], [90, 169], [90, 172], [90, 174], [90, 175], [91, 92], [91, 96], [91, 99], [91, 101], [91, 103], [91, 115], [91, 121], [91, 139], [91, 141], [91, 146], [91, 157], [91, 158], [91, 159], [91, 166], [91, 168], [91, 169], [91, 170], [91, 174], [92, 95], [92, 98], [92, 106], [92, 108], [92, 109], [92, 110], [92, 120], [92, 125], [92, 131], [92, 133], [92, 150], [92, 152], [92, 158], [92, 160], [92, 163], [92, 164], [92, 165], [92, 167], [92, 171], [92, 172], [93, 102], [93, 105], [93, 110], [93, 112], [93, 115], [93, 117], [93, 122], [93, 142], [93, 166], [93, 167], [93, 170], [93, 173], [94, 97], [94, 98], [94, 110], [94, 119], [94, 123], [94, 130], [94, 131], [94, 139], [94, 147], [94, 148], [94, 150], [94, 154], [94, 158], [94, 162], [94, 175], [95, 100], [95, 104], [95, 105], [95, 106], [95, 117], [95, 118], [95, 124], [95, 128], [95, 139], [95, 145], [95, 160], [95, 164], [95, 169], [95, 175], [95, 177], [96, 99], [96, 106], [96, 107], [96, 112], [96, 113], [96, 115], [96, 117], [96, 119], [96, 123], [96, 125], [96, 129], [96, 133], [96, 137], [96, 138], [96, 141], [96, 143], [96, 147], [96, 157], [96, 158], [96, 160], [96, 162], [96, 174], [97, 99], [97, 104], [97, 109], [97, 112], [97, 115], [97, 121], [97, 126], [97, 136], [97, 143], [97, 144], [97, 157], [97, 164], [97, 166], [98, 104], [98, 107], [98, 111], [98, 113], [98, 117], [98, 118], [98, 120], [98, 124], [98, 131], [98, 133], [98, 134], [98, 143], [98, 144], [98, 152], [98, 162], [98, 164], [98, 165], [98, 174], [98, 176], [98, 178], [99, 103], [99, 104], [99, 107], [99, 110], [99, 111], [99, 112], [99, 116], [99, 120], [99, 124], [99, 129], [99, 142], [99, 143], [99, 146], [99, 158], [99, 162], [99, 165], [99, 176], [100, 102], [100, 105], [100, 107], [100, 111], [100, 116], [100, 122], [100, 134], [100, 137], [100, 138], [100, 143], [100, 147], [100, 150], [100, 152], [100, 153], [100, 165], [100, 166], [100, 174], [100, 176], [100, 177], [101, 104], [101, 113], [101, 114], [101, 115], [101, 117], [101, 128], [101, 131], [101, 133], [101, 139], [101, 163], [101, 166], [101, 173], [101, 174], [101, 176], [101, 177], [102, 114], [102, 115], [102, 116], [102, 117], [102, 119], [102, 120], [102, 127], [102, 130], [102, 133], [102, 143], [102, 145], [102, 146], [102, 147], [102, 149], [102, 151], [102, 152], [102, 153], [102, 162], [102, 165], [102, 166], [102, 169], [102, 172], [102, 174], [102, 175], [103, 105], [103, 108], [103, 116], [103, 119], [103, 121], [103, 137], [103, 143], [103, 148], [103, 159], [103, 164], [103, 166], [103, 171], [103, 173], [103, 175], [103, 176], [104, 105], [104, 106], [104, 111], [104, 119], [104, 122], [104, 123], [104, 126], [104, 128], [104, 129], [104, 130], [104, 136], [104, 141], [104, 147], [104, 158], [104, 161], [104, 166], [104, 168], [104, 171], [105, 108], [105, 113], [105, 114], [105, 115], [105, 116], [105, 118], [105, 120], [105, 130], [105, 132], [105, 146], [105, 148], [105, 157], [105, 163], [105, 168], [106, 110], [106, 112], [106, 114], [106, 115], [106, 118], [106, 119], [106, 121], [106, 126], [106, 128], [106, 129], [106, 133], [106, 135], [106, 138], [106, 148], [106, 162], [106, 170], [106, 172], [107, 111], [107, 113], [107, 116], [107, 117], [107, 124], [107, 125], [107, 127], [107, 129], [107, 130], [107, 133], [107, 134], [107, 138], [107, 143], [107, 144], [107, 152], [107, 154], [107, 156], [107, 163], [107, 170], [107, 171], [107, 179], [108, 112], [108, 118], [108, 122], [108, 127], [108, 131], [108, 141], [108, 142], [108, 143], [108, 146], [108, 148], [108, 155], [108, 159], [108, 167], [108, 169], [108, 170], [108, 172], [108, 176], [108, 179], [109, 110], [109, 112], [109, 113], [109, 119], [109, 126], [109, 132], [109, 146], [109, 157], [109, 159], [109, 166], [109, 167], [109, 168], [109, 171], [109, 174], [109, 175], [110, 122], [110, 129], [110, 141], [110, 152], [110, 156], [110, 162], [110, 163], [110, 179], [111, 116], [111, 131], [111, 133], [111, 142], [111, 150], [111, 152], [111, 153], [111, 154], [111, 158], [111, 166], [111, 168], [111, 174], [112, 122], [112, 126], [112, 130], [112, 132], [112, 133], [112, 134], [112, 135], [112, 142], [112, 168], [113, 121], [113, 122], [113, 124], [113, 127], [113, 130], [113, 153], [113, 156], [113, 170], [113, 175], [113, 179], [114, 115], [114, 122], [114, 129], [114, 131], [114, 145], [114, 152], [114, 160], [114, 161], [114, 165], [115, 121], [115, 125], [115, 136], [115, 139], [115, 144], [115, 151], [115, 152], [115, 153], [115, 160], [115, 162], [115, 165], [115, 166], [115, 168], [115, 171], [115, 177], [116, 121], [116, 122], [116, 129], [116, 130], [116, 133], [116, 134], [116, 143], [116, 147], [116, 154], [116, 158], [116, 159], [116, 162], [116, 163], [116, 167], [116, 168], [116, 169], [116, 172], [116, 175], [116, 176], [117, 119], [117, 122], [117, 129], [117, 130], [118, 127], [118, 135], [118, 144], [118, 147], [118, 150], [118, 152], [118, 156], [118, 160], [118, 161], [118, 164], [118, 168], [118, 171], [118, 176], [118, 177], [119, 130], [119, 133], [119, 134], [119, 137], [119, 138], [119, 140], [119, 143], [119, 150], [119, 152], [119, 155], [119, 160], [119, 163], [119, 166], [119, 174], [119, 175], [119, 179], [120, 121], [120, 126], [120, 130], [120, 134], [120, 135], [120, 140], [120, 144], [120, 151], [120, 160], [120, 167], [120, 169], [120, 174], [121, 132], [121, 135], [121, 139], [121, 140], [121, 143], [121, 156], [121, 170], [122, 125], [122, 130], [122, 131], [122, 132], [122, 137], [122, 138], [122, 143], [122, 157], [122, 159], [122, 164], [122, 165], [122, 170], [122, 175], [123, 128], [123, 134], [123, 136], [123, 143], [123, 149], [123, 152], [123, 160], [123, 163], [123, 166], [123, 172], [124, 126], [124, 130], [124, 131], [124, 134], [124, 147], [124, 157], [124, 159], [124, 161], [125, 127], [125, 129], [125, 135], [125, 143], [125, 144], [125, 148], [125, 149], [125, 151], [125, 164], [125, 170], [125, 171], [125, 174], [126, 128], [126, 130], [126, 132], [126, 133], [126, 144], [126, 159], [126, 160], [126, 167], [126, 170], [126, 172], [126, 174], [126, 178], [127, 129], [127, 136], [127, 137], [127, 139], [127, 144], [127, 146], [127, 150], [127, 159], [127, 164], [127, 165], [127, 172], [127, 175], [128, 131], [128, 136], [128, 148], [128, 150], [128, 154], [128, 159], [128, 164], [128, 165], [128, 171], [128, 174], [128, 175], [128, 177], [128, 179], [129, 139], [129, 140], [129, 144], [129, 146], [129, 149], [129, 151], [129, 155], [129, 162], [129, 164], [129, 165], [129, 174], [129, 176], [129, 177], [130, 131], [130, 136], [130, 137], [130, 139], [130, 146], [130, 148], [130, 152], [130, 155], [130, 158], [130, 164], [130, 179], [131, 133], [131, 137], [131, 145], [131, 147], [131, 150], [131, 152], [131, 156], [131, 159], [131, 171], [131, 176], [131, 177], [132, 136], [132, 137], [132, 139], [132, 142], [132, 143], [132, 144], [132, 150], [132, 155], [132, 160], [132, 172], [132, 178], [133, 136], [133, 137], [133, 140], [133, 142], [133, 143], [133, 148], [133, 151], [133, 157], [133, 159], [134, 135], [134, 139], [134, 154], [134, 155], [134, 162], [134, 166], [134, 167], [134, 168], [134, 172], [134, 178], [135, 149], [135, 151], [135, 159], [135, 160], [135, 164], [136, 139], [136, 152], [136, 159], [136, 166], [136, 168], [136, 169], [136, 174], [136, 177], [137, 140], [137, 149], [137, 156], [137, 162], [137, 168], [137, 170], [137, 173], [138, 146], [138, 147], [138, 148], [138, 151], [138, 156], [138, 162], [139, 143], [139, 149], [139, 165], [139, 177], [140, 144], [140, 146], [140, 149], [140, 150], [140, 153], [140, 155], [140, 160], [140, 167], [140, 169], [140, 172], [141, 142], [141, 143], [141, 152], [141, 153], [141, 156], [141, 161], [141, 164], [141, 175], [142, 150], [142, 152], [142, 156], [142, 158], [142, 166], [142, 178], [143, 145], [143, 156], [143, 161], [143, 167], [143, 169], [143, 177], [144, 145], [144, 157], [144, 159], [144, 162], [144, 165], [144, 172], [144, 174], [145, 147], [145, 150], [145, 153], [145, 157], [145, 159], [145, 162], [145, 164], [145, 173], [145, 174], [146, 151], [146, 153], [146, 155], [146, 160], [146, 166], [146, 167], [146, 169], [146, 178], [147, 148], [147, 160], [147, 161], [147, 163], [147, 167], [147, 169], [147, 172], [147, 174], [147, 177], [148, 151], [148, 155], [148, 161], [148, 177], [149, 153], [149, 167], [149, 170], [149, 173], [149, 174], [149, 176], [149, 177], [150, 154], [150, 157], [150, 159], [150, 161], [150, 170], [150, 174], [151, 156], [151, 160], [151, 170], [151, 171], [152, 155], [152, 156], [152, 157], [152, 158], [152, 166], [152, 170], [152, 171], [152, 172], [152, 176], [152, 177], [153, 154], [153, 158], [153, 169], [153, 171], [153, 174], [154, 165], [154, 170], [154, 171], [154, 177], [154, 179], [155, 156], [155, 165], [155, 167], [155, 178], [156, 169], [156, 171], [156, 173], [156, 174], [156, 178], [157, 167], [158, 165], [158, 173], [158, 176], [158, 179], [159, 164], [159, 166], [159, 168], [159, 173], [159, 176], [159, 179], [160, 172], [160, 173], [161, 165], [161, 177], [162, 165], [162, 166], [162, 170], [162, 173], [163, 174], [166, 168], [166, 170], [166, 171], [166, 174], [167, 173], [167, 178], [168, 173], [168, 177], [169, 174], [169, 175], [169, 176], [169, 179], [170, 176], [171, 179], [172, 174], [172, 176], [173, 176], [174, 178], [176, 178]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s5/solution/solve.sh b/tasks/construct-nppc-dominating-set-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..99473aa06fe4ec20cf550b2a359d40247468c0b2 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [12, 23, 37, 39, 68, 69, 74, 83, 92, 96, 97, 111, 116, 151, 170]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l5-s5/tests/check.py b/tasks/construct-nppc-dominating-set-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-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-l5-s5/tests/instance.json b/tasks/construct-nppc-dominating-set-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dc28d3f02fb769fd2409d9dce104d5f812938cf7 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 1], [0, 9], [0, 16], [0, 18], [0, 21], [0, 32], [0, 33], [0, 36], [0, 39], [0, 40], [0, 44], [0, 47], [0, 52], [0, 58], [0, 63], [0, 72], [0, 73], [0, 75], [0, 76], [0, 77], [0, 80], [0, 86], [0, 93], [0, 97], [0, 103], [0, 105], [0, 108], [0, 111], [0, 112], [0, 113], [0, 119], [0, 125], [0, 133], [0, 137], [0, 139], [0, 145], [0, 152], [0, 157], [0, 158], [0, 163], [0, 165], [0, 169], [0, 174], [0, 177], [1, 5], [1, 6], [1, 11], [1, 20], [1, 22], [1, 30], [1, 37], [1, 55], [1, 62], [1, 64], [1, 76], [1, 77], [1, 81], [1, 83], [1, 91], [1, 104], [1, 117], [1, 120], [1, 123], [1, 125], [1, 126], [1, 128], [1, 129], [1, 133], [1, 144], [1, 145], [1, 152], [1, 157], [1, 160], [1, 163], [1, 164], [1, 169], [2, 8], [2, 9], [2, 12], [2, 24], [2, 25], [2, 27], [2, 34], [2, 35], [2, 37], [2, 41], [2, 42], [2, 50], [2, 52], [2, 55], [2, 56], [2, 68], [2, 77], [2, 79], [2, 81], [2, 91], [2, 96], [2, 104], [2, 105], [2, 109], [2, 111], [2, 112], [2, 113], [2, 114], [2, 128], [2, 129], [2, 130], [2, 132], [2, 137], [2, 139], [2, 140], [2, 143], [2, 150], [2, 152], [2, 157], [2, 159], [2, 170], [3, 6], [3, 20], [3, 21], [3, 26], [3, 38], [3, 42], [3, 43], [3, 52], [3, 59], [3, 61], [3, 65], [3, 68], [3, 76], [3, 78], [3, 87], [3, 88], [3, 97], [3, 99], [3, 104], [3, 111], [3, 115], [3, 118], [3, 126], [3, 130], [3, 132], [3, 146], [3, 153], [3, 156], [3, 161], [3, 177], [4, 8], [4, 9], [4, 15], [4, 21], [4, 37], [4, 40], [4, 41], [4, 42], [4, 48], [4, 55], [4, 58], [4, 63], [4, 65], [4, 68], [4, 69], [4, 71], [4, 73], [4, 79], [4, 81], [4, 86], [4, 87], [4, 88], [4, 89], [4, 95], [4, 100], [4, 101], [4, 102], [4, 108], [4, 111], [4, 130], [4, 131], [4, 145], [4, 148], [4, 150], [4, 152], [4, 157], [4, 159], [4, 164], [4, 175], [4, 178], [5, 11], [5, 12], [5, 19], [5, 22], [5, 23], [5, 27], [5, 34], [5, 36], [5, 44], [5, 45], [5, 51], [5, 54], [5, 56], [5, 60], [5, 67], [5, 70], [5, 72], [5, 79], [5, 86], [5, 88], [5, 96], [5, 105], [5, 106], [5, 108], [5, 113], [5, 124], [5, 127], [5, 134], [5, 135], [5, 142], [5, 147], [5, 159], [5, 162], [5, 166], [5, 169], [5, 174], [6, 7], [6, 9], [6, 19], [6, 21], [6, 27], [6, 28], [6, 29], [6, 37], [6, 38], [6, 39], [6, 45], [6, 47], [6, 54], [6, 55], [6, 61], [6, 63], [6, 68], [6, 69], [6, 74], [6, 77], [6, 78], [6, 100], [6, 103], [6, 105], [6, 108], [6, 111], [6, 113], [6, 115], [6, 126], [6, 129], [6, 134], [6, 135], [6, 140], [6, 151], [6, 155], [6, 168], [6, 171], [7, 25], [7, 31], [7, 34], [7, 37], [7, 39], [7, 42], [7, 49], [7, 50], [7, 62], [7, 63], [7, 67], [7, 75], [7, 80], [7, 88], [7, 89], [7, 91], [7, 92], [7, 93], [7, 99], [7, 107], [7, 112], [7, 115], [7, 126], [7, 132], [7, 137], [7, 140], [7, 145], [7, 147], [7, 162], [7, 163], [7, 165], [7, 176], [7, 178], [8, 10], [8, 12], [8, 14], [8, 16], [8, 18], [8, 19], [8, 22], [8, 24], [8, 28], [8, 37], [8, 42], [8, 49], [8, 50], [8, 51], [8, 52], [8, 56], [8, 64], [8, 67], [8, 68], [8, 69], [8, 70], [8, 74], [8, 76], [8, 78], [8, 82], [8, 86], [8, 89], [8, 102], [8, 110], [8, 116], [8, 118], [8, 121], [8, 124], [8, 126], [8, 127], [8, 129], [8, 143], [8, 145], [8, 159], [8, 163], [8, 170], [8, 171], [8, 176], [8, 178], [9, 12], [9, 13], [9, 23], [9, 27], [9, 38], [9, 43], [9, 46], [9, 47], [9, 50], [9, 57], [9, 65], [9, 72], [9, 73], [9, 78], [9, 82], [9, 83], [9, 97], [9, 107], [9, 115], [9, 124], [9, 125], [9, 129], [9, 130], [9, 139], [9, 146], [9, 147], [9, 161], [9, 164], [9, 172], [9, 176], [10, 11], [10, 16], [10, 17], [10, 28], [10, 34], [10, 35], [10, 38], [10, 52], [10, 54], [10, 64], [10, 69], [10, 78], [10, 91], [10, 106], [10, 111], [10, 115], [10, 117], [10, 121], [10, 134], [10, 135], [10, 140], [10, 152], [10, 157], [10, 167], [10, 170], [10, 174], [10, 177], [10, 178], [11, 22], [11, 27], [11, 34], [11, 36], [11, 44], [11, 46], [11, 50], [11, 57], [11, 59], [11, 64], [11, 73], [11, 74], [11, 83], [11, 95], [11, 111], [11, 113], [11, 114], [11, 119], [11, 137], [11, 143], [11, 145], [11, 148], [11, 151], [11, 152], [11, 154], [11, 162], [11, 165], [11, 174], [11, 178], [12, 15], [12, 22], [12, 35], [12, 41], [12, 43], [12, 45], [12, 49], [12, 50], [12, 51], [12, 54], [12, 56], [12, 59], [12, 62], [12, 67], [12, 75], [12, 79], [12, 85], [12, 86], [12, 87], [12, 93], [12, 98], [12, 101], [12, 102], [12, 103], [12, 108], [12, 113], [12, 118], [12, 122], [12, 124], [12, 126], [12, 138], [12, 143], [12, 164], [12, 165], [12, 167], [12, 176], [13, 22], [13, 27], [13, 32], [13, 40], [13, 44], [13, 50], [13, 56], [13, 65], [13, 83], [13, 87], [13, 94], [13, 102], [13, 106], [13, 113], [13, 115], [13, 117], [13, 123], [13, 130], [13, 137], [13, 141], [13, 143], [13, 164], [13, 165], [13, 169], [13, 170], [13, 172], [13, 179], [14, 21], [14, 25], [14, 31], [14, 32], [14, 37], [14, 47], [14, 57], [14, 58], [14, 60], [14, 66], [14, 67], [14, 69], [14, 92], [14, 93], [14, 103], [14, 108], [14, 111], [14, 114], [14, 125], [14, 127], [14, 129], [14, 131], [14, 153], [14, 163], [14, 166], [14, 172], [14, 174], [15, 18], [15, 25], [15, 30], [15, 31], [15, 34], [15, 35], [15, 40], [15, 50], [15, 56], [15, 63], [15, 65], [15, 66], [15, 71], [15, 78], [15, 81], [15, 85], [15, 92], [15, 104], [15, 110], [15, 111], [15, 115], [15, 117], [15, 129], [15, 130], [15, 137], [15, 145], [15, 151], [15, 152], [15, 154], [15, 161], [15, 163], [15, 170], [15, 174], [15, 178], [16, 20], [16, 21], [16, 23], [16, 27], [16, 29], [16, 33], [16, 37], [16, 47], [16, 50], [16, 57], [16, 59], [16, 67], [16, 68], [16, 84], [16, 95], [16, 105], [16, 112], [16, 113], [16, 117], [16, 124], [16, 126], [16, 127], [16, 130], [16, 135], [16, 136], [16, 137], [16, 145], [16, 146], [16, 149], [16, 150], [16, 154], [16, 155], [16, 167], [16, 169], [16, 170], [16, 178], [16, 179], [17, 23], [17, 24], [17, 25], [17, 33], [17, 42], [17, 60], [17, 78], [17, 79], [17, 82], [17, 93], [17, 94], [17, 99], [17, 100], [17, 104], [17, 112], [17, 119], [17, 123], [17, 127], [17, 133], [17, 136], [17, 137], [17, 138], [17, 139], [17, 142], [17, 150], [17, 157], [17, 159], [17, 165], [17, 170], [17, 172], [17, 173], [17, 174], [17, 177], [18, 45], [18, 46], [18, 51], [18, 52], [18, 53], [18, 54], [18, 56], [18, 60], [18, 67], [18, 73], [18, 75], [18, 78], [18, 79], [18, 83], [18, 86], [18, 89], [18, 90], [18, 95], [18, 97], [18, 98], [18, 104], [18, 106], [18, 108], [18, 113], [18, 116], [18, 124], [18, 134], [18, 141], [18, 145], [18, 151], [18, 153], [18, 164], [18, 165], [18, 166], [18, 174], [18, 179], [19, 24], [19, 25], [19, 26], [19, 30], [19, 32], [19, 40], [19, 47], [19, 54], [19, 58], [19, 62], [19, 64], [19, 65], [19, 69], [19, 75], [19, 77], [19, 79], [19, 83], [19, 87], [19, 94], [19, 104], [19, 105], [19, 109], [19, 115], [19, 116], [19, 133], [19, 139], [19, 152], [19, 153], [19, 154], [19, 161], [19, 162], [19, 164], [19, 167], [19, 169], [19, 172], [20, 27], [20, 46], [20, 51], [20, 59], [20, 65], [20, 76], [20, 83], [20, 90], [20, 92], [20, 94], [20, 102], [20, 105], [20, 111], [20, 123], [20, 133], [20, 134], [20, 148], [20, 150], [21, 24], [21, 25], [21, 36], [21, 38], [21, 43], [21, 54], [21, 58], [21, 61], [21, 62], [21, 67], [21, 69], [21, 72], [21, 75], [21, 81], [21, 87], [21, 88], [21, 92], [21, 94], [21, 98], [21, 104], [21, 106], [21, 114], [21, 122], [21, 124], [21, 125], [21, 127], [21, 128], [21, 136], [21, 138], [21, 148], [21, 155], [21, 176], [21, 177], [22, 23], [22, 30], [22, 39], [22, 40], [22, 41], [22, 57], [22, 62], [22, 68], [22, 69], [22, 70], [22, 72], [22, 75], [22, 77], [22, 81], [22, 88], [22, 89], [22, 94], [22, 95], [22, 97], [22, 109], [22, 110], [22, 116], [22, 119], [22, 121], [22, 125], [22, 126], [22, 144], [22, 145], [22, 146], [22, 149], [22, 152], [22, 154], [22, 157], [22, 167], [22, 174], [23, 28], [23, 29], [23, 31], [23, 32], [23, 37], [23, 39], [23, 41], [23, 47], [23, 49], [23, 54], [23, 55], [23, 64], [23, 65], [23, 73], [23, 75], [23, 78], [23, 79], [23, 86], [23, 88], [23, 90], [23, 94], [23, 99], [23, 100], [23, 102], [23, 111], [23, 113], [23, 115], [23, 124], [23, 131], [23, 133], [23, 136], [23, 137], [23, 138], [23, 139], [23, 140], [23, 142], [23, 144], [23, 147], [23, 150], [23, 157], [23, 159], [23, 167], [23, 168], [23, 173], [23, 175], [23, 179], [24, 26], [24, 27], [24, 34], [24, 43], [24, 49], [24, 53], [24, 70], [24, 72], [24, 76], [24, 78], [24, 90], [24, 94], [24, 95], [24, 99], [24, 100], [24, 105], [24, 113], [24, 114], [24, 116], [24, 118], [24, 124], [24, 127], [24, 128], [24, 129], [24, 134], [24, 135], [24, 136], [24, 139], [24, 144], [24, 151], [24, 155], [24, 156], [24, 158], [24, 161], [24, 167], [24, 172], [25, 32], [25, 37], [25, 39], [25, 43], [25, 46], [25, 60], [25, 65], [25, 74], [25, 76], [25, 77], [25, 79], [25, 86], [25, 91], [25, 102], [25, 106], [25, 107], [25, 108], [25, 110], [25, 111], [25, 113], [25, 126], [25, 127], [25, 129], [25, 133], [25, 137], [25, 140], [25, 153], [25, 168], [25, 173], [26, 34], [26, 48], [26, 52], [26, 54], [26, 58], [26, 60], [26, 62], [26, 64], [26, 69], [26, 76], [26, 77], [26, 82], [26, 85], [26, 86], [26, 89], [26, 90], [26, 91], [26, 97], [26, 98], [26, 99], [26, 101], [26, 104], [26, 108], [26, 112], [26, 115], [26, 117], [26, 118], [26, 125], [26, 131], [26, 132], [26, 138], [26, 139], [26, 146], [26, 150], [26, 166], [26, 168], [26, 173], [27, 30], [27, 36], [27, 49], [27, 56], [27, 57], [27, 58], [27, 72], [27, 76], [27, 78], [27, 89], [27, 90], [27, 93], [27, 95], [27, 103], [27, 104], [27, 105], [27, 116], [27, 121], [27, 126], [27, 127], [27, 131], [27, 137], [27, 145], [27, 149], [27, 162], [27, 165], [27, 166], [27, 170], [27, 172], [27, 173], [27, 179], [28, 36], [28, 43], [28, 47], [28, 51], [28, 58], [28, 59], [28, 62], [28, 66], [28, 68], [28, 70], [28, 71], [28, 73], [28, 74], [28, 75], [28, 76], [28, 95], [28, 97], [28, 107], [28, 110], [28, 121], [28, 135], [28, 138], [28, 141], [28, 146], [28, 164], [28, 167], [29, 31], [29, 53], [29, 60], [29, 69], [29, 72], [29, 75], [29, 76], [29, 77], [29, 82], [29, 83], [29, 91], [29, 98], [29, 113], [29, 120], [29, 121], [29, 123], [29, 126], [29, 133], [29, 148], [29, 150], [29, 167], [29, 169], [30, 33], [30, 38], [30, 41], [30, 42], [30, 43], [30, 52], [30, 57], [30, 63], [30, 72], [30, 81], [30, 83], [30, 84], [30, 89], [30, 90], [30, 96], [30, 97], [30, 102], [30, 105], [30, 108], [30, 115], [30, 126], [30, 127], [30, 134], [30, 136], [30, 137], [30, 138], [30, 139], [30, 140], [30, 141], [30, 151], [30, 163], [30, 165], [30, 168], [30, 169], [30, 171], [31, 35], [31, 39], [31, 43], [31, 52], [31, 69], [31, 70], [31, 85], [31, 86], [31, 90], [31, 91], [31, 120], [31, 123], [31, 126], [31, 132], [31, 135], [31, 151], [31, 157], [31, 172], [31, 177], [32, 33], [32, 36], [32, 37], [32, 41], [32, 48], [32, 52], [32, 54], [32, 61], [32, 68], [32, 71], [32, 75], [32, 77], [32, 87], [32, 92], [32, 94], [32, 98], [32, 100], [32, 105], [32, 107], [32, 112], [32, 115], [32, 116], [32, 121], [32, 138], [32, 140], [32, 141], [32, 152], [32, 156], [32, 162], [32, 166], [32, 167], [32, 168], [32, 169], [32, 178], [33, 35], [33, 42], [33, 50], [33, 53], [33, 59], [33, 66], [33, 67], [33, 68], [33, 79], [33, 80], [33, 90], [33, 96], [33, 100], [33, 102], [33, 104], [33, 108], [33, 109], [33, 121], [33, 122], [33, 125], [33, 131], [33, 148], [33, 151], [33, 153], [33, 178], [34, 39], [34, 45], [34, 46], [34, 50], [34, 57], [34, 65], [34, 68], [34, 70], [34, 71], [34, 78], [34, 84], [34, 85], [34, 89], [34, 92], [34, 104], [34, 112], [34, 115], [34, 121], [34, 123], [34, 124], [34, 129], [34, 131], [34, 132], [34, 134], [34, 139], [34, 148], [34, 150], [34, 151], [34, 155], [34, 161], [34, 163], [34, 173], [34, 179], [35, 39], [35, 42], [35, 43], [35, 54], [35, 55], [35, 56], [35, 67], [35, 74], [35, 85], [35, 90], [35, 92], [35, 93], [35, 99], [35, 109], [35, 112], [35, 113], [35, 115], [35, 120], [35, 121], [35, 123], [35, 126], [35, 133], [35, 134], [35, 137], [35, 138], [35, 140], [35, 141], [35, 144], [35, 149], [35, 150], [35, 151], [35, 153], [35, 157], [35, 163], [35, 168], [35, 171], [35, 174], [35, 178], [35, 179], [36, 39], [36, 43], [36, 50], [36, 60], [36, 63], [36, 72], [36, 84], [36, 97], [36, 99], [36, 100], [36, 102], [36, 110], [36, 127], [36, 140], [36, 141], [36, 144], [36, 146], [36, 147], [36, 150], [36, 171], [36, 173], [36, 175], [37, 38], [37, 46], [37, 47], [37, 48], [37, 55], [37, 59], [37, 63], [37, 67], [37, 70], [37, 81], [37, 82], [37, 84], [37, 85], [37, 86], [37, 91], [37, 92], [37, 94], [37, 96], [37, 102], [37, 106], [37, 110], [37, 117], [37, 119], [37, 120], [37, 124], [37, 127], [37, 128], [37, 131], [37, 132], [37, 135], [37, 137], [37, 138], [37, 148], [37, 153], [37, 154], [37, 158], [37, 162], [37, 163], [37, 169], [37, 171], [37, 178], [38, 42], [38, 49], [38, 50], [38, 52], [38, 54], [38, 55], [38, 56], [38, 60], [38, 61], [38, 71], [38, 72], [38, 75], [38, 79], [38, 84], [38, 87], [38, 105], [38, 115], [38, 119], [38, 123], [38, 126], [38, 133], [38, 136], [38, 137], [38, 138], [38, 142], [38, 144], [38, 148], [38, 151], [38, 153], [38, 156], [38, 157], [38, 162], [38, 164], [38, 171], [39, 43], [39, 45], [39, 52], [39, 58], [39, 65], [39, 68], [39, 71], [39, 72], [39, 74], [39, 76], [39, 78], [39, 80], [39, 95], [39, 96], [39, 97], [39, 111], [39, 113], [39, 121], [39, 124], [39, 129], [39, 132], [39, 135], [39, 150], [39, 154], [39, 160], [39, 162], [39, 167], [39, 169], [39, 170], [39, 171], [39, 174], [39, 176], [39, 177], [39, 178], [40, 42], [40, 44], [40, 47], [40, 51], [40, 69], [40, 86], [40, 87], [40, 89], [40, 90], [40, 96], [40, 100], [40, 107], [40, 120], [40, 130], [40, 131], [40, 132], [40, 138], [40, 143], [40, 150], [40, 151], [40, 161], [40, 165], [40, 166], [41, 46], [41, 50], [41, 55], [41, 56], [41, 73], [41, 88], [41, 90], [41, 92], [41, 97], [41, 103], [41, 104], [41, 105], [41, 106], [41, 107], [41, 108], [41, 110], [41, 129], [41, 133], [41, 142], [41, 159], [41, 162], [41, 164], [41, 173], [41, 177], [41, 178], [42, 50], [42, 53], [42, 70], [42, 75], [42, 80], [42, 87], [42, 90], [42, 91], [42, 92], [42, 94], [42, 105], [42, 117], [42, 121], [42, 128], [42, 131], [42, 137], [42, 139], [42, 140], [42, 172], [42, 173], [43, 52], [43, 56], [43, 59], [43, 61], [43, 64], [43, 65], [43, 73], [43, 82], [43, 83], [43, 85], [43, 88], [43, 103], [43, 104], [43, 121], [43, 122], [43, 125], [43, 133], [43, 137], [43, 139], [43, 148], [43, 154], [43, 158], [43, 168], [43, 169], [43, 176], [44, 52], [44, 54], [44, 61], [44, 67], [44, 75], [44, 76], [44, 79], [44, 81], [44, 83], [44, 85], [44, 87], [44, 88], [44, 91], [44, 98], [44, 103], [44, 105], [44, 108], [44, 115], [44, 116], [44, 120], [44, 125], [44, 132], [44, 136], [44, 140], [44, 158], [44, 160], [44, 161], [44, 170], [44, 172], [45, 67], [45, 70], [45, 73], [45, 85], [45, 88], [45, 89], [45, 95], [45, 98], [45, 102], [45, 105], [45, 107], [45, 108], [45, 111], [45, 118], [45, 125], [45, 132], [45, 141], [45, 142], [45, 145], [45, 152], [45, 162], [45, 166], [46, 61], [46, 67], [46, 71], [46, 77], [46, 79], [46, 83], [46, 86], [46, 87], [46, 88], [46, 94], [46, 97], [46, 98], [46, 102], [46, 108], [46, 115], [46, 116], [46, 118], [46, 128], [46, 132], [46, 136], [46, 141], [46, 144], [46, 157], [46, 159], [46, 161], [46, 168], [46, 169], [46, 173], [46, 175], [47, 52], [47, 53], [47, 57], [47, 59], [47, 60], [47, 71], [47, 77], [47, 89], [47, 91], [47, 99], [47, 101], [47, 108], [47, 109], [47, 116], [47, 119], [47, 123], [47, 127], [47, 130], [47, 134], [47, 149], [47, 152], [47, 158], [47, 162], [47, 167], [47, 174], [47, 175], [47, 179], [48, 63], [48, 64], [48, 66], [48, 73], [48, 74], [48, 77], [48, 78], [48, 81], [48, 87], [48, 93], [48, 94], [48, 96], [48, 102], [48, 104], [48, 108], [48, 111], [48, 113], [48, 125], [48, 130], [48, 134], [48, 142], [48, 145], [48, 147], [48, 149], [48, 151], [48, 155], [48, 156], [48, 164], [48, 165], [48, 170], [49, 52], [49, 59], [49, 63], [49, 65], [49, 68], [49, 70], [49, 77], [49, 78], [49, 89], [49, 92], [49, 96], [49, 100], [49, 102], [49, 112], [49, 116], [49, 122], [49, 125], [49, 138], [49, 139], [49, 142], [49, 144], [49, 148], [49, 149], [49, 151], [49, 154], [49, 158], [49, 160], [49, 164], [49, 173], [49, 178], [50, 60], [50, 62], [50, 65], [50, 66], [50, 75], [50, 87], [50, 92], [50, 99], [50, 101], [50, 113], [50, 114], [50, 117], [50, 127], [50, 129], [50, 135], [50, 144], [50, 157], [50, 161], [50, 170], [50, 179], [51, 57], [51, 62], [51, 75], [51, 80], [51, 89], [51, 95], [51, 103], [51, 104], [51, 111], [51, 116], [51, 117], [51, 118], [51, 123], [51, 124], [51, 132], [51, 143], [51, 159], [51, 161], [51, 167], [51, 172], [51, 176], [51, 177], [52, 56], [52, 63], [52, 65], [52, 70], [52, 73], [52, 74], [52, 78], [52, 80], [52, 82], [52, 89], [52, 91], [52, 93], [52, 94], [52, 95], [52, 98], [52, 101], [52, 112], [52, 115], [52, 120], [52, 128], [52, 133], [52, 136], [52, 141], [52, 143], [52, 144], [52, 145], [52, 150], [52, 152], [52, 158], [52, 159], [52, 166], [52, 168], [52, 169], [52, 172], [52, 175], [52, 176], [53, 55], [53, 61], [53, 62], [53, 63], [53, 76], [53, 79], [53, 83], [53, 92], [53, 94], [53, 103], [53, 107], [53, 109], [53, 115], [53, 116], [53, 118], [53, 121], [53, 133], [53, 134], [53, 141], [53, 144], [53, 154], [53, 162], [53, 167], [53, 172], [53, 177], [54, 55], [54, 70], [54, 72], [54, 74], [54, 77], [54, 79], [54, 80], [54, 83], [54, 94], [54, 97], [54, 100], [54, 103], [54, 105], [54, 111], [54, 114], [54, 115], [54, 130], [54, 144], [54, 145], [54, 148], [54, 150], [54, 168], [54, 175], [54, 178], [55, 60], [55, 63], [55, 70], [55, 71], [55, 73], [55, 74], [55, 77], [55, 78], [55, 94], [55, 99], [55, 103], [55, 108], [55, 111], [55, 112], [55, 117], [55, 126], [55, 137], [55, 144], [55, 149], [55, 152], [55, 154], [55, 171], [55, 176], [56, 58], [56, 62], [56, 81], [56, 83], [56, 92], [56, 94], [56, 96], [56, 120], [56, 121], [56, 122], [56, 124], [56, 129], [56, 135], [56, 141], [56, 147], [56, 150], [56, 151], [56, 155], [56, 164], [56, 169], [56, 173], [56, 177], [56, 179], [57, 59], [57, 64], [57, 67], [57, 68], [57, 69], [57, 75], [57, 82], [57, 85], [57, 88], [57, 89], [57, 97], [57, 108], [57, 125], [57, 135], [57, 139], [57, 145], [57, 157], [57, 158], [57, 160], [57, 170], [57, 174], [57, 176], [58, 60], [58, 63], [58, 68], [58, 72], [58, 87], [58, 88], [58, 99], [58, 103], [58, 104], [58, 106], [58, 111], [58, 113], [58, 123], [58, 125], [58, 129], [58, 131], [58, 132], [58, 137], [58, 138], [58, 139], [58, 140], [58, 146], [58, 150], [58, 155], [58, 158], [58, 174], [59, 60], [59, 64], [59, 65], [59, 66], [59, 69], [59, 76], [59, 81], [59, 85], [59, 88], [59, 98], [59, 101], [59, 108], [59, 111], [59, 120], [59, 128], [59, 129], [59, 130], [59, 153], [59, 155], [59, 158], [59, 160], [59, 161], [59, 162], [59, 164], [59, 172], [59, 178], [60, 71], [60, 73], [60, 74], [60, 81], [60, 84], [60, 88], [60, 90], [60, 97], [60, 106], [60, 107], [60, 115], [60, 116], [60, 123], [60, 126], [60, 136], [60, 143], [60, 144], [60, 163], [60, 165], [60, 166], [60, 177], [61, 62], [61, 67], [61, 77], [61, 78], [61, 80], [61, 83], [61, 87], [61, 91], [61, 97], [61, 99], [61, 101], [61, 116], [61, 122], [61, 125], [61, 126], [61, 131], [61, 135], [61, 136], [61, 138], [61, 143], [61, 151], [61, 156], [61, 160], [61, 164], [61, 167], [61, 170], [61, 172], [61, 174], [61, 175], [61, 177], [62, 81], [62, 92], [62, 95], [62, 100], [62, 101], [62, 105], [62, 108], [62, 115], [62, 116], [62, 118], [62, 120], [62, 127], [62, 134], [62, 144], [62, 145], [62, 149], [62, 154], [62, 162], [62, 168], [62, 173], [62, 179], [63, 64], [63, 67], [63, 74], [63, 75], [63, 78], [63, 85], [63, 88], [63, 92], [63, 97], [63, 101], [63, 103], [63, 107], [63, 110], [63, 117], [63, 124], [63, 125], [63, 129], [63, 130], [63, 131], [63, 138], [63, 147], [63, 153], [63, 162], [63, 173], [64, 65], [64, 68], [64, 69], [64, 83], [64, 91], [64, 95], [64, 97], [64, 117], [64, 119], [64, 121], [64, 127], [64, 135], [64, 138], [64, 139], [64, 143], [64, 166], [64, 178], [64, 179], [65, 70], [65, 75], [65, 77], [65, 81], [65, 82], [65, 87], [65, 93], [65, 97], [65, 101], [65, 102], [65, 114], [65, 121], [65, 125], [65, 128], [65, 134], [65, 148], [65, 152], [65, 157], [65, 158], [65, 159], [65, 166], [65, 167], [65, 170], [65, 171], [65, 175], [66, 84], [66, 109], [66, 112], [66, 113], [66, 134], [66, 137], [66, 148], [66, 151], [66, 157], [66, 168], [66, 173], [66, 177], [67, 70], [67, 73], [67, 79], [67, 80], [67, 84], [67, 88], [67, 93], [67, 95], [67, 97], [67, 98], [67, 99], [67, 102], [67, 103], [67, 106], [67, 107], [67, 116], [67, 122], [67, 124], [67, 126], [67, 133], [67, 141], [67, 143], [67, 144], [67, 146], [67, 149], [67, 154], [67, 167], [67, 168], [67, 172], [67, 174], [67, 175], [67, 176], [67, 177], [68, 80], [68, 81], [68, 85], [68, 89], [68, 91], [68, 96], [68, 106], [68, 107], [68, 112], [68, 120], [68, 121], [68, 130], [68, 136], [68, 139], [68, 148], [68, 150], [68, 154], [68, 156], [68, 159], [68, 164], [68, 165], [68, 175], [68, 177], [69, 71], [69, 79], [69, 85], [69, 86], [69, 87], [69, 88], [69, 89], [69, 90], [69, 101], [69, 104], [69, 106], [69, 114], [69, 126], [69, 127], [69, 128], [69, 135], [69, 138], [69, 140], [69, 144], [69, 159], [69, 161], [69, 164], [69, 167], [69, 170], [69, 174], [69, 177], [69, 179], [70, 71], [70, 74], [70, 75], [70, 77], [70, 86], [70, 92], [70, 93], [70, 96], [70, 111], [70, 115], [70, 123], [70, 128], [70, 143], [70, 145], [70, 146], [70, 153], [70, 158], [70, 164], [70, 167], [70, 172], [70, 175], [70, 177], [70, 178], [70, 179], [71, 72], [71, 74], [71, 76], [71, 85], [71, 87], [71, 97], [71, 101], [71, 106], [71, 116], [71, 119], [71, 135], [71, 142], [71, 148], [71, 159], [71, 163], [71, 165], [71, 172], [72, 74], [72, 75], [72, 83], [72, 85], [72, 90], [72, 94], [72, 95], [72, 97], [72, 98], [72, 101], [72, 103], [72, 106], [72, 108], [72, 111], [72, 125], [72, 134], [72, 135], [72, 139], [72, 152], [72, 156], [72, 160], [72, 162], [72, 165], [72, 168], [72, 169], [72, 175], [73, 92], [73, 98], [73, 99], [73, 113], [73, 116], [73, 123], [73, 124], [73, 130], [73, 140], [73, 141], [73, 147], [73, 154], [73, 156], [73, 161], [73, 171], [73, 174], [74, 79], [74, 85], [74, 88], [74, 92], [74, 93], [74, 95], [74, 118], [74, 122], [74, 123], [74, 124], [74, 127], [74, 130], [74, 134], [74, 145], [74, 150], [74, 153], [74, 155], [74, 159], [74, 161], [74, 167], [74, 171], [74, 172], [74, 176], [74, 177], [75, 106], [75, 107], [75, 116], [75, 121], [75, 127], [75, 128], [75, 148], [75, 149], [75, 150], [75, 154], [75, 161], [75, 162], [75, 166], [75, 169], [76, 79], [76, 80], [76, 81], [76, 82], [76, 85], [76, 88], [76, 92], [76, 116], [76, 129], [76, 130], [76, 134], [76, 143], [76, 144], [76, 148], [76, 150], [76, 161], [76, 162], [76, 166], [76, 169], [76, 179], [77, 78], [77, 83], [77, 84], [77, 91], [77, 107], [77, 111], [77, 119], [77, 121], [77, 123], [77, 128], [77, 130], [77, 131], [77, 133], [77, 136], [77, 139], [77, 140], [77, 144], [77, 149], [77, 152], [77, 157], [77, 158], [77, 159], [77, 162], [77, 163], [77, 167], [77, 169], [78, 80], [78, 83], [78, 85], [78, 86], [78, 88], [78, 96], [78, 103], [78, 119], [78, 123], [78, 125], [78, 139], [78, 140], [78, 141], [78, 143], [78, 149], [78, 151], [78, 155], [78, 156], [78, 157], [78, 158], [78, 167], [78, 178], [79, 83], [79, 89], [79, 102], [79, 103], [79, 110], [79, 111], [79, 113], [79, 114], [79, 118], [79, 128], [79, 129], [79, 130], [79, 131], [79, 137], [79, 143], [79, 151], [79, 164], [79, 169], [79, 173], [79, 174], [80, 82], [80, 86], [80, 92], [80, 105], [80, 116], [80, 117], [80, 118], [80, 125], [80, 126], [80, 132], [80, 140], [80, 142], [80, 153], [80, 162], [80, 164], [80, 168], [80, 178], [80, 179], [81, 83], [81, 86], [81, 93], [81, 111], [81, 122], [81, 123], [81, 124], [81, 126], [81, 129], [81, 131], [81, 139], [81, 148], [81, 160], [81, 162], [81, 168], [81, 170], [81, 171], [81, 174], [82, 84], [82, 90], [82, 91], [82, 100], [82, 106], [82, 109], [82, 110], [82, 111], [82, 124], [82, 128], [82, 133], [82, 147], [82, 155], [82, 159], [82, 174], [82, 176], [83, 111], [83, 115], [83, 118], [83, 119], [83, 123], [83, 126], [83, 129], [83, 135], [83, 139], [83, 140], [83, 146], [83, 155], [83, 159], [83, 165], [83, 167], [83, 171], [83, 173], [83, 179], [84, 96], [84, 97], [84, 98], [84, 99], [84, 100], [84, 102], [84, 105], [84, 113], [84, 116], [84, 117], [84, 123], [84, 128], [84, 130], [84, 135], [84, 137], [84, 139], [84, 143], [84, 147], [84, 156], [84, 157], [84, 160], [84, 174], [84, 179], [85, 88], [85, 92], [85, 109], [85, 112], [85, 113], [85, 116], [85, 123], [85, 124], [85, 125], [85, 128], [85, 129], [85, 135], [85, 152], [85, 156], [85, 158], [85, 161], [85, 163], [85, 164], [85, 165], [85, 169], [85, 174], [85, 176], [85, 178], [86, 92], [86, 95], [86, 99], [86, 102], [86, 105], [86, 108], [86, 112], [86, 116], [86, 119], [86, 123], [86, 132], [86, 136], [86, 137], [86, 139], [86, 142], [86, 145], [86, 146], [86, 151], [86, 173], [87, 97], [87, 103], [87, 115], [87, 124], [87, 127], [87, 128], [87, 129], [87, 139], [87, 140], [87, 147], [87, 149], [87, 156], [87, 157], [87, 162], [87, 163], [87, 169], [87, 171], [87, 174], [87, 178], [88, 93], [88, 102], [88, 105], [88, 106], [88, 111], [88, 118], [88, 127], [88, 133], [88, 140], [88, 141], [88, 144], [88, 158], [88, 164], [88, 166], [88, 175], [88, 176], [88, 178], [89, 92], [89, 102], [89, 104], [89, 105], [89, 107], [89, 110], [89, 115], [89, 130], [89, 131], [89, 145], [89, 156], [89, 157], [89, 160], [89, 170], [89, 171], [89, 172], [89, 177], [90, 91], [90, 93], [90, 103], [90, 109], [90, 114], [90, 115], [90, 118], [90, 122], [90, 134], [90, 146], [90, 148], [90, 149], [90, 155], [90, 158], [90, 160], [90, 163], [90, 169], [90, 172], [90, 174], [90, 175], [91, 92], [91, 96], [91, 99], [91, 101], [91, 103], [91, 115], [91, 121], [91, 139], [91, 141], [91, 146], [91, 157], [91, 158], [91, 159], [91, 166], [91, 168], [91, 169], [91, 170], [91, 174], [92, 95], [92, 98], [92, 106], [92, 108], [92, 109], [92, 110], [92, 120], [92, 125], [92, 131], [92, 133], [92, 150], [92, 152], [92, 158], [92, 160], [92, 163], [92, 164], [92, 165], [92, 167], [92, 171], [92, 172], [93, 102], [93, 105], [93, 110], [93, 112], [93, 115], [93, 117], [93, 122], [93, 142], [93, 166], [93, 167], [93, 170], [93, 173], [94, 97], [94, 98], [94, 110], [94, 119], [94, 123], [94, 130], [94, 131], [94, 139], [94, 147], [94, 148], [94, 150], [94, 154], [94, 158], [94, 162], [94, 175], [95, 100], [95, 104], [95, 105], [95, 106], [95, 117], [95, 118], [95, 124], [95, 128], [95, 139], [95, 145], [95, 160], [95, 164], [95, 169], [95, 175], [95, 177], [96, 99], [96, 106], [96, 107], [96, 112], [96, 113], [96, 115], [96, 117], [96, 119], [96, 123], [96, 125], [96, 129], [96, 133], [96, 137], [96, 138], [96, 141], [96, 143], [96, 147], [96, 157], [96, 158], [96, 160], [96, 162], [96, 174], [97, 99], [97, 104], [97, 109], [97, 112], [97, 115], [97, 121], [97, 126], [97, 136], [97, 143], [97, 144], [97, 157], [97, 164], [97, 166], [98, 104], [98, 107], [98, 111], [98, 113], [98, 117], [98, 118], [98, 120], [98, 124], [98, 131], [98, 133], [98, 134], [98, 143], [98, 144], [98, 152], [98, 162], [98, 164], [98, 165], [98, 174], [98, 176], [98, 178], [99, 103], [99, 104], [99, 107], [99, 110], [99, 111], [99, 112], [99, 116], [99, 120], [99, 124], [99, 129], [99, 142], [99, 143], [99, 146], [99, 158], [99, 162], [99, 165], [99, 176], [100, 102], [100, 105], [100, 107], [100, 111], [100, 116], [100, 122], [100, 134], [100, 137], [100, 138], [100, 143], [100, 147], [100, 150], [100, 152], [100, 153], [100, 165], [100, 166], [100, 174], [100, 176], [100, 177], [101, 104], [101, 113], [101, 114], [101, 115], [101, 117], [101, 128], [101, 131], [101, 133], [101, 139], [101, 163], [101, 166], [101, 173], [101, 174], [101, 176], [101, 177], [102, 114], [102, 115], [102, 116], [102, 117], [102, 119], [102, 120], [102, 127], [102, 130], [102, 133], [102, 143], [102, 145], [102, 146], [102, 147], [102, 149], [102, 151], [102, 152], [102, 153], [102, 162], [102, 165], [102, 166], [102, 169], [102, 172], [102, 174], [102, 175], [103, 105], [103, 108], [103, 116], [103, 119], [103, 121], [103, 137], [103, 143], [103, 148], [103, 159], [103, 164], [103, 166], [103, 171], [103, 173], [103, 175], [103, 176], [104, 105], [104, 106], [104, 111], [104, 119], [104, 122], [104, 123], [104, 126], [104, 128], [104, 129], [104, 130], [104, 136], [104, 141], [104, 147], [104, 158], [104, 161], [104, 166], [104, 168], [104, 171], [105, 108], [105, 113], [105, 114], [105, 115], [105, 116], [105, 118], [105, 120], [105, 130], [105, 132], [105, 146], [105, 148], [105, 157], [105, 163], [105, 168], [106, 110], [106, 112], [106, 114], [106, 115], [106, 118], [106, 119], [106, 121], [106, 126], [106, 128], [106, 129], [106, 133], [106, 135], [106, 138], [106, 148], [106, 162], [106, 170], [106, 172], [107, 111], [107, 113], [107, 116], [107, 117], [107, 124], [107, 125], [107, 127], [107, 129], [107, 130], [107, 133], [107, 134], [107, 138], [107, 143], [107, 144], [107, 152], [107, 154], [107, 156], [107, 163], [107, 170], [107, 171], [107, 179], [108, 112], [108, 118], [108, 122], [108, 127], [108, 131], [108, 141], [108, 142], [108, 143], [108, 146], [108, 148], [108, 155], [108, 159], [108, 167], [108, 169], [108, 170], [108, 172], [108, 176], [108, 179], [109, 110], [109, 112], [109, 113], [109, 119], [109, 126], [109, 132], [109, 146], [109, 157], [109, 159], [109, 166], [109, 167], [109, 168], [109, 171], [109, 174], [109, 175], [110, 122], [110, 129], [110, 141], [110, 152], [110, 156], [110, 162], [110, 163], [110, 179], [111, 116], [111, 131], [111, 133], [111, 142], [111, 150], [111, 152], [111, 153], [111, 154], [111, 158], [111, 166], [111, 168], [111, 174], [112, 122], [112, 126], [112, 130], [112, 132], [112, 133], [112, 134], [112, 135], [112, 142], [112, 168], [113, 121], [113, 122], [113, 124], [113, 127], [113, 130], [113, 153], [113, 156], [113, 170], [113, 175], [113, 179], [114, 115], [114, 122], [114, 129], [114, 131], [114, 145], [114, 152], [114, 160], [114, 161], [114, 165], [115, 121], [115, 125], [115, 136], [115, 139], [115, 144], [115, 151], [115, 152], [115, 153], [115, 160], [115, 162], [115, 165], [115, 166], [115, 168], [115, 171], [115, 177], [116, 121], [116, 122], [116, 129], [116, 130], [116, 133], [116, 134], [116, 143], [116, 147], [116, 154], [116, 158], [116, 159], [116, 162], [116, 163], [116, 167], [116, 168], [116, 169], [116, 172], [116, 175], [116, 176], [117, 119], [117, 122], [117, 129], [117, 130], [118, 127], [118, 135], [118, 144], [118, 147], [118, 150], [118, 152], [118, 156], [118, 160], [118, 161], [118, 164], [118, 168], [118, 171], [118, 176], [118, 177], [119, 130], [119, 133], [119, 134], [119, 137], [119, 138], [119, 140], [119, 143], [119, 150], [119, 152], [119, 155], [119, 160], [119, 163], [119, 166], [119, 174], [119, 175], [119, 179], [120, 121], [120, 126], [120, 130], [120, 134], [120, 135], [120, 140], [120, 144], [120, 151], [120, 160], [120, 167], [120, 169], [120, 174], [121, 132], [121, 135], [121, 139], [121, 140], [121, 143], [121, 156], [121, 170], [122, 125], [122, 130], [122, 131], [122, 132], [122, 137], [122, 138], [122, 143], [122, 157], [122, 159], [122, 164], [122, 165], [122, 170], [122, 175], [123, 128], [123, 134], [123, 136], [123, 143], [123, 149], [123, 152], [123, 160], [123, 163], [123, 166], [123, 172], [124, 126], [124, 130], [124, 131], [124, 134], [124, 147], [124, 157], [124, 159], [124, 161], [125, 127], [125, 129], [125, 135], [125, 143], [125, 144], [125, 148], [125, 149], [125, 151], [125, 164], [125, 170], [125, 171], [125, 174], [126, 128], [126, 130], [126, 132], [126, 133], [126, 144], [126, 159], [126, 160], [126, 167], [126, 170], [126, 172], [126, 174], [126, 178], [127, 129], [127, 136], [127, 137], [127, 139], [127, 144], [127, 146], [127, 150], [127, 159], [127, 164], [127, 165], [127, 172], [127, 175], [128, 131], [128, 136], [128, 148], [128, 150], [128, 154], [128, 159], [128, 164], [128, 165], [128, 171], [128, 174], [128, 175], [128, 177], [128, 179], [129, 139], [129, 140], [129, 144], [129, 146], [129, 149], [129, 151], [129, 155], [129, 162], [129, 164], [129, 165], [129, 174], [129, 176], [129, 177], [130, 131], [130, 136], [130, 137], [130, 139], [130, 146], [130, 148], [130, 152], [130, 155], [130, 158], [130, 164], [130, 179], [131, 133], [131, 137], [131, 145], [131, 147], [131, 150], [131, 152], [131, 156], [131, 159], [131, 171], [131, 176], [131, 177], [132, 136], [132, 137], [132, 139], [132, 142], [132, 143], [132, 144], [132, 150], [132, 155], [132, 160], [132, 172], [132, 178], [133, 136], [133, 137], [133, 140], [133, 142], [133, 143], [133, 148], [133, 151], [133, 157], [133, 159], [134, 135], [134, 139], [134, 154], [134, 155], [134, 162], [134, 166], [134, 167], [134, 168], [134, 172], [134, 178], [135, 149], [135, 151], [135, 159], [135, 160], [135, 164], [136, 139], [136, 152], [136, 159], [136, 166], [136, 168], [136, 169], [136, 174], [136, 177], [137, 140], [137, 149], [137, 156], [137, 162], [137, 168], [137, 170], [137, 173], [138, 146], [138, 147], [138, 148], [138, 151], [138, 156], [138, 162], [139, 143], [139, 149], [139, 165], [139, 177], [140, 144], [140, 146], [140, 149], [140, 150], [140, 153], [140, 155], [140, 160], [140, 167], [140, 169], [140, 172], [141, 142], [141, 143], [141, 152], [141, 153], [141, 156], [141, 161], [141, 164], [141, 175], [142, 150], [142, 152], [142, 156], [142, 158], [142, 166], [142, 178], [143, 145], [143, 156], [143, 161], [143, 167], [143, 169], [143, 177], [144, 145], [144, 157], [144, 159], [144, 162], [144, 165], [144, 172], [144, 174], [145, 147], [145, 150], [145, 153], [145, 157], [145, 159], [145, 162], [145, 164], [145, 173], [145, 174], [146, 151], [146, 153], [146, 155], [146, 160], [146, 166], [146, 167], [146, 169], [146, 178], [147, 148], [147, 160], [147, 161], [147, 163], [147, 167], [147, 169], [147, 172], [147, 174], [147, 177], [148, 151], [148, 155], [148, 161], [148, 177], [149, 153], [149, 167], [149, 170], [149, 173], [149, 174], [149, 176], [149, 177], [150, 154], [150, 157], [150, 159], [150, 161], [150, 170], [150, 174], [151, 156], [151, 160], [151, 170], [151, 171], [152, 155], [152, 156], [152, 157], [152, 158], [152, 166], [152, 170], [152, 171], [152, 172], [152, 176], [152, 177], [153, 154], [153, 158], [153, 169], [153, 171], [153, 174], [154, 165], [154, 170], [154, 171], [154, 177], [154, 179], [155, 156], [155, 165], [155, 167], [155, 178], [156, 169], [156, 171], [156, 173], [156, 174], [156, 178], [157, 167], [158, 165], [158, 173], [158, 176], [158, 179], [159, 164], [159, 166], [159, 168], [159, 173], [159, 176], [159, 179], [160, 172], [160, 173], [161, 165], [161, 177], [162, 165], [162, 166], [162, 170], [162, 173], [163, 174], [166, 168], [166, 170], [166, 171], [166, 174], [167, 173], [167, 178], [168, 173], [168, 177], [169, 174], [169, 175], [169, 176], [169, 179], [170, 176], [171, 179], [172, 174], [172, 176], [173, 176], [174, 178], [176, 178]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s5/tests/run.py b/tasks/construct-nppc-dominating-set-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-dominating-set-l5-s5/tests/test.sh b/tasks/construct-nppc-dominating-set-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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-l6-s0/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l6-s0/environment/instance.json b/tasks/construct-nppc-dominating-set-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba7faf107069bb53b65fb91b36e0552b41312071 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 300, "k": 20, "edges": [[0, 6], [0, 12], [0, 19], [0, 21], [0, 61], [0, 68], [0, 99], [0, 112], [0, 131], [0, 137], [0, 143], [0, 159], [0, 163], [0, 195], [0, 196], [0, 214], [0, 217], [0, 225], [0, 241], [0, 253], [0, 264], [1, 11], [1, 41], [1, 52], [1, 62], [1, 94], [1, 107], [1, 145], [1, 158], [1, 163], [1, 167], [1, 179], [1, 180], [1, 190], [1, 200], [1, 204], [1, 214], [1, 246], [1, 248], [1, 289], [1, 297], [2, 4], [2, 17], [2, 89], [2, 131], [2, 182], [2, 189], [2, 197], [2, 198], [2, 239], [2, 264], [2, 270], [2, 278], [3, 4], [3, 21], [3, 31], [3, 35], [3, 45], [3, 69], [3, 72], [3, 83], [3, 109], [3, 135], [3, 152], [3, 216], [3, 262], [3, 285], [3, 290], [4, 93], [4, 108], [4, 121], [4, 125], [4, 153], [4, 164], [4, 176], [4, 188], [4, 208], [4, 257], [4, 283], [5, 28], [5, 29], [5, 44], [5, 68], [5, 73], [5, 140], [5, 151], [5, 154], [5, 159], [5, 177], [5, 218], [5, 243], [5, 249], [5, 250], [5, 252], [5, 256], [5, 268], [6, 9], [6, 55], [6, 69], [6, 72], [6, 75], [6, 99], [6, 116], [6, 131], [6, 136], [6, 152], [6, 180], [6, 189], [6, 205], [6, 253], [6, 255], [6, 268], [6, 283], [6, 298], [7, 17], [7, 34], [7, 39], [7, 62], [7, 118], [7, 143], [7, 144], [7, 184], [7, 213], [7, 266], [7, 268], [7, 270], [7, 277], [7, 294], [8, 16], [8, 30], [8, 31], [8, 39], [8, 59], [8, 62], [8, 74], [8, 87], [8, 114], [8, 116], [8, 134], [8, 137], [8, 141], [8, 142], [8, 154], [8, 161], [8, 177], [8, 180], [8, 192], [8, 217], [8, 228], [8, 237], [8, 259], [8, 263], [8, 269], [8, 286], [8, 289], [8, 290], [9, 21], [9, 23], [9, 54], [9, 85], [9, 89], [9, 95], [9, 120], [9, 164], [9, 200], [9, 209], [9, 213], [9, 216], [9, 245], [9, 250], [9, 251], [9, 295], [10, 17], [10, 19], [10, 39], [10, 59], [10, 75], [10, 81], [10, 156], [10, 160], [10, 200], [10, 226], [10, 229], [10, 230], [10, 245], [10, 252], [11, 31], [11, 50], [11, 52], [11, 68], [11, 69], [11, 70], [11, 103], [11, 122], [11, 124], [11, 129], [11, 135], [11, 155], [11, 164], [11, 185], [11, 212], [11, 248], [11, 261], [11, 269], [11, 277], [11, 284], [11, 289], [12, 24], [12, 37], [12, 43], [12, 54], [12, 69], [12, 71], [12, 93], [12, 140], [12, 169], [12, 180], [12, 201], [12, 208], [12, 242], [12, 246], [12, 271], [12, 284], [13, 86], [13, 97], [13, 101], [13, 118], [13, 119], [13, 126], [13, 127], [13, 148], [13, 180], [13, 181], [13, 183], [13, 187], [13, 189], [13, 213], [13, 217], [13, 226], [13, 245], [13, 249], [13, 257], [13, 278], [13, 291], [13, 299], [14, 55], [14, 64], [14, 67], [14, 70], [14, 109], [14, 112], [14, 117], [14, 131], [14, 134], [14, 136], [14, 138], [14, 141], [14, 166], [14, 168], [14, 193], [14, 201], [14, 239], [14, 243], [15, 102], [15, 120], [15, 131], [15, 143], [15, 146], [15, 154], [15, 163], [15, 175], [15, 180], [15, 212], [15, 241], [15, 253], [15, 264], [15, 271], [15, 275], [15, 276], [15, 285], [16, 39], [16, 82], [16, 88], [16, 99], [16, 104], [16, 107], [16, 127], [16, 145], [16, 147], [16, 165], [16, 185], [16, 200], [16, 227], [16, 242], [16, 264], [16, 267], [16, 278], [16, 279], [16, 290], [17, 20], [17, 38], [17, 43], [17, 44], [17, 75], [17, 82], [17, 85], [17, 102], [17, 109], [17, 111], [17, 112], [17, 152], [17, 157], [17, 169], [17, 170], [17, 178], [17, 193], [17, 202], [17, 231], [17, 241], [18, 19], [18, 33], [18, 45], [18, 53], [18, 79], [18, 117], [18, 127], [18, 131], [18, 142], [18, 145], [18, 179], [18, 180], [18, 184], [18, 189], [18, 190], [18, 193], [18, 197], [18, 219], [18, 252], [18, 260], [18, 289], [18, 299], [19, 44], [19, 45], [19, 48], [19, 62], [19, 69], [19, 90], [19, 99], [19, 132], [19, 138], [19, 140], [19, 142], [19, 172], [19, 173], [19, 185], [19, 225], [19, 226], [19, 255], [19, 263], [19, 294], [20, 26], [20, 28], [20, 40], [20, 46], [20, 59], [20, 71], [20, 92], [20, 119], [20, 131], [20, 132], [20, 138], [20, 145], [20, 147], [20, 167], [20, 179], [20, 200], [20, 217], [20, 229], [20, 256], [20, 265], [20, 289], [20, 293], [21, 38], [21, 59], [21, 91], [21, 112], [21, 142], [21, 159], [21, 168], [21, 198], [21, 203], [21, 209], [21, 234], [21, 260], [21, 279], [22, 31], [22, 35], [22, 43], [22, 64], [22, 73], [22, 80], [22, 85], [22, 89], [22, 105], [22, 109], [22, 153], [22, 154], [22, 166], [22, 169], [22, 201], [22, 209], [22, 213], [22, 215], [22, 222], [22, 227], [22, 239], [22, 283], [23, 26], [23, 28], [23, 29], [23, 56], [23, 66], [23, 154], [23, 173], [23, 194], [23, 197], [23, 202], [23, 209], [23, 215], [23, 243], [23, 244], [23, 260], [23, 295], [23, 297], [24, 29], [24, 36], [24, 46], [24, 62], [24, 67], [24, 70], [24, 83], [24, 85], [24, 97], [24, 101], [24, 105], [24, 141], [24, 192], [24, 193], [24, 262], [24, 265], [24, 283], [24, 288], [24, 295], [25, 61], [25, 66], [25, 85], [25, 100], [25, 115], [25, 120], [25, 131], [25, 135], [25, 148], [25, 149], [25, 164], [25, 172], [25, 181], [25, 182], [25, 185], [25, 191], [25, 272], [26, 40], [26, 52], [26, 55], [26, 64], [26, 70], [26, 76], [26, 79], [26, 88], [26, 120], [26, 143], [26, 150], [26, 197], [26, 206], [26, 208], [26, 233], [26, 255], [26, 274], [26, 284], [26, 292], [27, 28], [27, 74], [27, 79], [27, 90], [27, 95], [27, 96], [27, 121], [27, 123], [27, 149], [27, 151], [27, 213], [27, 218], [27, 260], [27, 263], [27, 264], [27, 265], [28, 43], [28, 62], [28, 64], [28, 71], [28, 86], [28, 89], [28, 94], [28, 121], [28, 182], [28, 202], [28, 236], [28, 273], [28, 280], [28, 286], [29, 44], [29, 87], [29, 89], [29, 116], [29, 146], [29, 151], [29, 157], [29, 158], [29, 160], [29, 173], [29, 179], [29, 197], [29, 204], [29, 215], [29, 242], [29, 295], [30, 57], [30, 58], [30, 80], [30, 110], [30, 114], [30, 120], [30, 151], [30, 152], [30, 153], [30, 171], [30, 188], [30, 200], [30, 212], [30, 248], [31, 48], [31, 76], [31, 86], [31, 93], [31, 96], [31, 101], [31, 105], [31, 116], [31, 125], [31, 131], [31, 135], [31, 136], [31, 142], [31, 145], [31, 148], [31, 149], [31, 159], [31, 160], [31, 164], [31, 166], [31, 170], [31, 188], [31, 190], [31, 197], [31, 208], [31, 217], [31, 226], [31, 256], [31, 259], [31, 263], [31, 264], [31, 275], [31, 276], [31, 287], [31, 294], [32, 33], [32, 38], [32, 57], [32, 65], [32, 66], [32, 68], [32, 71], [32, 89], [32, 124], [32, 134], [32, 165], [32, 169], [32, 188], [32, 192], [32, 193], [32, 199], [32, 221], [32, 227], [32, 246], [32, 261], [32, 285], [32, 288], [32, 293], [32, 297], [33, 70], [33, 140], [33, 149], [33, 164], [33, 168], [33, 195], [33, 206], [33, 214], [33, 217], [33, 230], [33, 272], [33, 274], [33, 283], [33, 284], [34, 43], [34, 53], [34, 75], [34, 93], [34, 133], [34, 167], [34, 172], [34, 175], [34, 200], [34, 205], [34, 233], [34, 290], [34, 293], [34, 296], [34, 298], [35, 50], [35, 81], [35, 94], [35, 101], [35, 119], [35, 120], [35, 165], [35, 172], [35, 173], [35, 188], [35, 205], [35, 208], [35, 210], [35, 236], [35, 237], [35, 243], [35, 250], [35, 277], [35, 283], [35, 289], [36, 39], [36, 44], [36, 49], [36, 78], [36, 132], [36, 142], [36, 144], [36, 190], [36, 203], [36, 206], [36, 221], [36, 232], [36, 239], [36, 242], [36, 266], [36, 274], [36, 278], [36, 285], [37, 54], [37, 59], [37, 62], [37, 63], [37, 93], [37, 112], [37, 129], [37, 145], [37, 161], [37, 164], [37, 165], [37, 168], [37, 182], [37, 220], [37, 228], [37, 233], [37, 289], [38, 40], [38, 44], [38, 47], [38, 81], [38, 86], [38, 98], [38, 132], [38, 133], [38, 156], [38, 173], [38, 183], [38, 216], [38, 234], [38, 240], [38, 271], [38, 272], [38, 274], [38, 299], [39, 44], [39, 59], [39, 78], [39, 81], [39, 92], [39, 140], [39, 176], [39, 183], [39, 188], [39, 191], [39, 194], [39, 208], [39, 210], [39, 215], [39, 218], [39, 220], [39, 261], [39, 276], [40, 59], [40, 81], [40, 82], [40, 96], [40, 134], [40, 161], [40, 172], [40, 206], [40, 209], [40, 224], [40, 243], [40, 275], [40, 290], [40, 298], [41, 56], [41, 62], [41, 78], [41, 81], [41, 84], [41, 102], [41, 128], [41, 131], [41, 135], [41, 139], [41, 145], [41, 149], [41, 151], [41, 171], [41, 174], [41, 218], [41, 221], [41, 243], [41, 244], [41, 246], [41, 254], [41, 274], [41, 287], [41, 289], [42, 43], [42, 64], [42, 80], [42, 82], [42, 101], [42, 105], [42, 110], [42, 114], [42, 120], [42, 124], [42, 128], [42, 141], [42, 171], [42, 172], [42, 183], [42, 204], [42, 207], [42, 212], [42, 218], [42, 228], [42, 229], [42, 232], [42, 242], [42, 266], [42, 270], [42, 291], [43, 49], [43, 64], [43, 85], [43, 107], [43, 154], [43, 160], [43, 175], [43, 191], [43, 206], [43, 209], [43, 224], [43, 226], [43, 240], [43, 241], [43, 255], [43, 257], [43, 283], [43, 294], [44, 50], [44, 51], [44, 79], [44, 124], [44, 131], [44, 139], [44, 145], [44, 148], [44, 164], [44, 177], [44, 197], [44, 208], [44, 227], [44, 246], [44, 270], [44, 280], [44, 288], [44, 294], [44, 296], [44, 297], [45, 99], [45, 137], [45, 151], [45, 162], [45, 169], [45, 181], [45, 188], [45, 218], [45, 226], [45, 261], [45, 263], [45, 276], [46, 51], [46, 118], [46, 150], [46, 183], [46, 184], [46, 210], [46, 268], [46, 289], [46, 291], [47, 48], [47, 64], [47, 67], [47, 93], [47, 107], [47, 110], [47, 114], [47, 129], [47, 164], [47, 165], [47, 168], [47, 180], [47, 189], [47, 226], [47, 228], [47, 245], [47, 264], [48, 96], [48, 100], [48, 152], [48, 159], [48, 206], [48, 212], [48, 213], [48, 219], [48, 222], [48, 230], [48, 231], [48, 233], [48, 244], [48, 252], [48, 266], [48, 281], [48, 287], [48, 288], [48, 296], [49, 61], [49, 70], [49, 71], [49, 80], [49, 116], [49, 158], [49, 161], [49, 199], [49, 200], [49, 204], [49, 210], [49, 216], [49, 218], [49, 231], [49, 266], [50, 59], [50, 61], [50, 63], [50, 76], [50, 87], [50, 112], [50, 178], [50, 201], [50, 210], [50, 212], [50, 254], [50, 263], [50, 266], [51, 103], [51, 133], [51, 143], [51, 183], [51, 200], [51, 202], [51, 206], [51, 219], [51, 259], [51, 261], [51, 267], [51, 271], [51, 281], [52, 66], [52, 112], [52, 114], [52, 115], [52, 142], [52, 149], [52, 159], [52, 173], [52, 208], [52, 221], [52, 258], [52, 269], [52, 295], [52, 298], [53, 61], [53, 66], [53, 85], [53, 143], [53, 147], [53, 179], [53, 238], [53, 267], [54, 78], [54, 104], [54, 108], [54, 114], [54, 131], [54, 143], [54, 171], [54, 174], [54, 176], [54, 194], [54, 212], [54, 214], [54, 221], [54, 229], [54, 244], [54, 254], [54, 267], [54, 277], [54, 287], [54, 291], [55, 87], [55, 92], [55, 112], [55, 130], [55, 131], [55, 196], [55, 200], [55, 202], [55, 211], [55, 234], [55, 247], [55, 252], [56, 74], [56, 86], [56, 103], [56, 125], [56, 143], [56, 145], [56, 152], [56, 159], [56, 165], [56, 169], [56, 188], [56, 198], [56, 208], [56, 209], [56, 212], [56, 213], [56, 231], [56, 242], [56, 253], [56, 254], [56, 255], [56, 283], [57, 63], [57, 65], [57, 66], [57, 72], [57, 109], [57, 110], [57, 121], [57, 160], [57, 169], [57, 179], [57, 186], [57, 198], [57, 213], [57, 244], [57, 255], [57, 257], [57, 259], [57, 296], [58, 64], [58, 139], [58, 149], [58, 168], [58, 183], [58, 188], [58, 189], [58, 196], [58, 222], [58, 233], [58, 239], [58, 284], [59, 68], [59, 70], [59, 87], [59, 89], [59, 129], [59, 142], [59, 151], [59, 165], [59, 167], [59, 194], [59, 202], [59, 224], [59, 227], [59, 230], [59, 239], [59, 270], [59, 288], [59, 295], [60, 75], [60, 91], [60, 131], [60, 145], [60, 161], [60, 168], [60, 196], [60, 203], [60, 214], [60, 219], [60, 266], [60, 272], [60, 277], [61, 79], [61, 82], [61, 98], [61, 100], [61, 106], [61, 123], [61, 128], [61, 147], [61, 171], [61, 211], [61, 216], [61, 227], [61, 229], [61, 244], [61, 260], [61, 292], [61, 299], [62, 68], [62, 80], [62, 83], [62, 88], [62, 102], [62, 110], [62, 119], [62, 143], [62, 150], [62, 160], [62, 173], [62, 177], [62, 199], [62, 211], [62, 221], [62, 241], [62, 246], [62, 254], [62, 296], [63, 75], [63, 80], [63, 118], [63, 125], [63, 135], [63, 137], [63, 147], [63, 159], [63, 173], [63, 180], [63, 216], [63, 219], [63, 265], [63, 274], [63, 280], [63, 299], [64, 70], [64, 79], [64, 87], [64, 92], [64, 95], [64, 97], [64, 111], [64, 117], [64, 120], [64, 126], [64, 129], [64, 133], [64, 136], [64, 138], [64, 152], [64, 155], [64, 157], [64, 173], [64, 177], [64, 181], [64, 199], [64, 203], [64, 205], [64, 219], [64, 233], [64, 244], [64, 277], [64, 288], [64, 295], [64, 297], [65, 71], [65, 92], [65, 109], [65, 156], [65, 183], [65, 184], [65, 210], [65, 211], [65, 228], [65, 231], [65, 256], [65, 258], [65, 299], [66, 75], [66, 132], [66, 152], [66, 208], [66, 212], [66, 215], [66, 221], [66, 223], [66, 236], [66, 240], [66, 262], [66, 273], [66, 274], [66, 277], [66, 294], [67, 68], [67, 78], [67, 90], [67, 94], [67, 96], [67, 105], [67, 113], [67, 145], [67, 147], [67, 168], [67, 179], [67, 183], [67, 191], [67, 199], [67, 208], [67, 210], [67, 216], [67, 237], [67, 243], [67, 245], [67, 261], [67, 270], [67, 294], [68, 95], [68, 96], [68, 121], [68, 134], [68, 139], [68, 151], [68, 163], [68, 258], [68, 295], [69, 75], [69, 96], [69, 112], [69, 121], [69, 158], [69, 177], [69, 179], [69, 208], [69, 225], [69, 242], [69, 252], [69, 268], [69, 278], [69, 290], [69, 295], [70, 74], [70, 91], [70, 106], [70, 131], [70, 136], [70, 138], [70, 147], [70, 161], [70, 173], [70, 180], [70, 187], [70, 193], [70, 210], [70, 220], [70, 235], [70, 237], [70, 296], [71, 74], [71, 96], [71, 104], [71, 147], [71, 151], [71, 167], [71, 196], [71, 218], [71, 225], [71, 236], [71, 274], [71, 284], [72, 75], [72, 97], [72, 129], [72, 131], [72, 138], [72, 143], [72, 161], [72, 173], [72, 175], [72, 181], [72, 184], [72, 213], [72, 231], [72, 246], [72, 266], [72, 272], [72, 281], [72, 296], [73, 85], [73, 90], [73, 96], [73, 105], [73, 115], [73, 131], [73, 138], [73, 144], [73, 177], [73, 180], [73, 196], [73, 205], [73, 239], [73, 245], [73, 248], [73, 256], [73, 259], [73, 278], [73, 279], [73, 281], [74, 84], [74, 95], [74, 100], [74, 146], [74, 187], [74, 193], [74, 214], [74, 217], [74, 230], [74, 236], [74, 248], [74, 271], [74, 295], [75, 80], [75, 94], [75, 104], [75, 127], [75, 134], [75, 139], [75, 150], [75, 152], [75, 182], [75, 187], [75, 190], [75, 196], [75, 201], [75, 202], [75, 220], [75, 232], [75, 257], [75, 262], [75, 274], [75, 279], [75, 289], [75, 290], [75, 293], [76, 79], [76, 81], [76, 82], [76, 84], [76, 125], [76, 138], [76, 143], [76, 144], [76, 235], [76, 260], [76, 276], [76, 282], [77, 82], [77, 104], [77, 111], [77, 129], [77, 167], [77, 180], [77, 186], [77, 200], [77, 213], [77, 220], [77, 221], [77, 264], [78, 87], [78, 94], [78, 106], [78, 147], [78, 161], [78, 163], [78, 169], [78, 171], [78, 179], [78, 182], [78, 185], [78, 191], [78, 196], [78, 200], [78, 204], [78, 208], [78, 219], [78, 256], [78, 259], [78, 277], [78, 281], [78, 285], [79, 111], [79, 112], [79, 130], [79, 157], [79, 177], [79, 179], [79, 181], [79, 197], [79, 202], [79, 209], [79, 219], [79, 230], [79, 266], [80, 132], [80, 142], [80, 144], [80, 150], [80, 153], [80, 181], [80, 188], [80, 193], [80, 201], [80, 293], [81, 110], [81, 116], [81, 143], [81, 147], [81, 161], [81, 180], [81, 187], [81, 228], [81, 238], [81, 240], [81, 245], [81, 249], [81, 270], [81, 288], [82, 101], [82, 160], [82, 171], [82, 181], [82, 236], [82, 291], [82, 293], [83, 89], [83, 90], [83, 94], [83, 116], [83, 129], [83, 134], [83, 143], [83, 188], [83, 192], [83, 208], [83, 232], [83, 248], [83, 251], [83, 262], [83, 263], [83, 284], [83, 293], [83, 294], [84, 138], [84, 140], [84, 181], [84, 187], [84, 195], [84, 197], [84, 221], [84, 233], [84, 252], [84, 271], [84, 273], [84, 282], [84, 284], [85, 94], [85, 96], [85, 110], [85, 139], [85, 143], [85, 147], [85, 156], [85, 168], [85, 174], [85, 191], [85, 194], [85, 210], [85, 218], [85, 242], [85, 244], [85, 249], [85, 262], [85, 263], [85, 266], [85, 267], [85, 282], [85, 289], [86, 146], [86, 151], [86, 157], [86, 167], [86, 172], [86, 189], [86, 274], [86, 295], [87, 114], [87, 116], [87, 118], [87, 119], [87, 134], [87, 155], [87, 166], [87, 180], [87, 199], [87, 207], [87, 259], [87, 260], [87, 266], [87, 289], [88, 96], [88, 105], [88, 131], [88, 142], [88, 153], [88, 158], [88, 159], [88, 164], [88, 207], [88, 216], [88, 228], [88, 247], [88, 248], [88, 250], [88, 258], [88, 270], [88, 278], [89, 103], [89, 118], [89, 124], [89, 136], [89, 144], [89, 148], [89, 155], [89, 183], [89, 199], [89, 200], [89, 215], [89, 218], [89, 231], [89, 249], [89, 251], [89, 254], [90, 130], [90, 133], [90, 167], [90, 172], [90, 185], [90, 189], [90, 193], [90, 199], [90, 202], [90, 226], [90, 252], [90, 264], [90, 285], [90, 286], [90, 291], [90, 292], [90, 299], [91, 94], [91, 97], [91, 136], [91, 138], [91, 142], [91, 144], [91, 165], [91, 172], [91, 178], [91, 199], [91, 202], [91, 218], [91, 245], [91, 268], [92, 107], [92, 130], [92, 143], [92, 197], [92, 204], [92, 205], [92, 207], [92, 214], [92, 261], [92, 273], [92, 280], [92, 287], [92, 294], [93, 116], [93, 129], [93, 135], [93, 150], [93, 156], [93, 191], [93, 196], [93, 200], [93, 206], [93, 221], [93, 235], [93, 246], [93, 260], [93, 281], [93, 286], [93, 296], [94, 95], [94, 105], [94, 143], [94, 161], [94, 178], [94, 179], [94, 191], [94, 238], [94, 249], [94, 263], [94, 294], [95, 96], [95, 150], [95, 160], [95, 191], [95, 207], [95, 230], [95, 245], [95, 254], [95, 255], [95, 287], [95, 292], [96, 115], [96, 139], [96, 154], [96, 163], [96, 166], [96, 173], [96, 185], [96, 220], [96, 228], [96, 236], [96, 241], [96, 251], [96, 259], [96, 283], [96, 286], [96, 287], [96, 299], [97, 120], [97, 135], [97, 137], [97, 140], [97, 149], [97, 160], [97, 193], [97, 212], [97, 225], [97, 238], [97, 269], [97, 271], [98, 135], [98, 169], [98, 173], [98, 174], [98, 177], [98, 200], [98, 203], [98, 225], [98, 227], [98, 228], [98, 281], [98, 284], [98, 288], [98, 298], [99, 100], [99, 121], [99, 140], [99, 152], [99, 175], [99, 203], [99, 206], [99, 208], [99, 222], [99, 237], [99, 238], [99, 260], [100, 118], [100, 169], [100, 171], [100, 174], [100, 176], [100, 207], [100, 210], [100, 268], [100, 279], [101, 122], [101, 131], [101, 156], [101, 160], [101, 165], [101, 172], [101, 183], [101, 186], [101, 191], [101, 205], [101, 242], [101, 283], [101, 286], [101, 289], [101, 297], [102, 104], [102, 120], [102, 137], [102, 147], [102, 161], [102, 227], [102, 250], [102, 267], [102, 269], [102, 284], [102, 285], [103, 109], [103, 182], [103, 184], [103, 219], [103, 226], [103, 239], [103, 246], [103, 253], [103, 260], [103, 269], [103, 280], [103, 295], [103, 299], [104, 120], [104, 163], [104, 176], [104, 190], [104, 192], [104, 203], [104, 204], [104, 206], [104, 219], [104, 272], [104, 275], [104, 296], [105, 120], [105, 121], [105, 127], [105, 140], [105, 160], [105, 162], [105, 163], [105, 164], [105, 178], [105, 201], [105, 252], [105, 265], [106, 139], [106, 151], [106, 153], [106, 192], [106, 239], [107, 179], [107, 199], [107, 203], [107, 213], [107, 215], [107, 266], [107, 298], [108, 125], [108, 126], [108, 139], [108, 142], [108, 152], [108, 176], [108, 185], [108, 187], [108, 192], [108, 200], [108, 215], [108, 232], [108, 240], [108, 271], [108, 283], [109, 140], [109, 151], [109, 177], [109, 202], [109, 206], [109, 214], [109, 267], [109, 283], [109, 287], [109, 296], [110, 117], [110, 129], [110, 166], [110, 189], [110, 239], [110, 243], [110, 275], [110, 297], [111, 114], [111, 133], [111, 135], [111, 145], [111, 150], [111, 164], [111, 191], [111, 203], [111, 209], [111, 227], [111, 244], [111, 277], [111, 278], [111, 291], [111, 295], [111, 298], [112, 118], [112, 141], [112, 152], [112, 153], [112, 162], [112, 172], [112, 174], [112, 176], [112, 179], [112, 189], [112, 200], [112, 212], [112, 215], [112, 222], [112, 243], [112, 284], [113, 118], [113, 143], [113, 207], [113, 212], [113, 219], [113, 223], [113, 244], [113, 259], [113, 265], [113, 273], [113, 284], [113, 289], [113, 294], [114, 116], [114, 118], [114, 121], [114, 131], [114, 138], [114, 149], [114, 163], [114, 169], [114, 221], [114, 251], [114, 252], [114, 255], [114, 281], [115, 151], [115, 178], [115, 194], [115, 206], [115, 207], [115, 218], [115, 229], [115, 234], [115, 246], [115, 279], [115, 291], [115, 292], [115, 296], [115, 299], [116, 126], [116, 132], [116, 134], [116, 150], [116, 153], [116, 160], [116, 169], [116, 172], [116, 181], [116, 184], [116, 218], [116, 224], [116, 245], [116, 249], [116, 256], [116, 272], [117, 125], [117, 133], [117, 137], [117, 141], [117, 153], [117, 165], [117, 176], [117, 180], [117, 187], [117, 213], [117, 218], [117, 238], [117, 251], [117, 260], [117, 263], [117, 278], [117, 282], [117, 285], [117, 286], [117, 291], [117, 296], [118, 122], [118, 143], [118, 152], [118, 155], [118, 189], [118, 211], [118, 217], [118, 222], [118, 231], [118, 247], [118, 248], [118, 254], [118, 257], [118, 258], [118, 260], [118, 268], [118, 272], [118, 283], [118, 295], [119, 144], [119, 208], [119, 220], [119, 256], [119, 295], [119, 298], [120, 130], [120, 135], [120, 182], [120, 222], [120, 289], [120, 297], [121, 128], [121, 140], [121, 171], [121, 172], [121, 193], [121, 201], [121, 212], [121, 218], [121, 229], [121, 275], [122, 143], [122, 153], [122, 154], [122, 197], [122, 200], [122, 212], [122, 235], [122, 258], [122, 270], [122, 285], [122, 292], [123, 151], [123, 167], [123, 174], [123, 176], [123, 178], [123, 184], [123, 192], [123, 207], [123, 212], [123, 231], [123, 234], [123, 255], [123, 264], [123, 281], [123, 294], [123, 296], [123, 299], [124, 131], [124, 133], [124, 136], [124, 160], [124, 163], [124, 177], [124, 194], [124, 196], [124, 242], [124, 246], [124, 271], [124, 274], [124, 287], [125, 141], [125, 148], [125, 175], [125, 190], [125, 204], [125, 238], [125, 244], [125, 251], [125, 262], [125, 294], [126, 145], [126, 160], [126, 167], [126, 184], [126, 207], [126, 221], [126, 235], [126, 238], [126, 249], [126, 251], [126, 252], [126, 254], [126, 277], [126, 284], [127, 132], [127, 153], [127, 156], [127, 189], [127, 207], [127, 210], [127, 242], [127, 276], [127, 281], [127, 297], [128, 154], [128, 178], [128, 190], [128, 194], [128, 200], [128, 237], [128, 239], [128, 247], [128, 269], [128, 281], [129, 146], [129, 178], [129, 210], [129, 231], [129, 244], [129, 246], [129, 252], [129, 277], [129, 285], [129, 286], [129, 293], [130, 134], [130, 167], [130, 175], [130, 183], [130, 190], [130, 199], [130, 223], [130, 259], [130, 284], [131, 146], [131, 152], [131, 162], [131, 193], [131, 196], [131, 199], [131, 216], [131, 224], [131, 225], [131, 229], [131, 234], [131, 238], [131, 250], [131, 255], [131, 296], [132, 146], [132, 206], [132, 221], [132, 233], [132, 259], [132, 275], [132, 297], [133, 137], [133, 188], [133, 190], [133, 201], [133, 230], [133, 231], [133, 238], [133, 244], [133, 247], [133, 254], [133, 299], [134, 160], [134, 174], [134, 178], [134, 239], [134, 244], [134, 248], [134, 264], [134, 291], [134, 296], [135, 178], [135, 185], [135, 194], [135, 197], [135, 208], [135, 222], [135, 224], [135, 229], [135, 250], [135, 276], [135, 283], [136, 146], [136, 186], [136, 200], [136, 221], [136, 251], [136, 256], [136, 291], [136, 293], [137, 139], [137, 161], [137, 166], [137, 173], [137, 179], [137, 184], [137, 188], [137, 214], [137, 218], [137, 232], [137, 235], [137, 250], [137, 284], [137, 293], [138, 149], [138, 182], [138, 203], [138, 210], [138, 217], [138, 237], [138, 251], [138, 252], [138, 256], [138, 270], [139, 158], [139, 187], [139, 190], [139, 216], [139, 257], [139, 258], [139, 261], [139, 268], [140, 141], [140, 161], [140, 184], [140, 193], [140, 221], [140, 251], [140, 254], [140, 277], [140, 285], [141, 146], [141, 181], [141, 188], [141, 195], [141, 212], [141, 218], [141, 230], [141, 239], [141, 240], [141, 249], [141, 265], [142, 193], [142, 251], [142, 275], [143, 158], [143, 167], [143, 168], [143, 169], [143, 186], [143, 193], [143, 209], [143, 227], [143, 233], [143, 262], [143, 265], [143, 274], [143, 277], [144, 149], [144, 158], [144, 164], [144, 167], [144, 183], [144, 185], [144, 200], [144, 220], [144, 239], [144, 247], [144, 249], [144, 261], [144, 277], [144, 289], [145, 149], [145, 164], [145, 167], [145, 186], [145, 206], [145, 213], [145, 218], [145, 246], [145, 253], [145, 277], [145, 285], [145, 299], [146, 153], [146, 171], [146, 191], [146, 195], [146, 227], [146, 235], [146, 271], [146, 274], [147, 153], [147, 161], [147, 167], [147, 179], [147, 181], [147, 184], [147, 200], [147, 210], [147, 218], [147, 219], [147, 285], [147, 292], [147, 299], [148, 160], [148, 166], [148, 200], [148, 237], [148, 278], [148, 290], [148, 291], [148, 292], [149, 155], [149, 177], [149, 219], [149, 229], [149, 238], [149, 245], [149, 257], [149, 264], [149, 270], [150, 178], [150, 201], [150, 216], [150, 220], [150, 221], [150, 239], [150, 255], [150, 258], [150, 260], [151, 157], [151, 169], [151, 190], [151, 210], [151, 234], [151, 239], [151, 240], [151, 251], [151, 253], [151, 255], [151, 268], [151, 276], [151, 280], [152, 215], [152, 254], [152, 260], [152, 283], [152, 298], [153, 173], [153, 210], [153, 230], [153, 266], [153, 277], [153, 280], [154, 157], [154, 168], [154, 175], [154, 193], [154, 212], [154, 214], [154, 226], [154, 250], [154, 261], [155, 157], [155, 160], [155, 204], [155, 207], [155, 209], [155, 214], [155, 231], [155, 253], [156, 157], [156, 173], [156, 175], [156, 195], [156, 213], [156, 234], [156, 239], [156, 281], [156, 288], [157, 164], [157, 181], [157, 188], [157, 190], [157, 197], [157, 207], [157, 218], [157, 225], [157, 227], [157, 228], [157, 235], [157, 246], [157, 255], [157, 291], [158, 193], [158, 196], [158, 203], [158, 204], [158, 218], [158, 258], [158, 271], [158, 289], [158, 294], [158, 297], [159, 186], [159, 221], [159, 226], [159, 228], [159, 229], [159, 231], [159, 255], [159, 256], [159, 260], [159, 283], [159, 290], [159, 292], [160, 204], [160, 210], [160, 219], [160, 227], [160, 231], [160, 243], [160, 253], [160, 267], [160, 272], [160, 275], [160, 283], [160, 290], [160, 295], [161, 174], [161, 182], [161, 191], [161, 205], [161, 214], [161, 268], [161, 269], [162, 208], [162, 223], [162, 247], [162, 254], [162, 257], [162, 270], [163, 176], [163, 183], [163, 193], [163, 210], [163, 213], [163, 218], [163, 223], [163, 250], [163, 271], [163, 274], [163, 276], [163, 280], [163, 285], [163, 288], [164, 183], [164, 199], [164, 205], [164, 210], [164, 231], [164, 236], [164, 241], [164, 257], [164, 277], [165, 212], [165, 241], [165, 242], [165, 251], [165, 259], [165, 260], [165, 269], [166, 184], [166, 195], [166, 197], [166, 200], [166, 201], [166, 212], [166, 222], [166, 231], [166, 252], [166, 257], [166, 260], [166, 262], [166, 296], [167, 169], [167, 181], [167, 187], [167, 192], [167, 226], [167, 247], [167, 259], [167, 269], [167, 293], [168, 170], [168, 178], [168, 188], [168, 193], [168, 204], [168, 234], [168, 256], [168, 294], [169, 187], [169, 193], [169, 252], [169, 262], [169, 276], [169, 285], [169, 294], [169, 298], [170, 214], [170, 229], [170, 249], [170, 257], [170, 270], [170, 278], [171, 183], [171, 184], [171, 193], [171, 209], [171, 217], [171, 221], [171, 240], [171, 255], [171, 272], [171, 275], [171, 280], [171, 288], [172, 177], [172, 189], [172, 201], [172, 219], [172, 221], [172, 238], [172, 251], [172, 253], [172, 261], [172, 262], [172, 283], [172, 285], [172, 291], [173, 192], [173, 202], [173, 203], [173, 208], [173, 217], [173, 258], [173, 261], [173, 262], [174, 182], [174, 197], [174, 208], [174, 218], [174, 252], [174, 253], [174, 258], [174, 283], [175, 182], [175, 185], [175, 201], [175, 208], [175, 223], [175, 232], [175, 235], [175, 241], [175, 244], [175, 248], [175, 257], [175, 269], [175, 281], [176, 198], [176, 200], [176, 210], [176, 220], [176, 227], [176, 236], [176, 248], [176, 272], [176, 278], [176, 297], [177, 234], [177, 243], [177, 260], [177, 281], [177, 288], [177, 293], [178, 193], [178, 196], [178, 202], [178, 203], [178, 205], [178, 221], [178, 260], [178, 265], [178, 270], [178, 271], [178, 284], [178, 290], [179, 188], [179, 190], [179, 192], [179, 194], [179, 196], [179, 199], [179, 203], [179, 209], [179, 226], [179, 233], [179, 236], [179, 251], [179, 258], [179, 260], [179, 264], [179, 270], [179, 282], [179, 294], [180, 202], [180, 207], [180, 211], [180, 212], [180, 225], [180, 237], [180, 244], [180, 258], [180, 267], [181, 183], [181, 208], [181, 249], [181, 256], [181, 296], [182, 206], [182, 221], [182, 285], [182, 298], [183, 202], [183, 207], [183, 212], [183, 222], [183, 235], [183, 238], [183, 248], [183, 275], [183, 283], [184, 185], [184, 186], [184, 207], [184, 208], [184, 209], [184, 226], [184, 233], [184, 236], [184, 255], [184, 257], [184, 272], [185, 187], [185, 194], [185, 197], [185, 231], [185, 242], [185, 267], [185, 276], [185, 286], [185, 298], [186, 190], [186, 191], [186, 200], [186, 221], [186, 238], [186, 240], [186, 257], [186, 266], [186, 293], [187, 214], [187, 237], [187, 292], [188, 199], [188, 218], [188, 221], [188, 249], [188, 256], [188, 275], [188, 293], [188, 299], [189, 195], [189, 201], [189, 220], [189, 241], [189, 257], [189, 261], [189, 281], [189, 283], [189, 284], [189, 296], [190, 199], [190, 203], [190, 206], [190, 222], [190, 243], [190, 251], [190, 296], [191, 211], [191, 220], [191, 221], [191, 245], [191, 249], [191, 258], [191, 277], [191, 298], [192, 252], [193, 202], [193, 211], [193, 238], [193, 270], [193, 278], [193, 280], [193, 297], [194, 200], [194, 202], [194, 255], [194, 272], [194, 276], [195, 196], [195, 197], [195, 218], [195, 224], [195, 227], [195, 235], [195, 240], [195, 249], [195, 250], [196, 218], [196, 235], [196, 253], [196, 255], [196, 292], [196, 293], [197, 212], [197, 227], [197, 229], [197, 240], [197, 241], [197, 277], [198, 212], [198, 215], [198, 225], [198, 226], [198, 240], [198, 260], [198, 272], [198, 294], [199, 202], [199, 207], [199, 208], [199, 236], [199, 253], [199, 262], [200, 209], [200, 226], [200, 250], [200, 255], [200, 256], [200, 261], [200, 280], [200, 297], [201, 211], [201, 234], [201, 252], [201, 267], [201, 280], [201, 296], [202, 217], [202, 280], [202, 284], [202, 296], [203, 215], [203, 226], [203, 231], [203, 232], [203, 236], [203, 248], [203, 257], [203, 262], [204, 210], [204, 224], [204, 227], [204, 276], [204, 284], [204, 291], [204, 296], [204, 297], [205, 206], [205, 238], [205, 260], [205, 263], [205, 273], [205, 283], [205, 297], [205, 299], [206, 222], [206, 223], [206, 225], [206, 259], [206, 281], [206, 298], [207, 209], [207, 216], [207, 221], [207, 230], [207, 249], [207, 250], [207, 278], [207, 291], [208, 221], [208, 223], [208, 228], [208, 235], [208, 237], [208, 255], [208, 267], [208, 268], [208, 270], [208, 280], [208, 291], [209, 265], [209, 269], [209, 275], [209, 281], [209, 288], [209, 291], [210, 216], [210, 219], [210, 234], [210, 238], [210, 265], [210, 267], [210, 274], [210, 276], [210, 286], [210, 288], [211, 231], [211, 232], [211, 258], [211, 261], [212, 226], [212, 230], [212, 231], [212, 236], [212, 241], [212, 250], [212, 256], [212, 269], [212, 270], [212, 284], [213, 214], [213, 232], [213, 257], [213, 280], [213, 290], [213, 298], [214, 215], [214, 223], [214, 238], [214, 239], [214, 240], [214, 247], [214, 249], [214, 253], [214, 264], [214, 266], [214, 268], [214, 274], [214, 297], [214, 298], [214, 299], [215, 245], [215, 293], [216, 235], [216, 294], [217, 230], [217, 233], [217, 276], [217, 285], [218, 220], [218, 230], [218, 241], [218, 252], [218, 273], [218, 276], [219, 220], [219, 233], [219, 248], [219, 256], [219, 269], [220, 221], [220, 245], [220, 251], [220, 275], [220, 282], [221, 224], [221, 236], [221, 242], [221, 245], [221, 247], [221, 264], [221, 275], [221, 279], [221, 281], [222, 225], [222, 266], [223, 224], [223, 226], [223, 260], [223, 293], [224, 237], [224, 269], [225, 237], [225, 250], [225, 269], [225, 281], [226, 238], [226, 251], [226, 265], [226, 268], [226, 295], [227, 235], [227, 260], [227, 272], [227, 285], [227, 292], [228, 232], [228, 237], [229, 236], [229, 240], [229, 249], [229, 274], [229, 276], [229, 288], [230, 231], [230, 259], [230, 268], [231, 295], [232, 281], [232, 295], [233, 276], [234, 272], [234, 274], [234, 282], [234, 289], [234, 298], [235, 251], [235, 258], [235, 262], [235, 267], [235, 279], [235, 286], [235, 288], [236, 247], [237, 260], [237, 264], [237, 273], [237, 277], [237, 289], [237, 291], [238, 254], [238, 259], [238, 269], [238, 297], [239, 276], [239, 284], [239, 292], [239, 298], [240, 241], [240, 269], [240, 276], [240, 286], [240, 294], [241, 268], [241, 269], [241, 272], [241, 275], [241, 289], [241, 294], [242, 243], [242, 267], [243, 268], [243, 296], [243, 299], [244, 247], [245, 251], [245, 260], [245, 262], [245, 276], [245, 294], [245, 298], [246, 250], [246, 252], [247, 250], [247, 274], [247, 283], [247, 288], [247, 297], [248, 255], [248, 285], [248, 287], [248, 292], [249, 252], [249, 258], [249, 267], [249, 273], [249, 278], [249, 282], [249, 287], [250, 281], [250, 285], [251, 262], [251, 269], [251, 287], [251, 290], [253, 268], [253, 273], [253, 276], [253, 282], [253, 283], [254, 256], [254, 291], [254, 298], [255, 260], [255, 285], [255, 298], [256, 280], [256, 298], [257, 262], [257, 283], [258, 278], [258, 284], [259, 270], [259, 284], [259, 285], [260, 284], [260, 293], [260, 296], [260, 299], [261, 269], [261, 273], [262, 281], [262, 287], [262, 290], [263, 268], [264, 280], [265, 267], [266, 270], [267, 272], [267, 296], [268, 288], [269, 282], [270, 276], [270, 278], [270, 279], [270, 298], [271, 277], [271, 279], [271, 283], [271, 288], [271, 295], [272, 275], [276, 289], [277, 278], [278, 293], [279, 291], [279, 294], [281, 284], [281, 288], [281, 293], [283, 285], [288, 295], [290, 297], [291, 298], [292, 296]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l6-s0/solution/solve.sh b/tasks/construct-nppc-dominating-set-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c7d44e9f68dafa96d60e8c84558d29a5889c51a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [31, 40, 62, 64, 75, 85, 90, 118, 131, 151, 179, 200, 208, 210, 212, 214, 218, 221, 260, 277]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l6-s0/tests/check.py b/tasks/construct-nppc-dominating-set-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l6-s0/tests/instance.json b/tasks/construct-nppc-dominating-set-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba7faf107069bb53b65fb91b36e0552b41312071 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 300, "k": 20, "edges": [[0, 6], [0, 12], [0, 19], [0, 21], [0, 61], [0, 68], [0, 99], [0, 112], [0, 131], [0, 137], [0, 143], [0, 159], [0, 163], [0, 195], [0, 196], [0, 214], [0, 217], [0, 225], [0, 241], [0, 253], [0, 264], [1, 11], [1, 41], [1, 52], [1, 62], [1, 94], [1, 107], [1, 145], [1, 158], [1, 163], [1, 167], [1, 179], [1, 180], [1, 190], [1, 200], [1, 204], [1, 214], [1, 246], [1, 248], [1, 289], [1, 297], [2, 4], [2, 17], [2, 89], [2, 131], [2, 182], [2, 189], [2, 197], [2, 198], [2, 239], [2, 264], [2, 270], [2, 278], [3, 4], [3, 21], [3, 31], [3, 35], [3, 45], [3, 69], [3, 72], [3, 83], [3, 109], [3, 135], [3, 152], [3, 216], [3, 262], [3, 285], [3, 290], [4, 93], [4, 108], [4, 121], [4, 125], [4, 153], [4, 164], [4, 176], [4, 188], [4, 208], [4, 257], [4, 283], [5, 28], [5, 29], [5, 44], [5, 68], [5, 73], [5, 140], [5, 151], [5, 154], [5, 159], [5, 177], [5, 218], [5, 243], [5, 249], [5, 250], [5, 252], [5, 256], [5, 268], [6, 9], [6, 55], [6, 69], [6, 72], [6, 75], [6, 99], [6, 116], [6, 131], [6, 136], [6, 152], [6, 180], [6, 189], [6, 205], [6, 253], [6, 255], [6, 268], [6, 283], [6, 298], [7, 17], [7, 34], [7, 39], [7, 62], [7, 118], [7, 143], [7, 144], [7, 184], [7, 213], [7, 266], [7, 268], [7, 270], [7, 277], [7, 294], [8, 16], [8, 30], [8, 31], [8, 39], [8, 59], [8, 62], [8, 74], [8, 87], [8, 114], [8, 116], [8, 134], [8, 137], [8, 141], [8, 142], [8, 154], [8, 161], [8, 177], [8, 180], [8, 192], [8, 217], [8, 228], [8, 237], [8, 259], [8, 263], [8, 269], [8, 286], [8, 289], [8, 290], [9, 21], [9, 23], [9, 54], [9, 85], [9, 89], [9, 95], [9, 120], [9, 164], [9, 200], [9, 209], [9, 213], [9, 216], [9, 245], [9, 250], [9, 251], [9, 295], [10, 17], [10, 19], [10, 39], [10, 59], [10, 75], [10, 81], [10, 156], [10, 160], [10, 200], [10, 226], [10, 229], [10, 230], [10, 245], [10, 252], [11, 31], [11, 50], [11, 52], [11, 68], [11, 69], [11, 70], [11, 103], [11, 122], [11, 124], [11, 129], [11, 135], [11, 155], [11, 164], [11, 185], [11, 212], [11, 248], [11, 261], [11, 269], [11, 277], [11, 284], [11, 289], [12, 24], [12, 37], [12, 43], [12, 54], [12, 69], [12, 71], [12, 93], [12, 140], [12, 169], [12, 180], [12, 201], [12, 208], [12, 242], [12, 246], [12, 271], [12, 284], [13, 86], [13, 97], [13, 101], [13, 118], [13, 119], [13, 126], [13, 127], [13, 148], [13, 180], [13, 181], [13, 183], [13, 187], [13, 189], [13, 213], [13, 217], [13, 226], [13, 245], [13, 249], [13, 257], [13, 278], [13, 291], [13, 299], [14, 55], [14, 64], [14, 67], [14, 70], [14, 109], [14, 112], [14, 117], [14, 131], [14, 134], [14, 136], [14, 138], [14, 141], [14, 166], [14, 168], [14, 193], [14, 201], [14, 239], [14, 243], [15, 102], [15, 120], [15, 131], [15, 143], [15, 146], [15, 154], [15, 163], [15, 175], [15, 180], [15, 212], [15, 241], [15, 253], [15, 264], [15, 271], [15, 275], [15, 276], [15, 285], [16, 39], [16, 82], [16, 88], [16, 99], [16, 104], [16, 107], [16, 127], [16, 145], [16, 147], [16, 165], [16, 185], [16, 200], [16, 227], [16, 242], [16, 264], [16, 267], [16, 278], [16, 279], [16, 290], [17, 20], [17, 38], [17, 43], [17, 44], [17, 75], [17, 82], [17, 85], [17, 102], [17, 109], [17, 111], [17, 112], [17, 152], [17, 157], [17, 169], [17, 170], [17, 178], [17, 193], [17, 202], [17, 231], [17, 241], [18, 19], [18, 33], [18, 45], [18, 53], [18, 79], [18, 117], [18, 127], [18, 131], [18, 142], [18, 145], [18, 179], [18, 180], [18, 184], [18, 189], [18, 190], [18, 193], [18, 197], [18, 219], [18, 252], [18, 260], [18, 289], [18, 299], [19, 44], [19, 45], [19, 48], [19, 62], [19, 69], [19, 90], [19, 99], [19, 132], [19, 138], [19, 140], [19, 142], [19, 172], [19, 173], [19, 185], [19, 225], [19, 226], [19, 255], [19, 263], [19, 294], [20, 26], [20, 28], [20, 40], [20, 46], [20, 59], [20, 71], [20, 92], [20, 119], [20, 131], [20, 132], [20, 138], [20, 145], [20, 147], [20, 167], [20, 179], [20, 200], [20, 217], [20, 229], [20, 256], [20, 265], [20, 289], [20, 293], [21, 38], [21, 59], [21, 91], [21, 112], [21, 142], [21, 159], [21, 168], [21, 198], [21, 203], [21, 209], [21, 234], [21, 260], [21, 279], [22, 31], [22, 35], [22, 43], [22, 64], [22, 73], [22, 80], [22, 85], [22, 89], [22, 105], [22, 109], [22, 153], [22, 154], [22, 166], [22, 169], [22, 201], [22, 209], [22, 213], [22, 215], [22, 222], [22, 227], [22, 239], [22, 283], [23, 26], [23, 28], [23, 29], [23, 56], [23, 66], [23, 154], [23, 173], [23, 194], [23, 197], [23, 202], [23, 209], [23, 215], [23, 243], [23, 244], [23, 260], [23, 295], [23, 297], [24, 29], [24, 36], [24, 46], [24, 62], [24, 67], [24, 70], [24, 83], [24, 85], [24, 97], [24, 101], [24, 105], [24, 141], [24, 192], [24, 193], [24, 262], [24, 265], [24, 283], [24, 288], [24, 295], [25, 61], [25, 66], [25, 85], [25, 100], [25, 115], [25, 120], [25, 131], [25, 135], [25, 148], [25, 149], [25, 164], [25, 172], [25, 181], [25, 182], [25, 185], [25, 191], [25, 272], [26, 40], [26, 52], [26, 55], [26, 64], [26, 70], [26, 76], [26, 79], [26, 88], [26, 120], [26, 143], [26, 150], [26, 197], [26, 206], [26, 208], [26, 233], [26, 255], [26, 274], [26, 284], [26, 292], [27, 28], [27, 74], [27, 79], [27, 90], [27, 95], [27, 96], [27, 121], [27, 123], [27, 149], [27, 151], [27, 213], [27, 218], [27, 260], [27, 263], [27, 264], [27, 265], [28, 43], [28, 62], [28, 64], [28, 71], [28, 86], [28, 89], [28, 94], [28, 121], [28, 182], [28, 202], [28, 236], [28, 273], [28, 280], [28, 286], [29, 44], [29, 87], [29, 89], [29, 116], [29, 146], [29, 151], [29, 157], [29, 158], [29, 160], [29, 173], [29, 179], [29, 197], [29, 204], [29, 215], [29, 242], [29, 295], [30, 57], [30, 58], [30, 80], [30, 110], [30, 114], [30, 120], [30, 151], [30, 152], [30, 153], [30, 171], [30, 188], [30, 200], [30, 212], [30, 248], [31, 48], [31, 76], [31, 86], [31, 93], [31, 96], [31, 101], [31, 105], [31, 116], [31, 125], [31, 131], [31, 135], [31, 136], [31, 142], [31, 145], [31, 148], [31, 149], [31, 159], [31, 160], [31, 164], [31, 166], [31, 170], [31, 188], [31, 190], [31, 197], [31, 208], [31, 217], [31, 226], [31, 256], [31, 259], [31, 263], [31, 264], [31, 275], [31, 276], [31, 287], [31, 294], [32, 33], [32, 38], [32, 57], [32, 65], [32, 66], [32, 68], [32, 71], [32, 89], [32, 124], [32, 134], [32, 165], [32, 169], [32, 188], [32, 192], [32, 193], [32, 199], [32, 221], [32, 227], [32, 246], [32, 261], [32, 285], [32, 288], [32, 293], [32, 297], [33, 70], [33, 140], [33, 149], [33, 164], [33, 168], [33, 195], [33, 206], [33, 214], [33, 217], [33, 230], [33, 272], [33, 274], [33, 283], [33, 284], [34, 43], [34, 53], [34, 75], [34, 93], [34, 133], [34, 167], [34, 172], [34, 175], [34, 200], [34, 205], [34, 233], [34, 290], [34, 293], [34, 296], [34, 298], [35, 50], [35, 81], [35, 94], [35, 101], [35, 119], [35, 120], [35, 165], [35, 172], [35, 173], [35, 188], [35, 205], [35, 208], [35, 210], [35, 236], [35, 237], [35, 243], [35, 250], [35, 277], [35, 283], [35, 289], [36, 39], [36, 44], [36, 49], [36, 78], [36, 132], [36, 142], [36, 144], [36, 190], [36, 203], [36, 206], [36, 221], [36, 232], [36, 239], [36, 242], [36, 266], [36, 274], [36, 278], [36, 285], [37, 54], [37, 59], [37, 62], [37, 63], [37, 93], [37, 112], [37, 129], [37, 145], [37, 161], [37, 164], [37, 165], [37, 168], [37, 182], [37, 220], [37, 228], [37, 233], [37, 289], [38, 40], [38, 44], [38, 47], [38, 81], [38, 86], [38, 98], [38, 132], [38, 133], [38, 156], [38, 173], [38, 183], [38, 216], [38, 234], [38, 240], [38, 271], [38, 272], [38, 274], [38, 299], [39, 44], [39, 59], [39, 78], [39, 81], [39, 92], [39, 140], [39, 176], [39, 183], [39, 188], [39, 191], [39, 194], [39, 208], [39, 210], [39, 215], [39, 218], [39, 220], [39, 261], [39, 276], [40, 59], [40, 81], [40, 82], [40, 96], [40, 134], [40, 161], [40, 172], [40, 206], [40, 209], [40, 224], [40, 243], [40, 275], [40, 290], [40, 298], [41, 56], [41, 62], [41, 78], [41, 81], [41, 84], [41, 102], [41, 128], [41, 131], [41, 135], [41, 139], [41, 145], [41, 149], [41, 151], [41, 171], [41, 174], [41, 218], [41, 221], [41, 243], [41, 244], [41, 246], [41, 254], [41, 274], [41, 287], [41, 289], [42, 43], [42, 64], [42, 80], [42, 82], [42, 101], [42, 105], [42, 110], [42, 114], [42, 120], [42, 124], [42, 128], [42, 141], [42, 171], [42, 172], [42, 183], [42, 204], [42, 207], [42, 212], [42, 218], [42, 228], [42, 229], [42, 232], [42, 242], [42, 266], [42, 270], [42, 291], [43, 49], [43, 64], [43, 85], [43, 107], [43, 154], [43, 160], [43, 175], [43, 191], [43, 206], [43, 209], [43, 224], [43, 226], [43, 240], [43, 241], [43, 255], [43, 257], [43, 283], [43, 294], [44, 50], [44, 51], [44, 79], [44, 124], [44, 131], [44, 139], [44, 145], [44, 148], [44, 164], [44, 177], [44, 197], [44, 208], [44, 227], [44, 246], [44, 270], [44, 280], [44, 288], [44, 294], [44, 296], [44, 297], [45, 99], [45, 137], [45, 151], [45, 162], [45, 169], [45, 181], [45, 188], [45, 218], [45, 226], [45, 261], [45, 263], [45, 276], [46, 51], [46, 118], [46, 150], [46, 183], [46, 184], [46, 210], [46, 268], [46, 289], [46, 291], [47, 48], [47, 64], [47, 67], [47, 93], [47, 107], [47, 110], [47, 114], [47, 129], [47, 164], [47, 165], [47, 168], [47, 180], [47, 189], [47, 226], [47, 228], [47, 245], [47, 264], [48, 96], [48, 100], [48, 152], [48, 159], [48, 206], [48, 212], [48, 213], [48, 219], [48, 222], [48, 230], [48, 231], [48, 233], [48, 244], [48, 252], [48, 266], [48, 281], [48, 287], [48, 288], [48, 296], [49, 61], [49, 70], [49, 71], [49, 80], [49, 116], [49, 158], [49, 161], [49, 199], [49, 200], [49, 204], [49, 210], [49, 216], [49, 218], [49, 231], [49, 266], [50, 59], [50, 61], [50, 63], [50, 76], [50, 87], [50, 112], [50, 178], [50, 201], [50, 210], [50, 212], [50, 254], [50, 263], [50, 266], [51, 103], [51, 133], [51, 143], [51, 183], [51, 200], [51, 202], [51, 206], [51, 219], [51, 259], [51, 261], [51, 267], [51, 271], [51, 281], [52, 66], [52, 112], [52, 114], [52, 115], [52, 142], [52, 149], [52, 159], [52, 173], [52, 208], [52, 221], [52, 258], [52, 269], [52, 295], [52, 298], [53, 61], [53, 66], [53, 85], [53, 143], [53, 147], [53, 179], [53, 238], [53, 267], [54, 78], [54, 104], [54, 108], [54, 114], [54, 131], [54, 143], [54, 171], [54, 174], [54, 176], [54, 194], [54, 212], [54, 214], [54, 221], [54, 229], [54, 244], [54, 254], [54, 267], [54, 277], [54, 287], [54, 291], [55, 87], [55, 92], [55, 112], [55, 130], [55, 131], [55, 196], [55, 200], [55, 202], [55, 211], [55, 234], [55, 247], [55, 252], [56, 74], [56, 86], [56, 103], [56, 125], [56, 143], [56, 145], [56, 152], [56, 159], [56, 165], [56, 169], [56, 188], [56, 198], [56, 208], [56, 209], [56, 212], [56, 213], [56, 231], [56, 242], [56, 253], [56, 254], [56, 255], [56, 283], [57, 63], [57, 65], [57, 66], [57, 72], [57, 109], [57, 110], [57, 121], [57, 160], [57, 169], [57, 179], [57, 186], [57, 198], [57, 213], [57, 244], [57, 255], [57, 257], [57, 259], [57, 296], [58, 64], [58, 139], [58, 149], [58, 168], [58, 183], [58, 188], [58, 189], [58, 196], [58, 222], [58, 233], [58, 239], [58, 284], [59, 68], [59, 70], [59, 87], [59, 89], [59, 129], [59, 142], [59, 151], [59, 165], [59, 167], [59, 194], [59, 202], [59, 224], [59, 227], [59, 230], [59, 239], [59, 270], [59, 288], [59, 295], [60, 75], [60, 91], [60, 131], [60, 145], [60, 161], [60, 168], [60, 196], [60, 203], [60, 214], [60, 219], [60, 266], [60, 272], [60, 277], [61, 79], [61, 82], [61, 98], [61, 100], [61, 106], [61, 123], [61, 128], [61, 147], [61, 171], [61, 211], [61, 216], [61, 227], [61, 229], [61, 244], [61, 260], [61, 292], [61, 299], [62, 68], [62, 80], [62, 83], [62, 88], [62, 102], [62, 110], [62, 119], [62, 143], [62, 150], [62, 160], [62, 173], [62, 177], [62, 199], [62, 211], [62, 221], [62, 241], [62, 246], [62, 254], [62, 296], [63, 75], [63, 80], [63, 118], [63, 125], [63, 135], [63, 137], [63, 147], [63, 159], [63, 173], [63, 180], [63, 216], [63, 219], [63, 265], [63, 274], [63, 280], [63, 299], [64, 70], [64, 79], [64, 87], [64, 92], [64, 95], [64, 97], [64, 111], [64, 117], [64, 120], [64, 126], [64, 129], [64, 133], [64, 136], [64, 138], [64, 152], [64, 155], [64, 157], [64, 173], [64, 177], [64, 181], [64, 199], [64, 203], [64, 205], [64, 219], [64, 233], [64, 244], [64, 277], [64, 288], [64, 295], [64, 297], [65, 71], [65, 92], [65, 109], [65, 156], [65, 183], [65, 184], [65, 210], [65, 211], [65, 228], [65, 231], [65, 256], [65, 258], [65, 299], [66, 75], [66, 132], [66, 152], [66, 208], [66, 212], [66, 215], [66, 221], [66, 223], [66, 236], [66, 240], [66, 262], [66, 273], [66, 274], [66, 277], [66, 294], [67, 68], [67, 78], [67, 90], [67, 94], [67, 96], [67, 105], [67, 113], [67, 145], [67, 147], [67, 168], [67, 179], [67, 183], [67, 191], [67, 199], [67, 208], [67, 210], [67, 216], [67, 237], [67, 243], [67, 245], [67, 261], [67, 270], [67, 294], [68, 95], [68, 96], [68, 121], [68, 134], [68, 139], [68, 151], [68, 163], [68, 258], [68, 295], [69, 75], [69, 96], [69, 112], [69, 121], [69, 158], [69, 177], [69, 179], [69, 208], [69, 225], [69, 242], [69, 252], [69, 268], [69, 278], [69, 290], [69, 295], [70, 74], [70, 91], [70, 106], [70, 131], [70, 136], [70, 138], [70, 147], [70, 161], [70, 173], [70, 180], [70, 187], [70, 193], [70, 210], [70, 220], [70, 235], [70, 237], [70, 296], [71, 74], [71, 96], [71, 104], [71, 147], [71, 151], [71, 167], [71, 196], [71, 218], [71, 225], [71, 236], [71, 274], [71, 284], [72, 75], [72, 97], [72, 129], [72, 131], [72, 138], [72, 143], [72, 161], [72, 173], [72, 175], [72, 181], [72, 184], [72, 213], [72, 231], [72, 246], [72, 266], [72, 272], [72, 281], [72, 296], [73, 85], [73, 90], [73, 96], [73, 105], [73, 115], [73, 131], [73, 138], [73, 144], [73, 177], [73, 180], [73, 196], [73, 205], [73, 239], [73, 245], [73, 248], [73, 256], [73, 259], [73, 278], [73, 279], [73, 281], [74, 84], [74, 95], [74, 100], [74, 146], [74, 187], [74, 193], [74, 214], [74, 217], [74, 230], [74, 236], [74, 248], [74, 271], [74, 295], [75, 80], [75, 94], [75, 104], [75, 127], [75, 134], [75, 139], [75, 150], [75, 152], [75, 182], [75, 187], [75, 190], [75, 196], [75, 201], [75, 202], [75, 220], [75, 232], [75, 257], [75, 262], [75, 274], [75, 279], [75, 289], [75, 290], [75, 293], [76, 79], [76, 81], [76, 82], [76, 84], [76, 125], [76, 138], [76, 143], [76, 144], [76, 235], [76, 260], [76, 276], [76, 282], [77, 82], [77, 104], [77, 111], [77, 129], [77, 167], [77, 180], [77, 186], [77, 200], [77, 213], [77, 220], [77, 221], [77, 264], [78, 87], [78, 94], [78, 106], [78, 147], [78, 161], [78, 163], [78, 169], [78, 171], [78, 179], [78, 182], [78, 185], [78, 191], [78, 196], [78, 200], [78, 204], [78, 208], [78, 219], [78, 256], [78, 259], [78, 277], [78, 281], [78, 285], [79, 111], [79, 112], [79, 130], [79, 157], [79, 177], [79, 179], [79, 181], [79, 197], [79, 202], [79, 209], [79, 219], [79, 230], [79, 266], [80, 132], [80, 142], [80, 144], [80, 150], [80, 153], [80, 181], [80, 188], [80, 193], [80, 201], [80, 293], [81, 110], [81, 116], [81, 143], [81, 147], [81, 161], [81, 180], [81, 187], [81, 228], [81, 238], [81, 240], [81, 245], [81, 249], [81, 270], [81, 288], [82, 101], [82, 160], [82, 171], [82, 181], [82, 236], [82, 291], [82, 293], [83, 89], [83, 90], [83, 94], [83, 116], [83, 129], [83, 134], [83, 143], [83, 188], [83, 192], [83, 208], [83, 232], [83, 248], [83, 251], [83, 262], [83, 263], [83, 284], [83, 293], [83, 294], [84, 138], [84, 140], [84, 181], [84, 187], [84, 195], [84, 197], [84, 221], [84, 233], [84, 252], [84, 271], [84, 273], [84, 282], [84, 284], [85, 94], [85, 96], [85, 110], [85, 139], [85, 143], [85, 147], [85, 156], [85, 168], [85, 174], [85, 191], [85, 194], [85, 210], [85, 218], [85, 242], [85, 244], [85, 249], [85, 262], [85, 263], [85, 266], [85, 267], [85, 282], [85, 289], [86, 146], [86, 151], [86, 157], [86, 167], [86, 172], [86, 189], [86, 274], [86, 295], [87, 114], [87, 116], [87, 118], [87, 119], [87, 134], [87, 155], [87, 166], [87, 180], [87, 199], [87, 207], [87, 259], [87, 260], [87, 266], [87, 289], [88, 96], [88, 105], [88, 131], [88, 142], [88, 153], [88, 158], [88, 159], [88, 164], [88, 207], [88, 216], [88, 228], [88, 247], [88, 248], [88, 250], [88, 258], [88, 270], [88, 278], [89, 103], [89, 118], [89, 124], [89, 136], [89, 144], [89, 148], [89, 155], [89, 183], [89, 199], [89, 200], [89, 215], [89, 218], [89, 231], [89, 249], [89, 251], [89, 254], [90, 130], [90, 133], [90, 167], [90, 172], [90, 185], [90, 189], [90, 193], [90, 199], [90, 202], [90, 226], [90, 252], [90, 264], [90, 285], [90, 286], [90, 291], [90, 292], [90, 299], [91, 94], [91, 97], [91, 136], [91, 138], [91, 142], [91, 144], [91, 165], [91, 172], [91, 178], [91, 199], [91, 202], [91, 218], [91, 245], [91, 268], [92, 107], [92, 130], [92, 143], [92, 197], [92, 204], [92, 205], [92, 207], [92, 214], [92, 261], [92, 273], [92, 280], [92, 287], [92, 294], [93, 116], [93, 129], [93, 135], [93, 150], [93, 156], [93, 191], [93, 196], [93, 200], [93, 206], [93, 221], [93, 235], [93, 246], [93, 260], [93, 281], [93, 286], [93, 296], [94, 95], [94, 105], [94, 143], [94, 161], [94, 178], [94, 179], [94, 191], [94, 238], [94, 249], [94, 263], [94, 294], [95, 96], [95, 150], [95, 160], [95, 191], [95, 207], [95, 230], [95, 245], [95, 254], [95, 255], [95, 287], [95, 292], [96, 115], [96, 139], [96, 154], [96, 163], [96, 166], [96, 173], [96, 185], [96, 220], [96, 228], [96, 236], [96, 241], [96, 251], [96, 259], [96, 283], [96, 286], [96, 287], [96, 299], [97, 120], [97, 135], [97, 137], [97, 140], [97, 149], [97, 160], [97, 193], [97, 212], [97, 225], [97, 238], [97, 269], [97, 271], [98, 135], [98, 169], [98, 173], [98, 174], [98, 177], [98, 200], [98, 203], [98, 225], [98, 227], [98, 228], [98, 281], [98, 284], [98, 288], [98, 298], [99, 100], [99, 121], [99, 140], [99, 152], [99, 175], [99, 203], [99, 206], [99, 208], [99, 222], [99, 237], [99, 238], [99, 260], [100, 118], [100, 169], [100, 171], [100, 174], [100, 176], [100, 207], [100, 210], [100, 268], [100, 279], [101, 122], [101, 131], [101, 156], [101, 160], [101, 165], [101, 172], [101, 183], [101, 186], [101, 191], [101, 205], [101, 242], [101, 283], [101, 286], [101, 289], [101, 297], [102, 104], [102, 120], [102, 137], [102, 147], [102, 161], [102, 227], [102, 250], [102, 267], [102, 269], [102, 284], [102, 285], [103, 109], [103, 182], [103, 184], [103, 219], [103, 226], [103, 239], [103, 246], [103, 253], [103, 260], [103, 269], [103, 280], [103, 295], [103, 299], [104, 120], [104, 163], [104, 176], [104, 190], [104, 192], [104, 203], [104, 204], [104, 206], [104, 219], [104, 272], [104, 275], [104, 296], [105, 120], [105, 121], [105, 127], [105, 140], [105, 160], [105, 162], [105, 163], [105, 164], [105, 178], [105, 201], [105, 252], [105, 265], [106, 139], [106, 151], [106, 153], [106, 192], [106, 239], [107, 179], [107, 199], [107, 203], [107, 213], [107, 215], [107, 266], [107, 298], [108, 125], [108, 126], [108, 139], [108, 142], [108, 152], [108, 176], [108, 185], [108, 187], [108, 192], [108, 200], [108, 215], [108, 232], [108, 240], [108, 271], [108, 283], [109, 140], [109, 151], [109, 177], [109, 202], [109, 206], [109, 214], [109, 267], [109, 283], [109, 287], [109, 296], [110, 117], [110, 129], [110, 166], [110, 189], [110, 239], [110, 243], [110, 275], [110, 297], [111, 114], [111, 133], [111, 135], [111, 145], [111, 150], [111, 164], [111, 191], [111, 203], [111, 209], [111, 227], [111, 244], [111, 277], [111, 278], [111, 291], [111, 295], [111, 298], [112, 118], [112, 141], [112, 152], [112, 153], [112, 162], [112, 172], [112, 174], [112, 176], [112, 179], [112, 189], [112, 200], [112, 212], [112, 215], [112, 222], [112, 243], [112, 284], [113, 118], [113, 143], [113, 207], [113, 212], [113, 219], [113, 223], [113, 244], [113, 259], [113, 265], [113, 273], [113, 284], [113, 289], [113, 294], [114, 116], [114, 118], [114, 121], [114, 131], [114, 138], [114, 149], [114, 163], [114, 169], [114, 221], [114, 251], [114, 252], [114, 255], [114, 281], [115, 151], [115, 178], [115, 194], [115, 206], [115, 207], [115, 218], [115, 229], [115, 234], [115, 246], [115, 279], [115, 291], [115, 292], [115, 296], [115, 299], [116, 126], [116, 132], [116, 134], [116, 150], [116, 153], [116, 160], [116, 169], [116, 172], [116, 181], [116, 184], [116, 218], [116, 224], [116, 245], [116, 249], [116, 256], [116, 272], [117, 125], [117, 133], [117, 137], [117, 141], [117, 153], [117, 165], [117, 176], [117, 180], [117, 187], [117, 213], [117, 218], [117, 238], [117, 251], [117, 260], [117, 263], [117, 278], [117, 282], [117, 285], [117, 286], [117, 291], [117, 296], [118, 122], [118, 143], [118, 152], [118, 155], [118, 189], [118, 211], [118, 217], [118, 222], [118, 231], [118, 247], [118, 248], [118, 254], [118, 257], [118, 258], [118, 260], [118, 268], [118, 272], [118, 283], [118, 295], [119, 144], [119, 208], [119, 220], [119, 256], [119, 295], [119, 298], [120, 130], [120, 135], [120, 182], [120, 222], [120, 289], [120, 297], [121, 128], [121, 140], [121, 171], [121, 172], [121, 193], [121, 201], [121, 212], [121, 218], [121, 229], [121, 275], [122, 143], [122, 153], [122, 154], [122, 197], [122, 200], [122, 212], [122, 235], [122, 258], [122, 270], [122, 285], [122, 292], [123, 151], [123, 167], [123, 174], [123, 176], [123, 178], [123, 184], [123, 192], [123, 207], [123, 212], [123, 231], [123, 234], [123, 255], [123, 264], [123, 281], [123, 294], [123, 296], [123, 299], [124, 131], [124, 133], [124, 136], [124, 160], [124, 163], [124, 177], [124, 194], [124, 196], [124, 242], [124, 246], [124, 271], [124, 274], [124, 287], [125, 141], [125, 148], [125, 175], [125, 190], [125, 204], [125, 238], [125, 244], [125, 251], [125, 262], [125, 294], [126, 145], [126, 160], [126, 167], [126, 184], [126, 207], [126, 221], [126, 235], [126, 238], [126, 249], [126, 251], [126, 252], [126, 254], [126, 277], [126, 284], [127, 132], [127, 153], [127, 156], [127, 189], [127, 207], [127, 210], [127, 242], [127, 276], [127, 281], [127, 297], [128, 154], [128, 178], [128, 190], [128, 194], [128, 200], [128, 237], [128, 239], [128, 247], [128, 269], [128, 281], [129, 146], [129, 178], [129, 210], [129, 231], [129, 244], [129, 246], [129, 252], [129, 277], [129, 285], [129, 286], [129, 293], [130, 134], [130, 167], [130, 175], [130, 183], [130, 190], [130, 199], [130, 223], [130, 259], [130, 284], [131, 146], [131, 152], [131, 162], [131, 193], [131, 196], [131, 199], [131, 216], [131, 224], [131, 225], [131, 229], [131, 234], [131, 238], [131, 250], [131, 255], [131, 296], [132, 146], [132, 206], [132, 221], [132, 233], [132, 259], [132, 275], [132, 297], [133, 137], [133, 188], [133, 190], [133, 201], [133, 230], [133, 231], [133, 238], [133, 244], [133, 247], [133, 254], [133, 299], [134, 160], [134, 174], [134, 178], [134, 239], [134, 244], [134, 248], [134, 264], [134, 291], [134, 296], [135, 178], [135, 185], [135, 194], [135, 197], [135, 208], [135, 222], [135, 224], [135, 229], [135, 250], [135, 276], [135, 283], [136, 146], [136, 186], [136, 200], [136, 221], [136, 251], [136, 256], [136, 291], [136, 293], [137, 139], [137, 161], [137, 166], [137, 173], [137, 179], [137, 184], [137, 188], [137, 214], [137, 218], [137, 232], [137, 235], [137, 250], [137, 284], [137, 293], [138, 149], [138, 182], [138, 203], [138, 210], [138, 217], [138, 237], [138, 251], [138, 252], [138, 256], [138, 270], [139, 158], [139, 187], [139, 190], [139, 216], [139, 257], [139, 258], [139, 261], [139, 268], [140, 141], [140, 161], [140, 184], [140, 193], [140, 221], [140, 251], [140, 254], [140, 277], [140, 285], [141, 146], [141, 181], [141, 188], [141, 195], [141, 212], [141, 218], [141, 230], [141, 239], [141, 240], [141, 249], [141, 265], [142, 193], [142, 251], [142, 275], [143, 158], [143, 167], [143, 168], [143, 169], [143, 186], [143, 193], [143, 209], [143, 227], [143, 233], [143, 262], [143, 265], [143, 274], [143, 277], [144, 149], [144, 158], [144, 164], [144, 167], [144, 183], [144, 185], [144, 200], [144, 220], [144, 239], [144, 247], [144, 249], [144, 261], [144, 277], [144, 289], [145, 149], [145, 164], [145, 167], [145, 186], [145, 206], [145, 213], [145, 218], [145, 246], [145, 253], [145, 277], [145, 285], [145, 299], [146, 153], [146, 171], [146, 191], [146, 195], [146, 227], [146, 235], [146, 271], [146, 274], [147, 153], [147, 161], [147, 167], [147, 179], [147, 181], [147, 184], [147, 200], [147, 210], [147, 218], [147, 219], [147, 285], [147, 292], [147, 299], [148, 160], [148, 166], [148, 200], [148, 237], [148, 278], [148, 290], [148, 291], [148, 292], [149, 155], [149, 177], [149, 219], [149, 229], [149, 238], [149, 245], [149, 257], [149, 264], [149, 270], [150, 178], [150, 201], [150, 216], [150, 220], [150, 221], [150, 239], [150, 255], [150, 258], [150, 260], [151, 157], [151, 169], [151, 190], [151, 210], [151, 234], [151, 239], [151, 240], [151, 251], [151, 253], [151, 255], [151, 268], [151, 276], [151, 280], [152, 215], [152, 254], [152, 260], [152, 283], [152, 298], [153, 173], [153, 210], [153, 230], [153, 266], [153, 277], [153, 280], [154, 157], [154, 168], [154, 175], [154, 193], [154, 212], [154, 214], [154, 226], [154, 250], [154, 261], [155, 157], [155, 160], [155, 204], [155, 207], [155, 209], [155, 214], [155, 231], [155, 253], [156, 157], [156, 173], [156, 175], [156, 195], [156, 213], [156, 234], [156, 239], [156, 281], [156, 288], [157, 164], [157, 181], [157, 188], [157, 190], [157, 197], [157, 207], [157, 218], [157, 225], [157, 227], [157, 228], [157, 235], [157, 246], [157, 255], [157, 291], [158, 193], [158, 196], [158, 203], [158, 204], [158, 218], [158, 258], [158, 271], [158, 289], [158, 294], [158, 297], [159, 186], [159, 221], [159, 226], [159, 228], [159, 229], [159, 231], [159, 255], [159, 256], [159, 260], [159, 283], [159, 290], [159, 292], [160, 204], [160, 210], [160, 219], [160, 227], [160, 231], [160, 243], [160, 253], [160, 267], [160, 272], [160, 275], [160, 283], [160, 290], [160, 295], [161, 174], [161, 182], [161, 191], [161, 205], [161, 214], [161, 268], [161, 269], [162, 208], [162, 223], [162, 247], [162, 254], [162, 257], [162, 270], [163, 176], [163, 183], [163, 193], [163, 210], [163, 213], [163, 218], [163, 223], [163, 250], [163, 271], [163, 274], [163, 276], [163, 280], [163, 285], [163, 288], [164, 183], [164, 199], [164, 205], [164, 210], [164, 231], [164, 236], [164, 241], [164, 257], [164, 277], [165, 212], [165, 241], [165, 242], [165, 251], [165, 259], [165, 260], [165, 269], [166, 184], [166, 195], [166, 197], [166, 200], [166, 201], [166, 212], [166, 222], [166, 231], [166, 252], [166, 257], [166, 260], [166, 262], [166, 296], [167, 169], [167, 181], [167, 187], [167, 192], [167, 226], [167, 247], [167, 259], [167, 269], [167, 293], [168, 170], [168, 178], [168, 188], [168, 193], [168, 204], [168, 234], [168, 256], [168, 294], [169, 187], [169, 193], [169, 252], [169, 262], [169, 276], [169, 285], [169, 294], [169, 298], [170, 214], [170, 229], [170, 249], [170, 257], [170, 270], [170, 278], [171, 183], [171, 184], [171, 193], [171, 209], [171, 217], [171, 221], [171, 240], [171, 255], [171, 272], [171, 275], [171, 280], [171, 288], [172, 177], [172, 189], [172, 201], [172, 219], [172, 221], [172, 238], [172, 251], [172, 253], [172, 261], [172, 262], [172, 283], [172, 285], [172, 291], [173, 192], [173, 202], [173, 203], [173, 208], [173, 217], [173, 258], [173, 261], [173, 262], [174, 182], [174, 197], [174, 208], [174, 218], [174, 252], [174, 253], [174, 258], [174, 283], [175, 182], [175, 185], [175, 201], [175, 208], [175, 223], [175, 232], [175, 235], [175, 241], [175, 244], [175, 248], [175, 257], [175, 269], [175, 281], [176, 198], [176, 200], [176, 210], [176, 220], [176, 227], [176, 236], [176, 248], [176, 272], [176, 278], [176, 297], [177, 234], [177, 243], [177, 260], [177, 281], [177, 288], [177, 293], [178, 193], [178, 196], [178, 202], [178, 203], [178, 205], [178, 221], [178, 260], [178, 265], [178, 270], [178, 271], [178, 284], [178, 290], [179, 188], [179, 190], [179, 192], [179, 194], [179, 196], [179, 199], [179, 203], [179, 209], [179, 226], [179, 233], [179, 236], [179, 251], [179, 258], [179, 260], [179, 264], [179, 270], [179, 282], [179, 294], [180, 202], [180, 207], [180, 211], [180, 212], [180, 225], [180, 237], [180, 244], [180, 258], [180, 267], [181, 183], [181, 208], [181, 249], [181, 256], [181, 296], [182, 206], [182, 221], [182, 285], [182, 298], [183, 202], [183, 207], [183, 212], [183, 222], [183, 235], [183, 238], [183, 248], [183, 275], [183, 283], [184, 185], [184, 186], [184, 207], [184, 208], [184, 209], [184, 226], [184, 233], [184, 236], [184, 255], [184, 257], [184, 272], [185, 187], [185, 194], [185, 197], [185, 231], [185, 242], [185, 267], [185, 276], [185, 286], [185, 298], [186, 190], [186, 191], [186, 200], [186, 221], [186, 238], [186, 240], [186, 257], [186, 266], [186, 293], [187, 214], [187, 237], [187, 292], [188, 199], [188, 218], [188, 221], [188, 249], [188, 256], [188, 275], [188, 293], [188, 299], [189, 195], [189, 201], [189, 220], [189, 241], [189, 257], [189, 261], [189, 281], [189, 283], [189, 284], [189, 296], [190, 199], [190, 203], [190, 206], [190, 222], [190, 243], [190, 251], [190, 296], [191, 211], [191, 220], [191, 221], [191, 245], [191, 249], [191, 258], [191, 277], [191, 298], [192, 252], [193, 202], [193, 211], [193, 238], [193, 270], [193, 278], [193, 280], [193, 297], [194, 200], [194, 202], [194, 255], [194, 272], [194, 276], [195, 196], [195, 197], [195, 218], [195, 224], [195, 227], [195, 235], [195, 240], [195, 249], [195, 250], [196, 218], [196, 235], [196, 253], [196, 255], [196, 292], [196, 293], [197, 212], [197, 227], [197, 229], [197, 240], [197, 241], [197, 277], [198, 212], [198, 215], [198, 225], [198, 226], [198, 240], [198, 260], [198, 272], [198, 294], [199, 202], [199, 207], [199, 208], [199, 236], [199, 253], [199, 262], [200, 209], [200, 226], [200, 250], [200, 255], [200, 256], [200, 261], [200, 280], [200, 297], [201, 211], [201, 234], [201, 252], [201, 267], [201, 280], [201, 296], [202, 217], [202, 280], [202, 284], [202, 296], [203, 215], [203, 226], [203, 231], [203, 232], [203, 236], [203, 248], [203, 257], [203, 262], [204, 210], [204, 224], [204, 227], [204, 276], [204, 284], [204, 291], [204, 296], [204, 297], [205, 206], [205, 238], [205, 260], [205, 263], [205, 273], [205, 283], [205, 297], [205, 299], [206, 222], [206, 223], [206, 225], [206, 259], [206, 281], [206, 298], [207, 209], [207, 216], [207, 221], [207, 230], [207, 249], [207, 250], [207, 278], [207, 291], [208, 221], [208, 223], [208, 228], [208, 235], [208, 237], [208, 255], [208, 267], [208, 268], [208, 270], [208, 280], [208, 291], [209, 265], [209, 269], [209, 275], [209, 281], [209, 288], [209, 291], [210, 216], [210, 219], [210, 234], [210, 238], [210, 265], [210, 267], [210, 274], [210, 276], [210, 286], [210, 288], [211, 231], [211, 232], [211, 258], [211, 261], [212, 226], [212, 230], [212, 231], [212, 236], [212, 241], [212, 250], [212, 256], [212, 269], [212, 270], [212, 284], [213, 214], [213, 232], [213, 257], [213, 280], [213, 290], [213, 298], [214, 215], [214, 223], [214, 238], [214, 239], [214, 240], [214, 247], [214, 249], [214, 253], [214, 264], [214, 266], [214, 268], [214, 274], [214, 297], [214, 298], [214, 299], [215, 245], [215, 293], [216, 235], [216, 294], [217, 230], [217, 233], [217, 276], [217, 285], [218, 220], [218, 230], [218, 241], [218, 252], [218, 273], [218, 276], [219, 220], [219, 233], [219, 248], [219, 256], [219, 269], [220, 221], [220, 245], [220, 251], [220, 275], [220, 282], [221, 224], [221, 236], [221, 242], [221, 245], [221, 247], [221, 264], [221, 275], [221, 279], [221, 281], [222, 225], [222, 266], [223, 224], [223, 226], [223, 260], [223, 293], [224, 237], [224, 269], [225, 237], [225, 250], [225, 269], [225, 281], [226, 238], [226, 251], [226, 265], [226, 268], [226, 295], [227, 235], [227, 260], [227, 272], [227, 285], [227, 292], [228, 232], [228, 237], [229, 236], [229, 240], [229, 249], [229, 274], [229, 276], [229, 288], [230, 231], [230, 259], [230, 268], [231, 295], [232, 281], [232, 295], [233, 276], [234, 272], [234, 274], [234, 282], [234, 289], [234, 298], [235, 251], [235, 258], [235, 262], [235, 267], [235, 279], [235, 286], [235, 288], [236, 247], [237, 260], [237, 264], [237, 273], [237, 277], [237, 289], [237, 291], [238, 254], [238, 259], [238, 269], [238, 297], [239, 276], [239, 284], [239, 292], [239, 298], [240, 241], [240, 269], [240, 276], [240, 286], [240, 294], [241, 268], [241, 269], [241, 272], [241, 275], [241, 289], [241, 294], [242, 243], [242, 267], [243, 268], [243, 296], [243, 299], [244, 247], [245, 251], [245, 260], [245, 262], [245, 276], [245, 294], [245, 298], [246, 250], [246, 252], [247, 250], [247, 274], [247, 283], [247, 288], [247, 297], [248, 255], [248, 285], [248, 287], [248, 292], [249, 252], [249, 258], [249, 267], [249, 273], [249, 278], [249, 282], [249, 287], [250, 281], [250, 285], [251, 262], [251, 269], [251, 287], [251, 290], [253, 268], [253, 273], [253, 276], [253, 282], [253, 283], [254, 256], [254, 291], [254, 298], [255, 260], [255, 285], [255, 298], [256, 280], [256, 298], [257, 262], [257, 283], [258, 278], [258, 284], [259, 270], [259, 284], [259, 285], [260, 284], [260, 293], [260, 296], [260, 299], [261, 269], [261, 273], [262, 281], [262, 287], [262, 290], [263, 268], [264, 280], [265, 267], [266, 270], [267, 272], [267, 296], [268, 288], [269, 282], [270, 276], [270, 278], [270, 279], [270, 298], [271, 277], [271, 279], [271, 283], [271, 288], [271, 295], [272, 275], [276, 289], [277, 278], [278, 293], [279, 291], [279, 294], [281, 284], [281, 288], [281, 293], [283, 285], [288, 295], [290, 297], [291, 298], [292, 296]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l6-s0/tests/run.py b/tasks/construct-nppc-dominating-set-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l6-s0/tests/test.sh b/tasks/construct-nppc-dominating-set-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l6-s7/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l6-s7/environment/instance.json b/tasks/construct-nppc-dominating-set-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8888fa07560162e00796e458d25b51f83d2f7bf1 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 300, "k": 20, "edges": [[0, 11], [0, 26], [0, 37], [0, 42], [0, 45], [0, 58], [0, 77], [0, 118], [0, 126], [0, 133], [0, 134], [0, 158], [0, 163], [0, 173], [0, 175], [0, 182], [0, 222], [0, 223], [0, 224], [0, 234], [0, 236], [0, 239], [0, 244], [0, 245], [0, 272], [0, 279], [1, 30], [1, 35], [1, 51], [1, 54], [1, 64], [1, 72], [1, 93], [1, 95], [1, 119], [1, 122], [1, 127], [1, 179], [1, 180], [1, 196], [1, 231], [1, 254], [1, 296], [2, 21], [2, 36], [2, 38], [2, 39], [2, 88], [2, 97], [2, 105], [2, 118], [2, 148], [2, 155], [2, 163], [2, 165], [2, 181], [2, 202], [2, 234], [2, 243], [2, 263], [2, 268], [2, 269], [2, 273], [2, 289], [3, 5], [3, 7], [3, 31], [3, 42], [3, 50], [3, 64], [3, 65], [3, 74], [3, 145], [3, 183], [3, 206], [3, 215], [3, 228], [3, 261], [3, 269], [3, 296], [4, 7], [4, 11], [4, 52], [4, 105], [4, 107], [4, 122], [4, 126], [4, 138], [4, 149], [4, 173], [4, 194], [4, 235], [4, 243], [4, 246], [4, 256], [4, 270], [4, 273], [4, 292], [5, 18], [5, 54], [5, 92], [5, 98], [5, 157], [5, 163], [5, 168], [5, 189], [5, 221], [5, 222], [5, 226], [5, 228], [5, 232], [5, 284], [5, 294], [5, 298], [6, 41], [6, 61], [6, 64], [6, 65], [6, 67], [6, 70], [6, 77], [6, 82], [6, 90], [6, 96], [6, 111], [6, 137], [6, 165], [6, 175], [6, 183], [6, 190], [6, 211], [6, 214], [6, 240], [6, 241], [6, 253], [6, 278], [6, 292], [7, 86], [7, 87], [7, 115], [7, 125], [7, 131], [7, 140], [7, 147], [7, 153], [7, 162], [7, 163], [7, 175], [7, 193], [7, 197], [7, 201], [7, 205], [7, 236], [7, 252], [7, 255], [7, 288], [7, 295], [8, 36], [8, 112], [8, 125], [8, 138], [8, 142], [8, 155], [8, 158], [8, 160], [8, 180], [8, 188], [8, 201], [8, 208], [8, 245], [8, 269], [8, 274], [8, 279], [8, 288], [9, 22], [9, 62], [9, 63], [9, 75], [9, 81], [9, 95], [9, 98], [9, 99], [9, 138], [9, 148], [9, 158], [9, 159], [9, 172], [9, 188], [9, 189], [9, 213], [9, 214], [9, 227], [9, 244], [9, 245], [9, 250], [9, 263], [10, 33], [10, 38], [10, 55], [10, 97], [10, 130], [10, 158], [10, 190], [10, 236], [10, 240], [10, 247], [10, 260], [10, 267], [10, 279], [10, 283], [11, 16], [11, 24], [11, 27], [11, 65], [11, 69], [11, 75], [11, 77], [11, 87], [11, 101], [11, 108], [11, 128], [11, 137], [11, 149], [11, 152], [11, 156], [11, 164], [11, 167], [11, 171], [11, 173], [11, 192], [11, 202], [11, 254], [11, 259], [11, 266], [11, 286], [12, 35], [12, 53], [12, 62], [12, 63], [12, 84], [12, 96], [12, 103], [12, 105], [12, 110], [12, 118], [12, 129], [12, 139], [12, 143], [12, 150], [12, 167], [12, 180], [12, 191], [12, 198], [12, 226], [12, 229], [12, 230], [12, 231], [12, 232], [12, 252], [12, 267], [12, 268], [13, 34], [13, 44], [13, 77], [13, 81], [13, 90], [13, 100], [13, 110], [13, 136], [13, 149], [13, 188], [13, 194], [13, 198], [13, 209], [13, 210], [13, 221], [13, 233], [13, 237], [13, 241], [13, 257], [13, 261], [13, 271], [14, 30], [14, 32], [14, 36], [14, 38], [14, 44], [14, 56], [14, 60], [14, 61], [14, 68], [14, 80], [14, 107], [14, 118], [14, 123], [14, 135], [14, 146], [14, 153], [14, 168], [14, 205], [14, 209], [14, 210], [14, 222], [14, 233], [14, 253], [14, 256], [14, 270], [15, 39], [15, 47], [15, 86], [15, 88], [15, 100], [15, 137], [15, 150], [15, 153], [15, 170], [15, 172], [15, 187], [15, 248], [15, 251], [15, 252], [15, 257], [15, 268], [15, 296], [16, 29], [16, 70], [16, 105], [16, 110], [16, 121], [16, 123], [16, 128], [16, 133], [16, 139], [16, 167], [16, 173], [16, 174], [16, 217], [16, 231], [16, 253], [16, 278], [17, 19], [17, 62], [17, 68], [17, 86], [17, 91], [17, 93], [17, 99], [17, 137], [17, 142], [17, 154], [17, 169], [17, 269], [17, 272], [17, 274], [17, 279], [17, 289], [17, 290], [18, 38], [18, 57], [18, 62], [18, 72], [18, 75], [18, 81], [18, 100], [18, 162], [18, 166], [18, 197], [18, 236], [18, 247], [18, 263], [18, 267], [18, 277], [19, 22], [19, 50], [19, 58], [19, 71], [19, 84], [19, 99], [19, 177], [19, 183], [19, 190], [19, 205], [19, 219], [19, 245], [19, 268], [19, 290], [19, 295], [19, 296], [20, 39], [20, 45], [20, 61], [20, 65], [20, 77], [20, 81], [20, 100], [20, 116], [20, 131], [20, 135], [20, 186], [20, 195], [20, 203], [20, 208], [20, 240], [20, 242], [20, 246], [20, 255], [20, 260], [20, 268], [20, 276], [20, 282], [20, 285], [20, 297], [21, 59], [21, 95], [21, 103], [21, 108], [21, 111], [21, 134], [21, 158], [21, 159], [21, 206], [21, 226], [21, 246], [21, 249], [21, 279], [21, 287], [21, 292], [22, 42], [22, 50], [22, 70], [22, 76], [22, 78], [22, 88], [22, 91], [22, 111], [22, 124], [22, 132], [22, 134], [22, 137], [22, 143], [22, 145], [22, 151], [22, 169], [22, 175], [22, 179], [22, 189], [22, 192], [22, 205], [22, 242], [22, 249], [22, 277], [23, 47], [23, 61], [23, 85], [23, 88], [23, 99], [23, 114], [23, 116], [23, 119], [23, 142], [23, 145], [23, 150], [23, 155], [23, 167], [23, 170], [23, 172], [23, 173], [23, 176], [23, 191], [23, 234], [23, 268], [23, 275], [23, 286], [23, 291], [24, 26], [24, 41], [24, 56], [24, 69], [24, 84], [24, 151], [24, 156], [24, 161], [24, 170], [24, 174], [24, 206], [24, 255], [24, 259], [24, 261], [24, 277], [24, 289], [25, 30], [25, 40], [25, 41], [25, 45], [25, 61], [25, 75], [25, 78], [25, 82], [25, 90], [25, 96], [25, 122], [25, 152], [25, 166], [25, 168], [25, 182], [25, 192], [25, 236], [25, 269], [25, 283], [26, 73], [26, 136], [26, 157], [26, 217], [26, 237], [26, 238], [26, 247], [26, 276], [26, 278], [26, 280], [27, 28], [27, 35], [27, 37], [27, 38], [27, 56], [27, 63], [27, 65], [27, 101], [27, 123], [27, 132], [27, 141], [27, 152], [27, 159], [27, 281], [27, 289], [28, 56], [28, 63], [28, 120], [28, 121], [28, 132], [28, 141], [28, 165], [28, 173], [28, 185], [28, 199], [28, 200], [28, 223], [28, 239], [28, 244], [28, 267], [28, 276], [28, 286], [28, 290], [28, 296], [29, 52], [29, 69], [29, 97], [29, 111], [29, 152], [29, 177], [29, 208], [29, 228], [29, 261], [29, 287], [29, 293], [30, 40], [30, 114], [30, 164], [30, 198], [30, 212], [31, 38], [31, 44], [31, 51], [31, 54], [31, 73], [31, 90], [31, 91], [31, 97], [31, 101], [31, 107], [31, 111], [31, 121], [31, 128], [31, 137], [31, 141], [31, 166], [31, 188], [31, 220], [31, 224], [31, 231], [31, 250], [32, 42], [32, 60], [32, 86], [32, 97], [32, 99], [32, 134], [32, 156], [32, 189], [32, 193], [32, 200], [32, 206], [32, 209], [32, 227], [32, 249], [32, 257], [32, 274], [32, 278], [32, 279], [32, 287], [33, 74], [33, 76], [33, 122], [33, 123], [33, 130], [33, 163], [33, 202], [33, 213], [33, 227], [33, 235], [33, 236], [33, 252], [33, 255], [33, 275], [33, 281], [33, 292], [33, 293], [34, 35], [34, 54], [34, 57], [34, 73], [34, 78], [34, 82], [34, 86], [34, 99], [34, 103], [34, 104], [34, 107], [34, 118], [34, 125], [34, 168], [34, 169], [34, 183], [34, 231], [34, 277], [34, 295], [35, 36], [35, 39], [35, 52], [35, 53], [35, 60], [35, 79], [35, 86], [35, 95], [35, 99], [35, 108], [35, 132], [35, 140], [35, 148], [35, 167], [35, 178], [35, 203], [35, 249], [35, 289], [36, 39], [36, 67], [36, 70], [36, 119], [36, 124], [36, 173], [36, 181], [36, 183], [36, 187], [36, 192], [36, 218], [36, 225], [36, 250], [36, 265], [36, 270], [36, 287], [36, 291], [36, 292], [37, 41], [37, 61], [37, 86], [37, 90], [37, 106], [37, 111], [37, 124], [37, 132], [37, 186], [37, 188], [37, 191], [37, 210], [37, 249], [37, 260], [37, 290], [38, 41], [38, 53], [38, 65], [38, 74], [38, 114], [38, 128], [38, 130], [38, 202], [38, 240], [38, 247], [38, 262], [39, 41], [39, 47], [39, 67], [39, 82], [39, 86], [39, 118], [39, 145], [39, 153], [39, 160], [39, 163], [39, 168], [39, 208], [39, 211], [39, 236], [39, 239], [39, 244], [39, 255], [40, 49], [40, 51], [40, 59], [40, 84], [40, 94], [40, 105], [40, 148], [40, 157], [40, 168], [40, 209], [40, 231], [40, 249], [40, 254], [40, 262], [40, 269], [40, 273], [40, 274], [40, 288], [40, 289], [40, 295], [41, 86], [41, 87], [41, 92], [41, 93], [41, 95], [41, 96], [41, 117], [41, 119], [41, 126], [41, 142], [41, 151], [41, 166], [41, 183], [41, 188], [41, 196], [41, 206], [41, 209], [41, 215], [41, 220], [41, 222], [41, 224], [41, 226], [41, 258], [41, 264], [41, 266], [41, 267], [41, 269], [41, 272], [41, 279], [41, 299], [42, 48], [42, 53], [42, 79], [42, 134], [42, 156], [42, 174], [42, 192], [42, 206], [42, 226], [42, 232], [42, 236], [42, 237], [42, 239], [42, 283], [43, 60], [43, 104], [43, 105], [43, 110], [43, 115], [43, 125], [43, 145], [43, 149], [43, 154], [43, 176], [43, 181], [43, 198], [43, 220], [43, 229], [43, 235], [43, 239], [43, 248], [43, 261], [43, 279], [43, 282], [44, 45], [44, 54], [44, 59], [44, 73], [44, 93], [44, 94], [44, 104], [44, 113], [44, 145], [44, 152], [44, 160], [44, 207], [44, 221], [44, 234], [44, 244], [44, 270], [44, 272], [44, 277], [44, 283], [44, 291], [45, 57], [45, 60], [45, 66], [45, 79], [45, 91], [45, 150], [45, 151], [45, 171], [45, 181], [45, 191], [45, 215], [45, 231], [45, 233], [45, 236], [45, 241], [45, 283], [46, 52], [46, 58], [46, 89], [46, 90], [46, 115], [46, 149], [46, 165], [46, 166], [46, 179], [46, 181], [46, 182], [46, 190], [46, 199], [46, 220], [46, 227], [46, 235], [46, 247], [46, 261], [46, 263], [46, 268], [46, 278], [46, 285], [46, 291], [46, 294], [47, 67], [47, 72], [47, 87], [47, 105], [47, 121], [47, 132], [47, 135], [47, 139], [47, 143], [47, 231], [47, 232], [47, 240], [47, 243], [47, 259], [47, 263], [47, 290], [48, 49], [48, 59], [48, 91], [48, 93], [48, 113], [48, 115], [48, 123], [48, 148], [48, 173], [48, 180], [48, 191], [48, 193], [48, 194], [48, 196], [48, 200], [48, 204], [48, 228], [48, 239], [48, 251], [48, 263], [48, 285], [49, 65], [49, 66], [49, 70], [49, 73], [49, 83], [49, 133], [49, 142], [49, 156], [49, 183], [49, 261], [49, 264], [49, 272], [49, 280], [49, 282], [49, 290], [50, 79], [50, 82], [50, 101], [50, 106], [50, 118], [50, 124], [50, 149], [50, 170], [50, 175], [50, 214], [50, 225], [50, 251], [50, 254], [50, 276], [51, 63], [51, 85], [51, 86], [51, 111], [51, 135], [51, 161], [51, 163], [51, 167], [51, 203], [51, 209], [51, 235], [51, 250], [51, 257], [51, 271], [51, 276], [52, 56], [52, 60], [52, 82], [52, 97], [52, 102], [52, 129], [52, 137], [52, 148], [52, 151], [52, 227], [52, 231], [52, 232], [52, 246], [52, 279], [52, 280], [52, 297], [53, 60], [53, 61], [53, 71], [53, 97], [53, 167], [53, 183], [53, 215], [53, 224], [53, 243], [53, 245], [53, 259], [53, 264], [53, 278], [53, 283], [53, 293], [54, 56], [54, 58], [54, 62], [54, 69], [54, 72], [54, 76], [54, 81], [54, 84], [54, 97], [54, 99], [54, 113], [54, 119], [54, 120], [54, 121], [54, 125], [54, 150], [54, 153], [54, 178], [54, 182], [54, 193], [54, 194], [54, 220], [54, 251], [54, 265], [54, 274], [54, 280], [55, 57], [55, 82], [55, 97], [55, 106], [55, 138], [55, 140], [55, 146], [55, 148], [55, 161], [55, 170], [55, 216], [55, 223], [55, 226], [55, 227], [55, 239], [55, 244], [55, 262], [55, 267], [55, 281], [56, 65], [56, 67], [56, 73], [56, 76], [56, 134], [56, 142], [56, 174], [56, 206], [56, 215], [56, 222], [56, 235], [56, 242], [56, 266], [57, 62], [57, 103], [57, 134], [57, 172], [57, 220], [57, 227], [57, 241], [57, 269], [57, 276], [57, 278], [58, 72], [58, 119], [58, 135], [58, 140], [58, 160], [58, 230], [58, 231], [58, 235], [58, 269], [58, 293], [59, 76], [59, 82], [59, 112], [59, 122], [59, 131], [59, 141], [59, 148], [59, 159], [59, 180], [59, 227], [59, 262], [59, 268], [60, 66], [60, 78], [60, 80], [60, 85], [60, 92], [60, 102], [60, 103], [60, 108], [60, 111], [60, 129], [60, 133], [60, 135], [60, 149], [60, 150], [60, 186], [60, 192], [60, 246], [60, 266], [60, 276], [60, 281], [60, 292], [61, 112], [61, 144], [61, 160], [61, 165], [61, 190], [61, 200], [61, 202], [61, 233], [61, 253], [61, 282], [62, 75], [62, 95], [62, 105], [62, 125], [62, 129], [62, 146], [62, 162], [62, 164], [62, 202], [62, 208], [62, 211], [62, 216], [62, 222], [62, 231], [62, 241], [62, 245], [62, 255], [62, 273], [62, 280], [62, 289], [63, 71], [63, 104], [63, 128], [63, 132], [63, 145], [63, 147], [63, 158], [63, 160], [63, 178], [63, 192], [63, 201], [63, 211], [63, 261], [63, 264], [63, 268], [63, 276], [63, 298], [64, 102], [64, 105], [64, 107], [64, 118], [64, 120], [64, 132], [64, 147], [64, 192], [64, 241], [64, 243], [64, 251], [64, 274], [64, 293], [65, 83], [65, 104], [65, 106], [65, 138], [65, 144], [65, 171], [65, 182], [65, 193], [65, 198], [65, 200], [65, 243], [65, 288], [66, 75], [66, 121], [66, 147], [66, 155], [66, 164], [66, 168], [66, 177], [66, 180], [66, 188], [66, 190], [66, 195], [66, 196], [66, 214], [66, 243], [66, 253], [66, 255], [66, 272], [66, 274], [66, 289], [67, 152], [67, 164], [67, 179], [67, 189], [67, 207], [67, 215], [67, 216], [67, 229], [67, 230], [67, 232], [67, 234], [67, 263], [67, 277], [67, 279], [68, 78], [68, 85], [68, 92], [68, 173], [68, 174], [68, 247], [68, 252], [68, 272], [68, 282], [69, 83], [69, 88], [69, 123], [69, 139], [69, 153], [69, 193], [69, 225], [69, 236], [69, 242], [69, 286], [69, 295], [69, 296], [70, 78], [70, 88], [70, 90], [70, 92], [70, 93], [70, 98], [70, 104], [70, 108], [70, 111], [70, 122], [70, 133], [70, 164], [70, 191], [70, 233], [70, 247], [70, 264], [70, 276], [71, 95], [71, 114], [71, 126], [71, 134], [71, 139], [71, 150], [71, 152], [71, 154], [71, 165], [71, 166], [71, 202], [71, 210], [71, 232], [71, 236], [71, 262], [71, 263], [71, 264], [71, 267], [71, 276], [72, 78], [72, 94], [72, 111], [72, 115], [72, 137], [72, 143], [72, 144], [72, 163], [72, 169], [72, 181], [72, 229], [72, 230], [72, 235], [72, 245], [72, 295], [73, 108], [73, 113], [73, 142], [73, 199], [73, 267], [73, 272], [73, 288], [73, 291], [73, 296], [74, 82], [74, 103], [74, 142], [74, 145], [74, 152], [74, 182], [74, 194], [74, 211], [74, 231], [74, 239], [74, 253], [74, 258], [74, 293], [75, 85], [75, 92], [75, 107], [75, 199], [75, 243], [75, 251], [75, 256], [75, 258], [75, 265], [75, 278], [75, 289], [76, 98], [76, 99], [76, 104], [76, 128], [76, 149], [76, 163], [76, 223], [76, 230], [76, 233], [76, 248], [76, 251], [76, 257], [76, 288], [77, 92], [77, 109], [77, 153], [77, 154], [77, 181], [77, 227], [77, 235], [77, 236], [77, 238], [77, 243], [77, 260], [77, 262], [77, 265], [77, 274], [77, 289], [77, 299], [78, 82], [78, 86], [78, 96], [78, 106], [78, 126], [78, 145], [78, 152], [78, 159], [78, 164], [78, 169], [78, 183], [78, 185], [78, 193], [78, 211], [78, 218], [78, 242], [78, 245], [78, 275], [78, 276], [78, 286], [78, 291], [79, 91], [79, 104], [79, 130], [79, 141], [79, 155], [79, 161], [79, 179], [79, 180], [79, 222], [79, 236], [79, 246], [79, 249], [79, 287], [79, 293], [80, 97], [80, 105], [80, 115], [80, 137], [80, 163], [80, 169], [80, 192], [80, 201], [80, 211], [80, 217], [80, 260], [81, 85], [81, 88], [81, 98], [81, 110], [81, 129], [81, 145], [81, 153], [81, 168], [81, 180], [81, 215], [81, 229], [81, 242], [81, 265], [81, 269], [81, 286], [81, 293], [82, 101], [82, 106], [82, 122], [82, 131], [82, 133], [82, 146], [82, 166], [82, 170], [82, 182], [82, 192], [82, 195], [82, 200], [82, 225], [82, 230], [82, 232], [82, 235], [82, 243], [82, 246], [82, 261], [82, 279], [82, 280], [82, 286], [83, 103], [83, 109], [83, 118], [83, 119], [83, 123], [83, 129], [83, 135], [83, 139], [83, 141], [83, 155], [83, 157], [83, 170], [83, 190], [83, 196], [83, 212], [83, 238], [83, 276], [83, 285], [83, 297], [84, 89], [84, 106], [84, 134], [84, 143], [84, 152], [84, 164], [84, 174], [84, 193], [84, 220], [84, 263], [84, 268], [85, 90], [85, 99], [85, 108], [85, 143], [85, 203], [85, 204], [85, 209], [85, 236], [85, 266], [85, 286], [85, 289], [86, 103], [86, 110], [86, 112], [86, 114], [86, 148], [86, 150], [86, 161], [86, 173], [86, 177], [86, 178], [86, 180], [86, 202], [86, 217], [86, 260], [86, 267], [86, 269], [86, 276], [86, 296], [87, 100], [87, 209], [87, 226], [87, 232], [87, 253], [87, 284], [88, 91], [88, 130], [88, 153], [88, 163], [88, 167], [88, 183], [88, 189], [88, 214], [88, 219], [88, 234], [88, 238], [88, 254], [88, 287], [89, 90], [89, 93], [89, 99], [89, 105], [89, 132], [89, 152], [89, 166], [89, 188], [89, 218], [89, 234], [89, 248], [89, 261], [89, 281], [89, 299], [90, 92], [90, 108], [90, 123], [90, 131], [90, 148], [90, 149], [90, 154], [90, 165], [90, 174], [90, 179], [90, 186], [90, 190], [90, 196], [90, 212], [90, 215], [90, 216], [90, 219], [90, 221], [90, 244], [90, 250], [90, 282], [90, 290], [90, 292], [90, 293], [91, 122], [91, 152], [91, 166], [91, 173], [91, 207], [91, 235], [91, 241], [91, 248], [91, 256], [91, 268], [91, 269], [91, 277], [91, 278], [91, 282], [91, 286], [91, 290], [92, 100], [92, 110], [92, 172], [92, 184], [92, 192], [92, 237], [92, 245], [92, 259], [92, 278], [92, 292], [93, 95], [93, 138], [93, 161], [93, 170], [93, 175], [93, 176], [93, 201], [93, 232], [93, 236], [93, 245], [93, 263], [93, 289], [94, 107], [94, 135], [94, 141], [94, 168], [94, 190], [94, 206], [94, 215], [94, 220], [94, 252], [94, 277], [94, 297], [95, 134], [95, 152], [95, 154], [95, 158], [95, 196], [95, 222], [95, 233], [95, 236], [95, 240], [95, 285], [95, 291], [96, 105], [96, 106], [96, 116], [96, 121], [96, 128], [96, 157], [96, 210], [96, 211], [96, 221], [96, 248], [96, 271], [96, 284], [96, 294], [97, 102], [97, 129], [97, 135], [97, 189], [97, 193], [97, 204], [97, 233], [97, 239], [97, 244], [97, 270], [97, 274], [97, 290], [97, 293], [98, 113], [98, 118], [98, 129], [98, 139], [98, 140], [98, 147], [98, 154], [98, 169], [98, 177], [98, 223], [98, 234], [98, 251], [99, 100], [99, 111], [99, 115], [99, 129], [99, 164], [99, 172], [99, 183], [99, 187], [99, 193], [99, 198], [99, 206], [99, 207], [99, 217], [99, 220], [99, 245], [99, 253], [99, 255], [99, 268], [99, 277], [100, 161], [100, 167], [100, 177], [100, 200], [100, 230], [100, 235], [100, 236], [100, 241], [100, 249], [100, 251], [100, 264], [100, 269], [100, 276], [100, 294], [101, 138], [101, 140], [101, 180], [101, 266], [101, 290], [101, 291], [101, 299], [102, 114], [102, 125], [102, 134], [102, 142], [102, 144], [102, 159], [102, 168], [102, 212], [102, 223], [102, 278], [102, 279], [103, 131], [103, 137], [103, 151], [103, 154], [103, 183], [103, 202], [103, 211], [103, 220], [103, 234], [103, 240], [103, 255], [103, 268], [103, 272], [104, 142], [104, 195], [104, 198], [104, 219], [104, 229], [104, 236], [104, 283], [104, 287], [104, 290], [105, 114], [105, 139], [105, 140], [105, 152], [105, 158], [105, 179], [105, 185], [105, 193], [105, 249], [105, 271], [105, 272], [105, 283], [105, 284], [106, 114], [106, 115], [106, 122], [106, 164], [106, 166], [106, 206], [106, 244], [106, 265], [106, 291], [107, 122], [107, 127], [107, 152], [107, 166], [107, 168], [107, 188], [107, 201], [107, 204], [107, 232], [107, 244], [107, 249], [107, 269], [107, 297], [108, 128], [108, 174], [108, 175], [108, 201], [108, 202], [108, 205], [108, 238], [108, 257], [108, 262], [108, 277], [108, 299], [109, 110], [109, 112], [109, 168], [109, 176], [109, 178], [109, 179], [109, 181], [109, 183], [109, 189], [109, 198], [109, 202], [109, 240], [109, 246], [109, 278], [109, 284], [109, 287], [109, 298], [110, 159], [110, 185], [110, 209], [110, 213], [110, 230], [110, 232], [110, 269], [110, 291], [111, 113], [111, 133], [111, 142], [111, 176], [111, 202], [111, 226], [111, 234], [111, 239], [111, 254], [111, 285], [112, 130], [112, 145], [112, 146], [112, 152], [112, 155], [112, 206], [112, 227], [112, 240], [112, 250], [112, 269], [112, 270], [112, 273], [112, 277], [112, 290], [112, 294], [112, 296], [113, 133], [113, 175], [113, 193], [113, 226], [113, 274], [113, 288], [114, 115], [114, 134], [114, 148], [114, 151], [114, 153], [114, 191], [114, 206], [114, 230], [114, 236], [114, 241], [114, 242], [114, 250], [114, 280], [114, 290], [114, 292], [115, 125], [115, 136], [115, 156], [115, 195], [115, 200], [115, 240], [115, 241], [115, 250], [115, 265], [115, 267], [115, 299], [116, 136], [116, 171], [116, 172], [116, 204], [116, 234], [116, 250], [116, 255], [116, 277], [116, 284], [116, 291], [117, 123], [117, 136], [117, 138], [117, 171], [117, 172], [117, 232], [117, 262], [118, 129], [118, 170], [118, 190], [118, 196], [118, 198], [118, 229], [118, 263], [118, 277], [119, 137], [119, 155], [119, 159], [119, 166], [119, 170], [119, 176], [119, 182], [119, 185], [119, 189], [119, 217], [119, 222], [119, 246], [119, 291], [119, 298], [120, 133], [120, 148], [120, 149], [120, 150], [120, 155], [120, 214], [120, 229], [120, 242], [120, 257], [120, 279], [120, 281], [120, 282], [121, 131], [121, 134], [121, 187], [121, 194], [121, 195], [121, 269], [121, 284], [122, 132], [122, 163], [122, 215], [122, 216], [122, 225], [122, 240], [122, 243], [123, 130], [123, 148], [123, 158], [123, 170], [123, 189], [123, 192], [123, 199], [123, 204], [123, 206], [123, 207], [123, 217], [123, 277], [124, 125], [124, 142], [124, 147], [124, 162], [124, 180], [124, 234], [124, 254], [124, 286], [125, 153], [125, 164], [125, 179], [125, 183], [125, 200], [125, 201], [125, 212], [125, 220], [125, 230], [125, 232], [125, 251], [125, 256], [125, 261], [125, 279], [126, 132], [126, 156], [126, 159], [126, 164], [126, 193], [126, 204], [126, 216], [126, 279], [127, 129], [127, 134], [127, 158], [127, 183], [127, 228], [127, 250], [127, 263], [127, 269], [128, 141], [128, 150], [128, 157], [128, 175], [128, 249], [128, 251], [128, 276], [128, 282], [128, 284], [129, 131], [129, 178], [129, 181], [129, 198], [129, 222], [129, 226], [129, 242], [129, 265], [129, 266], [129, 276], [129, 293], [129, 296], [130, 169], [130, 180], [130, 198], [130, 216], [130, 261], [131, 173], [131, 218], [131, 219], [131, 220], [131, 230], [131, 231], [131, 233], [131, 258], [131, 265], [132, 143], [132, 161], [132, 170], [132, 199], [132, 211], [132, 240], [132, 275], [133, 143], [133, 144], [133, 177], [133, 179], [133, 181], [133, 208], [133, 221], [133, 227], [133, 230], [133, 254], [133, 261], [133, 291], [134, 143], [134, 160], [134, 186], [134, 219], [134, 227], [134, 237], [134, 238], [134, 245], [134, 250], [134, 251], [134, 255], [135, 146], [135, 165], [135, 176], [135, 203], [135, 232], [135, 240], [135, 247], [135, 251], [135, 256], [135, 266], [135, 271], [135, 283], [136, 138], [136, 156], [136, 158], [136, 183], [136, 203], [136, 232], [136, 238], [136, 248], [136, 266], [136, 291], [136, 299], [137, 145], [137, 148], [137, 159], [137, 162], [137, 173], [137, 180], [137, 203], [137, 231], [137, 243], [137, 274], [137, 275], [138, 152], [138, 153], [138, 183], [138, 205], [138, 209], [138, 230], [138, 251], [138, 268], [138, 291], [139, 141], [139, 172], [139, 192], [139, 198], [139, 228], [139, 232], [139, 260], [139, 269], [139, 278], [140, 161], [140, 164], [140, 183], [140, 196], [140, 202], [140, 215], [140, 225], [140, 240], [140, 245], [140, 258], [140, 263], [140, 289], [141, 202], [141, 205], [141, 215], [141, 217], [141, 237], [141, 249], [141, 254], [141, 264], [141, 291], [141, 297], [142, 151], [142, 157], [142, 190], [142, 224], [142, 230], [142, 245], [142, 277], [143, 184], [143, 201], [143, 202], [143, 203], [143, 207], [143, 225], [143, 231], [143, 239], [143, 246], [143, 248], [143, 264], [143, 270], [143, 278], [143, 283], [143, 287], [144, 153], [144, 174], [144, 191], [144, 193], [144, 218], [144, 237], [144, 276], [144, 289], [144, 291], [144, 293], [145, 154], [145, 173], [145, 181], [145, 208], [145, 213], [145, 256], [145, 262], [145, 273], [145, 295], [146, 199], [146, 209], [146, 227], [146, 228], [146, 229], [146, 255], [146, 273], [146, 275], [146, 290], [146, 293], [147, 156], [147, 220], [147, 269], [147, 283], [147, 298], [148, 165], [148, 169], [148, 210], [148, 223], [148, 257], [148, 279], [148, 290], [149, 151], [149, 156], [149, 157], [149, 163], [149, 167], [149, 171], [149, 174], [149, 182], [149, 190], [149, 196], [149, 197], [149, 206], [149, 208], [149, 210], [149, 216], [149, 228], [149, 234], [149, 236], [149, 268], [149, 282], [149, 295], [150, 169], [150, 171], [150, 176], [150, 179], [150, 180], [150, 183], [150, 193], [150, 198], [150, 206], [150, 232], [150, 233], [150, 248], [150, 268], [150, 280], [150, 281], [150, 287], [150, 289], [150, 297], [151, 165], [151, 176], [151, 199], [151, 266], [151, 268], [151, 269], [151, 284], [151, 286], [152, 181], [152, 208], [152, 253], [152, 267], [152, 284], [153, 155], [153, 195], [153, 205], [153, 231], [154, 221], [154, 253], [154, 254], [154, 260], [154, 261], [154, 284], [154, 291], [155, 170], [155, 191], [155, 194], [155, 208], [155, 209], [155, 264], [155, 283], [155, 295], [155, 296], [156, 237], [156, 263], [156, 266], [156, 292], [156, 293], [156, 294], [157, 208], [157, 228], [157, 236], [157, 284], [158, 204], [158, 208], [158, 222], [158, 231], [158, 262], [158, 294], [159, 161], [159, 172], [159, 176], [159, 203], [159, 215], [159, 222], [159, 227], [159, 250], [159, 253], [159, 263], [159, 269], [159, 270], [159, 280], [159, 283], [159, 284], [159, 290], [159, 295], [160, 183], [160, 193], [160, 196], [160, 233], [160, 238], [160, 269], [161, 163], [161, 200], [161, 262], [161, 283], [161, 296], [161, 297], [162, 177], [162, 183], [162, 214], [162, 236], [162, 258], [162, 261], [162, 269], [163, 165], [163, 175], [163, 188], [163, 236], [163, 239], [163, 245], [163, 256], [163, 260], [163, 265], [163, 270], [163, 299], [164, 167], [164, 205], [164, 230], [164, 245], [164, 248], [164, 253], [165, 183], [165, 203], [165, 206], [165, 230], [165, 231], [165, 239], [165, 281], [165, 288], [166, 182], [166, 195], [166, 207], [166, 212], [166, 219], [166, 221], [166, 229], [166, 265], [166, 269], [166, 274], [167, 178], [167, 189], [167, 216], [167, 227], [167, 239], [167, 241], [167, 255], [167, 273], [167, 282], [168, 187], [168, 189], [168, 200], [168, 218], [168, 223], [168, 227], [168, 228], [168, 250], [168, 269], [168, 286], [168, 297], [169, 210], [169, 220], [169, 256], [169, 269], [169, 285], [170, 173], [170, 212], [170, 217], [170, 219], [170, 242], [170, 244], [170, 250], [170, 253], [170, 266], [170, 273], [170, 282], [170, 291], [171, 180], [171, 183], [171, 201], [171, 237], [171, 243], [171, 288], [171, 290], [171, 299], [172, 203], [172, 204], [172, 211], [172, 217], [172, 249], [172, 266], [172, 296], [173, 189], [173, 242], [173, 262], [173, 268], [173, 274], [173, 280], [173, 291], [173, 298], [174, 181], [174, 193], [174, 235], [174, 279], [175, 176], [175, 202], [175, 203], [175, 263], [175, 270], [175, 277], [176, 194], [176, 208], [176, 227], [176, 261], [176, 269], [176, 271], [176, 284], [177, 183], [177, 186], [177, 198], [177, 211], [177, 223], [177, 229], [177, 246], [177, 248], [177, 251], [177, 258], [177, 270], [177, 280], [178, 215], [178, 226], [178, 271], [178, 279], [179, 195], [179, 246], [179, 277], [179, 278], [179, 284], [179, 286], [180, 185], [180, 200], [180, 208], [180, 219], [180, 224], [180, 238], [180, 270], [180, 271], [180, 277], [180, 285], [180, 296], [181, 193], [181, 218], [181, 229], [181, 241], [181, 243], [181, 249], [181, 255], [181, 263], [181, 271], [181, 297], [182, 199], [182, 200], [182, 225], [182, 239], [182, 249], [182, 258], [182, 269], [182, 291], [182, 292], [183, 189], [183, 191], [183, 192], [183, 204], [183, 205], [183, 214], [183, 215], [183, 223], [183, 228], [183, 253], [183, 255], [183, 258], [183, 284], [183, 298], [183, 299], [184, 195], [184, 203], [184, 218], [184, 224], [184, 229], [184, 273], [184, 298], [185, 194], [185, 208], [185, 247], [185, 253], [185, 264], [185, 265], [185, 282], [186, 188], [186, 224], [186, 230], [186, 234], [186, 270], [186, 292], [187, 203], [187, 212], [187, 231], [187, 246], [187, 249], [187, 274], [187, 296], [188, 233], [188, 248], [188, 271], [188, 289], [189, 201], [189, 203], [189, 214], [189, 228], [189, 267], [189, 281], [190, 194], [190, 196], [190, 224], [190, 247], [190, 279], [190, 288], [191, 195], [191, 200], [191, 201], [191, 209], [191, 227], [191, 239], [191, 243], [191, 291], [191, 295], [191, 296], [192, 201], [192, 218], [192, 223], [192, 230], [192, 231], [192, 245], [192, 265], [193, 201], [193, 217], [193, 225], [193, 228], [193, 242], [193, 251], [193, 264], [193, 296], [194, 215], [194, 223], [194, 226], [194, 228], [194, 256], [194, 273], [194, 279], [194, 281], [194, 294], [194, 297], [195, 208], [195, 239], [195, 248], [195, 276], [196, 206], [196, 226], [196, 231], [196, 233], [196, 256], [196, 266], [196, 267], [196, 280], [196, 291], [197, 203], [197, 218], [197, 233], [197, 236], [197, 243], [197, 252], [197, 259], [197, 268], [197, 271], [197, 274], [197, 282], [197, 286], [198, 209], [198, 211], [198, 246], [198, 255], [198, 290], [199, 211], [199, 214], [199, 223], [199, 228], [199, 229], [199, 287], [200, 227], [200, 240], [200, 242], [200, 294], [201, 203], [201, 211], [201, 214], [201, 217], [201, 228], [201, 241], [201, 242], [201, 269], [201, 280], [201, 290], [201, 297], [202, 204], [202, 227], [202, 229], [202, 265], [202, 276], [202, 280], [203, 249], [203, 275], [203, 285], [203, 286], [203, 291], [203, 292], [203, 294], [204, 205], [204, 236], [204, 249], [204, 250], [204, 267], [204, 270], [204, 275], [204, 295], [205, 215], [205, 266], [205, 294], [206, 210], [206, 213], [206, 217], [206, 234], [206, 254], [206, 263], [206, 279], [207, 216], [207, 218], [207, 232], [207, 242], [207, 255], [207, 270], [207, 279], [208, 211], [208, 234], [208, 238], [208, 242], [208, 244], [208, 264], [208, 267], [208, 273], [208, 277], [208, 288], [208, 291], [209, 231], [209, 238], [209, 243], [209, 246], [209, 256], [209, 271], [209, 294], [210, 237], [210, 244], [210, 245], [210, 277], [210, 287], [210, 289], [210, 291], [211, 230], [211, 240], [211, 249], [211, 260], [211, 275], [212, 229], [212, 272], [213, 220], [213, 226], [213, 238], [213, 254], [213, 265], [213, 277], [213, 288], [213, 291], [214, 236], [214, 243], [214, 262], [214, 280], [214, 282], [214, 293], [215, 221], [215, 242], [216, 227], [216, 255], [216, 258], [216, 262], [216, 285], [217, 225], [217, 237], [217, 244], [217, 246], [217, 252], [217, 284], [217, 285], [217, 299], [218, 255], [218, 261], [218, 265], [218, 276], [219, 222], [219, 230], [219, 237], [219, 241], [219, 245], [219, 246], [219, 266], [219, 270], [219, 276], [219, 285], [220, 261], [220, 270], [221, 225], [221, 226], [221, 238], [222, 234], [223, 288], [224, 241], [224, 255], [224, 272], [224, 276], [224, 279], [224, 283], [224, 286], [224, 290], [225, 234], [225, 237], [225, 244], [225, 245], [225, 282], [225, 288], [226, 286], [226, 292], [226, 295], [227, 229], [227, 230], [227, 231], [227, 232], [227, 234], [227, 248], [227, 277], [227, 287], [227, 288], [228, 234], [228, 251], [228, 283], [228, 286], [228, 287], [228, 290], [228, 297], [228, 298], [229, 233], [229, 234], [229, 247], [229, 250], [229, 255], [229, 277], [229, 282], [229, 293], [230, 252], [230, 265], [231, 234], [231, 244], [231, 263], [231, 268], [231, 274], [231, 285], [231, 287], [231, 298], [232, 236], [232, 268], [232, 297], [233, 236], [233, 249], [233, 257], [233, 271], [233, 279], [233, 281], [234, 249], [234, 260], [234, 269], [235, 260], [235, 278], [236, 241], [236, 252], [236, 262], [236, 270], [236, 277], [236, 288], [236, 291], [237, 268], [237, 269], [237, 281], [237, 287], [238, 254], [238, 259], [238, 276], [238, 294], [239, 246], [239, 253], [239, 260], [240, 256], [240, 299], [241, 255], [241, 273], [241, 277], [241, 280], [242, 256], [242, 269], [242, 270], [242, 292], [243, 262], [243, 264], [243, 273], [243, 280], [243, 291], [244, 258], [244, 269], [244, 278], [244, 288], [244, 294], [245, 246], [245, 275], [245, 276], [245, 280], [245, 284], [246, 284], [246, 290], [246, 295], [247, 251], [247, 259], [247, 261], [247, 285], [248, 276], [248, 286], [249, 260], [249, 267], [249, 271], [249, 276], [250, 266], [250, 283], [251, 260], [251, 278], [251, 279], [251, 281], [251, 285], [251, 299], [252, 268], [252, 278], [252, 287], [253, 257], [253, 273], [254, 269], [254, 277], [254, 284], [255, 262], [255, 267], [255, 288], [256, 260], [256, 261], [256, 286], [256, 293], [256, 298], [257, 270], [257, 277], [258, 259], [258, 264], [258, 272], [259, 275], [260, 265], [260, 272], [260, 273], [260, 294], [261, 269], [261, 282], [261, 297], [262, 272], [263, 274], [263, 289], [263, 291], [263, 296], [265, 293], [266, 287], [267, 281], [267, 282], [267, 284], [267, 287], [267, 290], [268, 270], [268, 273], [268, 277], [269, 279], [269, 281], [269, 297], [271, 276], [271, 277], [271, 284], [274, 290], [274, 291], [275, 292], [276, 282], [276, 284], [277, 278], [277, 286], [277, 298], [278, 299], [279, 290], [280, 298], [281, 295], [282, 298], [284, 290], [284, 291], [285, 291], [286, 298], [287, 289], [291, 294], [291, 295], [291, 297]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l6-s7/solution/solve.sh b/tasks/construct-nppc-dominating-set-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8908d100f8be547cba186eb2897af76c617dc46b --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [2, 11, 14, 41, 54, 60, 82, 90, 99, 132, 143, 180, 183, 208, 236, 251, 269, 276, 277, 291]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l6-s7/tests/check.py b/tasks/construct-nppc-dominating-set-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l6-s7/tests/instance.json b/tasks/construct-nppc-dominating-set-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8888fa07560162e00796e458d25b51f83d2f7bf1 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 300, "k": 20, "edges": [[0, 11], [0, 26], [0, 37], [0, 42], [0, 45], [0, 58], [0, 77], [0, 118], [0, 126], [0, 133], [0, 134], [0, 158], [0, 163], [0, 173], [0, 175], [0, 182], [0, 222], [0, 223], [0, 224], [0, 234], [0, 236], [0, 239], [0, 244], [0, 245], [0, 272], [0, 279], [1, 30], [1, 35], [1, 51], [1, 54], [1, 64], [1, 72], [1, 93], [1, 95], [1, 119], [1, 122], [1, 127], [1, 179], [1, 180], [1, 196], [1, 231], [1, 254], [1, 296], [2, 21], [2, 36], [2, 38], [2, 39], [2, 88], [2, 97], [2, 105], [2, 118], [2, 148], [2, 155], [2, 163], [2, 165], [2, 181], [2, 202], [2, 234], [2, 243], [2, 263], [2, 268], [2, 269], [2, 273], [2, 289], [3, 5], [3, 7], [3, 31], [3, 42], [3, 50], [3, 64], [3, 65], [3, 74], [3, 145], [3, 183], [3, 206], [3, 215], [3, 228], [3, 261], [3, 269], [3, 296], [4, 7], [4, 11], [4, 52], [4, 105], [4, 107], [4, 122], [4, 126], [4, 138], [4, 149], [4, 173], [4, 194], [4, 235], [4, 243], [4, 246], [4, 256], [4, 270], [4, 273], [4, 292], [5, 18], [5, 54], [5, 92], [5, 98], [5, 157], [5, 163], [5, 168], [5, 189], [5, 221], [5, 222], [5, 226], [5, 228], [5, 232], [5, 284], [5, 294], [5, 298], [6, 41], [6, 61], [6, 64], [6, 65], [6, 67], [6, 70], [6, 77], [6, 82], [6, 90], [6, 96], [6, 111], [6, 137], [6, 165], [6, 175], [6, 183], [6, 190], [6, 211], [6, 214], [6, 240], [6, 241], [6, 253], [6, 278], [6, 292], [7, 86], [7, 87], [7, 115], [7, 125], [7, 131], [7, 140], [7, 147], [7, 153], [7, 162], [7, 163], [7, 175], [7, 193], [7, 197], [7, 201], [7, 205], [7, 236], [7, 252], [7, 255], [7, 288], [7, 295], [8, 36], [8, 112], [8, 125], [8, 138], [8, 142], [8, 155], [8, 158], [8, 160], [8, 180], [8, 188], [8, 201], [8, 208], [8, 245], [8, 269], [8, 274], [8, 279], [8, 288], [9, 22], [9, 62], [9, 63], [9, 75], [9, 81], [9, 95], [9, 98], [9, 99], [9, 138], [9, 148], [9, 158], [9, 159], [9, 172], [9, 188], [9, 189], [9, 213], [9, 214], [9, 227], [9, 244], [9, 245], [9, 250], [9, 263], [10, 33], [10, 38], [10, 55], [10, 97], [10, 130], [10, 158], [10, 190], [10, 236], [10, 240], [10, 247], [10, 260], [10, 267], [10, 279], [10, 283], [11, 16], [11, 24], [11, 27], [11, 65], [11, 69], [11, 75], [11, 77], [11, 87], [11, 101], [11, 108], [11, 128], [11, 137], [11, 149], [11, 152], [11, 156], [11, 164], [11, 167], [11, 171], [11, 173], [11, 192], [11, 202], [11, 254], [11, 259], [11, 266], [11, 286], [12, 35], [12, 53], [12, 62], [12, 63], [12, 84], [12, 96], [12, 103], [12, 105], [12, 110], [12, 118], [12, 129], [12, 139], [12, 143], [12, 150], [12, 167], [12, 180], [12, 191], [12, 198], [12, 226], [12, 229], [12, 230], [12, 231], [12, 232], [12, 252], [12, 267], [12, 268], [13, 34], [13, 44], [13, 77], [13, 81], [13, 90], [13, 100], [13, 110], [13, 136], [13, 149], [13, 188], [13, 194], [13, 198], [13, 209], [13, 210], [13, 221], [13, 233], [13, 237], [13, 241], [13, 257], [13, 261], [13, 271], [14, 30], [14, 32], [14, 36], [14, 38], [14, 44], [14, 56], [14, 60], [14, 61], [14, 68], [14, 80], [14, 107], [14, 118], [14, 123], [14, 135], [14, 146], [14, 153], [14, 168], [14, 205], [14, 209], [14, 210], [14, 222], [14, 233], [14, 253], [14, 256], [14, 270], [15, 39], [15, 47], [15, 86], [15, 88], [15, 100], [15, 137], [15, 150], [15, 153], [15, 170], [15, 172], [15, 187], [15, 248], [15, 251], [15, 252], [15, 257], [15, 268], [15, 296], [16, 29], [16, 70], [16, 105], [16, 110], [16, 121], [16, 123], [16, 128], [16, 133], [16, 139], [16, 167], [16, 173], [16, 174], [16, 217], [16, 231], [16, 253], [16, 278], [17, 19], [17, 62], [17, 68], [17, 86], [17, 91], [17, 93], [17, 99], [17, 137], [17, 142], [17, 154], [17, 169], [17, 269], [17, 272], [17, 274], [17, 279], [17, 289], [17, 290], [18, 38], [18, 57], [18, 62], [18, 72], [18, 75], [18, 81], [18, 100], [18, 162], [18, 166], [18, 197], [18, 236], [18, 247], [18, 263], [18, 267], [18, 277], [19, 22], [19, 50], [19, 58], [19, 71], [19, 84], [19, 99], [19, 177], [19, 183], [19, 190], [19, 205], [19, 219], [19, 245], [19, 268], [19, 290], [19, 295], [19, 296], [20, 39], [20, 45], [20, 61], [20, 65], [20, 77], [20, 81], [20, 100], [20, 116], [20, 131], [20, 135], [20, 186], [20, 195], [20, 203], [20, 208], [20, 240], [20, 242], [20, 246], [20, 255], [20, 260], [20, 268], [20, 276], [20, 282], [20, 285], [20, 297], [21, 59], [21, 95], [21, 103], [21, 108], [21, 111], [21, 134], [21, 158], [21, 159], [21, 206], [21, 226], [21, 246], [21, 249], [21, 279], [21, 287], [21, 292], [22, 42], [22, 50], [22, 70], [22, 76], [22, 78], [22, 88], [22, 91], [22, 111], [22, 124], [22, 132], [22, 134], [22, 137], [22, 143], [22, 145], [22, 151], [22, 169], [22, 175], [22, 179], [22, 189], [22, 192], [22, 205], [22, 242], [22, 249], [22, 277], [23, 47], [23, 61], [23, 85], [23, 88], [23, 99], [23, 114], [23, 116], [23, 119], [23, 142], [23, 145], [23, 150], [23, 155], [23, 167], [23, 170], [23, 172], [23, 173], [23, 176], [23, 191], [23, 234], [23, 268], [23, 275], [23, 286], [23, 291], [24, 26], [24, 41], [24, 56], [24, 69], [24, 84], [24, 151], [24, 156], [24, 161], [24, 170], [24, 174], [24, 206], [24, 255], [24, 259], [24, 261], [24, 277], [24, 289], [25, 30], [25, 40], [25, 41], [25, 45], [25, 61], [25, 75], [25, 78], [25, 82], [25, 90], [25, 96], [25, 122], [25, 152], [25, 166], [25, 168], [25, 182], [25, 192], [25, 236], [25, 269], [25, 283], [26, 73], [26, 136], [26, 157], [26, 217], [26, 237], [26, 238], [26, 247], [26, 276], [26, 278], [26, 280], [27, 28], [27, 35], [27, 37], [27, 38], [27, 56], [27, 63], [27, 65], [27, 101], [27, 123], [27, 132], [27, 141], [27, 152], [27, 159], [27, 281], [27, 289], [28, 56], [28, 63], [28, 120], [28, 121], [28, 132], [28, 141], [28, 165], [28, 173], [28, 185], [28, 199], [28, 200], [28, 223], [28, 239], [28, 244], [28, 267], [28, 276], [28, 286], [28, 290], [28, 296], [29, 52], [29, 69], [29, 97], [29, 111], [29, 152], [29, 177], [29, 208], [29, 228], [29, 261], [29, 287], [29, 293], [30, 40], [30, 114], [30, 164], [30, 198], [30, 212], [31, 38], [31, 44], [31, 51], [31, 54], [31, 73], [31, 90], [31, 91], [31, 97], [31, 101], [31, 107], [31, 111], [31, 121], [31, 128], [31, 137], [31, 141], [31, 166], [31, 188], [31, 220], [31, 224], [31, 231], [31, 250], [32, 42], [32, 60], [32, 86], [32, 97], [32, 99], [32, 134], [32, 156], [32, 189], [32, 193], [32, 200], [32, 206], [32, 209], [32, 227], [32, 249], [32, 257], [32, 274], [32, 278], [32, 279], [32, 287], [33, 74], [33, 76], [33, 122], [33, 123], [33, 130], [33, 163], [33, 202], [33, 213], [33, 227], [33, 235], [33, 236], [33, 252], [33, 255], [33, 275], [33, 281], [33, 292], [33, 293], [34, 35], [34, 54], [34, 57], [34, 73], [34, 78], [34, 82], [34, 86], [34, 99], [34, 103], [34, 104], [34, 107], [34, 118], [34, 125], [34, 168], [34, 169], [34, 183], [34, 231], [34, 277], [34, 295], [35, 36], [35, 39], [35, 52], [35, 53], [35, 60], [35, 79], [35, 86], [35, 95], [35, 99], [35, 108], [35, 132], [35, 140], [35, 148], [35, 167], [35, 178], [35, 203], [35, 249], [35, 289], [36, 39], [36, 67], [36, 70], [36, 119], [36, 124], [36, 173], [36, 181], [36, 183], [36, 187], [36, 192], [36, 218], [36, 225], [36, 250], [36, 265], [36, 270], [36, 287], [36, 291], [36, 292], [37, 41], [37, 61], [37, 86], [37, 90], [37, 106], [37, 111], [37, 124], [37, 132], [37, 186], [37, 188], [37, 191], [37, 210], [37, 249], [37, 260], [37, 290], [38, 41], [38, 53], [38, 65], [38, 74], [38, 114], [38, 128], [38, 130], [38, 202], [38, 240], [38, 247], [38, 262], [39, 41], [39, 47], [39, 67], [39, 82], [39, 86], [39, 118], [39, 145], [39, 153], [39, 160], [39, 163], [39, 168], [39, 208], [39, 211], [39, 236], [39, 239], [39, 244], [39, 255], [40, 49], [40, 51], [40, 59], [40, 84], [40, 94], [40, 105], [40, 148], [40, 157], [40, 168], [40, 209], [40, 231], [40, 249], [40, 254], [40, 262], [40, 269], [40, 273], [40, 274], [40, 288], [40, 289], [40, 295], [41, 86], [41, 87], [41, 92], [41, 93], [41, 95], [41, 96], [41, 117], [41, 119], [41, 126], [41, 142], [41, 151], [41, 166], [41, 183], [41, 188], [41, 196], [41, 206], [41, 209], [41, 215], [41, 220], [41, 222], [41, 224], [41, 226], [41, 258], [41, 264], [41, 266], [41, 267], [41, 269], [41, 272], [41, 279], [41, 299], [42, 48], [42, 53], [42, 79], [42, 134], [42, 156], [42, 174], [42, 192], [42, 206], [42, 226], [42, 232], [42, 236], [42, 237], [42, 239], [42, 283], [43, 60], [43, 104], [43, 105], [43, 110], [43, 115], [43, 125], [43, 145], [43, 149], [43, 154], [43, 176], [43, 181], [43, 198], [43, 220], [43, 229], [43, 235], [43, 239], [43, 248], [43, 261], [43, 279], [43, 282], [44, 45], [44, 54], [44, 59], [44, 73], [44, 93], [44, 94], [44, 104], [44, 113], [44, 145], [44, 152], [44, 160], [44, 207], [44, 221], [44, 234], [44, 244], [44, 270], [44, 272], [44, 277], [44, 283], [44, 291], [45, 57], [45, 60], [45, 66], [45, 79], [45, 91], [45, 150], [45, 151], [45, 171], [45, 181], [45, 191], [45, 215], [45, 231], [45, 233], [45, 236], [45, 241], [45, 283], [46, 52], [46, 58], [46, 89], [46, 90], [46, 115], [46, 149], [46, 165], [46, 166], [46, 179], [46, 181], [46, 182], [46, 190], [46, 199], [46, 220], [46, 227], [46, 235], [46, 247], [46, 261], [46, 263], [46, 268], [46, 278], [46, 285], [46, 291], [46, 294], [47, 67], [47, 72], [47, 87], [47, 105], [47, 121], [47, 132], [47, 135], [47, 139], [47, 143], [47, 231], [47, 232], [47, 240], [47, 243], [47, 259], [47, 263], [47, 290], [48, 49], [48, 59], [48, 91], [48, 93], [48, 113], [48, 115], [48, 123], [48, 148], [48, 173], [48, 180], [48, 191], [48, 193], [48, 194], [48, 196], [48, 200], [48, 204], [48, 228], [48, 239], [48, 251], [48, 263], [48, 285], [49, 65], [49, 66], [49, 70], [49, 73], [49, 83], [49, 133], [49, 142], [49, 156], [49, 183], [49, 261], [49, 264], [49, 272], [49, 280], [49, 282], [49, 290], [50, 79], [50, 82], [50, 101], [50, 106], [50, 118], [50, 124], [50, 149], [50, 170], [50, 175], [50, 214], [50, 225], [50, 251], [50, 254], [50, 276], [51, 63], [51, 85], [51, 86], [51, 111], [51, 135], [51, 161], [51, 163], [51, 167], [51, 203], [51, 209], [51, 235], [51, 250], [51, 257], [51, 271], [51, 276], [52, 56], [52, 60], [52, 82], [52, 97], [52, 102], [52, 129], [52, 137], [52, 148], [52, 151], [52, 227], [52, 231], [52, 232], [52, 246], [52, 279], [52, 280], [52, 297], [53, 60], [53, 61], [53, 71], [53, 97], [53, 167], [53, 183], [53, 215], [53, 224], [53, 243], [53, 245], [53, 259], [53, 264], [53, 278], [53, 283], [53, 293], [54, 56], [54, 58], [54, 62], [54, 69], [54, 72], [54, 76], [54, 81], [54, 84], [54, 97], [54, 99], [54, 113], [54, 119], [54, 120], [54, 121], [54, 125], [54, 150], [54, 153], [54, 178], [54, 182], [54, 193], [54, 194], [54, 220], [54, 251], [54, 265], [54, 274], [54, 280], [55, 57], [55, 82], [55, 97], [55, 106], [55, 138], [55, 140], [55, 146], [55, 148], [55, 161], [55, 170], [55, 216], [55, 223], [55, 226], [55, 227], [55, 239], [55, 244], [55, 262], [55, 267], [55, 281], [56, 65], [56, 67], [56, 73], [56, 76], [56, 134], [56, 142], [56, 174], [56, 206], [56, 215], [56, 222], [56, 235], [56, 242], [56, 266], [57, 62], [57, 103], [57, 134], [57, 172], [57, 220], [57, 227], [57, 241], [57, 269], [57, 276], [57, 278], [58, 72], [58, 119], [58, 135], [58, 140], [58, 160], [58, 230], [58, 231], [58, 235], [58, 269], [58, 293], [59, 76], [59, 82], [59, 112], [59, 122], [59, 131], [59, 141], [59, 148], [59, 159], [59, 180], [59, 227], [59, 262], [59, 268], [60, 66], [60, 78], [60, 80], [60, 85], [60, 92], [60, 102], [60, 103], [60, 108], [60, 111], [60, 129], [60, 133], [60, 135], [60, 149], [60, 150], [60, 186], [60, 192], [60, 246], [60, 266], [60, 276], [60, 281], [60, 292], [61, 112], [61, 144], [61, 160], [61, 165], [61, 190], [61, 200], [61, 202], [61, 233], [61, 253], [61, 282], [62, 75], [62, 95], [62, 105], [62, 125], [62, 129], [62, 146], [62, 162], [62, 164], [62, 202], [62, 208], [62, 211], [62, 216], [62, 222], [62, 231], [62, 241], [62, 245], [62, 255], [62, 273], [62, 280], [62, 289], [63, 71], [63, 104], [63, 128], [63, 132], [63, 145], [63, 147], [63, 158], [63, 160], [63, 178], [63, 192], [63, 201], [63, 211], [63, 261], [63, 264], [63, 268], [63, 276], [63, 298], [64, 102], [64, 105], [64, 107], [64, 118], [64, 120], [64, 132], [64, 147], [64, 192], [64, 241], [64, 243], [64, 251], [64, 274], [64, 293], [65, 83], [65, 104], [65, 106], [65, 138], [65, 144], [65, 171], [65, 182], [65, 193], [65, 198], [65, 200], [65, 243], [65, 288], [66, 75], [66, 121], [66, 147], [66, 155], [66, 164], [66, 168], [66, 177], [66, 180], [66, 188], [66, 190], [66, 195], [66, 196], [66, 214], [66, 243], [66, 253], [66, 255], [66, 272], [66, 274], [66, 289], [67, 152], [67, 164], [67, 179], [67, 189], [67, 207], [67, 215], [67, 216], [67, 229], [67, 230], [67, 232], [67, 234], [67, 263], [67, 277], [67, 279], [68, 78], [68, 85], [68, 92], [68, 173], [68, 174], [68, 247], [68, 252], [68, 272], [68, 282], [69, 83], [69, 88], [69, 123], [69, 139], [69, 153], [69, 193], [69, 225], [69, 236], [69, 242], [69, 286], [69, 295], [69, 296], [70, 78], [70, 88], [70, 90], [70, 92], [70, 93], [70, 98], [70, 104], [70, 108], [70, 111], [70, 122], [70, 133], [70, 164], [70, 191], [70, 233], [70, 247], [70, 264], [70, 276], [71, 95], [71, 114], [71, 126], [71, 134], [71, 139], [71, 150], [71, 152], [71, 154], [71, 165], [71, 166], [71, 202], [71, 210], [71, 232], [71, 236], [71, 262], [71, 263], [71, 264], [71, 267], [71, 276], [72, 78], [72, 94], [72, 111], [72, 115], [72, 137], [72, 143], [72, 144], [72, 163], [72, 169], [72, 181], [72, 229], [72, 230], [72, 235], [72, 245], [72, 295], [73, 108], [73, 113], [73, 142], [73, 199], [73, 267], [73, 272], [73, 288], [73, 291], [73, 296], [74, 82], [74, 103], [74, 142], [74, 145], [74, 152], [74, 182], [74, 194], [74, 211], [74, 231], [74, 239], [74, 253], [74, 258], [74, 293], [75, 85], [75, 92], [75, 107], [75, 199], [75, 243], [75, 251], [75, 256], [75, 258], [75, 265], [75, 278], [75, 289], [76, 98], [76, 99], [76, 104], [76, 128], [76, 149], [76, 163], [76, 223], [76, 230], [76, 233], [76, 248], [76, 251], [76, 257], [76, 288], [77, 92], [77, 109], [77, 153], [77, 154], [77, 181], [77, 227], [77, 235], [77, 236], [77, 238], [77, 243], [77, 260], [77, 262], [77, 265], [77, 274], [77, 289], [77, 299], [78, 82], [78, 86], [78, 96], [78, 106], [78, 126], [78, 145], [78, 152], [78, 159], [78, 164], [78, 169], [78, 183], [78, 185], [78, 193], [78, 211], [78, 218], [78, 242], [78, 245], [78, 275], [78, 276], [78, 286], [78, 291], [79, 91], [79, 104], [79, 130], [79, 141], [79, 155], [79, 161], [79, 179], [79, 180], [79, 222], [79, 236], [79, 246], [79, 249], [79, 287], [79, 293], [80, 97], [80, 105], [80, 115], [80, 137], [80, 163], [80, 169], [80, 192], [80, 201], [80, 211], [80, 217], [80, 260], [81, 85], [81, 88], [81, 98], [81, 110], [81, 129], [81, 145], [81, 153], [81, 168], [81, 180], [81, 215], [81, 229], [81, 242], [81, 265], [81, 269], [81, 286], [81, 293], [82, 101], [82, 106], [82, 122], [82, 131], [82, 133], [82, 146], [82, 166], [82, 170], [82, 182], [82, 192], [82, 195], [82, 200], [82, 225], [82, 230], [82, 232], [82, 235], [82, 243], [82, 246], [82, 261], [82, 279], [82, 280], [82, 286], [83, 103], [83, 109], [83, 118], [83, 119], [83, 123], [83, 129], [83, 135], [83, 139], [83, 141], [83, 155], [83, 157], [83, 170], [83, 190], [83, 196], [83, 212], [83, 238], [83, 276], [83, 285], [83, 297], [84, 89], [84, 106], [84, 134], [84, 143], [84, 152], [84, 164], [84, 174], [84, 193], [84, 220], [84, 263], [84, 268], [85, 90], [85, 99], [85, 108], [85, 143], [85, 203], [85, 204], [85, 209], [85, 236], [85, 266], [85, 286], [85, 289], [86, 103], [86, 110], [86, 112], [86, 114], [86, 148], [86, 150], [86, 161], [86, 173], [86, 177], [86, 178], [86, 180], [86, 202], [86, 217], [86, 260], [86, 267], [86, 269], [86, 276], [86, 296], [87, 100], [87, 209], [87, 226], [87, 232], [87, 253], [87, 284], [88, 91], [88, 130], [88, 153], [88, 163], [88, 167], [88, 183], [88, 189], [88, 214], [88, 219], [88, 234], [88, 238], [88, 254], [88, 287], [89, 90], [89, 93], [89, 99], [89, 105], [89, 132], [89, 152], [89, 166], [89, 188], [89, 218], [89, 234], [89, 248], [89, 261], [89, 281], [89, 299], [90, 92], [90, 108], [90, 123], [90, 131], [90, 148], [90, 149], [90, 154], [90, 165], [90, 174], [90, 179], [90, 186], [90, 190], [90, 196], [90, 212], [90, 215], [90, 216], [90, 219], [90, 221], [90, 244], [90, 250], [90, 282], [90, 290], [90, 292], [90, 293], [91, 122], [91, 152], [91, 166], [91, 173], [91, 207], [91, 235], [91, 241], [91, 248], [91, 256], [91, 268], [91, 269], [91, 277], [91, 278], [91, 282], [91, 286], [91, 290], [92, 100], [92, 110], [92, 172], [92, 184], [92, 192], [92, 237], [92, 245], [92, 259], [92, 278], [92, 292], [93, 95], [93, 138], [93, 161], [93, 170], [93, 175], [93, 176], [93, 201], [93, 232], [93, 236], [93, 245], [93, 263], [93, 289], [94, 107], [94, 135], [94, 141], [94, 168], [94, 190], [94, 206], [94, 215], [94, 220], [94, 252], [94, 277], [94, 297], [95, 134], [95, 152], [95, 154], [95, 158], [95, 196], [95, 222], [95, 233], [95, 236], [95, 240], [95, 285], [95, 291], [96, 105], [96, 106], [96, 116], [96, 121], [96, 128], [96, 157], [96, 210], [96, 211], [96, 221], [96, 248], [96, 271], [96, 284], [96, 294], [97, 102], [97, 129], [97, 135], [97, 189], [97, 193], [97, 204], [97, 233], [97, 239], [97, 244], [97, 270], [97, 274], [97, 290], [97, 293], [98, 113], [98, 118], [98, 129], [98, 139], [98, 140], [98, 147], [98, 154], [98, 169], [98, 177], [98, 223], [98, 234], [98, 251], [99, 100], [99, 111], [99, 115], [99, 129], [99, 164], [99, 172], [99, 183], [99, 187], [99, 193], [99, 198], [99, 206], [99, 207], [99, 217], [99, 220], [99, 245], [99, 253], [99, 255], [99, 268], [99, 277], [100, 161], [100, 167], [100, 177], [100, 200], [100, 230], [100, 235], [100, 236], [100, 241], [100, 249], [100, 251], [100, 264], [100, 269], [100, 276], [100, 294], [101, 138], [101, 140], [101, 180], [101, 266], [101, 290], [101, 291], [101, 299], [102, 114], [102, 125], [102, 134], [102, 142], [102, 144], [102, 159], [102, 168], [102, 212], [102, 223], [102, 278], [102, 279], [103, 131], [103, 137], [103, 151], [103, 154], [103, 183], [103, 202], [103, 211], [103, 220], [103, 234], [103, 240], [103, 255], [103, 268], [103, 272], [104, 142], [104, 195], [104, 198], [104, 219], [104, 229], [104, 236], [104, 283], [104, 287], [104, 290], [105, 114], [105, 139], [105, 140], [105, 152], [105, 158], [105, 179], [105, 185], [105, 193], [105, 249], [105, 271], [105, 272], [105, 283], [105, 284], [106, 114], [106, 115], [106, 122], [106, 164], [106, 166], [106, 206], [106, 244], [106, 265], [106, 291], [107, 122], [107, 127], [107, 152], [107, 166], [107, 168], [107, 188], [107, 201], [107, 204], [107, 232], [107, 244], [107, 249], [107, 269], [107, 297], [108, 128], [108, 174], [108, 175], [108, 201], [108, 202], [108, 205], [108, 238], [108, 257], [108, 262], [108, 277], [108, 299], [109, 110], [109, 112], [109, 168], [109, 176], [109, 178], [109, 179], [109, 181], [109, 183], [109, 189], [109, 198], [109, 202], [109, 240], [109, 246], [109, 278], [109, 284], [109, 287], [109, 298], [110, 159], [110, 185], [110, 209], [110, 213], [110, 230], [110, 232], [110, 269], [110, 291], [111, 113], [111, 133], [111, 142], [111, 176], [111, 202], [111, 226], [111, 234], [111, 239], [111, 254], [111, 285], [112, 130], [112, 145], [112, 146], [112, 152], [112, 155], [112, 206], [112, 227], [112, 240], [112, 250], [112, 269], [112, 270], [112, 273], [112, 277], [112, 290], [112, 294], [112, 296], [113, 133], [113, 175], [113, 193], [113, 226], [113, 274], [113, 288], [114, 115], [114, 134], [114, 148], [114, 151], [114, 153], [114, 191], [114, 206], [114, 230], [114, 236], [114, 241], [114, 242], [114, 250], [114, 280], [114, 290], [114, 292], [115, 125], [115, 136], [115, 156], [115, 195], [115, 200], [115, 240], [115, 241], [115, 250], [115, 265], [115, 267], [115, 299], [116, 136], [116, 171], [116, 172], [116, 204], [116, 234], [116, 250], [116, 255], [116, 277], [116, 284], [116, 291], [117, 123], [117, 136], [117, 138], [117, 171], [117, 172], [117, 232], [117, 262], [118, 129], [118, 170], [118, 190], [118, 196], [118, 198], [118, 229], [118, 263], [118, 277], [119, 137], [119, 155], [119, 159], [119, 166], [119, 170], [119, 176], [119, 182], [119, 185], [119, 189], [119, 217], [119, 222], [119, 246], [119, 291], [119, 298], [120, 133], [120, 148], [120, 149], [120, 150], [120, 155], [120, 214], [120, 229], [120, 242], [120, 257], [120, 279], [120, 281], [120, 282], [121, 131], [121, 134], [121, 187], [121, 194], [121, 195], [121, 269], [121, 284], [122, 132], [122, 163], [122, 215], [122, 216], [122, 225], [122, 240], [122, 243], [123, 130], [123, 148], [123, 158], [123, 170], [123, 189], [123, 192], [123, 199], [123, 204], [123, 206], [123, 207], [123, 217], [123, 277], [124, 125], [124, 142], [124, 147], [124, 162], [124, 180], [124, 234], [124, 254], [124, 286], [125, 153], [125, 164], [125, 179], [125, 183], [125, 200], [125, 201], [125, 212], [125, 220], [125, 230], [125, 232], [125, 251], [125, 256], [125, 261], [125, 279], [126, 132], [126, 156], [126, 159], [126, 164], [126, 193], [126, 204], [126, 216], [126, 279], [127, 129], [127, 134], [127, 158], [127, 183], [127, 228], [127, 250], [127, 263], [127, 269], [128, 141], [128, 150], [128, 157], [128, 175], [128, 249], [128, 251], [128, 276], [128, 282], [128, 284], [129, 131], [129, 178], [129, 181], [129, 198], [129, 222], [129, 226], [129, 242], [129, 265], [129, 266], [129, 276], [129, 293], [129, 296], [130, 169], [130, 180], [130, 198], [130, 216], [130, 261], [131, 173], [131, 218], [131, 219], [131, 220], [131, 230], [131, 231], [131, 233], [131, 258], [131, 265], [132, 143], [132, 161], [132, 170], [132, 199], [132, 211], [132, 240], [132, 275], [133, 143], [133, 144], [133, 177], [133, 179], [133, 181], [133, 208], [133, 221], [133, 227], [133, 230], [133, 254], [133, 261], [133, 291], [134, 143], [134, 160], [134, 186], [134, 219], [134, 227], [134, 237], [134, 238], [134, 245], [134, 250], [134, 251], [134, 255], [135, 146], [135, 165], [135, 176], [135, 203], [135, 232], [135, 240], [135, 247], [135, 251], [135, 256], [135, 266], [135, 271], [135, 283], [136, 138], [136, 156], [136, 158], [136, 183], [136, 203], [136, 232], [136, 238], [136, 248], [136, 266], [136, 291], [136, 299], [137, 145], [137, 148], [137, 159], [137, 162], [137, 173], [137, 180], [137, 203], [137, 231], [137, 243], [137, 274], [137, 275], [138, 152], [138, 153], [138, 183], [138, 205], [138, 209], [138, 230], [138, 251], [138, 268], [138, 291], [139, 141], [139, 172], [139, 192], [139, 198], [139, 228], [139, 232], [139, 260], [139, 269], [139, 278], [140, 161], [140, 164], [140, 183], [140, 196], [140, 202], [140, 215], [140, 225], [140, 240], [140, 245], [140, 258], [140, 263], [140, 289], [141, 202], [141, 205], [141, 215], [141, 217], [141, 237], [141, 249], [141, 254], [141, 264], [141, 291], [141, 297], [142, 151], [142, 157], [142, 190], [142, 224], [142, 230], [142, 245], [142, 277], [143, 184], [143, 201], [143, 202], [143, 203], [143, 207], [143, 225], [143, 231], [143, 239], [143, 246], [143, 248], [143, 264], [143, 270], [143, 278], [143, 283], [143, 287], [144, 153], [144, 174], [144, 191], [144, 193], [144, 218], [144, 237], [144, 276], [144, 289], [144, 291], [144, 293], [145, 154], [145, 173], [145, 181], [145, 208], [145, 213], [145, 256], [145, 262], [145, 273], [145, 295], [146, 199], [146, 209], [146, 227], [146, 228], [146, 229], [146, 255], [146, 273], [146, 275], [146, 290], [146, 293], [147, 156], [147, 220], [147, 269], [147, 283], [147, 298], [148, 165], [148, 169], [148, 210], [148, 223], [148, 257], [148, 279], [148, 290], [149, 151], [149, 156], [149, 157], [149, 163], [149, 167], [149, 171], [149, 174], [149, 182], [149, 190], [149, 196], [149, 197], [149, 206], [149, 208], [149, 210], [149, 216], [149, 228], [149, 234], [149, 236], [149, 268], [149, 282], [149, 295], [150, 169], [150, 171], [150, 176], [150, 179], [150, 180], [150, 183], [150, 193], [150, 198], [150, 206], [150, 232], [150, 233], [150, 248], [150, 268], [150, 280], [150, 281], [150, 287], [150, 289], [150, 297], [151, 165], [151, 176], [151, 199], [151, 266], [151, 268], [151, 269], [151, 284], [151, 286], [152, 181], [152, 208], [152, 253], [152, 267], [152, 284], [153, 155], [153, 195], [153, 205], [153, 231], [154, 221], [154, 253], [154, 254], [154, 260], [154, 261], [154, 284], [154, 291], [155, 170], [155, 191], [155, 194], [155, 208], [155, 209], [155, 264], [155, 283], [155, 295], [155, 296], [156, 237], [156, 263], [156, 266], [156, 292], [156, 293], [156, 294], [157, 208], [157, 228], [157, 236], [157, 284], [158, 204], [158, 208], [158, 222], [158, 231], [158, 262], [158, 294], [159, 161], [159, 172], [159, 176], [159, 203], [159, 215], [159, 222], [159, 227], [159, 250], [159, 253], [159, 263], [159, 269], [159, 270], [159, 280], [159, 283], [159, 284], [159, 290], [159, 295], [160, 183], [160, 193], [160, 196], [160, 233], [160, 238], [160, 269], [161, 163], [161, 200], [161, 262], [161, 283], [161, 296], [161, 297], [162, 177], [162, 183], [162, 214], [162, 236], [162, 258], [162, 261], [162, 269], [163, 165], [163, 175], [163, 188], [163, 236], [163, 239], [163, 245], [163, 256], [163, 260], [163, 265], [163, 270], [163, 299], [164, 167], [164, 205], [164, 230], [164, 245], [164, 248], [164, 253], [165, 183], [165, 203], [165, 206], [165, 230], [165, 231], [165, 239], [165, 281], [165, 288], [166, 182], [166, 195], [166, 207], [166, 212], [166, 219], [166, 221], [166, 229], [166, 265], [166, 269], [166, 274], [167, 178], [167, 189], [167, 216], [167, 227], [167, 239], [167, 241], [167, 255], [167, 273], [167, 282], [168, 187], [168, 189], [168, 200], [168, 218], [168, 223], [168, 227], [168, 228], [168, 250], [168, 269], [168, 286], [168, 297], [169, 210], [169, 220], [169, 256], [169, 269], [169, 285], [170, 173], [170, 212], [170, 217], [170, 219], [170, 242], [170, 244], [170, 250], [170, 253], [170, 266], [170, 273], [170, 282], [170, 291], [171, 180], [171, 183], [171, 201], [171, 237], [171, 243], [171, 288], [171, 290], [171, 299], [172, 203], [172, 204], [172, 211], [172, 217], [172, 249], [172, 266], [172, 296], [173, 189], [173, 242], [173, 262], [173, 268], [173, 274], [173, 280], [173, 291], [173, 298], [174, 181], [174, 193], [174, 235], [174, 279], [175, 176], [175, 202], [175, 203], [175, 263], [175, 270], [175, 277], [176, 194], [176, 208], [176, 227], [176, 261], [176, 269], [176, 271], [176, 284], [177, 183], [177, 186], [177, 198], [177, 211], [177, 223], [177, 229], [177, 246], [177, 248], [177, 251], [177, 258], [177, 270], [177, 280], [178, 215], [178, 226], [178, 271], [178, 279], [179, 195], [179, 246], [179, 277], [179, 278], [179, 284], [179, 286], [180, 185], [180, 200], [180, 208], [180, 219], [180, 224], [180, 238], [180, 270], [180, 271], [180, 277], [180, 285], [180, 296], [181, 193], [181, 218], [181, 229], [181, 241], [181, 243], [181, 249], [181, 255], [181, 263], [181, 271], [181, 297], [182, 199], [182, 200], [182, 225], [182, 239], [182, 249], [182, 258], [182, 269], [182, 291], [182, 292], [183, 189], [183, 191], [183, 192], [183, 204], [183, 205], [183, 214], [183, 215], [183, 223], [183, 228], [183, 253], [183, 255], [183, 258], [183, 284], [183, 298], [183, 299], [184, 195], [184, 203], [184, 218], [184, 224], [184, 229], [184, 273], [184, 298], [185, 194], [185, 208], [185, 247], [185, 253], [185, 264], [185, 265], [185, 282], [186, 188], [186, 224], [186, 230], [186, 234], [186, 270], [186, 292], [187, 203], [187, 212], [187, 231], [187, 246], [187, 249], [187, 274], [187, 296], [188, 233], [188, 248], [188, 271], [188, 289], [189, 201], [189, 203], [189, 214], [189, 228], [189, 267], [189, 281], [190, 194], [190, 196], [190, 224], [190, 247], [190, 279], [190, 288], [191, 195], [191, 200], [191, 201], [191, 209], [191, 227], [191, 239], [191, 243], [191, 291], [191, 295], [191, 296], [192, 201], [192, 218], [192, 223], [192, 230], [192, 231], [192, 245], [192, 265], [193, 201], [193, 217], [193, 225], [193, 228], [193, 242], [193, 251], [193, 264], [193, 296], [194, 215], [194, 223], [194, 226], [194, 228], [194, 256], [194, 273], [194, 279], [194, 281], [194, 294], [194, 297], [195, 208], [195, 239], [195, 248], [195, 276], [196, 206], [196, 226], [196, 231], [196, 233], [196, 256], [196, 266], [196, 267], [196, 280], [196, 291], [197, 203], [197, 218], [197, 233], [197, 236], [197, 243], [197, 252], [197, 259], [197, 268], [197, 271], [197, 274], [197, 282], [197, 286], [198, 209], [198, 211], [198, 246], [198, 255], [198, 290], [199, 211], [199, 214], [199, 223], [199, 228], [199, 229], [199, 287], [200, 227], [200, 240], [200, 242], [200, 294], [201, 203], [201, 211], [201, 214], [201, 217], [201, 228], [201, 241], [201, 242], [201, 269], [201, 280], [201, 290], [201, 297], [202, 204], [202, 227], [202, 229], [202, 265], [202, 276], [202, 280], [203, 249], [203, 275], [203, 285], [203, 286], [203, 291], [203, 292], [203, 294], [204, 205], [204, 236], [204, 249], [204, 250], [204, 267], [204, 270], [204, 275], [204, 295], [205, 215], [205, 266], [205, 294], [206, 210], [206, 213], [206, 217], [206, 234], [206, 254], [206, 263], [206, 279], [207, 216], [207, 218], [207, 232], [207, 242], [207, 255], [207, 270], [207, 279], [208, 211], [208, 234], [208, 238], [208, 242], [208, 244], [208, 264], [208, 267], [208, 273], [208, 277], [208, 288], [208, 291], [209, 231], [209, 238], [209, 243], [209, 246], [209, 256], [209, 271], [209, 294], [210, 237], [210, 244], [210, 245], [210, 277], [210, 287], [210, 289], [210, 291], [211, 230], [211, 240], [211, 249], [211, 260], [211, 275], [212, 229], [212, 272], [213, 220], [213, 226], [213, 238], [213, 254], [213, 265], [213, 277], [213, 288], [213, 291], [214, 236], [214, 243], [214, 262], [214, 280], [214, 282], [214, 293], [215, 221], [215, 242], [216, 227], [216, 255], [216, 258], [216, 262], [216, 285], [217, 225], [217, 237], [217, 244], [217, 246], [217, 252], [217, 284], [217, 285], [217, 299], [218, 255], [218, 261], [218, 265], [218, 276], [219, 222], [219, 230], [219, 237], [219, 241], [219, 245], [219, 246], [219, 266], [219, 270], [219, 276], [219, 285], [220, 261], [220, 270], [221, 225], [221, 226], [221, 238], [222, 234], [223, 288], [224, 241], [224, 255], [224, 272], [224, 276], [224, 279], [224, 283], [224, 286], [224, 290], [225, 234], [225, 237], [225, 244], [225, 245], [225, 282], [225, 288], [226, 286], [226, 292], [226, 295], [227, 229], [227, 230], [227, 231], [227, 232], [227, 234], [227, 248], [227, 277], [227, 287], [227, 288], [228, 234], [228, 251], [228, 283], [228, 286], [228, 287], [228, 290], [228, 297], [228, 298], [229, 233], [229, 234], [229, 247], [229, 250], [229, 255], [229, 277], [229, 282], [229, 293], [230, 252], [230, 265], [231, 234], [231, 244], [231, 263], [231, 268], [231, 274], [231, 285], [231, 287], [231, 298], [232, 236], [232, 268], [232, 297], [233, 236], [233, 249], [233, 257], [233, 271], [233, 279], [233, 281], [234, 249], [234, 260], [234, 269], [235, 260], [235, 278], [236, 241], [236, 252], [236, 262], [236, 270], [236, 277], [236, 288], [236, 291], [237, 268], [237, 269], [237, 281], [237, 287], [238, 254], [238, 259], [238, 276], [238, 294], [239, 246], [239, 253], [239, 260], [240, 256], [240, 299], [241, 255], [241, 273], [241, 277], [241, 280], [242, 256], [242, 269], [242, 270], [242, 292], [243, 262], [243, 264], [243, 273], [243, 280], [243, 291], [244, 258], [244, 269], [244, 278], [244, 288], [244, 294], [245, 246], [245, 275], [245, 276], [245, 280], [245, 284], [246, 284], [246, 290], [246, 295], [247, 251], [247, 259], [247, 261], [247, 285], [248, 276], [248, 286], [249, 260], [249, 267], [249, 271], [249, 276], [250, 266], [250, 283], [251, 260], [251, 278], [251, 279], [251, 281], [251, 285], [251, 299], [252, 268], [252, 278], [252, 287], [253, 257], [253, 273], [254, 269], [254, 277], [254, 284], [255, 262], [255, 267], [255, 288], [256, 260], [256, 261], [256, 286], [256, 293], [256, 298], [257, 270], [257, 277], [258, 259], [258, 264], [258, 272], [259, 275], [260, 265], [260, 272], [260, 273], [260, 294], [261, 269], [261, 282], [261, 297], [262, 272], [263, 274], [263, 289], [263, 291], [263, 296], [265, 293], [266, 287], [267, 281], [267, 282], [267, 284], [267, 287], [267, 290], [268, 270], [268, 273], [268, 277], [269, 279], [269, 281], [269, 297], [271, 276], [271, 277], [271, 284], [274, 290], [274, 291], [275, 292], [276, 282], [276, 284], [277, 278], [277, 286], [277, 298], [278, 299], [279, 290], [280, 298], [281, 295], [282, 298], [284, 290], [284, 291], [285, 291], [286, 298], [287, 289], [291, 294], [291, 295], [291, 297]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l6-s7/tests/run.py b/tasks/construct-nppc-dominating-set-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l6-s7/tests/test.sh b/tasks/construct-nppc-dominating-set-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l6-s9/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l6-s9/environment/instance.json b/tasks/construct-nppc-dominating-set-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..817e884fbc5f6f70b5272ebb1fae71570bd393ba --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 300, "k": 20, "edges": [[0, 1], [0, 9], [0, 44], [0, 71], [0, 75], [0, 79], [0, 92], [0, 93], [0, 100], [0, 114], [0, 124], [0, 136], [0, 157], [0, 159], [0, 175], [0, 191], [0, 193], [0, 206], [0, 212], [0, 216], [0, 250], [0, 267], [0, 270], [0, 276], [1, 32], [1, 67], [1, 68], [1, 75], [1, 78], [1, 82], [1, 97], [1, 119], [1, 130], [1, 139], [1, 140], [1, 166], [1, 169], [1, 171], [1, 211], [1, 231], [1, 232], [1, 246], [1, 250], [1, 293], [1, 294], [2, 14], [2, 46], [2, 74], [2, 87], [2, 94], [2, 155], [2, 185], [2, 202], [2, 216], [2, 231], [2, 239], [2, 266], [2, 289], [2, 295], [3, 6], [3, 29], [3, 30], [3, 72], [3, 80], [3, 111], [3, 114], [3, 115], [3, 129], [3, 141], [3, 143], [3, 153], [3, 217], [3, 237], [3, 244], [3, 276], [3, 289], [3, 293], [3, 295], [4, 18], [4, 24], [4, 25], [4, 28], [4, 33], [4, 35], [4, 38], [4, 41], [4, 59], [4, 89], [4, 90], [4, 92], [4, 99], [4, 118], [4, 144], [4, 145], [4, 210], [4, 212], [4, 235], [4, 254], [4, 263], [4, 266], [4, 287], [5, 9], [5, 15], [5, 24], [5, 37], [5, 62], [5, 74], [5, 90], [5, 101], [5, 105], [5, 133], [5, 170], [5, 195], [5, 198], [5, 220], [5, 240], [5, 276], [5, 287], [5, 289], [5, 295], [6, 16], [6, 18], [6, 45], [6, 53], [6, 54], [6, 88], [6, 107], [6, 135], [6, 140], [6, 144], [6, 149], [6, 168], [6, 201], [6, 203], [6, 217], [6, 225], [6, 236], [6, 250], [6, 264], [6, 275], [6, 278], [6, 290], [6, 299], [7, 18], [7, 27], [7, 72], [7, 82], [7, 84], [7, 96], [7, 114], [7, 141], [7, 162], [7, 165], [7, 171], [7, 213], [7, 235], [7, 243], [7, 275], [7, 288], [8, 67], [8, 71], [8, 89], [8, 90], [8, 93], [8, 103], [8, 132], [8, 133], [8, 147], [8, 193], [8, 194], [8, 215], [8, 222], [8, 240], [8, 279], [8, 281], [9, 17], [9, 20], [9, 32], [9, 37], [9, 41], [9, 45], [9, 57], [9, 62], [9, 69], [9, 80], [9, 90], [9, 96], [9, 107], [9, 120], [9, 124], [9, 137], [9, 139], [9, 143], [9, 160], [9, 161], [9, 180], [9, 186], [9, 188], [9, 219], [9, 230], [9, 232], [9, 241], [9, 252], [9, 263], [9, 269], [9, 278], [9, 281], [9, 297], [10, 24], [10, 34], [10, 36], [10, 38], [10, 44], [10, 63], [10, 101], [10, 110], [10, 129], [10, 132], [10, 135], [10, 139], [10, 164], [10, 183], [10, 214], [10, 223], [10, 226], [10, 262], [10, 266], [10, 275], [10, 282], [11, 12], [11, 66], [11, 74], [11, 101], [11, 108], [11, 112], [11, 114], [11, 127], [11, 138], [11, 162], [11, 172], [11, 173], [11, 209], [11, 224], [11, 233], [11, 264], [11, 297], [12, 21], [12, 47], [12, 56], [12, 79], [12, 84], [12, 97], [12, 104], [12, 125], [12, 129], [12, 184], [12, 207], [12, 210], [12, 212], [12, 242], [12, 251], [12, 255], [12, 259], [12, 262], [13, 16], [13, 17], [13, 32], [13, 38], [13, 59], [13, 78], [13, 87], [13, 98], [13, 112], [13, 113], [13, 137], [13, 148], [13, 171], [13, 184], [13, 198], [13, 202], [13, 210], [13, 214], [13, 216], [13, 256], [13, 290], [13, 298], [14, 36], [14, 42], [14, 61], [14, 63], [14, 68], [14, 82], [14, 89], [14, 94], [14, 134], [14, 136], [14, 143], [14, 175], [14, 209], [14, 226], [14, 229], [14, 233], [14, 237], [14, 244], [14, 262], [14, 273], [14, 285], [14, 290], [15, 19], [15, 28], [15, 97], [15, 114], [15, 151], [15, 153], [15, 181], [15, 196], [15, 199], [15, 233], [15, 235], [15, 246], [15, 255], [15, 268], [15, 282], [15, 283], [15, 299], [16, 36], [16, 44], [16, 45], [16, 55], [16, 68], [16, 71], [16, 88], [16, 97], [16, 125], [16, 139], [16, 145], [16, 158], [16, 168], [16, 177], [16, 193], [16, 263], [16, 269], [16, 297], [17, 32], [17, 44], [17, 59], [17, 106], [17, 115], [17, 136], [17, 142], [17, 157], [17, 168], [17, 175], [17, 203], [17, 210], [17, 218], [17, 222], [17, 225], [17, 226], [17, 255], [17, 288], [18, 56], [18, 57], [18, 59], [18, 75], [18, 83], [18, 90], [18, 92], [18, 94], [18, 96], [18, 101], [18, 119], [18, 132], [18, 163], [18, 165], [18, 170], [18, 182], [18, 190], [18, 204], [18, 209], [18, 211], [18, 212], [18, 239], [18, 252], [18, 253], [18, 268], [18, 278], [18, 291], [19, 20], [19, 31], [19, 62], [19, 68], [19, 69], [19, 89], [19, 110], [19, 113], [19, 116], [19, 127], [19, 134], [19, 142], [19, 162], [19, 168], [19, 171], [19, 217], [19, 220], [19, 223], [19, 245], [19, 252], [19, 259], [19, 265], [19, 279], [19, 289], [19, 291], [19, 292], [19, 297], [20, 23], [20, 34], [20, 42], [20, 64], [20, 124], [20, 131], [20, 149], [20, 172], [20, 191], [20, 210], [20, 211], [20, 226], [20, 230], [20, 233], [20, 235], [20, 241], [20, 271], [20, 272], [20, 276], [20, 286], [20, 297], [21, 44], [21, 48], [21, 49], [21, 52], [21, 63], [21, 66], [21, 73], [21, 127], [21, 128], [21, 132], [21, 144], [21, 147], [21, 184], [21, 204], [21, 233], [21, 246], [21, 269], [21, 275], [21, 287], [21, 293], [21, 296], [22, 45], [22, 65], [22, 66], [22, 69], [22, 96], [22, 124], [22, 125], [22, 144], [22, 158], [22, 169], [22, 188], [22, 205], [22, 224], [22, 225], [22, 236], [22, 248], [22, 254], [22, 256], [22, 261], [22, 264], [22, 275], [22, 293], [23, 39], [23, 43], [23, 66], [23, 71], [23, 83], [23, 88], [23, 102], [23, 104], [23, 124], [23, 125], [23, 137], [23, 152], [23, 182], [23, 196], [23, 227], [24, 28], [24, 29], [24, 43], [24, 66], [24, 82], [24, 88], [24, 123], [24, 214], [24, 217], [24, 218], [24, 235], [24, 236], [24, 241], [24, 266], [24, 268], [24, 274], [24, 275], [25, 27], [25, 39], [25, 64], [25, 71], [25, 86], [25, 98], [25, 156], [25, 166], [25, 186], [25, 210], [25, 229], [25, 249], [25, 250], [25, 298], [26, 53], [26, 67], [26, 82], [26, 101], [26, 112], [26, 120], [26, 144], [26, 150], [26, 162], [26, 167], [26, 180], [26, 213], [26, 216], [26, 230], [26, 255], [26, 258], [26, 271], [26, 286], [27, 68], [27, 71], [27, 91], [27, 93], [27, 102], [27, 128], [27, 157], [27, 163], [27, 170], [27, 187], [27, 188], [27, 202], [27, 234], [27, 238], [27, 260], [27, 267], [27, 289], [27, 299], [28, 36], [28, 66], [28, 67], [28, 96], [28, 111], [28, 132], [28, 136], [28, 137], [28, 143], [28, 147], [28, 161], [28, 186], [28, 200], [28, 252], [28, 268], [28, 280], [28, 298], [29, 30], [29, 38], [29, 39], [29, 90], [29, 115], [29, 118], [29, 127], [29, 133], [29, 143], [29, 153], [29, 172], [29, 175], [29, 194], [29, 200], [29, 221], [29, 242], [29, 246], [29, 250], [29, 282], [30, 66], [30, 77], [30, 89], [30, 98], [30, 107], [30, 119], [30, 122], [30, 130], [30, 137], [30, 138], [30, 160], [30, 164], [30, 207], [30, 220], [30, 222], [30, 253], [30, 274], [30, 276], [31, 32], [31, 55], [31, 117], [31, 120], [31, 135], [31, 143], [31, 144], [31, 147], [31, 152], [31, 187], [31, 194], [31, 199], [31, 204], [31, 236], [31, 241], [31, 242], [31, 261], [32, 38], [32, 42], [32, 44], [32, 45], [32, 83], [32, 134], [32, 135], [32, 148], [32, 153], [32, 158], [32, 186], [32, 200], [32, 214], [32, 244], [32, 271], [32, 275], [32, 288], [33, 47], [33, 51], [33, 56], [33, 57], [33, 93], [33, 101], [33, 105], [33, 168], [33, 171], [33, 188], [33, 249], [33, 288], [33, 292], [33, 295], [34, 35], [34, 38], [34, 45], [34, 49], [34, 54], [34, 76], [34, 92], [34, 107], [34, 135], [34, 152], [34, 180], [34, 217], [34, 218], [34, 226], [34, 239], [34, 246], [34, 271], [34, 285], [34, 296], [34, 299], [35, 38], [35, 40], [35, 48], [35, 56], [35, 59], [35, 65], [35, 70], [35, 72], [35, 75], [35, 78], [35, 81], [35, 86], [35, 91], [35, 98], [35, 105], [35, 108], [35, 109], [35, 117], [35, 120], [35, 123], [35, 137], [35, 160], [35, 181], [35, 190], [35, 196], [35, 201], [35, 202], [35, 235], [35, 248], [35, 253], [35, 282], [35, 291], [35, 296], [36, 58], [36, 82], [36, 94], [36, 101], [36, 127], [36, 141], [36, 142], [36, 184], [36, 191], [36, 209], [36, 228], [36, 238], [36, 266], [36, 271], [36, 279], [36, 288], [36, 299], [37, 51], [37, 52], [37, 53], [37, 56], [37, 58], [37, 66], [37, 72], [37, 136], [37, 160], [37, 197], [37, 200], [37, 206], [37, 209], [37, 239], [37, 261], [37, 265], [37, 295], [38, 51], [38, 55], [38, 58], [38, 97], [38, 107], [38, 108], [38, 139], [38, 157], [38, 208], [38, 224], [38, 246], [38, 248], [39, 47], [39, 63], [39, 71], [39, 74], [39, 119], [39, 167], [39, 178], [39, 190], [39, 194], [39, 199], [39, 206], [39, 230], [39, 237], [39, 250], [39, 262], [39, 265], [39, 271], [39, 288], [39, 291], [40, 48], [40, 87], [40, 98], [40, 104], [40, 126], [40, 133], [40, 158], [40, 160], [40, 166], [40, 191], [40, 201], [40, 215], [40, 226], [40, 235], [40, 236], [40, 238], [40, 278], [40, 286], [41, 81], [41, 87], [41, 118], [41, 125], [41, 133], [41, 149], [41, 164], [41, 168], [41, 192], [41, 196], [41, 206], [41, 230], [41, 251], [41, 255], [41, 263], [41, 293], [42, 45], [42, 82], [42, 95], [42, 107], [42, 160], [42, 173], [42, 177], [42, 189], [42, 202], [42, 208], [42, 243], [42, 251], [42, 266], [42, 290], [43, 47], [43, 49], [43, 52], [43, 113], [43, 118], [43, 137], [43, 141], [43, 149], [43, 167], [43, 170], [43, 197], [43, 217], [43, 232], [43, 233], [43, 238], [43, 249], [43, 252], [43, 263], [43, 287], [44, 49], [44, 71], [44, 72], [44, 80], [44, 82], [44, 86], [44, 107], [44, 121], [44, 128], [44, 133], [44, 141], [44, 177], [44, 178], [44, 243], [44, 265], [44, 267], [44, 270], [45, 47], [45, 73], [45, 79], [45, 88], [45, 90], [45, 98], [45, 100], [45, 118], [45, 119], [45, 130], [45, 173], [45, 174], [45, 175], [45, 206], [45, 216], [45, 222], [45, 223], [45, 244], [45, 250], [45, 261], [45, 268], [45, 271], [45, 272], [45, 273], [45, 281], [45, 282], [45, 285], [45, 295], [45, 298], [46, 74], [46, 75], [46, 82], [46, 97], [46, 99], [46, 103], [46, 112], [46, 138], [46, 144], [46, 178], [46, 184], [46, 197], [46, 206], [46, 234], [46, 245], [46, 250], [46, 267], [47, 63], [47, 73], [47, 75], [47, 86], [47, 97], [47, 110], [47, 136], [47, 155], [47, 169], [47, 217], [47, 283], [47, 286], [48, 112], [48, 113], [48, 149], [48, 151], [48, 163], [48, 171], [48, 181], [48, 182], [48, 196], [48, 197], [48, 236], [48, 242], [48, 243], [48, 246], [48, 260], [48, 275], [49, 81], [49, 93], [49, 105], [49, 112], [49, 136], [49, 141], [49, 169], [49, 171], [49, 174], [49, 176], [49, 202], [49, 223], [49, 236], [49, 274], [50, 117], [50, 135], [50, 139], [50, 146], [50, 147], [50, 169], [50, 190], [50, 197], [50, 213], [50, 244], [50, 257], [50, 260], [50, 264], [50, 279], [50, 295], [50, 296], [50, 299], [51, 64], [51, 79], [51, 104], [51, 106], [51, 122], [51, 134], [51, 135], [51, 177], [51, 184], [51, 186], [51, 193], [51, 238], [51, 251], [51, 267], [52, 83], [52, 87], [52, 116], [52, 145], [52, 154], [52, 204], [52, 210], [52, 258], [52, 266], [52, 291], [53, 79], [53, 83], [53, 125], [53, 132], [53, 200], [53, 203], [53, 209], [53, 220], [53, 245], [53, 270], [53, 288], [54, 63], [54, 76], [54, 79], [54, 97], [54, 104], [54, 105], [54, 129], [54, 130], [54, 165], [54, 198], [54, 219], [55, 56], [55, 58], [55, 85], [55, 87], [55, 115], [55, 119], [55, 124], [55, 133], [55, 165], [55, 206], [55, 229], [55, 244], [55, 251], [55, 265], [55, 271], [56, 97], [56, 98], [56, 102], [56, 149], [56, 155], [56, 164], [56, 167], [56, 173], [56, 176], [56, 180], [56, 188], [56, 191], [56, 192], [56, 200], [56, 228], [56, 230], [56, 240], [56, 256], [56, 274], [57, 58], [57, 64], [57, 87], [57, 139], [57, 142], [57, 161], [57, 165], [57, 216], [57, 238], [57, 245], [58, 70], [58, 97], [58, 109], [58, 138], [58, 152], [58, 167], [58, 192], [58, 194], [58, 203], [58, 208], [58, 212], [58, 215], [58, 226], [58, 243], [58, 263], [58, 268], [58, 279], [59, 72], [59, 80], [59, 83], [59, 93], [59, 99], [59, 126], [59, 130], [59, 180], [59, 230], [59, 260], [59, 267], [59, 277], [59, 287], [60, 61], [60, 95], [60, 110], [60, 115], [60, 116], [60, 117], [60, 127], [60, 138], [60, 200], [60, 239], [60, 255], [60, 264], [60, 291], [61, 97], [61, 98], [61, 105], [61, 113], [61, 117], [61, 119], [61, 128], [61, 148], [61, 180], [61, 222], [61, 247], [61, 260], [61, 288], [61, 299], [62, 84], [62, 115], [62, 136], [62, 141], [62, 169], [62, 192], [62, 196], [62, 204], [62, 227], [62, 249], [62, 262], [62, 271], [62, 279], [62, 281], [62, 293], [63, 68], [63, 75], [63, 98], [63, 104], [63, 114], [63, 175], [63, 185], [63, 203], [63, 219], [63, 242], [63, 244], [63, 258], [63, 261], [63, 264], [63, 286], [64, 100], [64, 104], [64, 115], [64, 137], [64, 165], [64, 186], [64, 203], [64, 222], [64, 228], [64, 232], [64, 236], [64, 248], [65, 99], [65, 107], [65, 126], [65, 176], [65, 186], [65, 263], [65, 294], [66, 77], [66, 98], [66, 112], [66, 115], [66, 119], [66, 157], [66, 159], [66, 170], [66, 190], [66, 204], [66, 271], [66, 274], [66, 278], [67, 72], [67, 74], [67, 89], [67, 109], [67, 134], [67, 161], [67, 167], [67, 168], [67, 171], [67, 176], [67, 216], [67, 222], [67, 237], [67, 238], [67, 255], [67, 265], [67, 266], [67, 277], [67, 291], [68, 157], [68, 166], [68, 179], [68, 226], [68, 237], [68, 259], [68, 271], [68, 288], [69, 82], [69, 93], [69, 94], [69, 97], [69, 105], [69, 146], [69, 151], [69, 159], [69, 165], [69, 213], [69, 266], [69, 268], [70, 85], [70, 90], [70, 144], [70, 157], [70, 178], [70, 186], [70, 249], [70, 255], [70, 260], [70, 274], [70, 275], [70, 276], [70, 278], [70, 288], [71, 73], [71, 85], [71, 100], [71, 117], [71, 126], [71, 128], [71, 138], [71, 150], [71, 164], [71, 166], [71, 170], [71, 172], [71, 173], [71, 187], [71, 201], [71, 205], [71, 209], [71, 239], [71, 241], [71, 250], [71, 251], [71, 255], [71, 256], [71, 259], [71, 263], [71, 275], [71, 283], [71, 286], [71, 296], [71, 297], [72, 81], [72, 83], [72, 111], [72, 118], [72, 132], [72, 154], [72, 164], [72, 172], [72, 183], [72, 230], [72, 245], [72, 250], [72, 276], [72, 297], [73, 99], [73, 132], [73, 139], [73, 227], [73, 253], [73, 259], [74, 81], [74, 86], [74, 113], [74, 117], [74, 148], [74, 155], [74, 167], [74, 169], [74, 190], [74, 213], [74, 225], [74, 235], [74, 252], [74, 280], [74, 284], [74, 295], [75, 85], [75, 113], [75, 128], [75, 175], [75, 200], [75, 203], [75, 216], [75, 218], [75, 224], [75, 248], [75, 255], [75, 292], [76, 88], [76, 94], [76, 112], [76, 130], [76, 159], [76, 185], [76, 232], [76, 249], [76, 279], [77, 113], [77, 136], [77, 167], [77, 171], [77, 176], [77, 251], [77, 289], [77, 295], [77, 297], [78, 90], [78, 117], [78, 122], [78, 193], [78, 196], [78, 227], [78, 243], [78, 250], [78, 257], [78, 261], [78, 263], [78, 266], [78, 272], [78, 276], [78, 281], [79, 95], [79, 101], [79, 117], [79, 133], [79, 155], [79, 161], [79, 172], [79, 193], [79, 200], [79, 204], [79, 218], [79, 255], [79, 263], [79, 292], [80, 102], [80, 113], [80, 117], [80, 132], [80, 138], [80, 140], [80, 153], [80, 154], [80, 171], [80, 194], [80, 214], [80, 226], [80, 257], [80, 258], [80, 264], [80, 270], [80, 287], [81, 86], [81, 90], [81, 103], [81, 110], [81, 112], [81, 125], [81, 130], [81, 138], [81, 145], [81, 155], [81, 182], [81, 189], [81, 200], [81, 208], [81, 226], [81, 240], [81, 260], [81, 274], [81, 290], [82, 93], [82, 126], [82, 153], [82, 158], [82, 176], [82, 223], [82, 225], [82, 252], [82, 255], [82, 262], [82, 269], [82, 280], [82, 284], [82, 289], [83, 97], [83, 105], [83, 109], [83, 110], [83, 115], [83, 134], [83, 143], [83, 177], [83, 179], [83, 227], [83, 236], [83, 240], [83, 254], [83, 262], [84, 85], [84, 90], [84, 113], [84, 133], [84, 161], [84, 183], [84, 196], [84, 251], [84, 256], [84, 272], [84, 292], [84, 298], [85, 118], [85, 127], [85, 129], [85, 140], [85, 156], [85, 160], [85, 167], [85, 174], [85, 179], [85, 187], [85, 199], [85, 202], [85, 218], [85, 225], [85, 229], [85, 238], [85, 247], [85, 290], [86, 92], [86, 99], [86, 164], [86, 175], [86, 190], [86, 218], [86, 232], [86, 242], [86, 266], [86, 271], [87, 116], [87, 125], [87, 134], [87, 164], [87, 168], [87, 193], [87, 195], [87, 198], [87, 200], [87, 235], [87, 246], [87, 273], [87, 281], [88, 92], [88, 122], [88, 124], [88, 149], [88, 150], [88, 175], [88, 181], [88, 198], [88, 211], [88, 223], [88, 225], [88, 227], [88, 243], [88, 250], [88, 265], [88, 270], [89, 124], [89, 135], [89, 137], [89, 158], [89, 165], [89, 180], [89, 192], [89, 207], [89, 209], [89, 223], [89, 224], [89, 225], [89, 231], [89, 237], [89, 246], [89, 272], [90, 93], [90, 103], [90, 112], [90, 115], [90, 198], [90, 244], [90, 254], [90, 262], [90, 285], [91, 113], [91, 128], [91, 135], [91, 138], [91, 152], [91, 166], [91, 181], [91, 196], [91, 198], [91, 201], [91, 203], [91, 210], [91, 211], [91, 222], [91, 253], [91, 257], [91, 259], [91, 267], [91, 292], [92, 97], [92, 128], [92, 153], [92, 155], [92, 159], [92, 177], [92, 186], [92, 197], [92, 226], [92, 230], [92, 247], [92, 250], [92, 251], [92, 260], [92, 271], [93, 97], [93, 110], [93, 117], [93, 135], [93, 152], [93, 160], [93, 167], [93, 175], [93, 220], [93, 240], [93, 253], [93, 256], [93, 277], [93, 282], [93, 287], [94, 97], [94, 106], [94, 125], [94, 169], [94, 221], [94, 227], [94, 299], [95, 97], [95, 112], [95, 143], [95, 147], [95, 149], [95, 151], [95, 162], [95, 185], [95, 210], [95, 220], [95, 226], [95, 227], [95, 239], [95, 240], [95, 241], [95, 243], [95, 276], [95, 279], [95, 286], [95, 295], [96, 147], [96, 172], [96, 178], [96, 185], [96, 192], [96, 237], [96, 238], [96, 241], [96, 242], [96, 262], [96, 289], [97, 99], [97, 105], [97, 115], [97, 123], [97, 124], [97, 126], [97, 136], [97, 162], [97, 171], [97, 176], [97, 177], [97, 193], [97, 235], [97, 244], [98, 112], [98, 128], [98, 155], [98, 194], [98, 199], [98, 204], [98, 219], [98, 228], [98, 239], [98, 248], [98, 252], [98, 255], [98, 273], [98, 276], [98, 290], [98, 295], [99, 115], [99, 124], [99, 136], [99, 155], [99, 157], [99, 166], [99, 185], [99, 206], [99, 211], [99, 217], [99, 222], [99, 231], [99, 274], [99, 283], [99, 287], [99, 297], [100, 124], [100, 154], [100, 170], [100, 180], [100, 182], [100, 202], [100, 208], [100, 255], [100, 264], [100, 289], [100, 295], [101, 106], [101, 108], [101, 126], [101, 143], [101, 197], [101, 222], [101, 244], [101, 262], [101, 271], [101, 279], [102, 122], [102, 126], [102, 148], [102, 151], [102, 154], [102, 159], [102, 176], [102, 185], [102, 203], [102, 232], [102, 249], [102, 253], [102, 269], [102, 281], [102, 283], [103, 118], [103, 123], [103, 124], [103, 128], [103, 134], [103, 141], [103, 156], [103, 165], [103, 168], [103, 178], [103, 181], [103, 189], [103, 193], [103, 207], [103, 208], [103, 219], [103, 225], [103, 228], [103, 246], [103, 253], [103, 258], [103, 269], [104, 113], [104, 131], [104, 153], [104, 164], [104, 176], [104, 209], [104, 220], [104, 248], [104, 253], [104, 272], [104, 286], [105, 130], [105, 133], [105, 170], [105, 195], [105, 204], [105, 215], [105, 243], [105, 253], [105, 260], [105, 283], [105, 294], [106, 132], [106, 137], [106, 152], [106, 161], [106, 190], [106, 201], [106, 209], [106, 229], [106, 253], [106, 266], [106, 267], [106, 287], [106, 289], [107, 181], [107, 206], [107, 215], [107, 216], [107, 220], [107, 242], [107, 247], [107, 249], [108, 112], [108, 146], [108, 166], [108, 168], [108, 169], [108, 204], [108, 206], [108, 249], [108, 264], [108, 287], [108, 289], [109, 119], [109, 124], [109, 130], [109, 131], [109, 146], [109, 176], [109, 190], [109, 200], [109, 214], [109, 230], [109, 257], [109, 269], [109, 287], [110, 111], [110, 112], [110, 123], [110, 133], [110, 166], [110, 241], [110, 264], [110, 267], [110, 279], [111, 113], [111, 117], [111, 127], [111, 136], [111, 157], [111, 172], [111, 176], [111, 200], [111, 219], [111, 224], [111, 225], [111, 244], [111, 262], [111, 270], [111, 275], [112, 128], [112, 135], [112, 139], [112, 147], [112, 163], [112, 168], [112, 179], [112, 188], [112, 195], [112, 200], [112, 209], [112, 217], [112, 238], [112, 239], [112, 246], [112, 257], [112, 258], [112, 264], [112, 267], [112, 276], [112, 277], [113, 118], [113, 123], [113, 130], [113, 135], [113, 136], [113, 137], [113, 142], [113, 143], [113, 144], [113, 148], [113, 150], [113, 151], [113, 158], [113, 165], [113, 173], [113, 225], [113, 229], [113, 234], [113, 236], [113, 240], [113, 249], [113, 250], [113, 271], [113, 288], [113, 295], [114, 213], [114, 215], [114, 216], [114, 236], [114, 253], [114, 264], [114, 290], [115, 120], [115, 160], [115, 162], [115, 177], [115, 192], [115, 200], [115, 204], [115, 225], [115, 244], [115, 260], [115, 261], [115, 286], [116, 139], [116, 156], [116, 173], [116, 182], [116, 189], [116, 199], [116, 203], [116, 225], [116, 238], [116, 248], [116, 251], [116, 275], [116, 298], [117, 143], [117, 145], [117, 179], [117, 183], [117, 205], [117, 242], [117, 274], [118, 122], [118, 144], [118, 190], [118, 211], [118, 249], [118, 256], [118, 267], [118, 270], [118, 277], [119, 120], [119, 151], [119, 159], [119, 197], [119, 278], [119, 295], [120, 153], [120, 167], [120, 170], [120, 178], [120, 195], [120, 225], [120, 276], [120, 286], [120, 294], [120, 299], [121, 160], [121, 176], [121, 193], [121, 216], [121, 227], [121, 253], [121, 255], [121, 283], [121, 285], [122, 127], [122, 139], [122, 169], [122, 197], [122, 201], [122, 212], [122, 222], [122, 283], [123, 132], [123, 141], [123, 146], [123, 148], [123, 194], [123, 199], [123, 206], [123, 211], [123, 235], [123, 280], [124, 125], [124, 132], [124, 136], [124, 155], [124, 173], [124, 184], [124, 194], [124, 208], [124, 214], [124, 220], [124, 223], [124, 235], [124, 238], [124, 283], [124, 295], [124, 297], [125, 133], [125, 138], [125, 153], [125, 164], [125, 172], [125, 181], [125, 197], [125, 201], [125, 205], [125, 222], [125, 249], [125, 262], [125, 264], [125, 292], [126, 128], [126, 135], [126, 151], [126, 156], [126, 164], [126, 165], [126, 182], [126, 224], [126, 274], [126, 283], [126, 287], [126, 293], [127, 131], [127, 134], [127, 146], [127, 151], [127, 166], [127, 183], [127, 189], [127, 191], [127, 198], [127, 202], [127, 213], [127, 216], [127, 231], [127, 232], [127, 242], [127, 287], [127, 293], [128, 136], [128, 159], [128, 162], [128, 172], [128, 195], [128, 196], [128, 198], [128, 200], [128, 221], [128, 227], [128, 238], [128, 240], [128, 250], [128, 270], [128, 288], [129, 130], [129, 132], [129, 147], [129, 200], [129, 205], [129, 212], [129, 232], [129, 247], [130, 155], [130, 179], [130, 180], [130, 205], [130, 221], [130, 238], [130, 264], [131, 153], [131, 182], [131, 191], [131, 208], [131, 210], [131, 212], [131, 223], [131, 228], [131, 229], [131, 253], [131, 258], [131, 291], [132, 142], [132, 178], [132, 181], [132, 183], [132, 210], [132, 231], [132, 232], [132, 249], [132, 253], [132, 257], [132, 280], [133, 154], [133, 162], [133, 195], [133, 214], [133, 219], [133, 233], [133, 236], [133, 240], [133, 242], [133, 245], [133, 253], [133, 257], [133, 267], [133, 268], [133, 288], [133, 293], [134, 157], [134, 183], [134, 229], [134, 249], [134, 254], [134, 262], [134, 273], [134, 278], [134, 280], [134, 292], [134, 293], [134, 299], [135, 137], [135, 139], [135, 145], [135, 148], [135, 155], [135, 156], [135, 157], [135, 186], [135, 192], [135, 199], [135, 206], [135, 208], [135, 219], [135, 225], [135, 256], [135, 261], [135, 271], [135, 274], [135, 278], [135, 283], [135, 287], [135, 289], [136, 141], [136, 143], [136, 147], [136, 154], [136, 165], [136, 184], [136, 201], [136, 231], [136, 247], [136, 274], [136, 295], [137, 145], [137, 146], [137, 151], [137, 176], [137, 180], [137, 198], [137, 213], [137, 251], [137, 258], [137, 266], [137, 277], [137, 285], [137, 294], [138, 147], [138, 165], [138, 180], [138, 202], [138, 217], [138, 221], [138, 233], [138, 282], [138, 286], [139, 157], [139, 164], [139, 169], [139, 188], [139, 203], [139, 205], [139, 222], [139, 244], [139, 254], [139, 256], [140, 157], [140, 163], [140, 196], [140, 200], [140, 203], [140, 209], [140, 211], [140, 223], [140, 227], [140, 249], [141, 146], [141, 154], [141, 176], [141, 204], [141, 214], [141, 218], [141, 236], [141, 241], [141, 264], [141, 269], [141, 282], [141, 297], [142, 145], [142, 161], [142, 221], [142, 227], [142, 247], [142, 253], [142, 270], [142, 285], [143, 158], [143, 185], [143, 272], [143, 277], [144, 155], [144, 181], [144, 209], [144, 211], [144, 253], [144, 255], [144, 264], [144, 298], [145, 157], [145, 166], [145, 201], [145, 232], [145, 244], [145, 259], [146, 147], [146, 153], [146, 163], [146, 172], [146, 173], [146, 194], [146, 200], [146, 203], [146, 224], [146, 244], [146, 265], [146, 269], [147, 152], [147, 154], [147, 167], [147, 168], [147, 176], [147, 183], [147, 201], [147, 205], [147, 216], [147, 237], [147, 274], [147, 292], [147, 298], [148, 164], [148, 172], [148, 196], [148, 211], [148, 224], [148, 229], [148, 238], [148, 252], [148, 253], [148, 284], [148, 287], [149, 165], [149, 186], [149, 188], [149, 207], [149, 219], [149, 227], [149, 234], [149, 247], [149, 253], [149, 271], [149, 275], [149, 287], [149, 296], [150, 158], [150, 159], [150, 161], [150, 168], [150, 170], [150, 176], [150, 183], [150, 199], [150, 202], [150, 203], [150, 211], [150, 220], [150, 224], [150, 225], [150, 229], [150, 235], [150, 236], [150, 263], [150, 267], [151, 200], [151, 212], [151, 235], [151, 253], [151, 280], [151, 297], [152, 163], [152, 166], [152, 200], [152, 220], [152, 221], [152, 223], [152, 263], [152, 266], [152, 270], [152, 272], [152, 299], [153, 169], [153, 175], [153, 185], [153, 190], [153, 194], [153, 204], [153, 236], [153, 249], [153, 291], [154, 165], [154, 166], [154, 179], [154, 216], [154, 245], [154, 259], [154, 269], [155, 162], [155, 178], [155, 185], [155, 198], [155, 199], [155, 200], [155, 205], [155, 216], [155, 230], [155, 244], [155, 279], [156, 167], [156, 174], [156, 175], [156, 199], [156, 200], [156, 203], [156, 207], [156, 211], [156, 233], [156, 255], [156, 264], [156, 276], [156, 291], [156, 294], [157, 164], [157, 178], [157, 181], [157, 182], [157, 206], [157, 220], [157, 237], [157, 240], [157, 249], [157, 267], [157, 274], [157, 279], [157, 294], [157, 297], [158, 166], [158, 185], [158, 196], [158, 198], [158, 206], [158, 243], [158, 247], [158, 249], [158, 295], [158, 298], [159, 170], [159, 190], [159, 194], [159, 197], [159, 253], [159, 264], [159, 296], [159, 299], [160, 166], [160, 189], [160, 199], [160, 209], [160, 224], [160, 267], [160, 282], [161, 194], [161, 218], [161, 233], [161, 249], [161, 260], [161, 289], [161, 297], [161, 298], [162, 187], [162, 188], [162, 194], [162, 209], [162, 222], [162, 232], [162, 268], [163, 169], [163, 175], [163, 185], [163, 189], [163, 192], [163, 201], [163, 213], [163, 217], [163, 230], [163, 234], [163, 244], [163, 249], [163, 286], [164, 173], [164, 204], [164, 220], [164, 226], [164, 246], [164, 258], [164, 279], [164, 288], [164, 290], [165, 184], [165, 185], [165, 188], [165, 211], [165, 213], [165, 224], [165, 229], [165, 230], [165, 236], [165, 242], [165, 276], [165, 290], [166, 185], [166, 266], [166, 280], [167, 169], [167, 171], [167, 196], [167, 237], [167, 252], [167, 265], [167, 285], [167, 288], [167, 291], [168, 192], [168, 208], [168, 230], [168, 247], [168, 266], [168, 296], [169, 200], [169, 201], [169, 239], [169, 271], [169, 283], [169, 291], [169, 294], [170, 171], [170, 176], [170, 200], [170, 245], [170, 257], [170, 262], [170, 267], [171, 172], [171, 177], [171, 184], [171, 187], [171, 195], [171, 211], [171, 218], [171, 224], [171, 225], [171, 242], [171, 247], [171, 251], [171, 254], [171, 281], [171, 287], [171, 299], [172, 208], [172, 212], [172, 217], [172, 218], [172, 219], [172, 227], [172, 231], [172, 265], [172, 287], [173, 176], [173, 205], [173, 259], [173, 270], [173, 277], [173, 296], [174, 175], [174, 182], [174, 187], [174, 189], [174, 201], [174, 234], [174, 256], [175, 176], [175, 179], [175, 180], [175, 193], [175, 205], [175, 242], [175, 245], [175, 264], [175, 266], [175, 283], [175, 284], [175, 289], [176, 182], [176, 188], [176, 191], [176, 195], [176, 201], [176, 227], [176, 250], [176, 265], [177, 184], [177, 198], [177, 208], [177, 224], [177, 243], [177, 251], [177, 256], [177, 257], [177, 270], [177, 286], [178, 184], [178, 227], [178, 235], [178, 244], [178, 290], [179, 200], [179, 210], [179, 227], [179, 231], [179, 273], [179, 299], [180, 195], [180, 202], [180, 256], [180, 258], [180, 261], [180, 267], [180, 275], [180, 279], [180, 286], [180, 297], [181, 194], [181, 199], [181, 213], [181, 270], [181, 277], [181, 296], [182, 190], [182, 203], [182, 213], [182, 214], [182, 218], [182, 227], [182, 228], [182, 237], [182, 263], [182, 266], [182, 298], [183, 238], [183, 244], [183, 246], [183, 269], [184, 199], [184, 203], [184, 251], [184, 275], [184, 285], [184, 296], [184, 297], [185, 187], [185, 188], [185, 193], [185, 204], [185, 231], [185, 243], [185, 263], [185, 266], [185, 271], [185, 275], [186, 197], [186, 206], [186, 208], [186, 212], [186, 216], [186, 234], [186, 292], [187, 198], [187, 218], [187, 247], [187, 250], [187, 251], [188, 197], [188, 198], [188, 224], [188, 227], [188, 231], [188, 237], [188, 243], [188, 271], [188, 275], [188, 276], [188, 299], [189, 207], [189, 258], [189, 276], [190, 216], [190, 226], [190, 228], [190, 253], [190, 276], [190, 282], [190, 290], [190, 297], [191, 195], [191, 198], [191, 204], [191, 232], [191, 237], [191, 241], [191, 247], [191, 250], [191, 254], [191, 266], [192, 203], [192, 215], [192, 217], [192, 220], [192, 247], [192, 253], [192, 284], [192, 286], [192, 296], [192, 297], [193, 231], [193, 243], [193, 244], [193, 253], [193, 272], [193, 297], [194, 195], [194, 234], [194, 237], [194, 240], [194, 264], [195, 223], [195, 240], [195, 275], [196, 229], [196, 234], [196, 258], [196, 259], [196, 269], [197, 209], [197, 212], [197, 215], [197, 224], [197, 225], [197, 262], [197, 265], [197, 271], [197, 281], [197, 285], [197, 292], [198, 251], [198, 253], [198, 262], [198, 275], [198, 281], [198, 282], [198, 295], [199, 242], [199, 255], [199, 271], [199, 272], [199, 292], [199, 294], [199, 298], [200, 202], [200, 206], [200, 209], [200, 228], [200, 237], [200, 251], [200, 262], [200, 263], [200, 266], [200, 287], [200, 291], [200, 296], [201, 209], [201, 211], [201, 223], [201, 227], [201, 241], [201, 283], [202, 236], [202, 242], [202, 267], [202, 295], [203, 207], [203, 221], [203, 226], [203, 230], [203, 243], [203, 253], [203, 273], [203, 276], [203, 280], [203, 281], [203, 290], [203, 294], [203, 295], [204, 220], [204, 251], [204, 271], [204, 278], [204, 283], [204, 289], [204, 292], [205, 216], [205, 219], [205, 224], [205, 240], [205, 281], [205, 286], [205, 297], [206, 244], [206, 251], [206, 279], [207, 210], [207, 236], [207, 291], [208, 215], [208, 223], [208, 229], [208, 232], [208, 256], [208, 276], [208, 294], [208, 295], [209, 210], [209, 229], [209, 233], [209, 252], [210, 233], [210, 235], [210, 236], [210, 253], [210, 275], [211, 227], [211, 228], [211, 229], [211, 241], [211, 246], [211, 267], [212, 213], [212, 217], [212, 224], [212, 276], [212, 278], [212, 281], [212, 296], [212, 299], [213, 223], [213, 262], [213, 277], [213, 281], [213, 283], [213, 294], [214, 225], [214, 237], [214, 239], [214, 250], [214, 259], [214, 263], [214, 265], [214, 270], [214, 296], [214, 297], [215, 234], [215, 260], [215, 297], [216, 224], [216, 240], [216, 268], [216, 281], [216, 285], [216, 287], [217, 227], [217, 236], [217, 257], [217, 265], [218, 235], [218, 263], [219, 221], [219, 271], [220, 229], [220, 257], [220, 258], [220, 266], [220, 273], [220, 275], [220, 288], [220, 292], [221, 242], [221, 258], [221, 268], [221, 269], [221, 277], [222, 254], [222, 261], [223, 235], [223, 255], [223, 263], [223, 294], [224, 235], [224, 237], [224, 254], [224, 272], [224, 299], [225, 233], [225, 244], [225, 245], [225, 274], [225, 275], [226, 259], [226, 266], [226, 287], [226, 289], [227, 237], [227, 273], [227, 287], [228, 254], [228, 262], [228, 264], [228, 295], [228, 297], [229, 230], [229, 269], [229, 275], [229, 279], [230, 241], [230, 245], [230, 249], [230, 270], [230, 272], [230, 274], [230, 295], [231, 271], [231, 289], [231, 294], [231, 299], [232, 237], [232, 248], [232, 257], [232, 282], [232, 288], [232, 292], [233, 252], [233, 253], [233, 259], [233, 267], [233, 274], [233, 290], [234, 237], [234, 245], [234, 247], [234, 256], [234, 278], [234, 287], [234, 291], [235, 243], [235, 267], [235, 272], [235, 278], [235, 292], [236, 241], [236, 250], [236, 270], [236, 275], [236, 282], [236, 284], [237, 260], [237, 270], [238, 248], [238, 255], [238, 277], [238, 287], [239, 277], [239, 282], [240, 281], [240, 294], [240, 297], [241, 247], [241, 249], [241, 264], [241, 266], [241, 286], [242, 243], [242, 247], [242, 248], [242, 266], [242, 293], [243, 260], [244, 296], [245, 246], [245, 254], [245, 266], [245, 271], [245, 272], [245, 279], [245, 295], [246, 251], [246, 258], [246, 261], [247, 255], [247, 295], [248, 252], [248, 276], [248, 284], [249, 253], [249, 267], [249, 269], [249, 270], [250, 251], [250, 254], [250, 274], [250, 283], [251, 293], [251, 295], [251, 299], [252, 253], [252, 265], [252, 273], [252, 293], [252, 298], [253, 279], [253, 293], [253, 297], [253, 298], [254, 261], [254, 269], [254, 295], [255, 267], [256, 259], [256, 263], [256, 267], [256, 270], [256, 280], [256, 283], [256, 285], [257, 262], [257, 263], [257, 294], [257, 296], [257, 298], [258, 265], [258, 289], [259, 260], [259, 263], [259, 264], [259, 281], [260, 267], [260, 292], [260, 299], [261, 284], [262, 275], [262, 283], [262, 288], [262, 295], [264, 275], [264, 293], [265, 273], [265, 294], [266, 290], [267, 280], [267, 287], [268, 286], [268, 288], [268, 290], [268, 294], [269, 280], [269, 298], [270, 275], [270, 283], [271, 295], [272, 282], [272, 284], [273, 275], [273, 276], [273, 282], [273, 283], [274, 284], [274, 291], [276, 285], [278, 294], [278, 298], [279, 280], [280, 291], [281, 296], [282, 290], [284, 298], [286, 288], [287, 296], [288, 298], [295, 297]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l6-s9/solution/solve.sh b/tasks/construct-nppc-dominating-set-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..442829fa68ac5dc54a7ac31b24e913d03e3f7e52 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [9, 35, 45, 71, 82, 97, 103, 112, 113, 127, 133, 135, 171, 197, 200, 203, 204, 237, 253, 266]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l6-s9/tests/check.py b/tasks/construct-nppc-dominating-set-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l6-s9/tests/instance.json b/tasks/construct-nppc-dominating-set-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..817e884fbc5f6f70b5272ebb1fae71570bd393ba --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 300, "k": 20, "edges": [[0, 1], [0, 9], [0, 44], [0, 71], [0, 75], [0, 79], [0, 92], [0, 93], [0, 100], [0, 114], [0, 124], [0, 136], [0, 157], [0, 159], [0, 175], [0, 191], [0, 193], [0, 206], [0, 212], [0, 216], [0, 250], [0, 267], [0, 270], [0, 276], [1, 32], [1, 67], [1, 68], [1, 75], [1, 78], [1, 82], [1, 97], [1, 119], [1, 130], [1, 139], [1, 140], [1, 166], [1, 169], [1, 171], [1, 211], [1, 231], [1, 232], [1, 246], [1, 250], [1, 293], [1, 294], [2, 14], [2, 46], [2, 74], [2, 87], [2, 94], [2, 155], [2, 185], [2, 202], [2, 216], [2, 231], [2, 239], [2, 266], [2, 289], [2, 295], [3, 6], [3, 29], [3, 30], [3, 72], [3, 80], [3, 111], [3, 114], [3, 115], [3, 129], [3, 141], [3, 143], [3, 153], [3, 217], [3, 237], [3, 244], [3, 276], [3, 289], [3, 293], [3, 295], [4, 18], [4, 24], [4, 25], [4, 28], [4, 33], [4, 35], [4, 38], [4, 41], [4, 59], [4, 89], [4, 90], [4, 92], [4, 99], [4, 118], [4, 144], [4, 145], [4, 210], [4, 212], [4, 235], [4, 254], [4, 263], [4, 266], [4, 287], [5, 9], [5, 15], [5, 24], [5, 37], [5, 62], [5, 74], [5, 90], [5, 101], [5, 105], [5, 133], [5, 170], [5, 195], [5, 198], [5, 220], [5, 240], [5, 276], [5, 287], [5, 289], [5, 295], [6, 16], [6, 18], [6, 45], [6, 53], [6, 54], [6, 88], [6, 107], [6, 135], [6, 140], [6, 144], [6, 149], [6, 168], [6, 201], [6, 203], [6, 217], [6, 225], [6, 236], [6, 250], [6, 264], [6, 275], [6, 278], [6, 290], [6, 299], [7, 18], [7, 27], [7, 72], [7, 82], [7, 84], [7, 96], [7, 114], [7, 141], [7, 162], [7, 165], [7, 171], [7, 213], [7, 235], [7, 243], [7, 275], [7, 288], [8, 67], [8, 71], [8, 89], [8, 90], [8, 93], [8, 103], [8, 132], [8, 133], [8, 147], [8, 193], [8, 194], [8, 215], [8, 222], [8, 240], [8, 279], [8, 281], [9, 17], [9, 20], [9, 32], [9, 37], [9, 41], [9, 45], [9, 57], [9, 62], [9, 69], [9, 80], [9, 90], [9, 96], [9, 107], [9, 120], [9, 124], [9, 137], [9, 139], [9, 143], [9, 160], [9, 161], [9, 180], [9, 186], [9, 188], [9, 219], [9, 230], [9, 232], [9, 241], [9, 252], [9, 263], [9, 269], [9, 278], [9, 281], [9, 297], [10, 24], [10, 34], [10, 36], [10, 38], [10, 44], [10, 63], [10, 101], [10, 110], [10, 129], [10, 132], [10, 135], [10, 139], [10, 164], [10, 183], [10, 214], [10, 223], [10, 226], [10, 262], [10, 266], [10, 275], [10, 282], [11, 12], [11, 66], [11, 74], [11, 101], [11, 108], [11, 112], [11, 114], [11, 127], [11, 138], [11, 162], [11, 172], [11, 173], [11, 209], [11, 224], [11, 233], [11, 264], [11, 297], [12, 21], [12, 47], [12, 56], [12, 79], [12, 84], [12, 97], [12, 104], [12, 125], [12, 129], [12, 184], [12, 207], [12, 210], [12, 212], [12, 242], [12, 251], [12, 255], [12, 259], [12, 262], [13, 16], [13, 17], [13, 32], [13, 38], [13, 59], [13, 78], [13, 87], [13, 98], [13, 112], [13, 113], [13, 137], [13, 148], [13, 171], [13, 184], [13, 198], [13, 202], [13, 210], [13, 214], [13, 216], [13, 256], [13, 290], [13, 298], [14, 36], [14, 42], [14, 61], [14, 63], [14, 68], [14, 82], [14, 89], [14, 94], [14, 134], [14, 136], [14, 143], [14, 175], [14, 209], [14, 226], [14, 229], [14, 233], [14, 237], [14, 244], [14, 262], [14, 273], [14, 285], [14, 290], [15, 19], [15, 28], [15, 97], [15, 114], [15, 151], [15, 153], [15, 181], [15, 196], [15, 199], [15, 233], [15, 235], [15, 246], [15, 255], [15, 268], [15, 282], [15, 283], [15, 299], [16, 36], [16, 44], [16, 45], [16, 55], [16, 68], [16, 71], [16, 88], [16, 97], [16, 125], [16, 139], [16, 145], [16, 158], [16, 168], [16, 177], [16, 193], [16, 263], [16, 269], [16, 297], [17, 32], [17, 44], [17, 59], [17, 106], [17, 115], [17, 136], [17, 142], [17, 157], [17, 168], [17, 175], [17, 203], [17, 210], [17, 218], [17, 222], [17, 225], [17, 226], [17, 255], [17, 288], [18, 56], [18, 57], [18, 59], [18, 75], [18, 83], [18, 90], [18, 92], [18, 94], [18, 96], [18, 101], [18, 119], [18, 132], [18, 163], [18, 165], [18, 170], [18, 182], [18, 190], [18, 204], [18, 209], [18, 211], [18, 212], [18, 239], [18, 252], [18, 253], [18, 268], [18, 278], [18, 291], [19, 20], [19, 31], [19, 62], [19, 68], [19, 69], [19, 89], [19, 110], [19, 113], [19, 116], [19, 127], [19, 134], [19, 142], [19, 162], [19, 168], [19, 171], [19, 217], [19, 220], [19, 223], [19, 245], [19, 252], [19, 259], [19, 265], [19, 279], [19, 289], [19, 291], [19, 292], [19, 297], [20, 23], [20, 34], [20, 42], [20, 64], [20, 124], [20, 131], [20, 149], [20, 172], [20, 191], [20, 210], [20, 211], [20, 226], [20, 230], [20, 233], [20, 235], [20, 241], [20, 271], [20, 272], [20, 276], [20, 286], [20, 297], [21, 44], [21, 48], [21, 49], [21, 52], [21, 63], [21, 66], [21, 73], [21, 127], [21, 128], [21, 132], [21, 144], [21, 147], [21, 184], [21, 204], [21, 233], [21, 246], [21, 269], [21, 275], [21, 287], [21, 293], [21, 296], [22, 45], [22, 65], [22, 66], [22, 69], [22, 96], [22, 124], [22, 125], [22, 144], [22, 158], [22, 169], [22, 188], [22, 205], [22, 224], [22, 225], [22, 236], [22, 248], [22, 254], [22, 256], [22, 261], [22, 264], [22, 275], [22, 293], [23, 39], [23, 43], [23, 66], [23, 71], [23, 83], [23, 88], [23, 102], [23, 104], [23, 124], [23, 125], [23, 137], [23, 152], [23, 182], [23, 196], [23, 227], [24, 28], [24, 29], [24, 43], [24, 66], [24, 82], [24, 88], [24, 123], [24, 214], [24, 217], [24, 218], [24, 235], [24, 236], [24, 241], [24, 266], [24, 268], [24, 274], [24, 275], [25, 27], [25, 39], [25, 64], [25, 71], [25, 86], [25, 98], [25, 156], [25, 166], [25, 186], [25, 210], [25, 229], [25, 249], [25, 250], [25, 298], [26, 53], [26, 67], [26, 82], [26, 101], [26, 112], [26, 120], [26, 144], [26, 150], [26, 162], [26, 167], [26, 180], [26, 213], [26, 216], [26, 230], [26, 255], [26, 258], [26, 271], [26, 286], [27, 68], [27, 71], [27, 91], [27, 93], [27, 102], [27, 128], [27, 157], [27, 163], [27, 170], [27, 187], [27, 188], [27, 202], [27, 234], [27, 238], [27, 260], [27, 267], [27, 289], [27, 299], [28, 36], [28, 66], [28, 67], [28, 96], [28, 111], [28, 132], [28, 136], [28, 137], [28, 143], [28, 147], [28, 161], [28, 186], [28, 200], [28, 252], [28, 268], [28, 280], [28, 298], [29, 30], [29, 38], [29, 39], [29, 90], [29, 115], [29, 118], [29, 127], [29, 133], [29, 143], [29, 153], [29, 172], [29, 175], [29, 194], [29, 200], [29, 221], [29, 242], [29, 246], [29, 250], [29, 282], [30, 66], [30, 77], [30, 89], [30, 98], [30, 107], [30, 119], [30, 122], [30, 130], [30, 137], [30, 138], [30, 160], [30, 164], [30, 207], [30, 220], [30, 222], [30, 253], [30, 274], [30, 276], [31, 32], [31, 55], [31, 117], [31, 120], [31, 135], [31, 143], [31, 144], [31, 147], [31, 152], [31, 187], [31, 194], [31, 199], [31, 204], [31, 236], [31, 241], [31, 242], [31, 261], [32, 38], [32, 42], [32, 44], [32, 45], [32, 83], [32, 134], [32, 135], [32, 148], [32, 153], [32, 158], [32, 186], [32, 200], [32, 214], [32, 244], [32, 271], [32, 275], [32, 288], [33, 47], [33, 51], [33, 56], [33, 57], [33, 93], [33, 101], [33, 105], [33, 168], [33, 171], [33, 188], [33, 249], [33, 288], [33, 292], [33, 295], [34, 35], [34, 38], [34, 45], [34, 49], [34, 54], [34, 76], [34, 92], [34, 107], [34, 135], [34, 152], [34, 180], [34, 217], [34, 218], [34, 226], [34, 239], [34, 246], [34, 271], [34, 285], [34, 296], [34, 299], [35, 38], [35, 40], [35, 48], [35, 56], [35, 59], [35, 65], [35, 70], [35, 72], [35, 75], [35, 78], [35, 81], [35, 86], [35, 91], [35, 98], [35, 105], [35, 108], [35, 109], [35, 117], [35, 120], [35, 123], [35, 137], [35, 160], [35, 181], [35, 190], [35, 196], [35, 201], [35, 202], [35, 235], [35, 248], [35, 253], [35, 282], [35, 291], [35, 296], [36, 58], [36, 82], [36, 94], [36, 101], [36, 127], [36, 141], [36, 142], [36, 184], [36, 191], [36, 209], [36, 228], [36, 238], [36, 266], [36, 271], [36, 279], [36, 288], [36, 299], [37, 51], [37, 52], [37, 53], [37, 56], [37, 58], [37, 66], [37, 72], [37, 136], [37, 160], [37, 197], [37, 200], [37, 206], [37, 209], [37, 239], [37, 261], [37, 265], [37, 295], [38, 51], [38, 55], [38, 58], [38, 97], [38, 107], [38, 108], [38, 139], [38, 157], [38, 208], [38, 224], [38, 246], [38, 248], [39, 47], [39, 63], [39, 71], [39, 74], [39, 119], [39, 167], [39, 178], [39, 190], [39, 194], [39, 199], [39, 206], [39, 230], [39, 237], [39, 250], [39, 262], [39, 265], [39, 271], [39, 288], [39, 291], [40, 48], [40, 87], [40, 98], [40, 104], [40, 126], [40, 133], [40, 158], [40, 160], [40, 166], [40, 191], [40, 201], [40, 215], [40, 226], [40, 235], [40, 236], [40, 238], [40, 278], [40, 286], [41, 81], [41, 87], [41, 118], [41, 125], [41, 133], [41, 149], [41, 164], [41, 168], [41, 192], [41, 196], [41, 206], [41, 230], [41, 251], [41, 255], [41, 263], [41, 293], [42, 45], [42, 82], [42, 95], [42, 107], [42, 160], [42, 173], [42, 177], [42, 189], [42, 202], [42, 208], [42, 243], [42, 251], [42, 266], [42, 290], [43, 47], [43, 49], [43, 52], [43, 113], [43, 118], [43, 137], [43, 141], [43, 149], [43, 167], [43, 170], [43, 197], [43, 217], [43, 232], [43, 233], [43, 238], [43, 249], [43, 252], [43, 263], [43, 287], [44, 49], [44, 71], [44, 72], [44, 80], [44, 82], [44, 86], [44, 107], [44, 121], [44, 128], [44, 133], [44, 141], [44, 177], [44, 178], [44, 243], [44, 265], [44, 267], [44, 270], [45, 47], [45, 73], [45, 79], [45, 88], [45, 90], [45, 98], [45, 100], [45, 118], [45, 119], [45, 130], [45, 173], [45, 174], [45, 175], [45, 206], [45, 216], [45, 222], [45, 223], [45, 244], [45, 250], [45, 261], [45, 268], [45, 271], [45, 272], [45, 273], [45, 281], [45, 282], [45, 285], [45, 295], [45, 298], [46, 74], [46, 75], [46, 82], [46, 97], [46, 99], [46, 103], [46, 112], [46, 138], [46, 144], [46, 178], [46, 184], [46, 197], [46, 206], [46, 234], [46, 245], [46, 250], [46, 267], [47, 63], [47, 73], [47, 75], [47, 86], [47, 97], [47, 110], [47, 136], [47, 155], [47, 169], [47, 217], [47, 283], [47, 286], [48, 112], [48, 113], [48, 149], [48, 151], [48, 163], [48, 171], [48, 181], [48, 182], [48, 196], [48, 197], [48, 236], [48, 242], [48, 243], [48, 246], [48, 260], [48, 275], [49, 81], [49, 93], [49, 105], [49, 112], [49, 136], [49, 141], [49, 169], [49, 171], [49, 174], [49, 176], [49, 202], [49, 223], [49, 236], [49, 274], [50, 117], [50, 135], [50, 139], [50, 146], [50, 147], [50, 169], [50, 190], [50, 197], [50, 213], [50, 244], [50, 257], [50, 260], [50, 264], [50, 279], [50, 295], [50, 296], [50, 299], [51, 64], [51, 79], [51, 104], [51, 106], [51, 122], [51, 134], [51, 135], [51, 177], [51, 184], [51, 186], [51, 193], [51, 238], [51, 251], [51, 267], [52, 83], [52, 87], [52, 116], [52, 145], [52, 154], [52, 204], [52, 210], [52, 258], [52, 266], [52, 291], [53, 79], [53, 83], [53, 125], [53, 132], [53, 200], [53, 203], [53, 209], [53, 220], [53, 245], [53, 270], [53, 288], [54, 63], [54, 76], [54, 79], [54, 97], [54, 104], [54, 105], [54, 129], [54, 130], [54, 165], [54, 198], [54, 219], [55, 56], [55, 58], [55, 85], [55, 87], [55, 115], [55, 119], [55, 124], [55, 133], [55, 165], [55, 206], [55, 229], [55, 244], [55, 251], [55, 265], [55, 271], [56, 97], [56, 98], [56, 102], [56, 149], [56, 155], [56, 164], [56, 167], [56, 173], [56, 176], [56, 180], [56, 188], [56, 191], [56, 192], [56, 200], [56, 228], [56, 230], [56, 240], [56, 256], [56, 274], [57, 58], [57, 64], [57, 87], [57, 139], [57, 142], [57, 161], [57, 165], [57, 216], [57, 238], [57, 245], [58, 70], [58, 97], [58, 109], [58, 138], [58, 152], [58, 167], [58, 192], [58, 194], [58, 203], [58, 208], [58, 212], [58, 215], [58, 226], [58, 243], [58, 263], [58, 268], [58, 279], [59, 72], [59, 80], [59, 83], [59, 93], [59, 99], [59, 126], [59, 130], [59, 180], [59, 230], [59, 260], [59, 267], [59, 277], [59, 287], [60, 61], [60, 95], [60, 110], [60, 115], [60, 116], [60, 117], [60, 127], [60, 138], [60, 200], [60, 239], [60, 255], [60, 264], [60, 291], [61, 97], [61, 98], [61, 105], [61, 113], [61, 117], [61, 119], [61, 128], [61, 148], [61, 180], [61, 222], [61, 247], [61, 260], [61, 288], [61, 299], [62, 84], [62, 115], [62, 136], [62, 141], [62, 169], [62, 192], [62, 196], [62, 204], [62, 227], [62, 249], [62, 262], [62, 271], [62, 279], [62, 281], [62, 293], [63, 68], [63, 75], [63, 98], [63, 104], [63, 114], [63, 175], [63, 185], [63, 203], [63, 219], [63, 242], [63, 244], [63, 258], [63, 261], [63, 264], [63, 286], [64, 100], [64, 104], [64, 115], [64, 137], [64, 165], [64, 186], [64, 203], [64, 222], [64, 228], [64, 232], [64, 236], [64, 248], [65, 99], [65, 107], [65, 126], [65, 176], [65, 186], [65, 263], [65, 294], [66, 77], [66, 98], [66, 112], [66, 115], [66, 119], [66, 157], [66, 159], [66, 170], [66, 190], [66, 204], [66, 271], [66, 274], [66, 278], [67, 72], [67, 74], [67, 89], [67, 109], [67, 134], [67, 161], [67, 167], [67, 168], [67, 171], [67, 176], [67, 216], [67, 222], [67, 237], [67, 238], [67, 255], [67, 265], [67, 266], [67, 277], [67, 291], [68, 157], [68, 166], [68, 179], [68, 226], [68, 237], [68, 259], [68, 271], [68, 288], [69, 82], [69, 93], [69, 94], [69, 97], [69, 105], [69, 146], [69, 151], [69, 159], [69, 165], [69, 213], [69, 266], [69, 268], [70, 85], [70, 90], [70, 144], [70, 157], [70, 178], [70, 186], [70, 249], [70, 255], [70, 260], [70, 274], [70, 275], [70, 276], [70, 278], [70, 288], [71, 73], [71, 85], [71, 100], [71, 117], [71, 126], [71, 128], [71, 138], [71, 150], [71, 164], [71, 166], [71, 170], [71, 172], [71, 173], [71, 187], [71, 201], [71, 205], [71, 209], [71, 239], [71, 241], [71, 250], [71, 251], [71, 255], [71, 256], [71, 259], [71, 263], [71, 275], [71, 283], [71, 286], [71, 296], [71, 297], [72, 81], [72, 83], [72, 111], [72, 118], [72, 132], [72, 154], [72, 164], [72, 172], [72, 183], [72, 230], [72, 245], [72, 250], [72, 276], [72, 297], [73, 99], [73, 132], [73, 139], [73, 227], [73, 253], [73, 259], [74, 81], [74, 86], [74, 113], [74, 117], [74, 148], [74, 155], [74, 167], [74, 169], [74, 190], [74, 213], [74, 225], [74, 235], [74, 252], [74, 280], [74, 284], [74, 295], [75, 85], [75, 113], [75, 128], [75, 175], [75, 200], [75, 203], [75, 216], [75, 218], [75, 224], [75, 248], [75, 255], [75, 292], [76, 88], [76, 94], [76, 112], [76, 130], [76, 159], [76, 185], [76, 232], [76, 249], [76, 279], [77, 113], [77, 136], [77, 167], [77, 171], [77, 176], [77, 251], [77, 289], [77, 295], [77, 297], [78, 90], [78, 117], [78, 122], [78, 193], [78, 196], [78, 227], [78, 243], [78, 250], [78, 257], [78, 261], [78, 263], [78, 266], [78, 272], [78, 276], [78, 281], [79, 95], [79, 101], [79, 117], [79, 133], [79, 155], [79, 161], [79, 172], [79, 193], [79, 200], [79, 204], [79, 218], [79, 255], [79, 263], [79, 292], [80, 102], [80, 113], [80, 117], [80, 132], [80, 138], [80, 140], [80, 153], [80, 154], [80, 171], [80, 194], [80, 214], [80, 226], [80, 257], [80, 258], [80, 264], [80, 270], [80, 287], [81, 86], [81, 90], [81, 103], [81, 110], [81, 112], [81, 125], [81, 130], [81, 138], [81, 145], [81, 155], [81, 182], [81, 189], [81, 200], [81, 208], [81, 226], [81, 240], [81, 260], [81, 274], [81, 290], [82, 93], [82, 126], [82, 153], [82, 158], [82, 176], [82, 223], [82, 225], [82, 252], [82, 255], [82, 262], [82, 269], [82, 280], [82, 284], [82, 289], [83, 97], [83, 105], [83, 109], [83, 110], [83, 115], [83, 134], [83, 143], [83, 177], [83, 179], [83, 227], [83, 236], [83, 240], [83, 254], [83, 262], [84, 85], [84, 90], [84, 113], [84, 133], [84, 161], [84, 183], [84, 196], [84, 251], [84, 256], [84, 272], [84, 292], [84, 298], [85, 118], [85, 127], [85, 129], [85, 140], [85, 156], [85, 160], [85, 167], [85, 174], [85, 179], [85, 187], [85, 199], [85, 202], [85, 218], [85, 225], [85, 229], [85, 238], [85, 247], [85, 290], [86, 92], [86, 99], [86, 164], [86, 175], [86, 190], [86, 218], [86, 232], [86, 242], [86, 266], [86, 271], [87, 116], [87, 125], [87, 134], [87, 164], [87, 168], [87, 193], [87, 195], [87, 198], [87, 200], [87, 235], [87, 246], [87, 273], [87, 281], [88, 92], [88, 122], [88, 124], [88, 149], [88, 150], [88, 175], [88, 181], [88, 198], [88, 211], [88, 223], [88, 225], [88, 227], [88, 243], [88, 250], [88, 265], [88, 270], [89, 124], [89, 135], [89, 137], [89, 158], [89, 165], [89, 180], [89, 192], [89, 207], [89, 209], [89, 223], [89, 224], [89, 225], [89, 231], [89, 237], [89, 246], [89, 272], [90, 93], [90, 103], [90, 112], [90, 115], [90, 198], [90, 244], [90, 254], [90, 262], [90, 285], [91, 113], [91, 128], [91, 135], [91, 138], [91, 152], [91, 166], [91, 181], [91, 196], [91, 198], [91, 201], [91, 203], [91, 210], [91, 211], [91, 222], [91, 253], [91, 257], [91, 259], [91, 267], [91, 292], [92, 97], [92, 128], [92, 153], [92, 155], [92, 159], [92, 177], [92, 186], [92, 197], [92, 226], [92, 230], [92, 247], [92, 250], [92, 251], [92, 260], [92, 271], [93, 97], [93, 110], [93, 117], [93, 135], [93, 152], [93, 160], [93, 167], [93, 175], [93, 220], [93, 240], [93, 253], [93, 256], [93, 277], [93, 282], [93, 287], [94, 97], [94, 106], [94, 125], [94, 169], [94, 221], [94, 227], [94, 299], [95, 97], [95, 112], [95, 143], [95, 147], [95, 149], [95, 151], [95, 162], [95, 185], [95, 210], [95, 220], [95, 226], [95, 227], [95, 239], [95, 240], [95, 241], [95, 243], [95, 276], [95, 279], [95, 286], [95, 295], [96, 147], [96, 172], [96, 178], [96, 185], [96, 192], [96, 237], [96, 238], [96, 241], [96, 242], [96, 262], [96, 289], [97, 99], [97, 105], [97, 115], [97, 123], [97, 124], [97, 126], [97, 136], [97, 162], [97, 171], [97, 176], [97, 177], [97, 193], [97, 235], [97, 244], [98, 112], [98, 128], [98, 155], [98, 194], [98, 199], [98, 204], [98, 219], [98, 228], [98, 239], [98, 248], [98, 252], [98, 255], [98, 273], [98, 276], [98, 290], [98, 295], [99, 115], [99, 124], [99, 136], [99, 155], [99, 157], [99, 166], [99, 185], [99, 206], [99, 211], [99, 217], [99, 222], [99, 231], [99, 274], [99, 283], [99, 287], [99, 297], [100, 124], [100, 154], [100, 170], [100, 180], [100, 182], [100, 202], [100, 208], [100, 255], [100, 264], [100, 289], [100, 295], [101, 106], [101, 108], [101, 126], [101, 143], [101, 197], [101, 222], [101, 244], [101, 262], [101, 271], [101, 279], [102, 122], [102, 126], [102, 148], [102, 151], [102, 154], [102, 159], [102, 176], [102, 185], [102, 203], [102, 232], [102, 249], [102, 253], [102, 269], [102, 281], [102, 283], [103, 118], [103, 123], [103, 124], [103, 128], [103, 134], [103, 141], [103, 156], [103, 165], [103, 168], [103, 178], [103, 181], [103, 189], [103, 193], [103, 207], [103, 208], [103, 219], [103, 225], [103, 228], [103, 246], [103, 253], [103, 258], [103, 269], [104, 113], [104, 131], [104, 153], [104, 164], [104, 176], [104, 209], [104, 220], [104, 248], [104, 253], [104, 272], [104, 286], [105, 130], [105, 133], [105, 170], [105, 195], [105, 204], [105, 215], [105, 243], [105, 253], [105, 260], [105, 283], [105, 294], [106, 132], [106, 137], [106, 152], [106, 161], [106, 190], [106, 201], [106, 209], [106, 229], [106, 253], [106, 266], [106, 267], [106, 287], [106, 289], [107, 181], [107, 206], [107, 215], [107, 216], [107, 220], [107, 242], [107, 247], [107, 249], [108, 112], [108, 146], [108, 166], [108, 168], [108, 169], [108, 204], [108, 206], [108, 249], [108, 264], [108, 287], [108, 289], [109, 119], [109, 124], [109, 130], [109, 131], [109, 146], [109, 176], [109, 190], [109, 200], [109, 214], [109, 230], [109, 257], [109, 269], [109, 287], [110, 111], [110, 112], [110, 123], [110, 133], [110, 166], [110, 241], [110, 264], [110, 267], [110, 279], [111, 113], [111, 117], [111, 127], [111, 136], [111, 157], [111, 172], [111, 176], [111, 200], [111, 219], [111, 224], [111, 225], [111, 244], [111, 262], [111, 270], [111, 275], [112, 128], [112, 135], [112, 139], [112, 147], [112, 163], [112, 168], [112, 179], [112, 188], [112, 195], [112, 200], [112, 209], [112, 217], [112, 238], [112, 239], [112, 246], [112, 257], [112, 258], [112, 264], [112, 267], [112, 276], [112, 277], [113, 118], [113, 123], [113, 130], [113, 135], [113, 136], [113, 137], [113, 142], [113, 143], [113, 144], [113, 148], [113, 150], [113, 151], [113, 158], [113, 165], [113, 173], [113, 225], [113, 229], [113, 234], [113, 236], [113, 240], [113, 249], [113, 250], [113, 271], [113, 288], [113, 295], [114, 213], [114, 215], [114, 216], [114, 236], [114, 253], [114, 264], [114, 290], [115, 120], [115, 160], [115, 162], [115, 177], [115, 192], [115, 200], [115, 204], [115, 225], [115, 244], [115, 260], [115, 261], [115, 286], [116, 139], [116, 156], [116, 173], [116, 182], [116, 189], [116, 199], [116, 203], [116, 225], [116, 238], [116, 248], [116, 251], [116, 275], [116, 298], [117, 143], [117, 145], [117, 179], [117, 183], [117, 205], [117, 242], [117, 274], [118, 122], [118, 144], [118, 190], [118, 211], [118, 249], [118, 256], [118, 267], [118, 270], [118, 277], [119, 120], [119, 151], [119, 159], [119, 197], [119, 278], [119, 295], [120, 153], [120, 167], [120, 170], [120, 178], [120, 195], [120, 225], [120, 276], [120, 286], [120, 294], [120, 299], [121, 160], [121, 176], [121, 193], [121, 216], [121, 227], [121, 253], [121, 255], [121, 283], [121, 285], [122, 127], [122, 139], [122, 169], [122, 197], [122, 201], [122, 212], [122, 222], [122, 283], [123, 132], [123, 141], [123, 146], [123, 148], [123, 194], [123, 199], [123, 206], [123, 211], [123, 235], [123, 280], [124, 125], [124, 132], [124, 136], [124, 155], [124, 173], [124, 184], [124, 194], [124, 208], [124, 214], [124, 220], [124, 223], [124, 235], [124, 238], [124, 283], [124, 295], [124, 297], [125, 133], [125, 138], [125, 153], [125, 164], [125, 172], [125, 181], [125, 197], [125, 201], [125, 205], [125, 222], [125, 249], [125, 262], [125, 264], [125, 292], [126, 128], [126, 135], [126, 151], [126, 156], [126, 164], [126, 165], [126, 182], [126, 224], [126, 274], [126, 283], [126, 287], [126, 293], [127, 131], [127, 134], [127, 146], [127, 151], [127, 166], [127, 183], [127, 189], [127, 191], [127, 198], [127, 202], [127, 213], [127, 216], [127, 231], [127, 232], [127, 242], [127, 287], [127, 293], [128, 136], [128, 159], [128, 162], [128, 172], [128, 195], [128, 196], [128, 198], [128, 200], [128, 221], [128, 227], [128, 238], [128, 240], [128, 250], [128, 270], [128, 288], [129, 130], [129, 132], [129, 147], [129, 200], [129, 205], [129, 212], [129, 232], [129, 247], [130, 155], [130, 179], [130, 180], [130, 205], [130, 221], [130, 238], [130, 264], [131, 153], [131, 182], [131, 191], [131, 208], [131, 210], [131, 212], [131, 223], [131, 228], [131, 229], [131, 253], [131, 258], [131, 291], [132, 142], [132, 178], [132, 181], [132, 183], [132, 210], [132, 231], [132, 232], [132, 249], [132, 253], [132, 257], [132, 280], [133, 154], [133, 162], [133, 195], [133, 214], [133, 219], [133, 233], [133, 236], [133, 240], [133, 242], [133, 245], [133, 253], [133, 257], [133, 267], [133, 268], [133, 288], [133, 293], [134, 157], [134, 183], [134, 229], [134, 249], [134, 254], [134, 262], [134, 273], [134, 278], [134, 280], [134, 292], [134, 293], [134, 299], [135, 137], [135, 139], [135, 145], [135, 148], [135, 155], [135, 156], [135, 157], [135, 186], [135, 192], [135, 199], [135, 206], [135, 208], [135, 219], [135, 225], [135, 256], [135, 261], [135, 271], [135, 274], [135, 278], [135, 283], [135, 287], [135, 289], [136, 141], [136, 143], [136, 147], [136, 154], [136, 165], [136, 184], [136, 201], [136, 231], [136, 247], [136, 274], [136, 295], [137, 145], [137, 146], [137, 151], [137, 176], [137, 180], [137, 198], [137, 213], [137, 251], [137, 258], [137, 266], [137, 277], [137, 285], [137, 294], [138, 147], [138, 165], [138, 180], [138, 202], [138, 217], [138, 221], [138, 233], [138, 282], [138, 286], [139, 157], [139, 164], [139, 169], [139, 188], [139, 203], [139, 205], [139, 222], [139, 244], [139, 254], [139, 256], [140, 157], [140, 163], [140, 196], [140, 200], [140, 203], [140, 209], [140, 211], [140, 223], [140, 227], [140, 249], [141, 146], [141, 154], [141, 176], [141, 204], [141, 214], [141, 218], [141, 236], [141, 241], [141, 264], [141, 269], [141, 282], [141, 297], [142, 145], [142, 161], [142, 221], [142, 227], [142, 247], [142, 253], [142, 270], [142, 285], [143, 158], [143, 185], [143, 272], [143, 277], [144, 155], [144, 181], [144, 209], [144, 211], [144, 253], [144, 255], [144, 264], [144, 298], [145, 157], [145, 166], [145, 201], [145, 232], [145, 244], [145, 259], [146, 147], [146, 153], [146, 163], [146, 172], [146, 173], [146, 194], [146, 200], [146, 203], [146, 224], [146, 244], [146, 265], [146, 269], [147, 152], [147, 154], [147, 167], [147, 168], [147, 176], [147, 183], [147, 201], [147, 205], [147, 216], [147, 237], [147, 274], [147, 292], [147, 298], [148, 164], [148, 172], [148, 196], [148, 211], [148, 224], [148, 229], [148, 238], [148, 252], [148, 253], [148, 284], [148, 287], [149, 165], [149, 186], [149, 188], [149, 207], [149, 219], [149, 227], [149, 234], [149, 247], [149, 253], [149, 271], [149, 275], [149, 287], [149, 296], [150, 158], [150, 159], [150, 161], [150, 168], [150, 170], [150, 176], [150, 183], [150, 199], [150, 202], [150, 203], [150, 211], [150, 220], [150, 224], [150, 225], [150, 229], [150, 235], [150, 236], [150, 263], [150, 267], [151, 200], [151, 212], [151, 235], [151, 253], [151, 280], [151, 297], [152, 163], [152, 166], [152, 200], [152, 220], [152, 221], [152, 223], [152, 263], [152, 266], [152, 270], [152, 272], [152, 299], [153, 169], [153, 175], [153, 185], [153, 190], [153, 194], [153, 204], [153, 236], [153, 249], [153, 291], [154, 165], [154, 166], [154, 179], [154, 216], [154, 245], [154, 259], [154, 269], [155, 162], [155, 178], [155, 185], [155, 198], [155, 199], [155, 200], [155, 205], [155, 216], [155, 230], [155, 244], [155, 279], [156, 167], [156, 174], [156, 175], [156, 199], [156, 200], [156, 203], [156, 207], [156, 211], [156, 233], [156, 255], [156, 264], [156, 276], [156, 291], [156, 294], [157, 164], [157, 178], [157, 181], [157, 182], [157, 206], [157, 220], [157, 237], [157, 240], [157, 249], [157, 267], [157, 274], [157, 279], [157, 294], [157, 297], [158, 166], [158, 185], [158, 196], [158, 198], [158, 206], [158, 243], [158, 247], [158, 249], [158, 295], [158, 298], [159, 170], [159, 190], [159, 194], [159, 197], [159, 253], [159, 264], [159, 296], [159, 299], [160, 166], [160, 189], [160, 199], [160, 209], [160, 224], [160, 267], [160, 282], [161, 194], [161, 218], [161, 233], [161, 249], [161, 260], [161, 289], [161, 297], [161, 298], [162, 187], [162, 188], [162, 194], [162, 209], [162, 222], [162, 232], [162, 268], [163, 169], [163, 175], [163, 185], [163, 189], [163, 192], [163, 201], [163, 213], [163, 217], [163, 230], [163, 234], [163, 244], [163, 249], [163, 286], [164, 173], [164, 204], [164, 220], [164, 226], [164, 246], [164, 258], [164, 279], [164, 288], [164, 290], [165, 184], [165, 185], [165, 188], [165, 211], [165, 213], [165, 224], [165, 229], [165, 230], [165, 236], [165, 242], [165, 276], [165, 290], [166, 185], [166, 266], [166, 280], [167, 169], [167, 171], [167, 196], [167, 237], [167, 252], [167, 265], [167, 285], [167, 288], [167, 291], [168, 192], [168, 208], [168, 230], [168, 247], [168, 266], [168, 296], [169, 200], [169, 201], [169, 239], [169, 271], [169, 283], [169, 291], [169, 294], [170, 171], [170, 176], [170, 200], [170, 245], [170, 257], [170, 262], [170, 267], [171, 172], [171, 177], [171, 184], [171, 187], [171, 195], [171, 211], [171, 218], [171, 224], [171, 225], [171, 242], [171, 247], [171, 251], [171, 254], [171, 281], [171, 287], [171, 299], [172, 208], [172, 212], [172, 217], [172, 218], [172, 219], [172, 227], [172, 231], [172, 265], [172, 287], [173, 176], [173, 205], [173, 259], [173, 270], [173, 277], [173, 296], [174, 175], [174, 182], [174, 187], [174, 189], [174, 201], [174, 234], [174, 256], [175, 176], [175, 179], [175, 180], [175, 193], [175, 205], [175, 242], [175, 245], [175, 264], [175, 266], [175, 283], [175, 284], [175, 289], [176, 182], [176, 188], [176, 191], [176, 195], [176, 201], [176, 227], [176, 250], [176, 265], [177, 184], [177, 198], [177, 208], [177, 224], [177, 243], [177, 251], [177, 256], [177, 257], [177, 270], [177, 286], [178, 184], [178, 227], [178, 235], [178, 244], [178, 290], [179, 200], [179, 210], [179, 227], [179, 231], [179, 273], [179, 299], [180, 195], [180, 202], [180, 256], [180, 258], [180, 261], [180, 267], [180, 275], [180, 279], [180, 286], [180, 297], [181, 194], [181, 199], [181, 213], [181, 270], [181, 277], [181, 296], [182, 190], [182, 203], [182, 213], [182, 214], [182, 218], [182, 227], [182, 228], [182, 237], [182, 263], [182, 266], [182, 298], [183, 238], [183, 244], [183, 246], [183, 269], [184, 199], [184, 203], [184, 251], [184, 275], [184, 285], [184, 296], [184, 297], [185, 187], [185, 188], [185, 193], [185, 204], [185, 231], [185, 243], [185, 263], [185, 266], [185, 271], [185, 275], [186, 197], [186, 206], [186, 208], [186, 212], [186, 216], [186, 234], [186, 292], [187, 198], [187, 218], [187, 247], [187, 250], [187, 251], [188, 197], [188, 198], [188, 224], [188, 227], [188, 231], [188, 237], [188, 243], [188, 271], [188, 275], [188, 276], [188, 299], [189, 207], [189, 258], [189, 276], [190, 216], [190, 226], [190, 228], [190, 253], [190, 276], [190, 282], [190, 290], [190, 297], [191, 195], [191, 198], [191, 204], [191, 232], [191, 237], [191, 241], [191, 247], [191, 250], [191, 254], [191, 266], [192, 203], [192, 215], [192, 217], [192, 220], [192, 247], [192, 253], [192, 284], [192, 286], [192, 296], [192, 297], [193, 231], [193, 243], [193, 244], [193, 253], [193, 272], [193, 297], [194, 195], [194, 234], [194, 237], [194, 240], [194, 264], [195, 223], [195, 240], [195, 275], [196, 229], [196, 234], [196, 258], [196, 259], [196, 269], [197, 209], [197, 212], [197, 215], [197, 224], [197, 225], [197, 262], [197, 265], [197, 271], [197, 281], [197, 285], [197, 292], [198, 251], [198, 253], [198, 262], [198, 275], [198, 281], [198, 282], [198, 295], [199, 242], [199, 255], [199, 271], [199, 272], [199, 292], [199, 294], [199, 298], [200, 202], [200, 206], [200, 209], [200, 228], [200, 237], [200, 251], [200, 262], [200, 263], [200, 266], [200, 287], [200, 291], [200, 296], [201, 209], [201, 211], [201, 223], [201, 227], [201, 241], [201, 283], [202, 236], [202, 242], [202, 267], [202, 295], [203, 207], [203, 221], [203, 226], [203, 230], [203, 243], [203, 253], [203, 273], [203, 276], [203, 280], [203, 281], [203, 290], [203, 294], [203, 295], [204, 220], [204, 251], [204, 271], [204, 278], [204, 283], [204, 289], [204, 292], [205, 216], [205, 219], [205, 224], [205, 240], [205, 281], [205, 286], [205, 297], [206, 244], [206, 251], [206, 279], [207, 210], [207, 236], [207, 291], [208, 215], [208, 223], [208, 229], [208, 232], [208, 256], [208, 276], [208, 294], [208, 295], [209, 210], [209, 229], [209, 233], [209, 252], [210, 233], [210, 235], [210, 236], [210, 253], [210, 275], [211, 227], [211, 228], [211, 229], [211, 241], [211, 246], [211, 267], [212, 213], [212, 217], [212, 224], [212, 276], [212, 278], [212, 281], [212, 296], [212, 299], [213, 223], [213, 262], [213, 277], [213, 281], [213, 283], [213, 294], [214, 225], [214, 237], [214, 239], [214, 250], [214, 259], [214, 263], [214, 265], [214, 270], [214, 296], [214, 297], [215, 234], [215, 260], [215, 297], [216, 224], [216, 240], [216, 268], [216, 281], [216, 285], [216, 287], [217, 227], [217, 236], [217, 257], [217, 265], [218, 235], [218, 263], [219, 221], [219, 271], [220, 229], [220, 257], [220, 258], [220, 266], [220, 273], [220, 275], [220, 288], [220, 292], [221, 242], [221, 258], [221, 268], [221, 269], [221, 277], [222, 254], [222, 261], [223, 235], [223, 255], [223, 263], [223, 294], [224, 235], [224, 237], [224, 254], [224, 272], [224, 299], [225, 233], [225, 244], [225, 245], [225, 274], [225, 275], [226, 259], [226, 266], [226, 287], [226, 289], [227, 237], [227, 273], [227, 287], [228, 254], [228, 262], [228, 264], [228, 295], [228, 297], [229, 230], [229, 269], [229, 275], [229, 279], [230, 241], [230, 245], [230, 249], [230, 270], [230, 272], [230, 274], [230, 295], [231, 271], [231, 289], [231, 294], [231, 299], [232, 237], [232, 248], [232, 257], [232, 282], [232, 288], [232, 292], [233, 252], [233, 253], [233, 259], [233, 267], [233, 274], [233, 290], [234, 237], [234, 245], [234, 247], [234, 256], [234, 278], [234, 287], [234, 291], [235, 243], [235, 267], [235, 272], [235, 278], [235, 292], [236, 241], [236, 250], [236, 270], [236, 275], [236, 282], [236, 284], [237, 260], [237, 270], [238, 248], [238, 255], [238, 277], [238, 287], [239, 277], [239, 282], [240, 281], [240, 294], [240, 297], [241, 247], [241, 249], [241, 264], [241, 266], [241, 286], [242, 243], [242, 247], [242, 248], [242, 266], [242, 293], [243, 260], [244, 296], [245, 246], [245, 254], [245, 266], [245, 271], [245, 272], [245, 279], [245, 295], [246, 251], [246, 258], [246, 261], [247, 255], [247, 295], [248, 252], [248, 276], [248, 284], [249, 253], [249, 267], [249, 269], [249, 270], [250, 251], [250, 254], [250, 274], [250, 283], [251, 293], [251, 295], [251, 299], [252, 253], [252, 265], [252, 273], [252, 293], [252, 298], [253, 279], [253, 293], [253, 297], [253, 298], [254, 261], [254, 269], [254, 295], [255, 267], [256, 259], [256, 263], [256, 267], [256, 270], [256, 280], [256, 283], [256, 285], [257, 262], [257, 263], [257, 294], [257, 296], [257, 298], [258, 265], [258, 289], [259, 260], [259, 263], [259, 264], [259, 281], [260, 267], [260, 292], [260, 299], [261, 284], [262, 275], [262, 283], [262, 288], [262, 295], [264, 275], [264, 293], [265, 273], [265, 294], [266, 290], [267, 280], [267, 287], [268, 286], [268, 288], [268, 290], [268, 294], [269, 280], [269, 298], [270, 275], [270, 283], [271, 295], [272, 282], [272, 284], [273, 275], [273, 276], [273, 282], [273, 283], [274, 284], [274, 291], [276, 285], [278, 294], [278, 298], [279, 280], [280, 291], [281, 296], [282, 290], [284, 298], [286, 288], [287, 296], [288, 298], [295, 297]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l6-s9/tests/run.py b/tasks/construct-nppc-dominating-set-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l6-s9/tests/test.sh b/tasks/construct-nppc-dominating-set-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l3-s0/environment/Dockerfile b/tasks/construct-rg-graph-color-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s0/environment/instance.json b/tasks/construct-rg-graph-color-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..575036fb3ca0002a240f96201a5ea12a9eb47c21 --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 3, "edges": [[0, 3], [0, 5], [0, 6], [1, 3], [1, 5], [1, 9], [2, 4], [2, 5], [2, 6], [3, 6], [4, 8], [5, 6]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l3-s0/solution/solve.sh b/tasks/construct-rg-graph-color-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..83fb3d00132783318fa6471296e0cfd11b70c1c9 --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 2, 2, 2, 3, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l3-s0/tests/check.py b/tasks/construct-rg-graph-color-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s0/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l3-s0/tests/instance.json b/tasks/construct-rg-graph-color-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..575036fb3ca0002a240f96201a5ea12a9eb47c21 --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 3, "edges": [[0, 3], [0, 5], [0, 6], [1, 3], [1, 5], [1, 9], [2, 4], [2, 5], [2, 6], [3, 6], [4, 8], [5, 6]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l3-s0/tests/run.py b/tasks/construct-rg-graph-color-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s0/tests/test.sh b/tasks/construct-rg-graph-color-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s7/environment/Dockerfile b/tasks/construct-rg-graph-color-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s7/environment/instance.json b/tasks/construct-rg-graph-color-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7c01e83d59e748119834efc0c99b23764bd2f55a --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 3, "edges": [[0, 3], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 4], [2, 5], [2, 8], [3, 9], [4, 6], [4, 7], [4, 9], [6, 8], [7, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l3-s7/solution/solve.sh b/tasks/construct-rg-graph-color-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f60dd169ca5396e233bf318516c7d654a1b072d4 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 2, 2, 3, 1, 2, 2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l3-s7/tests/check.py b/tasks/construct-rg-graph-color-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s7/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l3-s7/tests/instance.json b/tasks/construct-rg-graph-color-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7c01e83d59e748119834efc0c99b23764bd2f55a --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 3, "edges": [[0, 3], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [2, 4], [2, 5], [2, 8], [3, 9], [4, 6], [4, 7], [4, 9], [6, 8], [7, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l3-s7/tests/run.py b/tasks/construct-rg-graph-color-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s7/tests/test.sh b/tasks/construct-rg-graph-color-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-l3-s9/environment/Dockerfile b/tasks/construct-rg-graph-color-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s9/environment/instance.json b/tasks/construct-rg-graph-color-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..769cfb0eaff9d7867cabdd22d191ec51a7eb04bc --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 3, "edges": [[0, 1], [0, 3], [0, 5], [0, 6], [0, 8], [1, 4], [1, 6], [1, 8], [2, 3], [2, 5], [2, 7], [4, 5], [4, 8], [5, 7]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l3-s9/solution/solve.sh b/tasks/construct-rg-graph-color-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a567fac3efc5fa763b162da1a9b99204717535c3 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 2, 1, 2, 1, 2, 3, 3, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l3-s9/tests/check.py b/tasks/construct-rg-graph-color-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s9/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l3-s9/tests/instance.json b/tasks/construct-rg-graph-color-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..769cfb0eaff9d7867cabdd22d191ec51a7eb04bc --- /dev/null +++ b/tasks/construct-rg-graph-color-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 3, "edges": [[0, 1], [0, 3], [0, 5], [0, 6], [0, 8], [1, 4], [1, 6], [1, 8], [2, 3], [2, 5], [2, 7], [4, 5], [4, 8], [5, 7]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l3-s9/tests/run.py b/tasks/construct-rg-graph-color-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l3-s9/tests/test.sh b/tasks/construct-rg-graph-color-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-simple-integration-l3-s1/environment/Dockerfile b/tasks/construct-rg-simple-integration-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s1/environment/instance.json b/tasks/construct-rg-simple-integration-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..02e12597d95e2533cabd5792053918f6658348b9 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "81*X**8/7 + 4*X**7/5 + 7*X**6/2 + 2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l3-s1/solution/solve.sh b/tasks/construct-rg-simple-integration-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..97d5bef2839cc42db8b5e3d59bfe5b9f8f8deff7 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "9*X**9/7 + X**8/10 + X**7/2 + 2*X + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l3-s1/tests/check.py b/tasks/construct-rg-simple-integration-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s1/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l3-s1/tests/instance.json b/tasks/construct-rg-simple-integration-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..02e12597d95e2533cabd5792053918f6658348b9 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "81*X**8/7 + 4*X**7/5 + 7*X**6/2 + 2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l3-s1/tests/run.py b/tasks/construct-rg-simple-integration-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s1/tests/test.sh b/tasks/construct-rg-simple-integration-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s6/environment/Dockerfile b/tasks/construct-rg-simple-integration-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s6/environment/instance.json b/tasks/construct-rg-simple-integration-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26ded8b94842ac2bd170cf11883856a8a780dc33 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "30*x**9 - 14*x**6 - 18*x**3 - 12*x**2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l3-s6/solution/solve.sh b/tasks/construct-rg-simple-integration-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cc03a2e6c27cd1451eacd8ba1bac0052cd83f64d --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "3*x**10 - 2*x**7 - 9*x**4/2 - 4*x**3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l3-s6/tests/check.py b/tasks/construct-rg-simple-integration-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s6/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l3-s6/tests/instance.json b/tasks/construct-rg-simple-integration-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26ded8b94842ac2bd170cf11883856a8a780dc33 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "30*x**9 - 14*x**6 - 18*x**3 - 12*x**2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l3-s6/tests/run.py b/tasks/construct-rg-simple-integration-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s6/tests/test.sh b/tasks/construct-rg-simple-integration-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s8/environment/Dockerfile b/tasks/construct-rg-simple-integration-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s8/environment/instance.json b/tasks/construct-rg-simple-integration-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6b9ddf5b5bf76a299bd9527e93f96c1b718fdf2 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-30*X**9 - 36*X**8 - 80*X**7/9", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l3-s8/solution/solve.sh b/tasks/construct-rg-simple-integration-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d1655b3235889a185f31c6dfd2b27b3be98d9cbc --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-3*X**10 - 4*X**9 - 10*X**8/9 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l3-s8/tests/check.py b/tasks/construct-rg-simple-integration-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s8/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l3-s8/tests/instance.json b/tasks/construct-rg-simple-integration-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f6b9ddf5b5bf76a299bd9527e93f96c1b718fdf2 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-30*X**9 - 36*X**8 - 80*X**7/9", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l3-s8/tests/run.py b/tasks/construct-rg-simple-integration-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l3-s8/tests/test.sh b/tasks/construct-rg-simple-integration-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s5/environment/Dockerfile b/tasks/construct-rg-simple-integration-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l4-s5/environment/instance.json b/tasks/construct-rg-simple-integration-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a8732abe7248c98f457239fd259e2a231979315 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "232*x**7/3 - 54*x**5 + 3*x**2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s5/solution/solve.sh b/tasks/construct-rg-simple-integration-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d351f2979f538dbc54e212215e7783e7077f7fbe --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "29*x**8/3 - 9*x**6 + x**3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l4-s5/tests/check.py b/tasks/construct-rg-simple-integration-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s5/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-s5/tests/instance.json b/tasks/construct-rg-simple-integration-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a8732abe7248c98f457239fd259e2a231979315 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "232*x**7/3 - 54*x**5 + 3*x**2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s5/tests/run.py b/tasks/construct-rg-simple-integration-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l4-s5/tests/test.sh b/tasks/construct-rg-simple-integration-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l1-s3/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l1-s3/environment/instance.json b/tasks/construct-rlve-antiderivative-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3c41317c8e8719d455264cde110f883bcd8383fa --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "1/(2*x)", "max_ops": 28, "max_len": 560, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s3/solution/solve.sh b/tasks/construct-rlve-antiderivative-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7bd0bad05a9982c8b6755a0f007002e2fab89a8 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"F": "log(x)/2"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l1-s3/tests/check.py b/tasks/construct-rlve-antiderivative-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-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-l1-s3/tests/instance.json b/tasks/construct-rlve-antiderivative-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3c41317c8e8719d455264cde110f883bcd8383fa --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "1/(2*x)", "max_ops": 28, "max_len": 560, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s3/tests/run.py b/tasks/construct-rlve-antiderivative-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l1-s3/tests/test.sh b/tasks/construct-rlve-antiderivative-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l2-s1/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s1/environment/instance.json b/tasks/construct-rlve-antiderivative-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bcb05f2dbda0902509ddc522925bc9cff2fcf0e1 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "1 - exp(x)", "max_ops": 32, "max_len": 680, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l2-s1/solution/solve.sh b/tasks/construct-rlve-antiderivative-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..86479b13f71df2c8f95077bd7e43a435ad9134b1 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "x - exp(x) + 2"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l2-s1/tests/check.py b/tasks/construct-rlve-antiderivative-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s1/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-l2-s1/tests/instance.json b/tasks/construct-rlve-antiderivative-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bcb05f2dbda0902509ddc522925bc9cff2fcf0e1 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "1 - exp(x)", "max_ops": 32, "max_len": 680, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l2-s1/tests/run.py b/tasks/construct-rlve-antiderivative-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s1/tests/test.sh b/tasks/construct-rlve-antiderivative-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s6/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s6/environment/instance.json b/tasks/construct-rlve-antiderivative-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08c23f29be45f0dadaa0e32b226d10da852c3a1c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "8*x", "max_ops": 32, "max_len": 600, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l2-s6/solution/solve.sh b/tasks/construct-rlve-antiderivative-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..296d8a0a163f11e393dbccca033cfabdc613eeec --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "4*x**2 - 1"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l2-s6/tests/check.py b/tasks/construct-rlve-antiderivative-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s6/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l2-s6/tests/instance.json b/tasks/construct-rlve-antiderivative-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08c23f29be45f0dadaa0e32b226d10da852c3a1c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "8*x", "max_ops": 32, "max_len": 600, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l2-s6/tests/run.py b/tasks/construct-rlve-antiderivative-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s6/tests/test.sh b/tasks/construct-rlve-antiderivative-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s8/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s8/environment/instance.json b/tasks/construct-rlve-antiderivative-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6cc9c371163621a67c40384ed48db4628051302e --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "3*sin(x - 1)*sin(cos(x - 1))*cos(cos(x - 1))**2", "max_ops": 36, "max_len": 760, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l2-s8/solution/solve.sh b/tasks/construct-rlve-antiderivative-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9672b782a7643c18996e8d208cad38996dc55c1c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "cos(cos(x - 1))**3"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l2-s8/tests/check.py b/tasks/construct-rlve-antiderivative-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s8/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l2-s8/tests/instance.json b/tasks/construct-rlve-antiderivative-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6cc9c371163621a67c40384ed48db4628051302e --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "3*sin(x - 1)*sin(cos(x - 1))*cos(cos(x - 1))**2", "max_ops": 36, "max_len": 760, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l2-s8/tests/run.py b/tasks/construct-rlve-antiderivative-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l2-s8/tests/test.sh b/tasks/construct-rlve-antiderivative-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l6-s7/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l6-s7/environment/instance.json b/tasks/construct-rlve-antiderivative-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..87f52e99b6f8cf8f1e0c8b145f7fb6205e306d6d --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "2 + (2 - 4*E)*exp(-x)/4", "max_ops": 52, "max_len": 900, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l6-s7/solution/solve.sh b/tasks/construct-rlve-antiderivative-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..782c85203240f141bb3071c42a449b313c89c1d7 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "2*x - (2 - 4*E)*exp(-x)/4"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l6-s7/tests/check.py b/tasks/construct-rlve-antiderivative-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s7/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l6-s7/tests/instance.json b/tasks/construct-rlve-antiderivative-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..87f52e99b6f8cf8f1e0c8b145f7fb6205e306d6d --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "2 + (2 - 4*E)*exp(-x)/4", "max_ops": 52, "max_len": 900, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l6-s7/tests/run.py b/tasks/construct-rlve-antiderivative-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l6-s7/tests/test.sh b/tasks/construct-rlve-antiderivative-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l6-s9/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l6-s9/environment/instance.json b/tasks/construct-rlve-antiderivative-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..540a217449de5675a4b045c43404bee9a402fc9c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-(18*x - 6)*sin(9*x**2 - 6*x)", "max_ops": 40, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l6-s9/solution/solve.sh b/tasks/construct-rlve-antiderivative-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..80e2895910952ff2f24f098d8e03e76ad83f28c8 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "cos(9*x**2 - 6*x)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l6-s9/tests/check.py b/tasks/construct-rlve-antiderivative-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s9/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l6-s9/tests/instance.json b/tasks/construct-rlve-antiderivative-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..540a217449de5675a4b045c43404bee9a402fc9c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-(18*x - 6)*sin(9*x**2 - 6*x)", "max_ops": 40, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l6-s9/tests/run.py b/tasks/construct-rlve-antiderivative-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l6-s9/tests/test.sh b/tasks/construct-rlve-antiderivative-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/environment/instance.json b/tasks/construct-rlve-bezout-identity-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a68203c4e01480821dbba157fde63fe5a9d526d --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [-18, -51, -393, 177, 147, -378], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..22a02c2f009c9efe29f154918a54d69a016a0f84 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [-3, 1, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/tests/check.py b/tasks/construct-rlve-bezout-identity-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l3-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/tests/instance.json b/tasks/construct-rlve-bezout-identity-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a68203c4e01480821dbba157fde63fe5a9d526d --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [-18, -51, -393, 177, 147, -378], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/tests/run.py b/tasks/construct-rlve-bezout-identity-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l3-s2/tests/test.sh b/tasks/construct-rlve-bezout-identity-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l4-s6/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l4-s6/environment/instance.json b/tasks/construct-rlve-bezout-identity-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..479aed056305d1fdd9b72897ed44d018c1d8fb6d --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [1704, -639, -1846, -1491, -1136, 994, 1207, -1633], "target": 71, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s6/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee0fe8b3c65bcf66d39738f03db40299955d72bc --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [-9, -27, 1, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l4-s6/tests/check.py b/tasks/construct-rlve-bezout-identity-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/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-s6/tests/instance.json b/tasks/construct-rlve-bezout-identity-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..479aed056305d1fdd9b72897ed44d018c1d8fb6d --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [1704, -639, -1846, -1491, -1136, 994, 1207, -1633], "target": 71, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s6/tests/run.py b/tasks/construct-rlve-bezout-identity-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l4-s6/tests/test.sh b/tasks/construct-rlve-bezout-identity-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l3-s2/environment/Dockerfile b/tasks/construct-rlve-crt-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l3-s2/environment/instance.json b/tasks/construct-rlve-crt-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5c58f62cd175a066d2ff578fb33cd13fa3ddf476 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [3208, 2834, 3050, 1569], "residues": [912, 1286, 1070, 982], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s2/solution/solve.sh b/tasks/construct-rlve-crt-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bd5732e81195fa23782b396014f914796cbbcbfe --- /dev/null +++ b/tasks/construct-rlve-crt-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": 4120} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l3-s2/tests/check.py b/tasks/construct-rlve-crt-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s2/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-s2/tests/instance.json b/tasks/construct-rlve-crt-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5c58f62cd175a066d2ff578fb33cd13fa3ddf476 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [3208, 2834, 3050, 1569], "residues": [912, 1286, 1070, 982], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s2/tests/run.py b/tasks/construct-rlve-crt-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l3-s2/tests/test.sh b/tasks/construct-rlve-crt-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l4-s1/environment/Dockerfile b/tasks/construct-rlve-crt-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l4-s1/environment/instance.json b/tasks/construct-rlve-crt-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56788cc4b51d85cbacdc6a7acd10f76cdaee7dd1 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [649311, 433378, 469245, 260543, 203405], "residues": [20564, 236497, 200630, 148789, 59660], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l4-s1/solution/solve.sh b/tasks/construct-rlve-crt-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6f64417d6e829d0590d11264a54dc68e6ebbc778 --- /dev/null +++ b/tasks/construct-rlve-crt-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' +{"x": 669875} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l4-s1/tests/check.py b/tasks/construct-rlve-crt-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s1/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l4-s1/tests/instance.json b/tasks/construct-rlve-crt-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56788cc4b51d85cbacdc6a7acd10f76cdaee7dd1 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [649311, 433378, 469245, 260543, 203405], "residues": [20564, 236497, 200630, 148789, 59660], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l4-s1/tests/test.sh b/tasks/construct-rlve-crt-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l4-s6/environment/Dockerfile b/tasks/construct-rlve-crt-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l4-s6/environment/instance.json b/tasks/construct-rlve-crt-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4e1cdb9965163dd8053b765470c6550f8011738 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [1935, 886885, 760338, 764706, 450973], "residues": [225, 57620, 184167, 179799, 42559], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l4-s6/solution/solve.sh b/tasks/construct-rlve-crt-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6456b6219623bc78783203b26edcdbf3dc2b46cc --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 944505} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l4-s6/tests/check.py b/tasks/construct-rlve-crt-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l4-s6/tests/instance.json b/tasks/construct-rlve-crt-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4e1cdb9965163dd8053b765470c6550f8011738 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [1935, 886885, 760338, 764706, 450973], "residues": [225, 57620, 184167, 179799, 42559], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l4-s6/tests/run.py b/tasks/construct-rlve-crt-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l4-s6/tests/test.sh b/tasks/construct-rlve-crt-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l4-s8/environment/Dockerfile b/tasks/construct-rlve-crt-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l4-s8/environment/instance.json b/tasks/construct-rlve-crt-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5eb624d0a58fe14f876527c3bba72d55325d8b05 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [684840, 495759, 595010, 509530, 177878], "residues": [296524, 485605, 386354, 471834, 91974], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l4-s8/solution/solve.sh b/tasks/construct-rlve-crt-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c9dba48d5486c19dcd6e7705a54ece6e167333f0 --- /dev/null +++ b/tasks/construct-rlve-crt-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": 981364} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l4-s8/tests/check.py b/tasks/construct-rlve-crt-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s8/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l4-s8/tests/instance.json b/tasks/construct-rlve-crt-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5eb624d0a58fe14f876527c3bba72d55325d8b05 --- /dev/null +++ b/tasks/construct-rlve-crt-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [684840, 495759, 595010, 509530, 177878], "residues": [296524, 485605, 386354, 471834, 91974], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l4-s8/tests/run.py b/tasks/construct-rlve-crt-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l4-s8/tests/test.sh b/tasks/construct-rlve-crt-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-distinct-subset-sum-permutation-l1-s0/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..78f3486dd483e7b4de0c5c6c4fc820b2786a759b --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": [1, 5, 2, 4], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..daca2503e681cbb68e5bdd0c2abd21e44e6477fe --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [2, 1, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..78f3486dd483e7b4de0c5c6c4fc820b2786a759b --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": [1, 5, 2, 4], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eda83b54086f4079d4a03cba0b0bd064f3868176 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": [5, 1, 4, 2], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3009ccdb4e78a6dffa048e05fc0f503a272e7bfe --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [1, 2, 5, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eda83b54086f4079d4a03cba0b0bd064f3868176 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": [5, 1, 4, 2], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..70d607dd3d33b309d925b4208a9176776799fcea --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [7, 0, 1, 4], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c2ce3002470ce80b4eb4b15d565bbaa9be5308aa --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [0, 1, 4, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..70d607dd3d33b309d925b4208a9176776799fcea --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [7, 0, 1, 4], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l2-s5/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bef4ef6360e067f5e988cbe933cafd2cc4296b2d --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": [13, 12, 10, 2, 6, 0, 5], "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-s5/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..efb99335fc8ea61c60132e1e6adfa0413764b0d6 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [0, 13, 12, 5, 10, 2, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-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-l2-s5/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bef4ef6360e067f5e988cbe933cafd2cc4296b2d --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": [13, 12, 10, 2, 6, 0, 5], "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-s5/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l2-s5/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l5-s1/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b25ee4b13a336cb7fd6ed2b702614150320d4458 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": [5, 1, 12, 25, 16, 15, 11, 24, 34, 6, 4, 7, 21, 0, 32, 19, 28, 13], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..facb0c10da6a66986457f3ec69973395d11ea815 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [6, 4, 13, 28, 19, 16, 12, 25, 0, 7, 5, 11, 24, 1, 34, 21, 32, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b25ee4b13a336cb7fd6ed2b702614150320d4458 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": [5, 1, 12, 25, 16, 15, 11, 24, 34, 6, 4, 7, 21, 0, 32, 19, 28, 13], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e81aff2b97c5984146d36cae6fecdfce040e883 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [19, 24, 5, 21, 35, 17, 2, 11, 23, 27, 30, 9, 32, 25, 10, 33, 20, 22], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d08301cb05fd419faed8fb59fdeb94a44ebc2f8e --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [20, 25, 9, 22, 2, 19, 5, 17, 24, 30, 32, 10, 33, 27, 11, 35, 21, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e81aff2b97c5984146d36cae6fecdfce040e883 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [19, 24, 5, 21, 35, 17, 2, 11, 23, 27, 30, 9, 32, 25, 10, 33, 20, 22], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d0b3519340a757943a20ba4fc37398056f5bef0 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": [26, 0, 17, 23, 18, 27, 1, 19, 8, 32, 22, 7, 2, 31, 6, 29, 11, 34], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2cff476c6e8451ce4fb22a708cdc88aa95e0d49f --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [27, 1, 18, 26, 19, 29, 2, 22, 11, 34, 23, 8, 6, 32, 7, 31, 17, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/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-l5-s8/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d0b3519340a757943a20ba4fc37398056f5bef0 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": [26, 0, 17, 23, 18, 27, 1, 19, 8, 32, 22, 7, 2, 31, 6, 29, 11, 34], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l4-s1/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l4-s1/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b81e2d23ce8deaa84de3ca4bd1926f1c425ee5d1 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 1], [0, 3], [0, 4], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 12], [1, 15], [2, 4], [2, 5], [2, 12], [2, 16], [3, 7], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 17], [4, 8], [4, 10], [5, 6], [5, 8], [5, 11], [5, 12], [5, 14], [5, 15], [6, 7], [6, 9], [6, 11], [6, 14], [6, 17], [7, 8], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 17], [8, 11], [8, 14], [8, 17], [9, 13], [9, 15], [9, 17], [10, 17], [11, 12], [11, 14], [11, 17], [12, 13], [12, 15], [13, 14], [13, 15], [13, 17], [14, 16], [15, 16], [15, 17], [16, 17]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l4-s1/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5da57e011a3b0310712832f1c4846bd5d28029a6 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 1, 2, 1, 1, 2, 1, 1, 1, 2, 2, 2, 2, 1, 1, 2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l4-s1/tests/check.py b/tasks/construct-rlve-even-degree-partition-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l4-s1/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b81e2d23ce8deaa84de3ca4bd1926f1c425ee5d1 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 1], [0, 3], [0, 4], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 12], [1, 15], [2, 4], [2, 5], [2, 12], [2, 16], [3, 7], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 17], [4, 8], [4, 10], [5, 6], [5, 8], [5, 11], [5, 12], [5, 14], [5, 15], [6, 7], [6, 9], [6, 11], [6, 14], [6, 17], [7, 8], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 17], [8, 11], [8, 14], [8, 17], [9, 13], [9, 15], [9, 17], [10, 17], [11, 12], [11, 14], [11, 17], [12, 13], [12, 15], [13, 14], [13, 15], [13, 17], [14, 16], [15, 16], [15, 17], [16, 17]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l4-s1/tests/run.py b/tasks/construct-rlve-even-degree-partition-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l4-s1/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l4-s6/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l4-s6/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cea77ee41b5cdd9f14873fb5f09ae255d6cdf4b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 2], [0, 8], [0, 9], [0, 16], [1, 2], [1, 3], [1, 8], [1, 9], [1, 12], [1, 16], [2, 4], [2, 5], [2, 6], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [4, 7], [4, 8], [4, 9], [4, 11], [4, 15], [5, 6], [5, 8], [5, 9], [5, 10], [5, 12], [5, 14], [5, 15], [5, 16], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [6, 15], [6, 16], [6, 17], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 16], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [8, 16], [8, 17], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [11, 12], [11, 14], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [13, 14], [14, 15], [14, 16], [15, 16], [16, 17]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l4-s6/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..640e0b94b4a0cd2048a170bd23131806568e745a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [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-rlve-even-degree-partition-l4-s6/tests/check.py b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l4-s6/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cea77ee41b5cdd9f14873fb5f09ae255d6cdf4b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 2], [0, 8], [0, 9], [0, 16], [1, 2], [1, 3], [1, 8], [1, 9], [1, 12], [1, 16], [2, 4], [2, 5], [2, 6], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [4, 7], [4, 8], [4, 9], [4, 11], [4, 15], [5, 6], [5, 8], [5, 9], [5, 10], [5, 12], [5, 14], [5, 15], [5, 16], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [6, 15], [6, 16], [6, 17], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 16], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [8, 16], [8, 17], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [11, 12], [11, 14], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [13, 14], [14, 15], [14, 16], [15, 16], [16, 17]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l4-s6/tests/run.py b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l4-s6/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l4-s8/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l4-s8/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6093702b17b59a9009f6ab27c6f1c375cf6c06eb --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 8], [0, 11], [0, 17], [1, 5], [1, 6], [1, 17], [2, 4], [2, 8], [2, 11], [2, 14], [2, 15], [2, 17], [3, 4], [3, 5], [3, 6], [3, 10], [3, 11], [3, 15], [4, 8], [4, 10], [4, 11], [4, 13], [4, 15], [4, 17], [5, 6], [5, 7], [5, 12], [5, 17], [6, 8], [6, 15], [7, 11], [7, 15], [8, 9], [8, 10], [8, 11], [8, 12], [8, 17], [9, 10], [9, 11], [9, 12], [9, 17], [10, 11], [10, 14], [12, 14], [14, 16], [14, 17], [15, 16]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l4-s8/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..60652d9b3784ad6a361495e1adc48e04d733f52f --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 2, 1, 2, 1, 2, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l4-s8/tests/check.py b/tasks/construct-rlve-even-degree-partition-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l4-s8/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6093702b17b59a9009f6ab27c6f1c375cf6c06eb --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 8], [0, 11], [0, 17], [1, 5], [1, 6], [1, 17], [2, 4], [2, 8], [2, 11], [2, 14], [2, 15], [2, 17], [3, 4], [3, 5], [3, 6], [3, 10], [3, 11], [3, 15], [4, 8], [4, 10], [4, 11], [4, 13], [4, 15], [4, 17], [5, 6], [5, 7], [5, 12], [5, 17], [6, 8], [6, 15], [7, 11], [7, 15], [8, 9], [8, 10], [8, 11], [8, 12], [8, 17], [9, 10], [9, 11], [9, 12], [9, 17], [10, 11], [10, 14], [12, 14], [14, 16], [14, 17], [15, 16]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l4-s8/tests/run.py b/tasks/construct-rlve-even-degree-partition-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l4-s8/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-graph-isomorphism-l1-s9/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s9/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..310fb0e5c616f8b7ea329101a8cd07471555ce6c --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[2, 4], [0, 2], [3, 4], [0, 1], [0, 3], [1, 2]], "edges2": [[1, 3], [2, 4], [3, 4], [1, 2], [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-s9/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79d5585a72e52ac57c74ac745f6698c31b8df984 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [3, 0, 1, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l1-s9/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-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-l1-s9/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..310fb0e5c616f8b7ea329101a8cd07471555ce6c --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges1": [[2, 4], [0, 2], [3, 4], [0, 1], [0, 3], [1, 2]], "edges2": [[1, 3], [2, 4], [3, 4], [1, 2], [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-s9/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l1-s9/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l2-s2/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l2-s2/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dc1f1ac7b75492480df948e0eb9ffa22092ff51f --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges1": [[2, 4], [6, 7], [5, 6], [0, 2], [2, 6], [1, 3], [0, 7], [0, 5], [2, 7], [3, 5], [1, 4], [2, 3], [0, 6], [4, 6], [0, 4]], "edges2": [[2, 6], [0, 3], [3, 6], [1, 2], [1, 4], [0, 2], [3, 5], [1, 3], [5, 6], [1, 6], [6, 7], [4, 7], [0, 7], [2, 5], [2, 3]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l2-s2/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..54bfe0428cd9280fa4bc99ea211d2a2766b194eb --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [3, 4, 6, 7, 1, 0, 2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dc1f1ac7b75492480df948e0eb9ffa22092ff51f --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges1": [[2, 4], [6, 7], [5, 6], [0, 2], [2, 6], [1, 3], [0, 7], [0, 5], [2, 7], [3, 5], [1, 4], [2, 3], [0, 6], [4, 6], [0, 4]], "edges2": [[2, 6], [0, 3], [3, 6], [1, 2], [1, 4], [0, 2], [3, 5], [1, 3], [5, 6], [1, 6], [6, 7], [4, 7], [0, 7], [2, 5], [2, 3]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l2-s2/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s6/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s6/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f4cba7f034e30132e6f31789aede169e86821d7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[3, 19], [10, 11], [2, 20], [15, 21], [8, 11], [2, 23], [6, 22], [10, 14], [2, 9], [6, 13], [8, 9], [3, 22], [3, 16], [0, 15], [2, 12], [12, 18], [7, 24], [2, 21], [2, 4], [3, 7], [11, 18], [1, 17], [1, 14], [15, 17], [19, 24], [1, 21], [16, 21], [0, 6], [6, 11], [9, 20], [5, 22], [19, 25], [2, 3], [14, 17], [7, 25], [11, 19], [4, 25], [0, 7], [9, 25], [7, 22], [7, 12], [13, 22], [18, 20], [16, 19], [16, 20], [6, 23], [3, 6], [2, 15], [1, 12], [3, 25], [21, 23], [12, 25], [5, 11], [11, 14], [3, 11], [5, 16], [14, 25], [13, 14], [4, 24], [0, 10], [2, 24], [19, 23], [15, 20], [3, 10], [8, 20], [18, 22], [4, 21], [0, 13], [0, 2], [18, 23], [8, 22], [1, 2], [18, 24], [4, 23], [17, 24], [8, 24], [5, 12], [17, 18], [4, 11], [8, 13], [9, 15]], "edges2": [[19, 21], [18, 22], [0, 21], [14, 25], [10, 24], [8, 11], [0, 2], [8, 16], [1, 8], [6, 25], [10, 15], [0, 19], [6, 16], [13, 25], [2, 20], [16, 21], [5, 19], [1, 9], [18, 23], [16, 19], [18, 21], [11, 18], [2, 13], [17, 20], [4, 10], [4, 20], [0, 1], [2, 4], [6, 15], [13, 20], [1, 20], [11, 16], [4, 19], [7, 10], [9, 24], [10, 22], [2, 23], [7, 9], [3, 22], [20, 23], [5, 11], [10, 23], [14, 21], [3, 12], [13, 17], [3, 24], [21, 22], [14, 23], [9, 13], [3, 17], [15, 17], [1, 7], [4, 24], [12, 21], [0, 15], [8, 22], [12, 22], [4, 8], [5, 18], [6, 22], [17, 24], [3, 11], [13, 23], [2, 22], [4, 14], [5, 20], [21, 25], [15, 20], [15, 19], [10, 16], [5, 9], [16, 18], [14, 22], [7, 25], [7, 8], [7, 20], [5, 12], [20, 21], [9, 20], [0, 3], [0, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s6/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e6f61f4e11ab47652f9f26d9f57af341aaa13f48 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [5, 17, 20, 21, 2, 6, 18, 19, 8, 1, 12, 22, 15, 11, 3, 9, 25, 24, 10, 14, 7, 13, 16, 23, 4, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-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-l5-s6/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f4cba7f034e30132e6f31789aede169e86821d7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[3, 19], [10, 11], [2, 20], [15, 21], [8, 11], [2, 23], [6, 22], [10, 14], [2, 9], [6, 13], [8, 9], [3, 22], [3, 16], [0, 15], [2, 12], [12, 18], [7, 24], [2, 21], [2, 4], [3, 7], [11, 18], [1, 17], [1, 14], [15, 17], [19, 24], [1, 21], [16, 21], [0, 6], [6, 11], [9, 20], [5, 22], [19, 25], [2, 3], [14, 17], [7, 25], [11, 19], [4, 25], [0, 7], [9, 25], [7, 22], [7, 12], [13, 22], [18, 20], [16, 19], [16, 20], [6, 23], [3, 6], [2, 15], [1, 12], [3, 25], [21, 23], [12, 25], [5, 11], [11, 14], [3, 11], [5, 16], [14, 25], [13, 14], [4, 24], [0, 10], [2, 24], [19, 23], [15, 20], [3, 10], [8, 20], [18, 22], [4, 21], [0, 13], [0, 2], [18, 23], [8, 22], [1, 2], [18, 24], [4, 23], [17, 24], [8, 24], [5, 12], [17, 18], [4, 11], [8, 13], [9, 15]], "edges2": [[19, 21], [18, 22], [0, 21], [14, 25], [10, 24], [8, 11], [0, 2], [8, 16], [1, 8], [6, 25], [10, 15], [0, 19], [6, 16], [13, 25], [2, 20], [16, 21], [5, 19], [1, 9], [18, 23], [16, 19], [18, 21], [11, 18], [2, 13], [17, 20], [4, 10], [4, 20], [0, 1], [2, 4], [6, 15], [13, 20], [1, 20], [11, 16], [4, 19], [7, 10], [9, 24], [10, 22], [2, 23], [7, 9], [3, 22], [20, 23], [5, 11], [10, 23], [14, 21], [3, 12], [13, 17], [3, 24], [21, 22], [14, 23], [9, 13], [3, 17], [15, 17], [1, 7], [4, 24], [12, 21], [0, 15], [8, 22], [12, 22], [4, 8], [5, 18], [6, 22], [17, 24], [3, 11], [13, 23], [2, 22], [4, 14], [5, 20], [21, 25], [15, 20], [15, 19], [10, 16], [5, 9], [16, 18], [14, 22], [7, 25], [7, 8], [7, 20], [5, 12], [20, 21], [9, 20], [0, 3], [0, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s6/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l6-s3/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s3/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d9bd4e7522ecbfe4a0287dba22eb6d5015e2958 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges1": [[11, 39], [3, 24], [2, 31], [11, 20], [22, 36], [14, 26], [1, 11], [3, 15], [15, 31], [27, 36], [24, 39], [11, 29], [7, 36], [0, 16], [1, 13], [11, 35], [4, 14], [8, 33], [25, 31], [3, 32], [1, 18], [12, 22], [28, 37], [6, 21], [6, 25], [19, 26], [0, 39], [3, 22], [26, 37], [9, 14], [4, 29], [8, 39], [10, 14], [0, 27], [7, 9], [22, 32], [21, 39], [2, 23], [0, 5], [1, 39], [9, 32], [18, 32], [1, 30], [1, 26], [11, 32], [20, 23], [22, 26], [28, 36], [11, 19], [18, 21], [2, 7], [30, 35], [5, 35], [11, 16], [3, 4], [18, 28], [24, 30], [13, 24], [9, 10], [16, 28], [1, 17], [4, 25], [16, 37], [3, 12], [1, 23], [9, 30], [17, 18], [1, 6], [22, 35], [6, 19], [4, 35], [29, 34], [0, 26], [3, 27], [9, 19], [8, 18], [11, 15], [2, 36], [12, 38], [0, 38], [25, 32], [19, 33], [19, 30], [2, 30], [3, 19], [0, 31], [0, 20], [13, 15], [18, 36], [6, 11], [3, 33], [7, 13], [27, 29], [8, 19], [20, 39], [3, 13], [7, 12], [5, 18], [19, 23], [6, 22], [20, 37], [24, 28], [13, 30], [7, 21], [32, 35], [30, 33], [9, 37], [5, 22], [26, 39], [36, 39], [0, 29], [12, 20], [0, 37], [5, 20], [5, 16], [21, 28], [17, 35]], "edges2": [[3, 11], [17, 23], [10, 20], [28, 38], [5, 20], [10, 12], [16, 21], [6, 22], [7, 39], [16, 33], [7, 11], [4, 30], [0, 24], [15, 22], [2, 5], [17, 30], [15, 23], [13, 18], [1, 21], [8, 31], [6, 16], [16, 17], [13, 26], [8, 19], [28, 34], [2, 26], [12, 20], [19, 34], [6, 35], [1, 17], [11, 39], [23, 30], [11, 27], [10, 38], [22, 35], [27, 31], [28, 30], [5, 11], [11, 12], [7, 10], [2, 3], [5, 38], [1, 34], [9, 17], [1, 35], [2, 33], [15, 21], [22, 31], [12, 30], [17, 31], [2, 6], [14, 33], [21, 28], [16, 35], [7, 23], [10, 39], [20, 37], [28, 31], [19, 20], [18, 33], [10, 23], [12, 24], [21, 38], [23, 29], [12, 26], [2, 17], [23, 25], [8, 25], [4, 20], [22, 39], [23, 26], [6, 21], [19, 31], [11, 24], [5, 28], [8, 36], [3, 7], [26, 28], [10, 24], [16, 32], [7, 19], [5, 13], [9, 26], [11, 34], [15, 29], [4, 37], [11, 28], [8, 10], [15, 31], [11, 18], [2, 38], [3, 36], [1, 2], [2, 12], [18, 38], [29, 38], [32, 34], [9, 15], [9, 19], [16, 27], [4, 18], [1, 25], [1, 16], [9, 22], [5, 15], [13, 36], [17, 39], [20, 35], [0, 12], [27, 33], [30, 35], [2, 23], [12, 25], [16, 30], [16, 36], [0, 15], [0, 17]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s3/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9cbc8c867c45627c0ffbfbcaf7311a911d989979 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [16, 23, 8, 11, 18, 21, 26, 19, 0, 20, 37, 2, 34, 7, 4, 3, 6, 29, 15, 12, 1, 9, 28, 25, 39, 13, 30, 27, 22, 33, 10, 36, 5, 24, 14, 38, 31, 35, 32, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d9bd4e7522ecbfe4a0287dba22eb6d5015e2958 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges1": [[11, 39], [3, 24], [2, 31], [11, 20], [22, 36], [14, 26], [1, 11], [3, 15], [15, 31], [27, 36], [24, 39], [11, 29], [7, 36], [0, 16], [1, 13], [11, 35], [4, 14], [8, 33], [25, 31], [3, 32], [1, 18], [12, 22], [28, 37], [6, 21], [6, 25], [19, 26], [0, 39], [3, 22], [26, 37], [9, 14], [4, 29], [8, 39], [10, 14], [0, 27], [7, 9], [22, 32], [21, 39], [2, 23], [0, 5], [1, 39], [9, 32], [18, 32], [1, 30], [1, 26], [11, 32], [20, 23], [22, 26], [28, 36], [11, 19], [18, 21], [2, 7], [30, 35], [5, 35], [11, 16], [3, 4], [18, 28], [24, 30], [13, 24], [9, 10], [16, 28], [1, 17], [4, 25], [16, 37], [3, 12], [1, 23], [9, 30], [17, 18], [1, 6], [22, 35], [6, 19], [4, 35], [29, 34], [0, 26], [3, 27], [9, 19], [8, 18], [11, 15], [2, 36], [12, 38], [0, 38], [25, 32], [19, 33], [19, 30], [2, 30], [3, 19], [0, 31], [0, 20], [13, 15], [18, 36], [6, 11], [3, 33], [7, 13], [27, 29], [8, 19], [20, 39], [3, 13], [7, 12], [5, 18], [19, 23], [6, 22], [20, 37], [24, 28], [13, 30], [7, 21], [32, 35], [30, 33], [9, 37], [5, 22], [26, 39], [36, 39], [0, 29], [12, 20], [0, 37], [5, 20], [5, 16], [21, 28], [17, 35]], "edges2": [[3, 11], [17, 23], [10, 20], [28, 38], [5, 20], [10, 12], [16, 21], [6, 22], [7, 39], [16, 33], [7, 11], [4, 30], [0, 24], [15, 22], [2, 5], [17, 30], [15, 23], [13, 18], [1, 21], [8, 31], [6, 16], [16, 17], [13, 26], [8, 19], [28, 34], [2, 26], [12, 20], [19, 34], [6, 35], [1, 17], [11, 39], [23, 30], [11, 27], [10, 38], [22, 35], [27, 31], [28, 30], [5, 11], [11, 12], [7, 10], [2, 3], [5, 38], [1, 34], [9, 17], [1, 35], [2, 33], [15, 21], [22, 31], [12, 30], [17, 31], [2, 6], [14, 33], [21, 28], [16, 35], [7, 23], [10, 39], [20, 37], [28, 31], [19, 20], [18, 33], [10, 23], [12, 24], [21, 38], [23, 29], [12, 26], [2, 17], [23, 25], [8, 25], [4, 20], [22, 39], [23, 26], [6, 21], [19, 31], [11, 24], [5, 28], [8, 36], [3, 7], [26, 28], [10, 24], [16, 32], [7, 19], [5, 13], [9, 26], [11, 34], [15, 29], [4, 37], [11, 28], [8, 10], [15, 31], [11, 18], [2, 38], [3, 36], [1, 2], [2, 12], [18, 38], [29, 38], [32, 34], [9, 15], [9, 19], [16, 27], [4, 18], [1, 25], [1, 16], [9, 22], [5, 15], [13, 36], [17, 39], [20, 35], [0, 12], [27, 33], [30, 35], [2, 23], [12, 25], [16, 30], [16, 36], [0, 15], [0, 17]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b64cb8722feac4e786fc94af031919122302af6d --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges1": [[0, 23], [14, 24], [31, 35], [7, 16], [11, 34], [17, 31], [4, 24], [23, 39], [1, 18], [21, 26], [3, 29], [4, 22], [27, 28], [36, 39], [2, 22], [22, 23], [11, 22], [30, 38], [19, 35], [1, 36], [28, 33], [1, 17], [3, 38], [24, 35], [14, 28], [12, 13], [0, 6], [21, 35], [19, 34], [24, 25], [14, 21], [13, 39], [15, 35], [20, 36], [18, 33], [18, 27], [30, 34], [10, 19], [25, 29], [0, 38], [12, 29], [2, 12], [5, 39], [18, 30], [9, 35], [11, 15], [0, 16], [7, 26], [23, 33], [9, 37], [1, 5], [33, 34], [23, 38], [11, 14], [8, 26], [0, 24], [20, 32], [12, 14], [10, 17], [0, 5], [6, 28], [11, 28], [12, 26], [2, 28], [11, 27], [0, 33], [27, 34], [10, 39], [22, 35], [23, 24], [15, 28], [23, 25], [30, 33], [7, 38], [2, 38], [24, 39], [0, 8], [1, 27], [9, 38], [23, 26], [16, 24], [17, 34], [23, 29], [5, 23], [35, 38], [7, 12], [19, 31], [17, 25], [14, 31], [7, 10], [9, 14], [21, 22], [35, 37], [9, 22], [0, 34], [3, 34], [17, 18], [8, 39], [7, 31], [2, 14], [2, 4], [8, 38], [6, 8], [30, 35], [12, 20], [5, 35], [1, 16], [6, 24], [11, 13], [32, 36], [5, 11], [0, 19], [25, 35], [23, 30], [3, 15], [13, 26], [19, 38], [15, 24], [7, 29], [0, 35], [10, 29], [12, 17], [4, 33], [18, 37], [21, 28], [20, 37], [1, 3], [21, 33], [24, 37], [1, 12], [29, 31], [5, 21], [5, 30], [18, 32], [13, 34], [0, 11], [19, 28], [1, 39], [28, 37], [3, 9], [2, 31], [3, 6], [13, 18], [10, 30], [27, 31], [10, 21], [2, 32], [17, 33], [16, 30], [1, 32], [11, 36], [0, 15], [21, 32], [18, 28], [6, 7], [8, 29], [3, 39], [6, 14], [5, 31], [16, 35], [22, 38], [15, 19], [20, 31], [2, 25], [5, 6], [6, 19], [13, 22], [14, 15], [0, 37], [23, 37], [22, 34], [1, 14], [1, 22], [34, 35], [8, 13], [8, 32], [10, 18], [0, 4], [10, 22], [7, 14], [11, 12], [25, 26], [13, 30], [3, 33], [34, 39], [36, 37], [20, 29], [0, 39], [5, 34], [0, 30], [8, 30], [2, 8], [6, 32], [7, 25], [19, 36], [26, 33], [6, 26], [25, 39], [4, 21], [20, 23], [15, 31], [2, 18], [26, 36], [13, 33], [5, 29], [22, 25], [16, 36], [27, 29], [3, 19], [0, 36], [9, 15], [19, 27], [16, 27], [14, 29], [15, 32], [27, 38], [24, 27], [10, 26], [10, 16], [29, 36], [31, 34], [5, 28], [1, 37], [7, 34], [10, 11], [10, 25], [22, 29], [17, 23], [2, 7], [30, 39], [13, 21], [24, 32], [18, 26], [26, 30], [17, 35], [23, 32], [6, 25], [18, 24], [19, 33], [29, 33], [5, 38], [3, 36], [21, 30], [1, 34], [5, 20], [28, 29], [1, 15], [26, 27], [5, 12], [14, 16], [13, 25], [11, 19], [9, 16], [11, 25], [7, 13], [9, 25], [11, 23], [4, 14], [31, 32], [37, 38], [11, 21], [6, 34], [2, 11], [9, 28], [2, 6], [10, 34], [3, 4], [4, 23], [20, 24], [4, 25], [10, 24], [3, 20], [6, 30], [12, 28], [6, 37], [9, 27], [6, 27], [16, 34], [4, 32], [16, 17], [13, 27], [25, 34], [26, 34], [11, 32], [25, 33], [5, 10], [7, 9], [2, 26], [4, 19], [15, 36], [9, 34], [12, 23], [6, 38], [11, 24], [9, 33], [22, 33], [9, 18], [12, 34], [0, 14], [0, 2], [0, 26], [27, 33], [25, 28], [15, 27], [29, 32], [4, 27], [17, 20], [21, 36], [9, 23], [28, 30], [34, 37], [4, 6], [3, 26], [11, 29], [3, 7], [12, 30], [4, 28], [29, 39], [4, 13], [0, 31], [11, 26], [9, 10], [5, 33], [29, 35], [13, 15], [3, 22], [16, 26], [3, 17], [35, 39], [14, 18], [2, 15], [12, 27], [14, 26], [4, 34], [8, 22], [5, 22], [4, 20], [22, 24], [1, 25], [6, 23], [18, 31], [3, 16], [19, 23], [13, 24], [3, 10], [12, 24], [18, 25], [23, 36], [3, 30], [4, 36], [17, 32], [2, 13], [12, 22], [14, 27], [19, 32], [5, 19], [34, 38], [25, 31], [15, 37], [6, 18], [15, 39], [7, 20], [17, 24], [1, 35], [0, 1], [18, 21], [26, 29], [32, 33], [8, 12], [15, 25], [4, 11], [15, 33], [8, 14], [0, 32], [8, 10], [18, 29], [4, 17], [8, 31], [6, 35], [7, 11], [13, 19], [31, 39], [11, 16], [7, 8], [5, 24], [18, 34], [5, 36], [10, 38], [6, 29], [2, 37], [7, 18], [10, 13], [3, 35], [26, 39], [21, 37], [10, 12], [0, 18], [31, 37], [20, 22], [4, 16], [11, 30], [14, 38], [17, 26], [1, 28], [13, 31], [33, 36], [24, 34], [4, 38], [6, 13], [1, 9], [2, 36], [21, 29], [2, 16], [5, 27], [16, 25], [7, 24], [8, 27], [11, 39], [16, 18], [2, 10], [24, 30], [16, 20], [22, 30], [10, 14], [19, 29], [26, 37], [6, 20], [14, 23], [9, 12], [14, 25], [5, 13], [3, 21], [3, 27], [0, 3], [32, 34], [13, 16], [5, 37], [0, 12], [16, 19], [32, 38], [0, 21], [28, 38], [9, 39], [4, 29], [22, 36], [16, 21], [5, 32], [19, 39], [5, 8], [9, 19], [28, 36], [1, 13], [16, 38], [12, 33], [16, 29], [15, 38], [8, 33], [1, 31], [13, 28], [25, 36], [7, 33], [17, 22], [22, 32], [26, 35], [21, 34], [17, 38], [1, 30], [20, 28], [1, 6], [13, 32], [8, 20], [3, 8], [18, 36], [21, 38], [8, 18], [28, 31], [3, 12], [6, 21], [19, 20], [20, 30], [20, 25], [2, 19], [8, 35], [9, 20], [25, 32], [18, 23], [7, 19], [27, 36], [13, 14], [15, 22], [17, 39], [9, 36], [35, 36], [4, 18], [4, 26], [22, 27], [20, 39], [7, 30], [3, 24], [2, 33], [10, 37], [6, 12], [18, 39], [1, 23], [12, 19], [9, 17], [12, 18]], "edges2": [[5, 30], [31, 35], [11, 33], [18, 24], [25, 26], [19, 39], [10, 22], [16, 24], [20, 29], [10, 12], [7, 35], [6, 39], [12, 33], [2, 3], [17, 29], [24, 36], [22, 30], [24, 39], [6, 35], [2, 27], [0, 11], [5, 27], [0, 4], [32, 37], [15, 16], [21, 24], [5, 31], [3, 24], [4, 7], [4, 29], [2, 24], [10, 37], [12, 34], [20, 39], [12, 29], [24, 28], [11, 30], [16, 35], [4, 15], [25, 30], [20, 31], [18, 31], [13, 26], [35, 37], [12, 22], [25, 39], [26, 37], [8, 18], [1, 35], [8, 22], [14, 18], [7, 12], [23, 25], [28, 38], [6, 15], [3, 17], [6, 34], [6, 9], [8, 38], [26, 32], [7, 8], [8, 32], [30, 31], [17, 27], [25, 37], [1, 9], [18, 35], [9, 36], [8, 24], [17, 38], [15, 23], [4, 16], [3, 25], [14, 38], [17, 32], [1, 3], [29, 39], [7, 30], [15, 20], [11, 35], [2, 36], [19, 26], [6, 13], [3, 30], [8, 15], [1, 18], [33, 39], [21, 25], [10, 21], [25, 35], [5, 19], [24, 31], [22, 34], [0, 21], [32, 36], [1, 10], [6, 25], [2, 20], [2, 35], [32, 35], [2, 33], [15, 28], [12, 14], [27, 34], [17, 34], [7, 31], [19, 36], [2, 10], [23, 29], [7, 16], [3, 9], [19, 24], [5, 26], [6, 31], [22, 24], [21, 39], [13, 34], [11, 22], [18, 28], [5, 28], [0, 20], [28, 32], [19, 22], [10, 18], [11, 20], [22, 33], [17, 19], [0, 14], [11, 32], [11, 15], [9, 23], [8, 36], [17, 23], [4, 35], [6, 37], [25, 33], [30, 39], [6, 21], [7, 14], [0, 35], [2, 32], [4, 37], [13, 14], [3, 22], [4, 17], [3, 27], [6, 17], [15, 27], [10, 23], [9, 17], [12, 13], [0, 22], [14, 24], [10, 11], [6, 19], [5, 38], [7, 13], [18, 36], [7, 39], [22, 25], [14, 31], [30, 33], [36, 38], [11, 28], [14, 29], [10, 33], [10, 24], [12, 15], [1, 14], [13, 33], [9, 37], [25, 27], [0, 13], [2, 23], [33, 36], [0, 8], [14, 39], [28, 31], [24, 27], [7, 25], [23, 28], [8, 16], [11, 37], [25, 32], [5, 22], [8, 30], [13, 28], [6, 28], [8, 34], [8, 10], [14, 35], [31, 39], [3, 16], [2, 6], [17, 25], [31, 33], [26, 29], [2, 29], [9, 38], [5, 16], [19, 37], [0, 10], [14, 37], [20, 28], [8, 29], [20, 23], [3, 34], [17, 20], [7, 18], [35, 38], [17, 31], [1, 11], [12, 16], [16, 17], [20, 34], [34, 36], [19, 27], [37, 39], [12, 38], [9, 27], [33, 35], [10, 16], [12, 36], [10, 31], [28, 34], [4, 30], [25, 29], [6, 30], [16, 38], [3, 13], [0, 25], [4, 19], [6, 22], [14, 15], [7, 36], [19, 30], [0, 34], [13, 25], [1, 8], [12, 19], [1, 32], [3, 7], [32, 34], [13, 29], [17, 30], [21, 38], [0, 12], [9, 10], [8, 31], [5, 12], [4, 23], [13, 17], [20, 21], [2, 22], [5, 32], [22, 39], [28, 30], [1, 27], [9, 13], [22, 29], [4, 22], [27, 28], [4, 18], [4, 24], [21, 30], [14, 28], [13, 31], [5, 6], [4, 32], [21, 26], [4, 31], [0, 7], [9, 39], [28, 33], [19, 38], [3, 14], [4, 28], [16, 28], [26, 33], [6, 36], [21, 37], [19, 21], [0, 16], [15, 37], [0, 29], [3, 15], [8, 11], [18, 19], [15, 34], [17, 33], [16, 26], [11, 19], [15, 21], [7, 34], [30, 38], [3, 19], [16, 37], [13, 37], [10, 13], [7, 29], [20, 24], [7, 24], [2, 38], [9, 33], [7, 10], [16, 34], [14, 22], [4, 5], [0, 2], [4, 38], [5, 18], [21, 23], [23, 38], [2, 28], [11, 31], [30, 36], [11, 24], [27, 29], [29, 36], [5, 24], [1, 5], [0, 5], [13, 23], [21, 33], [5, 29], [12, 17], [2, 34], [1, 6], [3, 5], [12, 32], [2, 15], [11, 23], [16, 30], [23, 34], [2, 19], [8, 35], [21, 34], [7, 38], [1, 24], [2, 11], [0, 33], [6, 32], [1, 20], [13, 38], [34, 39], [9, 19], [1, 34], [3, 11], [3, 36], [7, 32], [9, 25], [8, 37], [22, 35], [11, 34], [4, 6], [0, 31], [7, 9], [5, 7], [1, 36], [13, 21], [4, 25], [35, 39], [28, 39], [3, 18], [22, 26], [8, 19], [17, 39], [8, 28], [10, 28], [1, 26], [14, 21], [6, 16], [21, 36], [7, 33], [27, 35], [1, 38], [30, 34], [18, 25], [22, 23], [3, 6], [11, 21], [15, 24], [4, 21], [1, 28], [10, 26], [16, 25], [0, 1], [19, 25], [23, 39], [17, 21], [13, 27], [6, 10], [26, 39], [5, 23], [3, 23], [5, 14], [36, 37], [24, 34], [2, 30], [10, 20], [27, 33], [6, 23], [15, 31], [18, 37], [20, 25], [0, 15], [4, 12], [1, 29], [15, 29], [4, 26], [6, 20], [16, 33], [6, 33], [14, 20], [5, 34], [29, 38], [11, 39], [4, 9], [15, 25], [23, 26], [10, 32], [22, 31], [31, 38], [10, 39], [26, 34], [8, 14], [0, 27], [3, 12], [12, 23], [18, 23], [1, 13], [2, 5], [9, 32], [2, 12], [34, 35], [9, 18], [6, 14], [32, 38], [7, 22], [17, 28], [12, 37], [0, 30], [23, 31], [2, 9], [4, 27], [16, 20], [11, 12], [29, 37], [15, 38], [9, 14], [2, 17], [20, 37], [3, 39], [15, 32], [0, 38], [14, 25], [2, 14], [18, 32], [15, 17], [15, 35], [11, 27], [21, 28], [13, 32], [28, 35], [0, 39], [12, 26], [27, 38], [16, 27], [15, 26], [9, 26], [21, 27], [3, 32], [15, 33], [14, 16], [21, 31], [4, 10], [8, 17], [32, 39], [22, 28], [0, 9], [23, 35], [34, 37], [3, 38], [14, 19], [20, 33], [12, 31], [19, 35], [2, 25], [10, 29], [6, 26], [16, 18], [24, 33], [19, 20], [6, 38], [2, 8], [20, 27], [3, 31], [13, 18], [10, 34], [16, 22], [5, 10], [11, 18], [23, 36], [33, 34], [3, 33], [7, 37], [9, 30]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..19468b052ba95ef1a7ecb447eb5d6c19c8be6cbe --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [3, 32, 24, 25, 22, 38, 2, 20, 27, 37, 21, 31, 15, 28, 11, 18, 39, 26, 34, 14, 29, 30, 4, 12, 23, 10, 33, 35, 8, 0, 17, 1, 5, 16, 6, 9, 7, 36, 19, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b64cb8722feac4e786fc94af031919122302af6d --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges1": [[0, 23], [14, 24], [31, 35], [7, 16], [11, 34], [17, 31], [4, 24], [23, 39], [1, 18], [21, 26], [3, 29], [4, 22], [27, 28], [36, 39], [2, 22], [22, 23], [11, 22], [30, 38], [19, 35], [1, 36], [28, 33], [1, 17], [3, 38], [24, 35], [14, 28], [12, 13], [0, 6], [21, 35], [19, 34], [24, 25], [14, 21], [13, 39], [15, 35], [20, 36], [18, 33], [18, 27], [30, 34], [10, 19], [25, 29], [0, 38], [12, 29], [2, 12], [5, 39], [18, 30], [9, 35], [11, 15], [0, 16], [7, 26], [23, 33], [9, 37], [1, 5], [33, 34], [23, 38], [11, 14], [8, 26], [0, 24], [20, 32], [12, 14], [10, 17], [0, 5], [6, 28], [11, 28], [12, 26], [2, 28], [11, 27], [0, 33], [27, 34], [10, 39], [22, 35], [23, 24], [15, 28], [23, 25], [30, 33], [7, 38], [2, 38], [24, 39], [0, 8], [1, 27], [9, 38], [23, 26], [16, 24], [17, 34], [23, 29], [5, 23], [35, 38], [7, 12], [19, 31], [17, 25], [14, 31], [7, 10], [9, 14], [21, 22], [35, 37], [9, 22], [0, 34], [3, 34], [17, 18], [8, 39], [7, 31], [2, 14], [2, 4], [8, 38], [6, 8], [30, 35], [12, 20], [5, 35], [1, 16], [6, 24], [11, 13], [32, 36], [5, 11], [0, 19], [25, 35], [23, 30], [3, 15], [13, 26], [19, 38], [15, 24], [7, 29], [0, 35], [10, 29], [12, 17], [4, 33], [18, 37], [21, 28], [20, 37], [1, 3], [21, 33], [24, 37], [1, 12], [29, 31], [5, 21], [5, 30], [18, 32], [13, 34], [0, 11], [19, 28], [1, 39], [28, 37], [3, 9], [2, 31], [3, 6], [13, 18], [10, 30], [27, 31], [10, 21], [2, 32], [17, 33], [16, 30], [1, 32], [11, 36], [0, 15], [21, 32], [18, 28], [6, 7], [8, 29], [3, 39], [6, 14], [5, 31], [16, 35], [22, 38], [15, 19], [20, 31], [2, 25], [5, 6], [6, 19], [13, 22], [14, 15], [0, 37], [23, 37], [22, 34], [1, 14], [1, 22], [34, 35], [8, 13], [8, 32], [10, 18], [0, 4], [10, 22], [7, 14], [11, 12], [25, 26], [13, 30], [3, 33], [34, 39], [36, 37], [20, 29], [0, 39], [5, 34], [0, 30], [8, 30], [2, 8], [6, 32], [7, 25], [19, 36], [26, 33], [6, 26], [25, 39], [4, 21], [20, 23], [15, 31], [2, 18], [26, 36], [13, 33], [5, 29], [22, 25], [16, 36], [27, 29], [3, 19], [0, 36], [9, 15], [19, 27], [16, 27], [14, 29], [15, 32], [27, 38], [24, 27], [10, 26], [10, 16], [29, 36], [31, 34], [5, 28], [1, 37], [7, 34], [10, 11], [10, 25], [22, 29], [17, 23], [2, 7], [30, 39], [13, 21], [24, 32], [18, 26], [26, 30], [17, 35], [23, 32], [6, 25], [18, 24], [19, 33], [29, 33], [5, 38], [3, 36], [21, 30], [1, 34], [5, 20], [28, 29], [1, 15], [26, 27], [5, 12], [14, 16], [13, 25], [11, 19], [9, 16], [11, 25], [7, 13], [9, 25], [11, 23], [4, 14], [31, 32], [37, 38], [11, 21], [6, 34], [2, 11], [9, 28], [2, 6], [10, 34], [3, 4], [4, 23], [20, 24], [4, 25], [10, 24], [3, 20], [6, 30], [12, 28], [6, 37], [9, 27], [6, 27], [16, 34], [4, 32], [16, 17], [13, 27], [25, 34], [26, 34], [11, 32], [25, 33], [5, 10], [7, 9], [2, 26], [4, 19], [15, 36], [9, 34], [12, 23], [6, 38], [11, 24], [9, 33], [22, 33], [9, 18], [12, 34], [0, 14], [0, 2], [0, 26], [27, 33], [25, 28], [15, 27], [29, 32], [4, 27], [17, 20], [21, 36], [9, 23], [28, 30], [34, 37], [4, 6], [3, 26], [11, 29], [3, 7], [12, 30], [4, 28], [29, 39], [4, 13], [0, 31], [11, 26], [9, 10], [5, 33], [29, 35], [13, 15], [3, 22], [16, 26], [3, 17], [35, 39], [14, 18], [2, 15], [12, 27], [14, 26], [4, 34], [8, 22], [5, 22], [4, 20], [22, 24], [1, 25], [6, 23], [18, 31], [3, 16], [19, 23], [13, 24], [3, 10], [12, 24], [18, 25], [23, 36], [3, 30], [4, 36], [17, 32], [2, 13], [12, 22], [14, 27], [19, 32], [5, 19], [34, 38], [25, 31], [15, 37], [6, 18], [15, 39], [7, 20], [17, 24], [1, 35], [0, 1], [18, 21], [26, 29], [32, 33], [8, 12], [15, 25], [4, 11], [15, 33], [8, 14], [0, 32], [8, 10], [18, 29], [4, 17], [8, 31], [6, 35], [7, 11], [13, 19], [31, 39], [11, 16], [7, 8], [5, 24], [18, 34], [5, 36], [10, 38], [6, 29], [2, 37], [7, 18], [10, 13], [3, 35], [26, 39], [21, 37], [10, 12], [0, 18], [31, 37], [20, 22], [4, 16], [11, 30], [14, 38], [17, 26], [1, 28], [13, 31], [33, 36], [24, 34], [4, 38], [6, 13], [1, 9], [2, 36], [21, 29], [2, 16], [5, 27], [16, 25], [7, 24], [8, 27], [11, 39], [16, 18], [2, 10], [24, 30], [16, 20], [22, 30], [10, 14], [19, 29], [26, 37], [6, 20], [14, 23], [9, 12], [14, 25], [5, 13], [3, 21], [3, 27], [0, 3], [32, 34], [13, 16], [5, 37], [0, 12], [16, 19], [32, 38], [0, 21], [28, 38], [9, 39], [4, 29], [22, 36], [16, 21], [5, 32], [19, 39], [5, 8], [9, 19], [28, 36], [1, 13], [16, 38], [12, 33], [16, 29], [15, 38], [8, 33], [1, 31], [13, 28], [25, 36], [7, 33], [17, 22], [22, 32], [26, 35], [21, 34], [17, 38], [1, 30], [20, 28], [1, 6], [13, 32], [8, 20], [3, 8], [18, 36], [21, 38], [8, 18], [28, 31], [3, 12], [6, 21], [19, 20], [20, 30], [20, 25], [2, 19], [8, 35], [9, 20], [25, 32], [18, 23], [7, 19], [27, 36], [13, 14], [15, 22], [17, 39], [9, 36], [35, 36], [4, 18], [4, 26], [22, 27], [20, 39], [7, 30], [3, 24], [2, 33], [10, 37], [6, 12], [18, 39], [1, 23], [12, 19], [9, 17], [12, 18]], "edges2": [[5, 30], [31, 35], [11, 33], [18, 24], [25, 26], [19, 39], [10, 22], [16, 24], [20, 29], [10, 12], [7, 35], [6, 39], [12, 33], [2, 3], [17, 29], [24, 36], [22, 30], [24, 39], [6, 35], [2, 27], [0, 11], [5, 27], [0, 4], [32, 37], [15, 16], [21, 24], [5, 31], [3, 24], [4, 7], [4, 29], [2, 24], [10, 37], [12, 34], [20, 39], [12, 29], [24, 28], [11, 30], [16, 35], [4, 15], [25, 30], [20, 31], [18, 31], [13, 26], [35, 37], [12, 22], [25, 39], [26, 37], [8, 18], [1, 35], [8, 22], [14, 18], [7, 12], [23, 25], [28, 38], [6, 15], [3, 17], [6, 34], [6, 9], [8, 38], [26, 32], [7, 8], [8, 32], [30, 31], [17, 27], [25, 37], [1, 9], [18, 35], [9, 36], [8, 24], [17, 38], [15, 23], [4, 16], [3, 25], [14, 38], [17, 32], [1, 3], [29, 39], [7, 30], [15, 20], [11, 35], [2, 36], [19, 26], [6, 13], [3, 30], [8, 15], [1, 18], [33, 39], [21, 25], [10, 21], [25, 35], [5, 19], [24, 31], [22, 34], [0, 21], [32, 36], [1, 10], [6, 25], [2, 20], [2, 35], [32, 35], [2, 33], [15, 28], [12, 14], [27, 34], [17, 34], [7, 31], [19, 36], [2, 10], [23, 29], [7, 16], [3, 9], [19, 24], [5, 26], [6, 31], [22, 24], [21, 39], [13, 34], [11, 22], [18, 28], [5, 28], [0, 20], [28, 32], [19, 22], [10, 18], [11, 20], [22, 33], [17, 19], [0, 14], [11, 32], [11, 15], [9, 23], [8, 36], [17, 23], [4, 35], [6, 37], [25, 33], [30, 39], [6, 21], [7, 14], [0, 35], [2, 32], [4, 37], [13, 14], [3, 22], [4, 17], [3, 27], [6, 17], [15, 27], [10, 23], [9, 17], [12, 13], [0, 22], [14, 24], [10, 11], [6, 19], [5, 38], [7, 13], [18, 36], [7, 39], [22, 25], [14, 31], [30, 33], [36, 38], [11, 28], [14, 29], [10, 33], [10, 24], [12, 15], [1, 14], [13, 33], [9, 37], [25, 27], [0, 13], [2, 23], [33, 36], [0, 8], [14, 39], [28, 31], [24, 27], [7, 25], [23, 28], [8, 16], [11, 37], [25, 32], [5, 22], [8, 30], [13, 28], [6, 28], [8, 34], [8, 10], [14, 35], [31, 39], [3, 16], [2, 6], [17, 25], [31, 33], [26, 29], [2, 29], [9, 38], [5, 16], [19, 37], [0, 10], [14, 37], [20, 28], [8, 29], [20, 23], [3, 34], [17, 20], [7, 18], [35, 38], [17, 31], [1, 11], [12, 16], [16, 17], [20, 34], [34, 36], [19, 27], [37, 39], [12, 38], [9, 27], [33, 35], [10, 16], [12, 36], [10, 31], [28, 34], [4, 30], [25, 29], [6, 30], [16, 38], [3, 13], [0, 25], [4, 19], [6, 22], [14, 15], [7, 36], [19, 30], [0, 34], [13, 25], [1, 8], [12, 19], [1, 32], [3, 7], [32, 34], [13, 29], [17, 30], [21, 38], [0, 12], [9, 10], [8, 31], [5, 12], [4, 23], [13, 17], [20, 21], [2, 22], [5, 32], [22, 39], [28, 30], [1, 27], [9, 13], [22, 29], [4, 22], [27, 28], [4, 18], [4, 24], [21, 30], [14, 28], [13, 31], [5, 6], [4, 32], [21, 26], [4, 31], [0, 7], [9, 39], [28, 33], [19, 38], [3, 14], [4, 28], [16, 28], [26, 33], [6, 36], [21, 37], [19, 21], [0, 16], [15, 37], [0, 29], [3, 15], [8, 11], [18, 19], [15, 34], [17, 33], [16, 26], [11, 19], [15, 21], [7, 34], [30, 38], [3, 19], [16, 37], [13, 37], [10, 13], [7, 29], [20, 24], [7, 24], [2, 38], [9, 33], [7, 10], [16, 34], [14, 22], [4, 5], [0, 2], [4, 38], [5, 18], [21, 23], [23, 38], [2, 28], [11, 31], [30, 36], [11, 24], [27, 29], [29, 36], [5, 24], [1, 5], [0, 5], [13, 23], [21, 33], [5, 29], [12, 17], [2, 34], [1, 6], [3, 5], [12, 32], [2, 15], [11, 23], [16, 30], [23, 34], [2, 19], [8, 35], [21, 34], [7, 38], [1, 24], [2, 11], [0, 33], [6, 32], [1, 20], [13, 38], [34, 39], [9, 19], [1, 34], [3, 11], [3, 36], [7, 32], [9, 25], [8, 37], [22, 35], [11, 34], [4, 6], [0, 31], [7, 9], [5, 7], [1, 36], [13, 21], [4, 25], [35, 39], [28, 39], [3, 18], [22, 26], [8, 19], [17, 39], [8, 28], [10, 28], [1, 26], [14, 21], [6, 16], [21, 36], [7, 33], [27, 35], [1, 38], [30, 34], [18, 25], [22, 23], [3, 6], [11, 21], [15, 24], [4, 21], [1, 28], [10, 26], [16, 25], [0, 1], [19, 25], [23, 39], [17, 21], [13, 27], [6, 10], [26, 39], [5, 23], [3, 23], [5, 14], [36, 37], [24, 34], [2, 30], [10, 20], [27, 33], [6, 23], [15, 31], [18, 37], [20, 25], [0, 15], [4, 12], [1, 29], [15, 29], [4, 26], [6, 20], [16, 33], [6, 33], [14, 20], [5, 34], [29, 38], [11, 39], [4, 9], [15, 25], [23, 26], [10, 32], [22, 31], [31, 38], [10, 39], [26, 34], [8, 14], [0, 27], [3, 12], [12, 23], [18, 23], [1, 13], [2, 5], [9, 32], [2, 12], [34, 35], [9, 18], [6, 14], [32, 38], [7, 22], [17, 28], [12, 37], [0, 30], [23, 31], [2, 9], [4, 27], [16, 20], [11, 12], [29, 37], [15, 38], [9, 14], [2, 17], [20, 37], [3, 39], [15, 32], [0, 38], [14, 25], [2, 14], [18, 32], [15, 17], [15, 35], [11, 27], [21, 28], [13, 32], [28, 35], [0, 39], [12, 26], [27, 38], [16, 27], [15, 26], [9, 26], [21, 27], [3, 32], [15, 33], [14, 16], [21, 31], [4, 10], [8, 17], [32, 39], [22, 28], [0, 9], [23, 35], [34, 37], [3, 38], [14, 19], [20, 33], [12, 31], [19, 35], [2, 25], [10, 29], [6, 26], [16, 18], [24, 33], [19, 20], [6, 38], [2, 8], [20, 27], [3, 31], [13, 18], [10, 34], [16, 22], [5, 10], [11, 18], [23, 36], [33, 34], [3, 33], [7, 37], [9, 30]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s0/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s0/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fdf5f90fd3c7e38a2704a0406526b27139bef290 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["11", "11"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s0/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4c247301926b1e010808935453663851c72024b1 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["11", "11"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s0/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-s0/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fdf5f90fd3c7e38a2704a0406526b27139bef290 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["11", "11"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s2/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l2-s2/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..037ff6beb1e4ebd2fec0b7bdbbba2e30ae322e7b --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["11111", "01100", "00011"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s2/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b126372516e26de7656e257dbaced5e6bbeccbe --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["11110", "10010", "01101"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l2-s2/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-l2-s2/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..037ff6beb1e4ebd2fec0b7bdbbba2e30ae322e7b --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["11111", "01100", "00011"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l2-s2/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l2-s5/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l2-s5/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41e530eb6bc1b87a8c14a34567c1498521453d34 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["000", "111", "100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s5/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6e14e6f8ede5f90bb441f6f44610acc4e902e11b --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["001", "011", "010"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41e530eb6bc1b87a8c14a34567c1498521453d34 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["000", "111", "100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l2-s5/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l6-s3/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s3/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddb7cea2eb0b960205debb30b3c65faca2d42008 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["00011000010110111", "00100100100011010", "01011001000000000", "10100000010111110", "10110101110011000", "01110110000000101", "00110111010000001", "01110110010000000"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s3/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..752008e92eaf720eb35d5df07d0e107abe5e13f6 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"grid": ["00000000001000010", "00011000001010000", "00000000110000000", "01000000000010000", "01000000100000110", "00010100000000001", "00000000100000000", "00100010100000000"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddb7cea2eb0b960205debb30b3c65faca2d42008 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["00011000010110111", "00100100100011010", "01011001000000000", "10100000010111110", "10110101110011000", "01110110000000101", "00110111010000001", "01110110010000000"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ee70819bd186e99ad471edc6b60bd6acbcb2e1c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["0111000110", "0010010000", "1010000010", "1110111000", "0111110111", "1111000000", "0101010000", "1101100100", "1101010100", "0101011110", "1011101011", "1001111111", "1011010001", "1110110001", "1001110011", "1100110000", "0101100001", "1101101001", "1010011001", "0100100011", "1101110101", "1110000010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..69be4a0fad07a20b41792d8f45b413291f2c4455 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"grid": ["0010000100", "0000001000", "0000001000", "1010010110", "0101000001", "0000000010", "1010000110", "1110011011", "0010000010", "0100001000", "1001000000", "0000000011", "0000111011", "1010000010", "0101001101", "1110000000", "1100111101", "1000111000", "1100000000", "0000100001", "1001010000", "0010001100"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ee70819bd186e99ad471edc6b60bd6acbcb2e1c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["0111000110", "0010010000", "1010000010", "1110111000", "0111110111", "1111000000", "0101010000", "1101100100", "1101010100", "0101011110", "1011101011", "1001111111", "1011010001", "1110110001", "1001110011", "1100110000", "0101100001", "1101101001", "1010011001", "0100100011", "1101110101", "1110000010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s7/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l3-s7/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e804399ad22cf2f2a107376eea2bc2116ee3c4f3 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[4, 10], [9, 0], [3, 8], [0, 4], [11, 0], [10, 13], [11, 12], [6, 7], [9, 8], [2, 12], [4, 11], [7, 11], [5, 2]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s7/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5bf9bd1afffef45341e77412bf2c76dc17e8cbd7 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [0, 10, 11, 8, 4, 1, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s7/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-s7/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e804399ad22cf2f2a107376eea2bc2116ee3c4f3 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[4, 10], [9, 0], [3, 8], [0, 4], [11, 0], [10, 13], [11, 12], [6, 7], [9, 8], [2, 12], [4, 11], [7, 11], [5, 2]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l3-s7/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l4-s3/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s3/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d26f7a1b20958f4364148bbedfd24ce4a9e338c3 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[5, 15], [15, 11], [2, 4], [3, 8], [1, 15], [6, 11], [0, 0], [14, 17], [18, 0], [15, 13], [3, 10], [7, 3], [1, 17], [6, 13], [14, 3], [13, 6], [13, 2], [18, 8]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s3/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..890d52babd001f30c3adaa3547c046eae49350c6 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 3, 5, 7, 9, 1, 14, 16, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d26f7a1b20958f4364148bbedfd24ce4a9e338c3 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[5, 15], [15, 11], [2, 4], [3, 8], [1, 15], [6, 11], [0, 0], [14, 17], [18, 0], [15, 13], [3, 10], [7, 3], [1, 17], [6, 13], [14, 3], [13, 6], [13, 2], [18, 8]], "k": 9, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s4/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s4/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5846936db0dd448642ec4773bda4cb75161f460b --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 12], [18, 1], [5, 11], [12, 10], [0, 13], [6, 14], [13, 10], [7, 13], [17, 9], [14, 16], [0, 12], [18, 3], [8, 3], [8, 9], [5, 0], [6, 6], [17, 11], [4, 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-l4-s4/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3c8035cc058825e755a33ecfa752685991f7a2a1 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [0, 5, 9, 8, 11, 1, 15, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5846936db0dd448642ec4773bda4cb75161f460b --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 12], [18, 1], [5, 11], [12, 10], [0, 13], [6, 14], [13, 10], [7, 13], [17, 9], [14, 16], [0, 12], [18, 3], [8, 3], [8, 9], [5, 0], [6, 6], [17, 11], [4, 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-l4-s4/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-rectangle-l1-s7/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l1-s7/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cb561c4bf9600dc1a00ba2bad59e44c6d58f910 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-2, -3], [3, 3], [0, -3], [-2, -1], [-2, -5], [0, -5]], "area": 4, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s7/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fd28d7886db97b51cd5b2dedc509ced98881db22 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [0, 2, 5, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l1-s7/tests/check.py b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-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-l1-s7/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5cb561c4bf9600dc1a00ba2bad59e44c6d58f910 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-2, -3], [3, 3], [0, -3], [-2, -1], [-2, -5], [0, -5]], "area": 4, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l1-s7/tests/run.py b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l1-s7/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l2-s2/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l2-s2/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57b7ed580cf73a9c397bca07666d335fc273da18 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-10, -2], [0, -2], [2, 0], [-9, -8], [-2, 0], [-4, 7], [6, 5], [5, 9], [0, 2], [-5, -7]], "area": 8, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l2-s2/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e817dc3a4726b43bf2649048fd9ac7d5bcd8cb14 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 2, 8, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l2-s2/tests/check.py b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/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-l2-s2/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57b7ed580cf73a9c397bca07666d335fc273da18 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-10, -2], [0, -2], [2, 0], [-9, -8], [-2, 0], [-4, 7], [6, 5], [5, 9], [0, 2], [-5, -7]], "area": 8, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l2-s2/tests/run.py b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l2-s2/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2145ed94c952908957d7a6582c3fe0d602a25f4 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-7, 5], [9, -5], [5, -1], [-10, -1], [9, -1], [3, -9], [-7, -5], [7, 7], [5, -5], [4, -8]], "area": 16, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..15f48768c9a090856f318671a8ba0539d70a275a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 4, 2, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/tests/check.py b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2145ed94c952908957d7a6582c3fe0d602a25f4 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-7, 5], [9, -5], [5, -1], [-10, -1], [9, -1], [3, -9], [-7, -5], [7, 7], [5, -5], [4, -8]], "area": 16, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/tests/run.py b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l2-s5/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l5-s1/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s1/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..47606902aa862763d68e3e7961ed7aa480f29593 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-23, 21], [0, -23], [-25, 12], [6, 19], [17, 38], [-21, -27], [-6, 23], [5, 17], [6, 17], [1, 29], [-37, -7], [-9, 36], [12, -13], [18, 25], [15, 16], [9, 28], [10, -13], [25, 25], [15, -14], [-6, -40], [-31, 38], [-26, 32], [-39, -37], [-15, -15], [12, 8], [-11, 13], [18, 15], [-7, 36], [-7, -20], [-38, 10], [-40, -21], [-31, -28], [-35, 4], [-36, -10], [28, -34], [31, -11], [25, 2], [-7, -9], [-9, -12], [-22, 5]], "area": 90, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s1/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..06bf0afc15da1522244a11289ac18a17ebc32776 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [3, 14, 13, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l5-s1/tests/check.py b/tasks/construct-rlve-largest-rectangle-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-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-l5-s1/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..47606902aa862763d68e3e7961ed7aa480f29593 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-23, 21], [0, -23], [-25, 12], [6, 19], [17, 38], [-21, -27], [-6, 23], [5, 17], [6, 17], [1, 29], [-37, -7], [-9, 36], [12, -13], [18, 25], [15, 16], [9, 28], [10, -13], [25, 25], [15, -14], [-6, -40], [-31, 38], [-26, 32], [-39, -37], [-15, -15], [12, 8], [-11, 13], [18, 15], [-7, 36], [-7, -20], [-38, 10], [-40, -21], [-31, -28], [-35, 4], [-36, -10], [28, -34], [31, -11], [25, 2], [-7, -9], [-9, -12], [-22, 5]], "area": 90, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l5-s1/tests/run.py b/tasks/construct-rlve-largest-rectangle-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l5-s1/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l6-s3/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l6-s3/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa0fb2f0dff972b910c6d4b08e59b4e0562cc0ef --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-7, -60], [-4, 9], [17, 6], [47, -21], [20, 52], [-55, -40], [-23, 59], [23, 18], [13, -46], [-35, 54], [-50, -22], [54, -5], [-3, -15], [-54, -44], [-9, -50], [26, 25], [44, 33], [18, -21], [-9, -45], [37, -40], [60, -43], [15, -24], [-49, 51], [-51, -23], [-12, 23], [19, -15], [19, 28], [12, -53], [-27, -24], [-31, 22], [-21, -47], [7, -33], [33, -16], [22, -3], [-57, 35], [-13, -25], [21, 19], [-58, -44], [-45, 8], [42, -3], [-1, -12], [33, 13], [-16, -6], [-35, 24], [0, 41], [-57, 43], [-49, -19], [-56, 40], [59, 44], [-44, -43], [-33, -17], [-13, 39], [-57, -18], [-42, -30], [-38, -51], [-31, 43], [5, -56], [22, -50], [16, 21], [-52, -48]], "area": 58, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l6-s3/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9dbab4be4dc4d79df38f1a7c4cea2d16cc881328 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [7, 15, 26, 58]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l6-s3/tests/check.py b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l6-s3/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa0fb2f0dff972b910c6d4b08e59b4e0562cc0ef --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-7, -60], [-4, 9], [17, 6], [47, -21], [20, 52], [-55, -40], [-23, 59], [23, 18], [13, -46], [-35, 54], [-50, -22], [54, -5], [-3, -15], [-54, -44], [-9, -50], [26, 25], [44, 33], [18, -21], [-9, -45], [37, -40], [60, -43], [15, -24], [-49, 51], [-51, -23], [-12, 23], [19, -15], [19, 28], [12, -53], [-27, -24], [-31, 22], [-21, -47], [7, -33], [33, -16], [22, -3], [-57, 35], [-13, -25], [21, 19], [-58, -44], [-45, 8], [42, -3], [-1, -12], [33, 13], [-16, -6], [-35, 24], [0, 41], [-57, 43], [-49, -19], [-56, 40], [59, 44], [-44, -43], [-33, -17], [-13, 39], [-57, -18], [-42, -30], [-38, -51], [-31, 43], [5, -56], [22, -50], [16, 21], [-52, -48]], "area": 58, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l6-s3/tests/run.py b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l6-s3/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4dd7f35b3e1232eedc70a37caeb322e31edea990 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-47, 25], [-11, -57], [-11, -16], [15, 1], [59, 44], [-34, 9], [-16, -57], [-54, -27], [11, -48], [54, 5], [-38, 52], [11, -18], [-8, 11], [-47, 57], [43, -5], [-1, -42], [23, -39], [39, 18], [-59, 16], [4, -27], [22, 24], [-20, -19], [9, 15], [43, 56], [-27, 12], [17, 46], [59, 60], [-23, -36], [50, -48], [-38, -8], [-58, 5], [11, -52], [-46, 41], [32, 12], [-58, 18], [27, 10], [0, -28], [-24, -8], [32, 36], [9, 42], [-24, 49], [7, 17], [-34, 50], [-39, -7], [13, -5], [-50, -28], [-17, 39], [-53, -47], [19, -41], [13, 0], [-8, 0], [0, 49], [-42, -8], [-3, 10], [47, -27], [9, 22], [-12, 49], [38, -45], [-53, -21], [50, -3]], "area": 630, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..324268e88fa3b23bb8ef3406ddaa2982dd99f486 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [6, 8, 19, 27]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/tests/check.py b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4dd7f35b3e1232eedc70a37caeb322e31edea990 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-47, 25], [-11, -57], [-11, -16], [15, 1], [59, 44], [-34, 9], [-16, -57], [-54, -27], [11, -48], [54, 5], [-38, 52], [11, -18], [-8, 11], [-47, 57], [43, -5], [-1, -42], [23, -39], [39, 18], [-59, 16], [4, -27], [22, 24], [-20, -19], [9, 15], [43, 56], [-27, 12], [17, 46], [59, 60], [-23, -36], [50, -48], [-38, -8], [-58, 5], [11, -52], [-46, 41], [32, 12], [-58, 18], [27, 10], [0, -28], [-24, -8], [32, 36], [9, 42], [-24, 49], [7, 17], [-34, 50], [-39, -7], [13, -5], [-50, -28], [-17, 39], [-53, -47], [19, -41], [13, 0], [-8, 0], [0, 49], [-42, -8], [-3, 10], [47, -27], [9, 22], [-12, 49], [38, -45], [-53, -21], [50, -3]], "area": 630, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/tests/run.py b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l6-s4/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s2/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l4-s2/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d0ef6ea299e91e3a125fe18c3eef4503dbe73f5f --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 7, "edges": [[0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [1, 2], [1, 5], [1, 6], [1, 8], [1, 10], [2, 5], [2, 8], [2, 11], [3, 6], [3, 7], [3, 8], [4, 8], [4, 9], [4, 10], [5, 6], [5, 9], [5, 10], [5, 11], [6, 7], [6, 8], [7, 9], [7, 11], [8, 10], [8, 11], [9, 10], [9, 11]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s2/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..770ce3511a22b5f91302ca21a4f8a13670893925 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 0, 2, 3, 2, 3, 4, 4, 5, 6, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d0ef6ea299e91e3a125fe18c3eef4503dbe73f5f --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 7, "edges": [[0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [1, 2], [1, 5], [1, 6], [1, 8], [1, 10], [2, 5], [2, 8], [2, 11], [3, 6], [3, 7], [3, 8], [4, 8], [4, 9], [4, 10], [5, 6], [5, 9], [5, 10], [5, 11], [6, 7], [6, 8], [7, 9], [7, 11], [8, 10], [8, 11], [9, 10], [9, 11]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l4-s2/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l4-s5/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s5/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a0f7028f5a9359e44e294084e37111f9ab0c916 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 7, "edges": [[0, 2], [0, 3], [0, 7], [0, 9], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [2, 3], [2, 4], [2, 6], [2, 10], [3, 7], [3, 8], [3, 9], [3, 11], [4, 5], [4, 6], [4, 9], [4, 10], [4, 11], [5, 7], [5, 9], [5, 11], [6, 7], [6, 8], [6, 9], [6, 11], [8, 9], [9, 10], [9, 11], [10, 11]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s5/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..683399d7beffea8cd860093838bb5ab23a0a2adb --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 0, 1, 2, 2, 1, 3, 4, 5, 6, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a0f7028f5a9359e44e294084e37111f9ab0c916 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 7, "edges": [[0, 2], [0, 3], [0, 7], [0, 9], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [2, 3], [2, 4], [2, 6], [2, 10], [3, 7], [3, 8], [3, 9], [3, 11], [4, 5], [4, 6], [4, 9], [4, 10], [4, 11], [5, 7], [5, 9], [5, 11], [6, 7], [6, 8], [6, 9], [6, 11], [8, 9], [9, 10], [9, 11], [10, 11]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..80a23b7e163dd4a13f33beeacfc417bb7b4b83cd --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 3, "edges": [[0, 2], [0, 3], [2, 3]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9647e9e6eb16ddcbbb54db57a2379bb1a16d597c --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 2, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..80a23b7e163dd4a13f33beeacfc417bb7b4b83cd --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 3, "edges": [[0, 2], [0, 3], [2, 3]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0015b761eb48d5901045060a902b4ef8003961eb --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 3, "edges": [[0, 2], [1, 2], [1, 3], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..68b3339e5efe327315a1c785d186c3228fd36bc6 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 1, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0015b761eb48d5901045060a902b4ef8003961eb --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 3, "edges": [[0, 2], [1, 2], [1, 3], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s6/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s6/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c40b84b138ba19f5942366d8d6f42816aa6944 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 5], [2, 6], [2, 9], [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 9], [6, 7], [7, 8], [7, 9]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s6/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..be4a433d78cfe26382f65dc13cd59cf344f56818 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 3, 4, 4, 5, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-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-l2-s6/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8c40b84b138ba19f5942366d8d6f42816aa6944 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [2, 3], [2, 5], [2, 6], [2, 9], [3, 4], [3, 5], [3, 6], [3, 7], [3, 9], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 9], [6, 7], [7, 8], [7, 9]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s6/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s8/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s8/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b0950995eb466e27630c0afbd11c2da37de3b56 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 3, "edges": [[0, 1], [0, 5], [0, 6], [2, 3], [2, 7], [2, 8], [3, 5], [3, 8], [4, 7], [4, 9], [7, 9]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s8/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e70edc9a69983ce553c29877f035b85b35cfa61c --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 0, 2, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s8/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-s8/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b0950995eb466e27630c0afbd11c2da37de3b56 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 3, "edges": [[0, 1], [0, 5], [0, 6], [2, 3], [2, 7], [2, 8], [3, 5], [3, 8], [4, 7], [4, 9], [7, 9]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s8/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l5-s2/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s2/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d37cae6f7c16391bb6b12517ce91748e42034f67 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "k": 8, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 7], [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, 23], [1, 3], [1, 5], [1, 6], [1, 7], [1, 10], [1, 11], [1, 13], [1, 14], [1, 17], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [3, 6], [3, 8], [3, 9], [3, 11], [3, 13], [3, 14], [3, 15], [3, 18], [3, 19], [3, 22], [4, 6], [4, 8], [4, 11], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 21], [6, 22], [6, 23], [7, 8], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 22], [7, 23], [8, 11], [8, 12], [8, 14], [8, 15], [8, 16], [8, 19], [8, 20], [8, 21], [8, 23], [9, 13], [9, 14], [9, 16], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [10, 11], [10, 12], [10, 13], [10, 14], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 13], [11, 15], [11, 17], [11, 18], [11, 21], [11, 23], [12, 14], [12, 15], [12, 19], [12, 20], [12, 23], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [14, 16], [14, 17], [14, 20], [14, 21], [15, 16], [15, 17], [15, 23], [16, 17], [16, 18], [16, 20], [16, 22], [16, 23], [17, 18], [17, 21], [17, 22], [17, 23], [18, 21], [18, 22], [18, 23], [19, 20], [19, 22], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s2/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..837529905be6f6c8e2cac919bf7b982e10316e1c --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 0, 1, 1, 2, 2, 3, 3, 0, 2, 4, 5, 2, 3, 5, 4, 6, 7, 4, 6, 7, 6, 5, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d37cae6f7c16391bb6b12517ce91748e42034f67 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "k": 8, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 7], [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, 23], [1, 3], [1, 5], [1, 6], [1, 7], [1, 10], [1, 11], [1, 13], [1, 14], [1, 17], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [3, 6], [3, 8], [3, 9], [3, 11], [3, 13], [3, 14], [3, 15], [3, 18], [3, 19], [3, 22], [4, 6], [4, 8], [4, 11], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [6, 15], [6, 16], [6, 17], [6, 19], [6, 21], [6, 22], [6, 23], [7, 8], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 22], [7, 23], [8, 11], [8, 12], [8, 14], [8, 15], [8, 16], [8, 19], [8, 20], [8, 21], [8, 23], [9, 13], [9, 14], [9, 16], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [10, 11], [10, 12], [10, 13], [10, 14], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 13], [11, 15], [11, 17], [11, 18], [11, 21], [11, 23], [12, 14], [12, 15], [12, 19], [12, 20], [12, 23], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [14, 16], [14, 17], [14, 20], [14, 21], [15, 16], [15, 17], [15, 23], [16, 17], [16, 18], [16, 20], [16, 22], [16, 23], [17, 18], [17, 21], [17, 22], [17, 23], [18, 21], [18, 22], [18, 23], [19, 20], [19, 22], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5e1008743d0269c78b41335bc69078a6bf4be8da --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "k": 9, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 11], [0, 12], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [1, 2], [1, 4], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 21], [1, 22], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 7], [5, 9], [5, 11], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 11], [6, 13], [6, 14], [6, 15], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [7, 8], [7, 9], [7, 10], [7, 13], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 23], [8, 9], [8, 10], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [9, 10], [9, 11], [9, 14], [9, 15], [9, 17], [9, 18], [9, 21], [9, 22], [9, 23], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 23], [11, 12], [11, 18], [11, 20], [11, 22], [12, 13], [12, 14], [12, 15], [12, 16], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 17], [14, 18], [14, 20], [14, 22], [15, 16], [15, 17], [15, 18], [15, 21], [15, 22], [15, 23], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [19, 21], [19, 22], [19, 23], [20, 21], [20, 23], [21, 22], [22, 23]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..850df44d96f2e7f6bb1a23bd50e7c43361f0175f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 2, 1, 3, 4, 5, 6, 4, 0, 5, 2, 4, 0, 2, 7, 8, 8, 3, 7, 7, 5, 6, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5e1008743d0269c78b41335bc69078a6bf4be8da --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "k": 9, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 11], [0, 12], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [1, 2], [1, 4], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 21], [1, 22], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 7], [5, 9], [5, 11], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 11], [6, 13], [6, 14], [6, 15], [6, 17], [6, 18], [6, 19], [6, 20], [6, 22], [7, 8], [7, 9], [7, 10], [7, 13], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 23], [8, 9], [8, 10], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [9, 10], [9, 11], [9, 14], [9, 15], [9, 17], [9, 18], [9, 21], [9, 22], [9, 23], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 23], [11, 12], [11, 18], [11, 20], [11, 22], [12, 13], [12, 14], [12, 15], [12, 16], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 17], [14, 18], [14, 20], [14, 22], [15, 16], [15, 17], [15, 18], [15, 21], [15, 22], [15, 23], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [19, 21], [19, 22], [19, 23], [20, 21], [20, 23], [21, 22], [22, 23]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s9/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s9/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a6b31de4572d53ae73ad322944b8cc2beb3bfe0 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 7, "edges": [[0, 4], [0, 9], [0, 14], [0, 17], [0, 18], [0, 19], [0, 22], [0, 24], [0, 25], [0, 26], [0, 28], [0, 29], [1, 3], [1, 5], [1, 8], [1, 19], [1, 21], [1, 23], [1, 27], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [2, 11], [2, 13], [2, 14], [2, 15], [2, 17], [2, 19], [2, 20], [2, 21], [2, 24], [2, 25], [2, 26], [2, 29], [3, 9], [3, 13], [3, 21], [3, 24], [3, 25], [4, 5], [4, 7], [4, 10], [4, 11], [4, 12], [4, 15], [4, 18], [4, 20], [4, 25], [4, 26], [4, 28], [4, 29], [5, 6], [5, 8], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 18], [5, 22], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [6, 7], [6, 11], [6, 13], [6, 20], [6, 21], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 17], [7, 19], [7, 20], [7, 22], [7, 25], [7, 26], [7, 27], [8, 10], [8, 12], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 27], [8, 28], [9, 10], [9, 11], [9, 12], [9, 13], [9, 16], [9, 25], [9, 28], [9, 29], [10, 18], [10, 19], [10, 20], [10, 21], [10, 23], [10, 24], [10, 25], [10, 29], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [12, 13], [12, 14], [12, 16], [12, 20], [12, 25], [12, 27], [12, 28], [12, 29], [13, 15], [13, 16], [13, 17], [13, 18], [13, 20], [13, 22], [13, 24], [13, 25], [13, 29], [14, 19], [14, 24], [14, 25], [14, 28], [15, 16], [15, 17], [15, 22], [15, 24], [15, 26], [15, 28], [15, 29], [16, 18], [16, 21], [16, 22], [16, 23], [16, 24], [16, 28], [16, 29], [17, 18], [17, 21], [17, 22], [17, 25], [18, 22], [18, 24], [18, 27], [19, 23], [19, 24], [19, 26], [19, 29], [20, 21], [20, 22], [20, 26], [20, 27], [20, 28], [21, 22], [21, 23], [21, 24], [21, 26], [21, 27], [22, 23], [22, 29], [23, 26], [24, 25], [24, 27], [24, 28], [25, 26], [25, 27], [25, 29], [26, 28], [26, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s9/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..69d888906151d90086c9eb94cca5bc1c4520ad05 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 0, 0, 1, 1, 2, 0, 2, 1, 3, 0, 4, 0, 5, 1, 2, 1, 3, 4, 6, 3, 2, 6, 3, 3, 6, 5, 5, 4, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-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-l6-s9/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a6b31de4572d53ae73ad322944b8cc2beb3bfe0 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 7, "edges": [[0, 4], [0, 9], [0, 14], [0, 17], [0, 18], [0, 19], [0, 22], [0, 24], [0, 25], [0, 26], [0, 28], [0, 29], [1, 3], [1, 5], [1, 8], [1, 19], [1, 21], [1, 23], [1, 27], [2, 4], [2, 5], [2, 7], [2, 8], [2, 9], [2, 11], [2, 13], [2, 14], [2, 15], [2, 17], [2, 19], [2, 20], [2, 21], [2, 24], [2, 25], [2, 26], [2, 29], [3, 9], [3, 13], [3, 21], [3, 24], [3, 25], [4, 5], [4, 7], [4, 10], [4, 11], [4, 12], [4, 15], [4, 18], [4, 20], [4, 25], [4, 26], [4, 28], [4, 29], [5, 6], [5, 8], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 18], [5, 22], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [6, 7], [6, 11], [6, 13], [6, 20], [6, 21], [6, 23], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 17], [7, 19], [7, 20], [7, 22], [7, 25], [7, 26], [7, 27], [8, 10], [8, 12], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 27], [8, 28], [9, 10], [9, 11], [9, 12], [9, 13], [9, 16], [9, 25], [9, 28], [9, 29], [10, 18], [10, 19], [10, 20], [10, 21], [10, 23], [10, 24], [10, 25], [10, 29], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [12, 13], [12, 14], [12, 16], [12, 20], [12, 25], [12, 27], [12, 28], [12, 29], [13, 15], [13, 16], [13, 17], [13, 18], [13, 20], [13, 22], [13, 24], [13, 25], [13, 29], [14, 19], [14, 24], [14, 25], [14, 28], [15, 16], [15, 17], [15, 22], [15, 24], [15, 26], [15, 28], [15, 29], [16, 18], [16, 21], [16, 22], [16, 23], [16, 24], [16, 28], [16, 29], [17, 18], [17, 21], [17, 22], [17, 25], [18, 22], [18, 24], [18, 27], [19, 23], [19, 24], [19, 26], [19, 29], [20, 21], [20, 22], [20, 26], [20, 27], [20, 28], [21, 22], [21, 23], [21, 24], [21, 26], [21, 27], [22, 23], [22, 29], [23, 26], [24, 25], [24, 27], [24, 28], [25, 26], [25, 27], [25, 29], [26, 28], [26, 29]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s9/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b38882e2699cd6a08261065dc0e61fa54532bf88 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 1], [0, 4], [0, 5], [3, 4]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1472fee40c7062b99c49548b0057dbdb00f764f1 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b38882e2699cd6a08261065dc0e61fa54532bf88 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 1], [0, 4], [0, 5], [3, 4]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..836b5917bccd239e2b18e146eaba9cc5a1475322 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 5], [2, 4], [3, 4], [4, 5]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6f624e40896d25c9011bcc083227a50892b2778b --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..836b5917bccd239e2b18e146eaba9cc5a1475322 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 5], [2, 4], [3, 4], [4, 5]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29b64999980d7515c2b03279f2e057a423fcb58f --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 2], [0, 5], [2, 5], [3, 4]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..81f9708659d7fe7943111914e76aa632dcea69ca --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 0, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29b64999980d7515c2b03279f2e057a423fcb58f --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 2], [0, 5], [2, 5], [3, 4]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s2/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-rlve-min-harmonious-coloring-l2-s2/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..93f490085aa772e47d8e8e4bb94107f8c0a41043 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 3, "edges": [[2, 5], [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-s2/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..17ae7297b898b073ca9c42f511beddcb4cc6ec30 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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' +{"colors": [0, 0, 0, 0, 0, 1, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l2-s2/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/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-s2/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..93f490085aa772e47d8e8e4bb94107f8c0a41043 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 3, "edges": [[2, 5], [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-s2/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-rlve-min-harmonious-coloring-l2-s2/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-rlve-min-harmonious-coloring-l5-s1/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s1/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e9faa64a4e173f07ab080df8febb0e1748088e3 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 9, "edges": [[0, 7], [1, 11], [1, 13], [2, 3], [2, 4], [2, 6], [2, 10], [2, 11], [2, 13], [3, 5], [3, 8], [3, 10], [3, 14], [5, 11], [6, 7], [6, 8], [6, 9], [7, 11], [7, 14], [8, 12], [8, 13], [9, 13], [9, 14], [10, 13], [11, 12], [11, 14]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s1/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc207d64f6a00d02b976f2e4b3112267d8fd93c1 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 1, 0, 3, 3, 4, 0, 5, 4, 6, 5, 7, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/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-l5-s1/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e9faa64a4e173f07ab080df8febb0e1748088e3 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 9, "edges": [[0, 7], [1, 11], [1, 13], [2, 3], [2, 4], [2, 6], [2, 10], [2, 11], [2, 13], [3, 5], [3, 8], [3, 10], [3, 14], [5, 11], [6, 7], [6, 8], [6, 9], [7, 11], [7, 14], [8, 12], [8, 13], [9, 13], [9, 14], [10, 13], [11, 12], [11, 14]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce8c8cf29404b14df425cbfd644573902033edcc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 6, "edges": [[0, 13], [1, 3], [1, 7], [1, 8], [1, 9], [1, 11], [2, 12], [2, 14], [3, 5], [3, 8], [4, 12], [6, 11], [8, 10], [9, 14], [13, 14]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b2c69610b8b2c1949c4329bf698c72e24ce87174 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 2, 2, 0, 2, 0, 3, 4, 4, 5, 4, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce8c8cf29404b14df425cbfd644573902033edcc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 6, "edges": [[0, 13], [1, 3], [1, 7], [1, 8], [1, 9], [1, 11], [2, 12], [2, 14], [3, 5], [3, 8], [4, 12], [6, 11], [8, 10], [9, 14], [13, 14]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd9b43e62dd5fd61b540c8f9deb64399b5bda37a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 6, "edges": [[0, 3], [0, 5], [0, 9], [0, 10], [1, 2], [1, 5], [1, 9], [1, 11], [1, 14], [2, 4], [3, 6], [6, 9], [6, 12], [8, 12], [9, 14]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1983d3ff2b28401ed4cf9058a83d45bbc80b94a8 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 2, 3, 4, 4, 0, 2, 3, 5, 0, 5, 0, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd9b43e62dd5fd61b540c8f9deb64399b5bda37a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 6, "edges": [[0, 3], [0, 5], [0, 9], [0, 10], [1, 2], [1, 5], [1, 9], [1, 11], [1, 14], [2, 4], [3, 6], [6, 9], [6, 12], [8, 12], [9, 14]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l3-s0/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42e834324b83a929ed45eac54364f532b33985c0 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "sums": [9, 15, 17, 7, 18, 8, 20, 23, 10, 8, 17, 21, 5, 9, 3, 13, 4, 6, 18, 30, 19, 10, 22, 20, 11, 7, 5, 16], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..083c8ea5c0221783976e0242ecde969a153d65c8 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 2, 3, 4, 6, 7, 14, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42e834324b83a929ed45eac54364f532b33985c0 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "sums": [9, 15, 17, 7, 18, 8, 20, 23, 10, 8, 17, 21, 5, 9, 3, 13, 4, 6, 18, 30, 19, 10, 22, 20, 11, 7, 5, 16], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l3-s0/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l3-s9/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l3-s9/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d3d20b645020521380ecc09245e946b49db7489 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "sums": [18, 19, 25, 29, 21, 14, 25, 22, 11, 27, 21, 30, 28, 13, 23, 18, 19, 20, 16, 26, 22, 21, 15, 23, 12, 19, 17, 20], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c211ee30d2bd52cf735165ef28f24ee8e95d3b66 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [5, 6, 7, 9, 12, 13, 14, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d3d20b645020521380ecc09245e946b49db7489 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "sums": [18, 19, 25, 29, 21, 14, 25, 22, 11, 27, 21, 30, 28, 13, 23, 18, 19, 20, 16, 26, 22, 21, 15, 23, 12, 19, 17, 20], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l3-s9/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l4-s4/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2852905718db979289347ebb71cac4b622476780 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [46, 38, 27, 10, 17, 25, 47, 14, 22, 33, 35, 16, 17, 21, 28, 6, 23, 28, 45, 33, 23, 21, 14, 36, 31, 20, 26, 4, 13, 25, 16, 27, 21, 39, 34, 29, 35, 35, 37, 32, 19, 23, 13, 36, 19, 15, 34, 25, 12, 33, 40, 15, 27, 26, 22, 11, 32, 25, 29, 18, 12, 34, 24, 8, 14, 24], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..70aa3f311e1670d77fd9680d1e4d17a78861f0d4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 3, 5, 9, 10, 11, 12, 13, 16, 22, 23, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/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-s4/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2852905718db979289347ebb71cac4b622476780 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [46, 38, 27, 10, 17, 25, 47, 14, 22, 33, 35, 16, 17, 21, 28, 6, 23, 28, 45, 33, 23, 21, 14, 36, 31, 20, 26, 4, 13, 25, 16, 27, 21, 39, 34, 29, 35, 35, 37, 32, 19, 23, 13, 36, 19, 15, 34, 25, 12, 33, 40, 15, 27, 26, 22, 11, 32, 25, 29, 18, 12, 34, 24, 8, 14, 24], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l4-s4/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pan-solar-panels-l2-s2/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l2-s2/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b43c7ba32c1d7bbdb6acac1c11d5643009fe2c2b --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": 368, "B": 412, "C": 669, "D": 864, "target": 412, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s2/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff8dfac61e089344ff863947bf34f4b3b0d3ffa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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": 412, "Y": 824} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b43c7ba32c1d7bbdb6acac1c11d5643009fe2c2b --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": 368, "B": 412, "C": 669, "D": 864, "target": 412, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l2-s2/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l2-s5/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l2-s5/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..091934ced79977fc4ee07295a7b1ac65ed2d8a2d --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": 663, "B": 736, "C": 476, "D": 592, "target": 245, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s5/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c26706fadaea2202d823e31470595698e6fb9912 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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": 735, "Y": 490} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..091934ced79977fc4ee07295a7b1ac65ed2d8a2d --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": 663, "B": 736, "C": 476, "D": 592, "target": 245, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l2-s5/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s6/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s6/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c097edba4ab578ca795229373b48c9f6c79dd84a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": 623690500, "B": 944166939, "C": 17135601, "D": 60968488, "target": 60968488, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s6/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..01ad97a4a85a6be50f212c909c6059219e207548 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 914527320, "Y": 60968488} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-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-l5-s6/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c097edba4ab578ca795229373b48c9f6c79dd84a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": 623690500, "B": 944166939, "C": 17135601, "D": 60968488, "target": 60968488, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s6/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s8/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s8/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d5f16fdab159e2a41e34bc6d834df3c6cbe7e56 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": 548331659, "B": 884012473, "C": 250808177, "D": 360530747, "target": 360530747, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s8/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..db47b3aad7d6f2fcf3cf7ad889c601df2b1990d3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 721061494, "Y": 360530747} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/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-s8/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d5f16fdab159e2a41e34bc6d834df3c6cbe7e56 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": 548331659, "B": 884012473, "C": 250808177, "D": 360530747, "target": 360530747, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..268075a17b896cc747b3ecbdc337483d57a325f5 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": 53637784682, "B": 64678784162, "C": 7975294607, "D": 38996404042, "target": 32339392081, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d27ac6b12648bb7cd72757868b0585d94a6b5999 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 64678784162, "Y": 32339392081} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..268075a17b896cc747b3ecbdc337483d57a325f5 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": 53637784682, "B": 64678784162, "C": 7975294607, "D": 38996404042, "target": 32339392081, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2eda9f923e47167e9f8357a3940e553eda03af7 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": 8138612883, "B": 32217432600, "C": 80648584982, "D": 92047726236, "target": 30682575412, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6b87889e47b0281020ebe391f9ac95d19e442968 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 30682575412, "Y": 92047726236} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2eda9f923e47167e9f8357a3940e553eda03af7 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": 8138612883, "B": 32217432600, "C": 80648584982, "D": 92047726236, "target": 30682575412, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-global-minimum-l3-s1/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bf7eebca4f856e1dfbae9afb175b28fc7769890 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [5, -8, 7, -4, 1, 0, 1], "fmin": "1.69667515419507119226579346765472617101625085", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..82455a1e58b228a6a9289cfa21ae711deb27cc2c --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.8297724319303421} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bf7eebca4f856e1dfbae9afb175b28fc7769890 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [5, -8, 7, -4, 1, 0, 1], "fmin": "1.69667515419507119226579346765472617101625085", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-global-minimum-l3-s1/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-global-minimum-l3-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-global-minimum-l3-s6/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ae46ef348fcf65643b53b88d55ac0e07d721125 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [25, 46, 41, 28, 16, 6, 1], "fmin": "0.302176497910558206534386684258452194888657946", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..82693271cb895cb3daf38a78bf1cc5eaa4846135 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -1.723584662053382} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ae46ef348fcf65643b53b88d55ac0e07d721125 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [25, 46, 41, 28, 16, 6, 1], "fmin": "0.302176497910558206534386684258452194888657946", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-global-minimum-l3-s6/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-global-minimum-l3-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l3-s8/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aca3fc227c322f2b606e9ffe91f016426a8eb737 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [17, -38, 40, -28, 16, -6, 1], "fmin": "1.84336768688194447748236972497826351284182613", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1cb912c538ded85a08cb351d20b5c3491d6ed224 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.164807302064863} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aca3fc227c322f2b606e9ffe91f016426a8eb737 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [17, -38, 40, -28, 16, -6, 1], "fmin": "1.84336768688194447748236972497826351284182613", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l3-s8/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s2/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da1063c661dd0def7eb730ae32923fa9a333fa77 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [17, -38, 41, -28, 16, -6, 1, 0, 1], "fmin": "3.46633500593890112836775579236407510292207695", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b0c5c1b42fe3fc53dadcf1e01622f6e657f10ef3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.8528978226813155} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/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-s2/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da1063c661dd0def7eb730ae32923fa9a333fa77 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [17, -38, 41, -28, 16, -6, 1, 0, 1], "fmin": "3.46633500593890112836775579236407510292207695", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l4-s2/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-integer-roots-l3-s0/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l3-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l3-s9/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aa9c7c3031ccaf1b67ed01f1535d623cf1b84f9b --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -288, 444, 133, -455, 166, 10, -11, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f4a74b24a5b536ef208dfe4bf6e54a18cad0d577 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-4, -1, 0, 1, 1, 3, 3, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/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-s9/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aa9c7c3031ccaf1b67ed01f1535d623cf1b84f9b --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -288, 444, 133, -455, 166, 10, -11, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l3-s9/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-integer-roots-l4-s3/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aeeebda39243ca0a29144005f361e08e5f8f92bc --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-3345408000, 2286028800, 198635520, -571101952, 174921632, -8925368, -5508876, 1237022, -85943, -3252, 866, -50, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1198db2a745a390c9acdbdb45816b692cddabd57 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-11, -5, -2, 4, 4, 4, 5, 6, 10, 11, 12, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aeeebda39243ca0a29144005f361e08e5f8f92bc --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-3345408000, 2286028800, 198635520, -571101952, 174921632, -8925368, -5508876, 1237022, -85943, -3252, 866, -50, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-integer-roots-l4-s3/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-integer-roots-l4-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-integer-roots-l4-s4/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b0f9a9e6d582db3bc28b7692da834afb10c98a8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-167270400, 97574400, 166922016, -105574976, 1165402, 8206805, -845311, -208047, 28593, 1823, -301, -5, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f0ae9dd9f6426b3c88e7da1c244e1d0d549f895f --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-12, -11, -6, -5, -1, 1, 3, 4, 5, 8, 8, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b0f9a9e6d582db3bc28b7692da834afb10c98a8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-167270400, 97574400, 166922016, -105574976, 1165402, 8206805, -845311, -208047, 28593, 1823, -301, -5, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-integer-roots-l4-s4/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-interpolation-l3-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l3-s3/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ff7c206a5dac5b0103f3016cfaae882c88f1d3c5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"X": [4, -3, 3, 6, -5, -6, 2], "Y": [6197, 415, 1207, 62839, 10391, 33067, 115], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l3-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..16cac87131cc1f09110fced4cf0ae452e75c348d --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [1, -3, 0, -3, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ff7c206a5dac5b0103f3016cfaae882c88f1d3c5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"X": [4, -3, 3, 6, -5, -6, 2], "Y": [6197, 415, 1207, 62839, 10391, 33067, 115], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l3-s3/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l4-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s7/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b75b95e1beceb54acf1487f9c5d2a9adb6dc867 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"X": [7, 4, -4, 6, -9, 1, 3, -2, -5, 8], "Y": [112096775, 658472, -778856, 27470604, -1185491961, -1, 44295, -1060, -5912185, 377702800], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e1141b9eeea3fe828167b70ec1e8ca0241f753e2 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [0, 2, -2, -3, 5, -2, 1, -4, -1, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/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-s7/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b75b95e1beceb54acf1487f9c5d2a9adb6dc867 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"X": [7, 4, -4, 6, -9, 1, 3, -2, -5, 8], "Y": [112096775, 658472, -778856, 27470604, -1185491961, -1, 44295, -1060, -5912185, 377702800], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b529366aa87ea3ed8499941ec6d13d54198781a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 227, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c99eb58247b72603b8ffb09f70ffbb5d1d37823c --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 115, 77, 58, 92, 39, 66, 143, 102, 160, 63, 20, 36, 147, 107, 72, 188, 165, 13, 194, 174, 32, 80, 124, 110, 132, 186, 74, 48, 54, 23, 150, 173, 208, 14, 83, 136, 7, 164, 211, 73, 201, 133, 130, 112, 154, 30, 176, 140, 169, 139, 180, 31, 207, 195, 151, 5, 138, 178, 141, 68, 12, 210, 189, 8, 87, 62, 218, 103, 121, 17, 42, 29, 182, 113, 4, 172, 196, 24, 106, 214, 37, 94, 101, 220, 67, 168, 179, 177, 170, 6, 191, 84, 129, 185, 202, 111, 184, 134, 85, 10, 70, 109, 204, 81, 16, 158, 104, 26, 98, 46, 76, 226, 3, 153, 183, 131, 203, 125, 71, 213, 148, 25, 120, 159, 219, 144, 95, 45, 118, 27, 44, 100, 145, 38, 223, 59, 52, 50, 61, 162, 9, 128, 135, 192, 15, 123, 205, 33, 57, 225, 116, 47, 200, 187, 212, 108, 126, 11, 167, 142, 221, 40, 19, 217, 161, 88, 51, 91, 224, 78, 34, 22, 198, 49, 90, 60, 89, 53, 199, 75, 117, 99, 96, 28, 156, 18, 65, 222, 93, 146, 215, 21, 56, 79, 206, 175, 181, 155, 43, 97, 119, 105, 149, 197, 55, 35, 216, 64, 41, 157, 122, 82, 193, 209, 166, 69, 127, 86, 163, 190, 137, 171, 152, 114, 227]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b529366aa87ea3ed8499941ec6d13d54198781a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 227, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40f996b226f166002c52914561f8d273b59d2e7b --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 211, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7992e4ecb7b6ac56e0149973d746295fa60a0666 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 107, 142, 54, 170, 177, 182, 133, 48, 191, 97, 89, 66, 197, 198, 67, 150, 130, 101, 96, 202, 49, 157, 45, 77, 139, 87, 99, 132, 205, 178, 34, 33, 181, 206, 171, 155, 51, 93, 154, 176, 207, 55, 25, 137, 79, 10, 23, 57, 39, 121, 70, 5, 44, 189, 50, 175, 172, 94, 103, 129, 195, 68, 123, 14, 17, 64, 91, 53, 209, 108, 86, 186, 78, 167, 26, 75, 47, 204, 183, 100, 194, 151, 104, 73, 28, 115, 13, 148, 69, 161, 40, 60, 111, 21, 12, 125, 29, 82, 20, 118, 61, 85, 141, 210, 3, 72, 128, 152, 95, 193, 131, 184, 88, 201, 192, 102, 153, 173, 52, 144, 65, 200, 98, 185, 140, 109, 62, 19, 113, 30, 9, 166, 138, 187, 46, 135, 27, 127, 105, 4, 160, 122, 149, 196, 199, 90, 145, 18, 84, 110, 119, 41, 38, 163, 24, 169, 208, 143, 92, 174, 156, 190, 203, 134, 76, 188, 158, 6, 37, 59, 120, 162, 58, 42, 7, 32, 180, 179, 35, 8, 81, 114, 126, 74, 136, 168, 56, 164, 11, 117, 112, 83, 63, 146, 15, 16, 147, 124, 116, 22, 165, 80, 31, 36, 43, 159, 71, 106, 211]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40f996b226f166002c52914561f8d273b59d2e7b --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 211, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s8/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l3-s8/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32e519c1d316bcd0e6d180724e063ff5bf29c884 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 223, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s8/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4d25e66d6fba7c54fd0ea44fe18da8d2905779a7 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 113, 150, 57, 135, 187, 33, 29, 125, 68, 143, 94, 104, 17, 120, 15, 106, 63, 48, 146, 86, 72, 98, 159, 117, 164, 191, 9, 101, 172, 37, 8, 197, 165, 52, 32, 218, 136, 184, 185, 137, 155, 84, 148, 115, 161, 20, 80, 133, 59, 36, 194, 102, 96, 74, 5, 91, 51, 190, 198, 118, 19, 178, 116, 200, 99, 11, 83, 182, 138, 23, 128, 56, 221, 114, 180, 85, 204, 49, 93, 213, 69, 44, 78, 22, 154, 183, 186, 219, 58, 175, 81, 13, 122, 55, 152, 24, 67, 215, 30, 54, 130, 14, 209, 18, 163, 199, 160, 179, 149, 222, 3, 76, 46, 65, 26, 62, 207, 16, 211, 95, 171, 195, 10, 158, 201, 73, 170, 103, 212, 144, 50, 167, 6, 39, 42, 71, 203, 147, 181, 156, 12, 132, 176, 21, 140, 45, 111, 4, 169, 97, 202, 87, 43, 142, 214, 126, 25, 109, 47, 206, 107, 27, 35, 174, 134, 220, 151, 129, 123, 31, 189, 166, 92, 145, 205, 64, 110, 77, 141, 70, 88, 40, 41, 89, 7, 193, 173, 60, 28, 217, 188, 53, 124, 216, 34, 61, 108, 66, 127, 153, 139, 79, 177, 162, 119, 210, 105, 208, 121, 131, 82, 157, 100, 196, 192, 38, 90, 168, 75, 112, 223]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32e519c1d316bcd0e6d180724e063ff5bf29c884 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 223, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l3-s8/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s2/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b804f83218a726d131ad6a17b96ec8af742143f8 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 1297, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s2/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ccb16ee06261eb8c8600f311e1ce53717db57ff6 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 650, 866, 974, 520, 1082, 557, 1136, 1154, 909, 119, 1190, 899, 279, 174, 1217, 764, 1226, 1025, 455, 1051, 60, 283, 1244, 883, 450, 1250, 140, 493, 736, 1047, 609, 905, 1031, 631, 1262, 632, 513, 1165, 228, 349, 526, 182, 679, 491, 142, 139, 1271, 451, 442, 1120, 874, 882, 1274, 284, 719, 1207, 247, 23, 1017, 405, 524, 351, 305, 440, 453, 1027, 516, 95, 316, 1024, 1280, 765, 965, 295, 257, 759, 583, 1101, 763, 1282, 175, 1173, 912, 413, 740, 165, 340, 1196, 246, 1241, 720, 782, 70, 984, 636, 469, 226, 1167, 870, 245, 1209, 341, 1086, 211, 1090, 898, 1286, 120, 791, 1076, 360, 265, 604, 1095, 124, 389, 12, 110, 509, 955, 203, 117, 911, 1215, 176, 481, 153, 926, 869, 1199, 227, 1259, 514, 1029, 907, 1156, 48, 29, 807, 47, 1161, 908, 1289, 1137, 383, 151, 483, 915, 148, 817, 129, 374, 380, 729, 292, 1108, 551, 727, 382, 1153, 1290, 558, 88, 960, 587, 234, 1105, 968, 207, 403, 1019, 16, 83, 127, 819, 873, 1247, 443, 772, 44, 621, 568, 1009, 646, 1040, 542, 684, 550, 1141, 293, 967, 1130, 235, 1012, 762, 1219, 584, 555, 1084, 343, 123, 1183, 605, 330, 171, 897, 1192, 212, 106, 210, 1194, 342, 1098, 556, 1292, 521, 709, 688, 396, 359, 1187, 792, 829, 99, 133, 41, 951, 658, 548, 686, 711, 168, 195, 288, 655, 800, 704, 446, 255, 297, 478, 428, 102, 91, 59, 1277, 456, 824, 608, 1267, 737, 852, 241, 1003, 77, 541, 1112, 647, 435, 488, 600, 938, 114, 696, 630, 1264, 906, 1163, 515, 1231, 454, 1279, 1227, 317, 673, 399, 15, 1126, 404, 1238, 24, 56, 581, 761, 1103, 236, 645, 1114, 569, 157, 192, 333, 76, 1043, 242, 822, 458, 322, 723, 768, 409, 947, 65, 860, 836, 922, 839, 979, 365, 368, 795, 635, 1203, 71, 276, 627, 364, 989, 840, 300, 577, 519, 1294, 867, 928, 473, 693, 206, 1129, 1106, 294, 1224, 766, 725, 553, 586, 1133, 89, 104, 214, 202, 1177, 510, 798, 657, 1070, 42, 774, 64, 995, 410, 486, 437, 465, 624, 902, 222, 113, 1035, 601, 671, 319, 311, 932, 933, 312, 505, 472, 972, 868, 1169, 154, 920, 838, 991, 837, 924, 155, 571, 161, 147, 1149, 484, 412, 1214, 1174, 118, 1288, 1155, 1162, 1030, 1265, 610, 221, 941, 625, 278, 1285, 1191, 1091, 172, 281, 62, 776, 592, 530, 303, 353, 814, 386, 86, 560, 449, 1273, 1245, 875, 755, 617, 702, 802, 754, 881, 1246, 1121, 820, 244, 1198, 1168, 927, 973, 1295, 651, 261, 812, 355, 835, 993, 66, 847, 51, 180, 528, 594, 240, 1045, 738, 415, 27, 50, 858, 67, 273, 21, 249, 476, 299, 978, 990, 923, 921, 992, 861, 356, 676, 733, 662, 98, 1074, 793, 370, 328, 607, 1049, 457, 1001, 243, 872, 1122, 128, 1147, 149, 385, 888, 354, 863, 262, 700, 619, 46, 1158, 30, 564, 639, 753, 877, 703, 1061, 656, 953, 511, 634, 986, 369, 828, 1075, 1188, 121, 345, 502, 666, 39, 135, 271, 69, 1205, 721, 324, 6, 218, 591, 893, 63, 949, 43, 1118, 444, 706, 408, 997, 724, 964, 1225, 1281, 1218, 1102, 1013, 582, 1221, 258, 188, 616, 880, 876, 803, 640, 231, 614, 190, 159, 573, 337, 714, 200, 216, 8, 164, 1212, 414, 851, 1046, 1268, 494, 661, 832, 677, 184, 291, 1143, 381, 1139, 552, 963, 767, 998, 323, 781, 1206, 1242, 285, 539, 79, 199, 745, 338, 167, 1066, 687, 1080, 522, 407, 770, 445, 1060, 801, 878, 618, 810, 263, 362, 629, 1033, 115, 205, 970, 474, 251, 33, 395, 1079, 710, 1067, 549, 1110, 543, 420, 598, 490, 1254, 183, 732, 833, 357, 398, 1022, 318, 936, 602, 267, 36, 38, 787, 503, 314, 97, 831, 734, 495, 547, 1069, 952, 799, 1062, 289, 186, 260, 865, 1296, 3, 434, 1039, 1113, 1010, 237, 500, 347, 230, 752, 804, 565, 468, 1202, 985, 796, 512, 1261, 1263, 1032, 697, 363, 981, 277, 901, 942, 466, 567, 1116, 45, 809, 701, 879, 756, 189, 750, 232, 589, 220, 904, 1266, 1048, 825, 329, 1094, 1184, 266, 670, 937, 1036, 489, 681, 421, 498, 239, 854, 529, 892, 777, 219, 612, 233, 1132, 961, 554, 1100, 1220, 760, 1014, 57, 93, 518, 976, 301, 532, 336, 747, 160, 918, 156, 1008, 1115, 622, 467, 638, 805, 31, 253, 448, 885, 87, 1135, 1291, 1083, 1099, 585, 962, 726, 1140, 1109, 685, 1068, 659, 496, 423, 419, 683, 1111, 1041, 78, 717, 286, 197, 81, 18, 74, 335, 575, 302, 891, 593, 855, 181, 1256, 350, 1236, 406, 708, 1081, 1293, 975, 578, 94, 1230, 1028, 1164, 1260, 633, 797, 954, 1178, 111, 224, 471, 930, 313, 665, 788, 346, 643, 238, 596, 422, 546, 660, 735, 1269, 141, 1253, 680, 599, 1037, 436, 945, 411, 914, 1150, 152, 1171, 177, 427, 1056, 298, 842, 250, 692, 971, 929, 506, 225, 1201, 637, 566, 623, 943, 438, 307, 378, 376, 309, 321, 1000, 823, 1050, 1278, 1026, 1232, 441, 1249, 1272, 884, 561, 254, 1059, 705, 771, 1119, 1248, 452, 1233, 306, 464, 944, 487, 1038, 648, 4, 326, 372, 131, 101, 1055, 479, 178, 53, 418, 545, 497, 597, 682, 544, 424, 54, 26, 850, 739, 1213, 913, 485, 946, 996, 769, 707, 523, 1237, 1018, 1127, 208, 108, 14, 1021, 674, 358, 1078, 689, 34, 269, 137, 144, 11, 1181, 125, 85, 887, 815, 150, 1152, 1138, 728, 1144, 375, 462, 308, 461, 379, 1145, 130, 431, 327, 827, 794, 987, 366, 367, 988, 980, 628, 698, 264, 1186, 1077, 397, 675, 834, 862, 813, 889, 304, 1235, 525, 1257, 229, 642, 501, 789, 122, 1097, 1085, 1195, 1210, 166, 713, 746, 574, 533, 75, 1005, 193, 170, 1093, 606, 826, 371, 432, 5, 780, 722, 999, 459, 310, 935, 672, 1023, 1228, 96, 664, 504, 931, 934, 320, 460, 377, 463, 439, 1234, 352, 890, 531, 576, 977, 841, 477, 1057, 256, 1223, 966, 1107, 1142, 730, 185, 654, 1063, 196, 538, 718, 1243, 1275, 61, 895, 173, 1284, 900, 626, 982, 72, 20, 845, 68, 784, 136, 393, 35, 669, 603, 1185, 361, 699, 811, 864, 652, 187, 758, 1222, 296, 1058, 447, 562, 32, 691, 475, 843, 22, 1240, 1208, 1197, 871, 821, 1002, 1044, 853, 595, 499, 644, 1011, 1104, 1131, 588, 613, 751, 641, 348, 1258, 1166, 1200, 470, 507, 112, 940, 903, 611, 590, 778, 7, 743, 201, 957, 105, 1089, 1193, 1087, 107, 402, 1128, 969, 694, 116, 1176, 956, 215, 744, 715, 80, 537, 287, 1064, 169, 332, 1006, 158, 749, 615, 757, 259, 653, 290, 731, 678, 1255, 527, 856, 52, 426, 480, 1172, 1216, 1283, 280, 896, 1092, 331, 194, 1065, 712, 339, 1211, 741, 9, 146, 917, 572, 748, 191, 1007, 570, 919, 925, 1170, 482, 1151, 384, 816, 1148, 916, 162, 10, 391, 138, 1252, 492, 1270, 1251, 143, 392, 270, 785, 40, 1072, 100, 430, 373, 1146, 818, 1123, 84, 388, 1182, 1096, 344, 790, 1189, 1287, 910, 1175, 204, 695, 1034, 939, 223, 508, 1179, 13, 401, 209, 1088, 213, 958, 90, 1054, 429, 132, 1073, 830, 663, 315, 1229, 517, 579, 58, 1053, 103, 959, 1134, 559, 886, 387, 126, 1124, 17, 536, 198, 716, 540, 1042, 1004, 334, 534, 19, 275, 983, 1204, 783, 272, 846, 859, 994, 948, 775, 894, 282, 1276, 1052, 92, 580, 1015, 25, 417, 425, 179, 857, 848, 28, 1160, 1157, 808, 620, 1117, 773, 950, 1071, 134, 786, 667, 37, 668, 268, 394, 690, 252, 563, 806, 1159, 49, 849, 416, 55, 1016, 1239, 248, 844, 274, 73, 535, 82, 1125, 1020, 400, 109, 1180, 390, 145, 163, 742, 217, 779, 325, 433, 649, 1297]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-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(), 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-s2/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b804f83218a726d131ad6a17b96ec8af742143f8 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 1297, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s2/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-recursive-sequence-sum-l1-s2/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l1-s2/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d1b13c374996a9cbc576b8e95b9368cdd08b69e --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"F0": 110, "A": 8, "B": 2247, "S": 27263, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s2/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0522b8ac283d8e01f9b68293254f761e6b7bc69c --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d1b13c374996a9cbc576b8e95b9368cdd08b69e --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"F0": 110, "A": 8, "B": 2247, "S": 27263, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l1-s2/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l1-s5/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l1-s5/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..01c733818340915fc1c9d412ee1d2fee8e4f3b5d --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"F0": 2, "A": 10, "B": 4625, "S": 51075, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s5/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0522b8ac283d8e01f9b68293254f761e6b7bc69c --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..01c733818340915fc1c9d412ee1d2fee8e4f3b5d --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"F0": 2, "A": 10, "B": 4625, "S": 51075, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l1-s5/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-s7/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s7/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..144f9a239ae1af86e48c8eee3f5cf00d62cbea64 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"F0": 19, "A": 10, "B": 9981, "S": 12533324317, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s7/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b9203a6c353f3a0400dcb0fb533baa3785f2e6eb --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 4, 5, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..144f9a239ae1af86e48c8eee3f5cf00d62cbea64 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"F0": 19, "A": 10, "B": 9981, "S": 12533324317, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s3/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l5-s3/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4736d61c4cd0e123a7932c0beec3500c951324d6 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"F0": 27, "A": 13, "B": 8580, "S": 353976626698897852087699828143575637015, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s3/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fd24bb6e4763e068fd26c9446a9a2d8b370098f0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 31, 32]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4736d61c4cd0e123a7932c0beec3500c951324d6 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"F0": 27, "A": 13, "B": 8580, "S": 353976626698897852087699828143575637015, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l5-s3/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l5-s4/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l5-s4/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ac62b02a616ebb7b1d4129fd6128fd26087b9c4 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"F0": 50, "A": 7, "B": 9065, "S": 1970105697997884436771222379785, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s4/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6762e1e44bd0c6692885e2520f576263f131c835 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 4, 7, 8, 10, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 31, 32]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8ac62b02a616ebb7b1d4129fd6128fd26087b9c4 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"F0": 50, "A": 7, "B": 9065, "S": 1970105697997884436771222379785, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l5-s4/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s8/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s8/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9cbd85e4ea7b494cd6d0381f1e18eb0abb1de9b8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [2, 8, 9, 10, 13, 15, 16, 17, 18, 20, 21, 23, 27, 28, 29, 34, 35, 39, 44, 45, 46, 47, 48, 49, 51, 53, 58, 59, 60]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-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-l6-s8/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4832f714d87bc0ad8d212edb83251bdd13f9c23f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"F0": 35, "A": 1, "B": 11947, "S": 11040043, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s2/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l1-s2/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26406fc3daa81eb3935dd84f91e8e0caa8fb19d6 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 5, "edges1": [[0, 3]], "edges2": [[0, 1], [1, 4]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s2/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b199b0b3f95f03e1bc927e7d583f2233d2f3d933 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [4, 2, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26406fc3daa81eb3935dd84f91e8e0caa8fb19d6 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n1": 4, "n2": 5, "edges1": [[0, 3]], "edges2": [[0, 1], [1, 4]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l1-s2/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l1-s5/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l1-s5/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db64627b9f0862940190d70a08f51d79c5a49e48 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n1": 3, "n2": 5, "edges1": [[0, 2]], "edges2": [[1, 2], [0, 3]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s5/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4adb2c62180ffbd67e18fb188682e7a980295dc --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [0, 1, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db64627b9f0862940190d70a08f51d79c5a49e48 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n1": 3, "n2": 5, "edges1": [[0, 2]], "edges2": [[1, 2], [0, 3]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l1-s5/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l5-s3/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l5-s3/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..33c417d23e98fdadea62d4c94acc7ce12602869c --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n1": 14, "n2": 26, "edges1": [[6, 11], [0, 13], [8, 12], [3, 9], [10, 12], [9, 13], [0, 9], [2, 5], [2, 4], [0, 4], [1, 6], [9, 11], [1, 4], [7, 10], [3, 6], [1, 12], [2, 10], [7, 13], [11, 12], [6, 7], [5, 6], [3, 7], [4, 13], [5, 13], [8, 11], [2, 6], [0, 7], [4, 10], [1, 11], [0, 10], [7, 8], [1, 13], [7, 11], [4, 5], [0, 1], [1, 2], [1, 7], [0, 8], [0, 12], [2, 13], [5, 9], [10, 11], [2, 11], [1, 5], [6, 10], [5, 7], [3, 10], [4, 7], [7, 9], [2, 7], [5, 11], [8, 13], [2, 8], [6, 12], [10, 13], [3, 13], [6, 9], [4, 6], [4, 8]], "edges2": [[1, 11], [9, 16], [0, 21], [19, 24], [4, 24], [9, 13], [21, 22], [12, 16], [5, 9], [14, 20], [10, 15], [15, 23], [0, 9], [14, 18], [12, 18], [15, 20], [6, 19], [14, 21], [2, 5], [7, 25], [7, 14], [12, 23], [2, 7], [0, 13], [1, 12], [17, 23], [5, 18], [8, 21], [12, 19], [6, 18], [3, 5], [0, 6], [1, 9], [5, 11], [22, 25], [3, 23], [1, 15], [0, 24], [1, 23], [13, 14], [2, 20], [9, 11], [4, 22], [12, 22], [6, 20], [19, 25], [14, 24], [5, 7], [11, 17], [3, 15], [8, 17], [6, 25], [6, 22], [2, 16], [18, 21], [3, 9], [16, 21], [2, 21], [9, 15], [2, 3], [3, 13], [16, 18], [8, 24], [10, 24], [20, 22], [5, 23], [15, 21], [1, 8], [11, 14], [23, 24], [9, 17], [11, 24], [4, 23], [12, 17], [14, 22], [7, 8], [3, 6], [19, 20], [4, 25], [5, 25], [14, 16], [7, 22], [3, 14], [1, 3], [9, 10], [1, 4], [1, 7], [16, 19], [8, 12], [18, 22], [6, 14], [17, 18], [9, 12], [3, 4], [4, 7], [2, 15], [10, 22], [5, 8], [1, 21], [18, 19], [13, 15], [3, 8], [19, 23], [5, 21], [0, 2], [7, 23], [0, 19], [1, 13], [5, 17], [15, 19], [7, 9], [3, 12], [14, 25], [10, 14], [0, 25], [5, 24], [7, 18], [7, 15], [2, 22], [21, 25], [18, 20], [13, 22], [1, 24], [7, 24], [5, 19], [0, 17], [4, 11], [18, 25], [5, 22], [4, 5], [12, 20], [15, 24], [11, 13], [12, 15], [5, 12], [13, 19], [11, 25], [6, 12], [2, 19], [9, 22], [4, 13], [20, 25], [2, 18], [0, 7], [7, 16], [11, 20], [4, 16], [11, 22], [1, 5], [10, 19], [6, 10], [13, 24], [16, 24], [12, 13], [7, 17], [7, 11], [13, 21], [8, 15], [4, 20], [3, 24], [2, 6], [23, 25], [2, 23], [9, 20], [0, 22], [13, 16], [11, 12], [15, 25], [2, 9], [14, 23], [4, 14], [8, 22], [0, 8], [3, 16], [12, 25], [7, 13], [5, 16], [13, 18], [10, 13], [7, 20], [12, 24], [4, 15], [10, 20], [8, 9], [20, 21], [16, 20], [3, 20], [8, 19], [10, 12], [8, 13], [11, 23], [13, 25], [17, 19], [2, 13], [10, 21], [5, 10], [18, 24], [5, 20], [0, 11], [17, 24], [4, 9], [7, 10], [11, 18], [8, 10], [1, 2], [2, 25], [6, 16], [5, 14], [17, 21], [10, 18], [0, 15]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l5-s3/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6d5ac2dee4fe34e8ad18d2ee5fdfc6177430a8a7 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [2, 19, 10, 4, 18, 12, 24, 5, 21, 3, 7, 8, 0, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/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-l5-s3/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..33c417d23e98fdadea62d4c94acc7ce12602869c --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n1": 14, "n2": 26, "edges1": [[6, 11], [0, 13], [8, 12], [3, 9], [10, 12], [9, 13], [0, 9], [2, 5], [2, 4], [0, 4], [1, 6], [9, 11], [1, 4], [7, 10], [3, 6], [1, 12], [2, 10], [7, 13], [11, 12], [6, 7], [5, 6], [3, 7], [4, 13], [5, 13], [8, 11], [2, 6], [0, 7], [4, 10], [1, 11], [0, 10], [7, 8], [1, 13], [7, 11], [4, 5], [0, 1], [1, 2], [1, 7], [0, 8], [0, 12], [2, 13], [5, 9], [10, 11], [2, 11], [1, 5], [6, 10], [5, 7], [3, 10], [4, 7], [7, 9], [2, 7], [5, 11], [8, 13], [2, 8], [6, 12], [10, 13], [3, 13], [6, 9], [4, 6], [4, 8]], "edges2": [[1, 11], [9, 16], [0, 21], [19, 24], [4, 24], [9, 13], [21, 22], [12, 16], [5, 9], [14, 20], [10, 15], [15, 23], [0, 9], [14, 18], [12, 18], [15, 20], [6, 19], [14, 21], [2, 5], [7, 25], [7, 14], [12, 23], [2, 7], [0, 13], [1, 12], [17, 23], [5, 18], [8, 21], [12, 19], [6, 18], [3, 5], [0, 6], [1, 9], [5, 11], [22, 25], [3, 23], [1, 15], [0, 24], [1, 23], [13, 14], [2, 20], [9, 11], [4, 22], [12, 22], [6, 20], [19, 25], [14, 24], [5, 7], [11, 17], [3, 15], [8, 17], [6, 25], [6, 22], [2, 16], [18, 21], [3, 9], [16, 21], [2, 21], [9, 15], [2, 3], [3, 13], [16, 18], [8, 24], [10, 24], [20, 22], [5, 23], [15, 21], [1, 8], [11, 14], [23, 24], [9, 17], [11, 24], [4, 23], [12, 17], [14, 22], [7, 8], [3, 6], [19, 20], [4, 25], [5, 25], [14, 16], [7, 22], [3, 14], [1, 3], [9, 10], [1, 4], [1, 7], [16, 19], [8, 12], [18, 22], [6, 14], [17, 18], [9, 12], [3, 4], [4, 7], [2, 15], [10, 22], [5, 8], [1, 21], [18, 19], [13, 15], [3, 8], [19, 23], [5, 21], [0, 2], [7, 23], [0, 19], [1, 13], [5, 17], [15, 19], [7, 9], [3, 12], [14, 25], [10, 14], [0, 25], [5, 24], [7, 18], [7, 15], [2, 22], [21, 25], [18, 20], [13, 22], [1, 24], [7, 24], [5, 19], [0, 17], [4, 11], [18, 25], [5, 22], [4, 5], [12, 20], [15, 24], [11, 13], [12, 15], [5, 12], [13, 19], [11, 25], [6, 12], [2, 19], [9, 22], [4, 13], [20, 25], [2, 18], [0, 7], [7, 16], [11, 20], [4, 16], [11, 22], [1, 5], [10, 19], [6, 10], [13, 24], [16, 24], [12, 13], [7, 17], [7, 11], [13, 21], [8, 15], [4, 20], [3, 24], [2, 6], [23, 25], [2, 23], [9, 20], [0, 22], [13, 16], [11, 12], [15, 25], [2, 9], [14, 23], [4, 14], [8, 22], [0, 8], [3, 16], [12, 25], [7, 13], [5, 16], [13, 18], [10, 13], [7, 20], [12, 24], [4, 15], [10, 20], [8, 9], [20, 21], [16, 20], [3, 20], [8, 19], [10, 12], [8, 13], [11, 23], [13, 25], [17, 19], [2, 13], [10, 21], [5, 10], [18, 24], [5, 20], [0, 11], [17, 24], [4, 9], [7, 10], [11, 18], [8, 10], [1, 2], [2, 25], [6, 16], [5, 14], [17, 21], [10, 18], [0, 15]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l5-s3/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l5-s4/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l5-s4/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6638f63e08991e0905a945021e862266a01b5954 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n1": 16, "n2": 26, "edges1": [[4, 9], [7, 12], [5, 6], [3, 5], [1, 2], [10, 13], [7, 13], [8, 12], [1, 14], [4, 5], [2, 15], [2, 12], [1, 4], [4, 15], [3, 6], [3, 4]], "edges2": [[1, 6], [18, 21], [1, 22], [3, 13], [5, 13], [10, 19], [2, 14], [0, 3], [2, 24], [6, 14], [11, 18], [1, 19], [6, 10], [7, 24], [6, 18], [1, 20], [21, 23], [16, 25], [0, 4], [0, 14], [3, 14], [17, 23], [1, 11], [1, 12], [0, 2], [13, 15], [7, 11], [3, 24], [3, 19], [0, 22], [10, 18], [8, 16], [6, 23], [0, 1], [7, 20], [4, 19], [13, 17], [18, 23], [14, 20], [6, 25], [16, 21], [16, 17], [3, 15], [10, 15], [4, 6], [5, 22], [9, 22], [20, 25]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l5-s4/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b350bd0d89f475baaa8c6892c37b7f8852f8805 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [8, 4, 0, 18, 6, 23, 21, 5, 9, 25, 15, 24, 22, 13, 19, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/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-l5-s4/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6638f63e08991e0905a945021e862266a01b5954 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n1": 16, "n2": 26, "edges1": [[4, 9], [7, 12], [5, 6], [3, 5], [1, 2], [10, 13], [7, 13], [8, 12], [1, 14], [4, 5], [2, 15], [2, 12], [1, 4], [4, 15], [3, 6], [3, 4]], "edges2": [[1, 6], [18, 21], [1, 22], [3, 13], [5, 13], [10, 19], [2, 14], [0, 3], [2, 24], [6, 14], [11, 18], [1, 19], [6, 10], [7, 24], [6, 18], [1, 20], [21, 23], [16, 25], [0, 4], [0, 14], [3, 14], [17, 23], [1, 11], [1, 12], [0, 2], [13, 15], [7, 11], [3, 24], [3, 19], [0, 22], [10, 18], [8, 16], [6, 23], [0, 1], [7, 20], [4, 19], [13, 17], [18, 23], [14, 20], [6, 25], [16, 21], [16, 17], [3, 15], [10, 15], [4, 6], [5, 22], [9, 22], [20, 25]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l5-s4/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l6-s1/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l6-s1/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8631040eff899d00d9f2456c467b3071ec6cabd1 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n1": 27, "n2": 36, "edges1": [[12, 17], [5, 26], [2, 5], [1, 10], [3, 25], [3, 12], [20, 25], [1, 21], [11, 14], [1, 3], [10, 18], [6, 12], [6, 17], [21, 26], [1, 22], [25, 26], [6, 18], [10, 13], [4, 10], [20, 23], [2, 12], [8, 16], [23, 25], [15, 18], [12, 23], [7, 23], [8, 9], [1, 4], [16, 20], [9, 22], [9, 15], [10, 11], [17, 20], [20, 21], [11, 21], [20, 24], [2, 22], [5, 24], [9, 16], [12, 20], [9, 18], [1, 25], [5, 14], [0, 22], [1, 23], [4, 18], [19, 21], [3, 18], [21, 23], [4, 17], [4, 14], [3, 11], [16, 18], [14, 16], [3, 24], [10, 15], [9, 12], [0, 6], [0, 25], [1, 26], [1, 12], [4, 6], [8, 18], [3, 9], [8, 15], [15, 17], [2, 15], [1, 15], [7, 13], [0, 21], [2, 11], [2, 6], [12, 21], [6, 25], [1, 19], [4, 5], [6, 24], [1, 7], [9, 20], [3, 22], [4, 24], [9, 14], [12, 26], [13, 15], [10, 19], [0, 26], [15, 25], [7, 11], [13, 24], [1, 9], [7, 14], [12, 22], [6, 23], [13, 16], [14, 21], [4, 13], [8, 14], [0, 12], [4, 7], [4, 26], [13, 21], [5, 9], [9, 26], [3, 14], [5, 23], [9, 24], [8, 19], [8, 10], [17, 18], [13, 14], [8, 22], [20, 22], [18, 19], [6, 16], [10, 21], [19, 23], [2, 7], [7, 17], [0, 7], [1, 14], [3, 8], [3, 23], [13, 20], [7, 19], [5, 6], [5, 7], [9, 17], [23, 24], [6, 22], [6, 20], [7, 16], [13, 17], [5, 25], [2, 26], [9, 25], [3, 5], [3, 7], [6, 19], [4, 8], [12, 24], [10, 20], [0, 18], [5, 15], [3, 16], [10, 16], [7, 20], [14, 20], [0, 13], [17, 25], [4, 12], [8, 23], [2, 10], [18, 25], [3, 6], [5, 16], [7, 26], [12, 25], [0, 16], [6, 9], [10, 17], [3, 4], [5, 20], [11, 12], [21, 22]], "edges2": [[10, 15], [5, 19], [32, 34], [6, 11], [15, 21], [12, 29], [17, 27], [3, 15], [18, 20], [8, 19], [11, 17], [18, 23], [24, 33], [14, 18], [2, 24], [13, 25], [9, 24], [7, 10], [11, 35], [12, 19], [25, 33], [2, 23], [19, 22], [2, 33], [1, 34], [18, 32], [23, 30], [3, 8], [2, 7], [22, 32], [21, 31], [17, 22], [13, 34], [3, 30], [27, 35], [16, 24], [6, 7], [14, 25], [8, 24], [23, 34], [1, 18], [10, 14], [7, 25], [18, 28], [13, 33], [34, 35], [11, 24], [11, 12], [9, 17], [12, 28], [32, 35], [16, 18], [10, 23], [15, 19], [28, 33], [13, 26], [7, 34], [29, 30], [1, 20], [4, 13], [5, 34], [10, 27], [2, 19], [12, 23], [12, 15], [8, 27], [10, 30], [24, 28], [12, 31], [13, 28], [9, 15], [22, 24], [14, 23], [5, 13], [4, 24], [16, 34], [0, 4], [9, 20], [0, 10], [11, 18], [2, 32], [20, 25], [24, 27], [2, 3], [6, 34], [5, 32], [12, 35], [5, 18], [22, 30], [25, 32], [19, 28], [28, 29], [2, 9], [31, 33], [23, 32], [5, 33], [2, 25], [0, 29], [14, 35], [30, 33], [4, 16], [9, 12], [20, 29], [8, 31], [20, 31], [10, 33], [16, 32], [20, 22], [7, 31], [8, 21], [16, 29], [0, 19], [25, 29], [5, 35], [3, 34], [6, 32], [9, 23], [13, 22], [20, 34], [10, 31], [26, 32], [0, 27], [18, 26], [18, 35], [19, 20], [4, 8], [15, 35], [8, 14], [19, 24], [2, 27], [17, 32], [6, 17], [15, 22], [14, 22], [9, 34], [27, 28], [17, 28], [16, 19], [21, 26], [21, 24], [5, 24], [11, 23], [3, 14], [16, 28], [33, 34], [6, 15], [6, 9], [0, 26], [7, 19], [4, 26], [12, 16], [7, 12], [20, 21], [3, 24], [12, 34], [21, 23], [0, 28], [7, 13], [9, 18], [8, 29], [18, 31], [9, 16], [4, 17], [19, 29], [2, 15], [11, 20], [13, 18], [1, 2], [17, 30], [14, 32], [24, 31], [11, 22], [10, 32], [21, 29], [4, 10], [14, 26], [4, 12], [24, 35], [2, 13], [20, 33], [4, 14], [17, 23], [1, 3], [1, 27], [21, 35], [17, 24], [4, 29], [23, 28], [7, 17], [24, 26], [9, 26], [31, 32], [25, 31], [0, 31], [7, 28], [10, 22], [6, 12], [3, 33], [6, 29], [11, 28], [2, 30], [15, 26], [3, 27], [25, 34], [7, 11], [12, 13], [10, 19], [10, 24], [33, 35], [18, 30], [2, 12], [4, 22], [2, 10], [23, 26], [6, 27], [26, 30], [7, 15], [8, 32], [4, 7], [15, 25], [1, 35], [3, 20], [19, 25], [27, 31], [4, 32], [6, 30], [5, 28], [4, 27], [7, 8], [17, 29], [2, 29], [20, 23], [13, 14], [4, 30], [4, 18], [0, 20], [12, 25], [13, 21], [7, 27], [0, 9], [13, 17], [16, 31], [5, 22], [8, 18], [17, 33], [1, 5], [1, 6], [22, 28], [11, 29], [1, 21], [19, 34], [22, 31], [3, 6], [3, 22], [11, 16], [6, 26], [4, 28], [5, 29], [19, 35], [21, 28], [3, 32], [7, 22], [26, 34], [28, 31], [15, 33], [6, 25], [3, 4], [5, 14], [3, 11], [17, 31], [1, 28], [4, 5], [14, 34], [3, 17], [15, 24], [3, 12], [13, 16], [22, 35], [8, 30], [8, 23], [13, 20], [14, 16], [10, 28]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s1/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e023b5184af1fcdcd43288a6f14c83c837850f48 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [29, 3, 23, 24, 33, 10, 28, 2, 35, 22, 34, 9, 17, 25, 15, 14, 19, 13, 5, 1, 7, 6, 11, 27, 31, 4, 30]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-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-l6-s1/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8631040eff899d00d9f2456c467b3071ec6cabd1 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n1": 27, "n2": 36, "edges1": [[12, 17], [5, 26], [2, 5], [1, 10], [3, 25], [3, 12], [20, 25], [1, 21], [11, 14], [1, 3], [10, 18], [6, 12], [6, 17], [21, 26], [1, 22], [25, 26], [6, 18], [10, 13], [4, 10], [20, 23], [2, 12], [8, 16], [23, 25], [15, 18], [12, 23], [7, 23], [8, 9], [1, 4], [16, 20], [9, 22], [9, 15], [10, 11], [17, 20], [20, 21], [11, 21], [20, 24], [2, 22], [5, 24], [9, 16], [12, 20], [9, 18], [1, 25], [5, 14], [0, 22], [1, 23], [4, 18], [19, 21], [3, 18], [21, 23], [4, 17], [4, 14], [3, 11], [16, 18], [14, 16], [3, 24], [10, 15], [9, 12], [0, 6], [0, 25], [1, 26], [1, 12], [4, 6], [8, 18], [3, 9], [8, 15], [15, 17], [2, 15], [1, 15], [7, 13], [0, 21], [2, 11], [2, 6], [12, 21], [6, 25], [1, 19], [4, 5], [6, 24], [1, 7], [9, 20], [3, 22], [4, 24], [9, 14], [12, 26], [13, 15], [10, 19], [0, 26], [15, 25], [7, 11], [13, 24], [1, 9], [7, 14], [12, 22], [6, 23], [13, 16], [14, 21], [4, 13], [8, 14], [0, 12], [4, 7], [4, 26], [13, 21], [5, 9], [9, 26], [3, 14], [5, 23], [9, 24], [8, 19], [8, 10], [17, 18], [13, 14], [8, 22], [20, 22], [18, 19], [6, 16], [10, 21], [19, 23], [2, 7], [7, 17], [0, 7], [1, 14], [3, 8], [3, 23], [13, 20], [7, 19], [5, 6], [5, 7], [9, 17], [23, 24], [6, 22], [6, 20], [7, 16], [13, 17], [5, 25], [2, 26], [9, 25], [3, 5], [3, 7], [6, 19], [4, 8], [12, 24], [10, 20], [0, 18], [5, 15], [3, 16], [10, 16], [7, 20], [14, 20], [0, 13], [17, 25], [4, 12], [8, 23], [2, 10], [18, 25], [3, 6], [5, 16], [7, 26], [12, 25], [0, 16], [6, 9], [10, 17], [3, 4], [5, 20], [11, 12], [21, 22]], "edges2": [[10, 15], [5, 19], [32, 34], [6, 11], [15, 21], [12, 29], [17, 27], [3, 15], [18, 20], [8, 19], [11, 17], [18, 23], [24, 33], [14, 18], [2, 24], [13, 25], [9, 24], [7, 10], [11, 35], [12, 19], [25, 33], [2, 23], [19, 22], [2, 33], [1, 34], [18, 32], [23, 30], [3, 8], [2, 7], [22, 32], [21, 31], [17, 22], [13, 34], [3, 30], [27, 35], [16, 24], [6, 7], [14, 25], [8, 24], [23, 34], [1, 18], [10, 14], [7, 25], [18, 28], [13, 33], [34, 35], [11, 24], [11, 12], [9, 17], [12, 28], [32, 35], [16, 18], [10, 23], [15, 19], [28, 33], [13, 26], [7, 34], [29, 30], [1, 20], [4, 13], [5, 34], [10, 27], [2, 19], [12, 23], [12, 15], [8, 27], [10, 30], [24, 28], [12, 31], [13, 28], [9, 15], [22, 24], [14, 23], [5, 13], [4, 24], [16, 34], [0, 4], [9, 20], [0, 10], [11, 18], [2, 32], [20, 25], [24, 27], [2, 3], [6, 34], [5, 32], [12, 35], [5, 18], [22, 30], [25, 32], [19, 28], [28, 29], [2, 9], [31, 33], [23, 32], [5, 33], [2, 25], [0, 29], [14, 35], [30, 33], [4, 16], [9, 12], [20, 29], [8, 31], [20, 31], [10, 33], [16, 32], [20, 22], [7, 31], [8, 21], [16, 29], [0, 19], [25, 29], [5, 35], [3, 34], [6, 32], [9, 23], [13, 22], [20, 34], [10, 31], [26, 32], [0, 27], [18, 26], [18, 35], [19, 20], [4, 8], [15, 35], [8, 14], [19, 24], [2, 27], [17, 32], [6, 17], [15, 22], [14, 22], [9, 34], [27, 28], [17, 28], [16, 19], [21, 26], [21, 24], [5, 24], [11, 23], [3, 14], [16, 28], [33, 34], [6, 15], [6, 9], [0, 26], [7, 19], [4, 26], [12, 16], [7, 12], [20, 21], [3, 24], [12, 34], [21, 23], [0, 28], [7, 13], [9, 18], [8, 29], [18, 31], [9, 16], [4, 17], [19, 29], [2, 15], [11, 20], [13, 18], [1, 2], [17, 30], [14, 32], [24, 31], [11, 22], [10, 32], [21, 29], [4, 10], [14, 26], [4, 12], [24, 35], [2, 13], [20, 33], [4, 14], [17, 23], [1, 3], [1, 27], [21, 35], [17, 24], [4, 29], [23, 28], [7, 17], [24, 26], [9, 26], [31, 32], [25, 31], [0, 31], [7, 28], [10, 22], [6, 12], [3, 33], [6, 29], [11, 28], [2, 30], [15, 26], [3, 27], [25, 34], [7, 11], [12, 13], [10, 19], [10, 24], [33, 35], [18, 30], [2, 12], [4, 22], [2, 10], [23, 26], [6, 27], [26, 30], [7, 15], [8, 32], [4, 7], [15, 25], [1, 35], [3, 20], [19, 25], [27, 31], [4, 32], [6, 30], [5, 28], [4, 27], [7, 8], [17, 29], [2, 29], [20, 23], [13, 14], [4, 30], [4, 18], [0, 20], [12, 25], [13, 21], [7, 27], [0, 9], [13, 17], [16, 31], [5, 22], [8, 18], [17, 33], [1, 5], [1, 6], [22, 28], [11, 29], [1, 21], [19, 34], [22, 31], [3, 6], [3, 22], [11, 16], [6, 26], [4, 28], [5, 29], [19, 35], [21, 28], [3, 32], [7, 22], [26, 34], [28, 31], [15, 33], [6, 25], [3, 4], [5, 14], [3, 11], [17, 31], [1, 28], [4, 5], [14, 34], [3, 17], [15, 24], [3, 12], [13, 16], [22, 35], [8, 30], [8, 23], [13, 20], [14, 16], [10, 28]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l6-s1/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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/optimize-ae-p31-furstenberg-sarkozy-k2/environment/Dockerfile b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p31-furstenberg-sarkozy-k2/environment/instance.json b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a7e189dbc74c0d43a537fd577a6d43fd92358543 --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "max_m": 1000000, "max_size": 3000, "direction": "maximize", "family": "ae_p31_furstenberg_sarkozy", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/solution/solve.sh b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6aff20498979c28a733ef3654a42cea6767d99da --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"m": 205, "residues": [0, 2, 8, 14, 77, 79, 85, 96, 103, 109, 111, 181]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/check.py b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..296ac248623e85e3ff5e54bab1732a30c7889e1a --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/check.py @@ -0,0 +1,47 @@ +"""Ruzsa-type modular construction for the Furstenberg-Sarkozy problem. + +A subset A of Z/mZ (m square-free) with no two distinct elements differing by a non-zero k-th power residue +gives subsets of {1..N} with no k-th power differences of size N^{(k-1)/k + log|A|/(k log m)} (Ruzsa 1984). +Score = that exponent. Mirrors upstream `get_score` (furstenberg_sarkozy_problem.ipynb), which silently +reduced/deduplicated the list; here entries must be distinct residues in [0, m). +""" +import math + +import numpy as np + +from run import Invalid, as_int, int_list + + +def squarefree(m): + d = 2 + while d * d <= m: + if m % (d * d) == 0: + return False + d += 1 + return True + + +def check(inst, ans): + k = inst["k"] + m = as_int(ans.get("m"), "m", 2, inst["max_m"]) + if not squarefree(m): + raise Invalid("m must be square-free") + A = int_list(ans.get("residues"), None, 0, m - 1, "residues") + if not 1 <= len(A) <= inst["max_size"]: + raise Invalid(f"need 1 <= |A| <= {inst['max_size']}") + if len(set(A)) != len(A): + raise Invalid("duplicate residues") + y = np.arange(1, m, dtype=np.int64) + r = y % m + for _ in range(k - 1): + r = (r * y) % m + forb = np.zeros(m, dtype=bool) + forb[r] = True + forb[0] = False + a = np.array(A, dtype=np.int64) + diff = (a[:, None] - a[None, :]) % m + np.fill_diagonal(diff, 0) + if forb[diff].any(): + i, j = np.argwhere(forb[diff])[0] + raise Invalid(f"{A[i]} - {A[j]} is a non-zero k-th power residue mod {m} (k = {k})") + return (k - 1) / k + math.log(len(A)) / (k * math.log(m)), {"m": m, "size": len(A)} diff --git a/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/instance.json b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e282b6dab3238c6c1b3fadb1b7628fdbd8d6a5f --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "max_m": 1000000, "max_size": 3000, "direction": "maximize", "best_known": 0.7334117970402727, "baseline": 0.5, "family": "ae_p31_furstenberg_sarkozy", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/run.py b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p31-furstenberg-sarkozy-k2/tests/test.sh b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p31-furstenberg-sarkozy-k2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt