diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s3/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l3-s3/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b1b22e06d71f6107862ae8c7646d2c5d1f7f52c0 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"N": 275, "t": 83, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s3/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f4f517b4c7f6c3e0e9bd290d28d55477dd1dad40 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [83, 83, 83, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 84, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 97, 97, 101, 101, 103, 103, 104, 104, 104, 104, 104, 104, 104, 106, 106, 106, 106, 106, 107, 107, 109, 109, 111, 111, 111, 111, 111, 111, 111, 113, 113, 118, 118, 118, 118, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 127, 127, 128, 128, 131, 131, 134, 134, 134, 134, 137, 137, 139, 142, 142, 142, 146, 146, 146, 149, 151, 157, 158, 158, 158, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b1b22e06d71f6107862ae8c7646d2c5d1f7f52c0 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"N": 275, "t": 83, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l3-s3/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l3-s4/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s4/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a42ef11d56f0b8bd29bd9258494df31530a8a9c5 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"N": 284, "t": 85, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s4/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9924ff4e5a4b0d1a2b68ae8b68eaa35eb9a4885c --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"factors": [85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 85, 86, 86, 86, 86, 86, 86, 87, 87, 87, 87, 87, 87, 87, 87, 87, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 88, 89, 89, 89, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 92, 93, 93, 93, 93, 93, 93, 93, 93, 93, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 96, 97, 97, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 98, 101, 101, 102, 102, 102, 102, 102, 103, 103, 106, 106, 106, 106, 106, 107, 107, 109, 109, 111, 111, 111, 111, 111, 111, 111, 113, 113, 118, 118, 118, 118, 122, 122, 122, 122, 123, 123, 123, 123, 123, 123, 126, 127, 127, 128, 131, 131, 134, 134, 134, 134, 137, 137, 139, 139, 142, 142, 142, 142, 146, 146, 146, 149, 151, 157, 158, 158, 158, 163, 166, 166, 166, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a42ef11d56f0b8bd29bd9258494df31530a8a9c5 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"N": 284, "t": 85, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s8/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l3-s8/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..50abcb7cc3e71d0046e921550f952b93fccc58ea --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"N": 1067, "t": 43, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s8/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9d1b3e3f2f522672d14833a4f3a1d4551bb66972 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..50abcb7cc3e71d0046e921550f952b93fccc58ea --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"N": 1067, "t": 43, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l3-s8/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-mc-bibd-l4-s1/environment/Dockerfile b/tasks/construct-mc-bibd-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l4-s1/environment/instance.json b/tasks/construct-mc-bibd-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6036b18bf14c0d9945c7afce57b25eba4b52ffb3 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 3, "lambda": 2, "b": 52, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l4-s1/solution/solve.sh b/tasks/construct-mc-bibd-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ca267da3f960f3b0aa9e0e6bbff798247df5f31 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[2, 5, 7], [5, 10, 11], [0, 11, 12], [0, 10, 12], [0, 1, 5], [0, 3, 10], [0, 5, 11], [0, 3, 9], [0, 1, 2], [5, 10, 12], [1, 7, 12], [1, 5, 9], [5, 8, 9], [1, 7, 11], [1, 9, 11], [1, 3, 12], [2, 9, 11], [2, 5, 12], [7, 9, 10], [2, 6, 7], [3, 7, 11], [3, 7, 9], [0, 2, 6], [1, 3, 6], [3, 6, 12], [2, 3, 10], [2, 3, 8], [2, 11, 12], [8, 10, 11], [1, 2, 8], [3, 8, 11], [4, 8, 12], [0, 8, 9], [0, 4, 7], [3, 4, 5], [3, 4, 5], [1, 4, 10], [4, 9, 12], [2, 4, 10], [1, 4, 8], [4, 6, 11], [2, 4, 9], [0, 4, 7], [4, 6, 11], [5, 6, 7], [5, 6, 8], [6, 9, 10], [1, 6, 10], [7, 8, 12], [7, 8, 10], [0, 6, 8], [6, 9, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l4-s1/tests/check.py b/tasks/construct-mc-bibd-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-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-l4-s1/tests/instance.json b/tasks/construct-mc-bibd-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6036b18bf14c0d9945c7afce57b25eba4b52ffb3 --- /dev/null +++ b/tasks/construct-mc-bibd-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 3, "lambda": 2, "b": 52, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l4-s1/tests/run.py b/tasks/construct-mc-bibd-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l4-s1/tests/test.sh b/tasks/construct-mc-bibd-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-costas-array-l1-s3/environment/Dockerfile b/tasks/construct-mc-costas-array-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l1-s3/environment/instance.json b/tasks/construct-mc-costas-array-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e54bc14552ab244d0e9f401f3655b10ea70ec837 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l1-s3/solution/solve.sh b/tasks/construct-mc-costas-array-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ee9b9e28e7e460cb3427cad46d3aa70c31e645b1 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 2, 3, 1, 4]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l1-s3/tests/check.py b/tasks/construct-mc-costas-array-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l1-s3/tests/instance.json b/tasks/construct-mc-costas-array-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e54bc14552ab244d0e9f401f3655b10ea70ec837 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l1-s3/tests/run.py b/tasks/construct-mc-costas-array-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l1-s3/tests/test.sh b/tasks/construct-mc-costas-array-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l1-s4/environment/Dockerfile b/tasks/construct-mc-costas-array-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l1-s4/environment/instance.json b/tasks/construct-mc-costas-array-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..69459ce0daed749c61e8eb9c54233d125b9e43b5 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "fixed": [["x", 1, 1]], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l1-s4/solution/solve.sh b/tasks/construct-mc-costas-array-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e914f80957917faeaaf1012ae77e306259ed9abb --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 1, 6, 4, 3, 5, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l1-s4/tests/check.py b/tasks/construct-mc-costas-array-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l1-s4/tests/instance.json b/tasks/construct-mc-costas-array-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..69459ce0daed749c61e8eb9c54233d125b9e43b5 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "fixed": [["x", 1, 1]], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l1-s4/tests/run.py b/tasks/construct-mc-costas-array-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l1-s4/tests/test.sh b/tasks/construct-mc-costas-array-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-golomb-l2-s0/environment/Dockerfile b/tasks/construct-mc-golomb-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l2-s0/environment/instance.json b/tasks/construct-mc-golomb-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb1e19f55d2e7ee39d0185d0e0fdc41f66b331bd --- /dev/null +++ b/tasks/construct-mc-golomb-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "max_length": 44, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l2-s0/solution/solve.sh b/tasks/construct-mc-golomb-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7d899199777d5c2f5410231d0bcb663c96da1d74 --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 1, 5, 12, 25, 27, 35, 41, 44]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l2-s0/tests/check.py b/tasks/construct-mc-golomb-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l2-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-l2-s0/tests/instance.json b/tasks/construct-mc-golomb-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb1e19f55d2e7ee39d0185d0e0fdc41f66b331bd --- /dev/null +++ b/tasks/construct-mc-golomb-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "max_length": 44, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l2-s0/tests/run.py b/tasks/construct-mc-golomb-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l2-s0/tests/test.sh b/tasks/construct-mc-golomb-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-golomb-l6-s1/environment/Dockerfile b/tasks/construct-mc-golomb-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-golomb-l6-s1/environment/instance.json b/tasks/construct-mc-golomb-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..005b756cbc744217eb96ba2faddd57f3cbb58d5e --- /dev/null +++ b/tasks/construct-mc-golomb-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 19, "max_length": 246, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l6-s1/solution/solve.sh b/tasks/construct-mc-golomb-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6cc2256e454d735bd1981ac9a3044e94ef19cda8 --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 1, 6, 25, 32, 72, 100, 108, 120, 130, 153, 169, 187, 190, 204, 231, 233, 242, 246]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l6-s1/tests/check.py b/tasks/construct-mc-golomb-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l6-s1/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l6-s1/tests/instance.json b/tasks/construct-mc-golomb-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..005b756cbc744217eb96ba2faddd57f3cbb58d5e --- /dev/null +++ b/tasks/construct-mc-golomb-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 19, "max_length": 246, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l6-s1/tests/run.py b/tasks/construct-mc-golomb-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-golomb-l6-s1/tests/test.sh b/tasks/construct-mc-golomb-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-hadamard-l4-s3/environment/Dockerfile b/tasks/construct-mc-hadamard-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l4-s3/environment/instance.json b/tasks/construct-mc-hadamard-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..22a097d6b1a9137a499a78dc071e27b6cd6fd917 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 27, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l4-s3/solution/solve.sh b/tasks/construct-mc-hadamard-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6bfb73e643d405cbafdb79696f2903addb0b3433 --- /dev/null +++ b/tasks/construct-mc-hadamard-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": [-1, 1, 1, 1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1], "y": [1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, 1, -1, 1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l4-s3/tests/check.py b/tasks/construct-mc-hadamard-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Legendre pair of odd length n (MathConstraint hadamard, CC-BY-4.0): x, y in {-1,+1}^n with +sum(x) = sum(y) = 1 and PAF_x(k) + PAF_y(k) = -2 for k = 1..(n-1)/2 (periodic autocorrelation).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, -1, 1, "x") + y = int_list(ans.get("y"), n, -1, 1, "y") + if 0 in x or 0 in y: + raise Invalid("entries must be -1 or +1") + if sum(x) != 1 or sum(y) != 1: + raise Invalid("sum(x) and sum(y) must both equal 1") + for k in range(1, (n - 1) // 2 + 1): + p = sum(x[i] * x[(i + k) % n] for i in range(n)) + sum(y[i] * y[(i + k) % n] for i in range(n)) + if p != -2: + raise Invalid(f"PAF_x({k}) + PAF_y({k}) = {p}, need -2") + return None, {} diff --git a/tasks/construct-mc-hadamard-l4-s3/tests/instance.json b/tasks/construct-mc-hadamard-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..22a097d6b1a9137a499a78dc071e27b6cd6fd917 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 27, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l4-s3/tests/run.py b/tasks/construct-mc-hadamard-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l4-s3/tests/test.sh b/tasks/construct-mc-hadamard-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l4-s4/environment/Dockerfile b/tasks/construct-mc-hadamard-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l4-s4/environment/instance.json b/tasks/construct-mc-hadamard-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e85070d7fc8b32f65c74575c7654595675ab469b --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l4-s4/solution/solve.sh b/tasks/construct-mc-hadamard-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..509a9d183286c19875d173960dae97ce049d7c6e --- /dev/null +++ b/tasks/construct-mc-hadamard-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": [1, 1, 1, 1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, 1, 1, -1, -1, -1], "y": [1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l4-s4/tests/check.py b/tasks/construct-mc-hadamard-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s4/tests/check.py @@ -0,0 +1,18 @@ +"""Legendre pair of odd length n (MathConstraint hadamard, CC-BY-4.0): x, y in {-1,+1}^n with +sum(x) = sum(y) = 1 and PAF_x(k) + PAF_y(k) = -2 for k = 1..(n-1)/2 (periodic autocorrelation).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, -1, 1, "x") + y = int_list(ans.get("y"), n, -1, 1, "y") + if 0 in x or 0 in y: + raise Invalid("entries must be -1 or +1") + if sum(x) != 1 or sum(y) != 1: + raise Invalid("sum(x) and sum(y) must both equal 1") + for k in range(1, (n - 1) // 2 + 1): + p = sum(x[i] * x[(i + k) % n] for i in range(n)) + sum(y[i] * y[(i + k) % n] for i in range(n)) + if p != -2: + raise Invalid(f"PAF_x({k}) + PAF_y({k}) = {p}, need -2") + return None, {} diff --git a/tasks/construct-mc-hadamard-l4-s4/tests/instance.json b/tasks/construct-mc-hadamard-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e85070d7fc8b32f65c74575c7654595675ab469b --- /dev/null +++ b/tasks/construct-mc-hadamard-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l4-s4/tests/run.py b/tasks/construct-mc-hadamard-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l4-s4/tests/test.sh b/tasks/construct-mc-hadamard-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-low-autocorrelation-l2-s1/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l2-s1/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd575ed522aad2521cb17a30eb2d3d784bcc29b7 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 17, "bound": 40, "fixed": [["seq", 1, -1], ["seq", 6, 1], ["seq", 9, -1], ["c", 7, 3], ["c", 8, -2], ["c", 12, 0]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l2-s1/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9bd454e4b5e7e755e61237bd50eebf5daa97f2c5 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-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-l2-s1/tests/check.py b/tasks/construct-mc-low-autocorrelation-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l2-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-l2-s1/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cd575ed522aad2521cb17a30eb2d3d784bcc29b7 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 17, "bound": 40, "fixed": [["seq", 1, -1], ["seq", 6, 1], ["seq", 9, -1], ["c", 7, 3], ["c", 8, -2], ["c", 12, 0]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l2-s1/tests/run.py b/tasks/construct-mc-low-autocorrelation-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l2-s1/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l6-s0/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-low-autocorrelation-l6-s0/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab11e00d0c46cda7b1b8170981cf0dbd0f89b185 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "bound": 134, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l6-s0/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..43036a9f8b6d7725acefcd3cff6fa9545194a4af --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"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, -1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l6-s0/tests/check.py b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l6-s0/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab11e00d0c46cda7b1b8170981cf0dbd0f89b185 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "bound": 134, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l6-s0/tests/run.py b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-low-autocorrelation-l6-s0/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l5-s0/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l5-s0/environment/instance.json b/tasks/construct-mc-magic-sequence-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c3599a16972234c93b7c9a530535dd8a31c13ae --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 128, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l5-s0/solution/solve.sh b/tasks/construct-mc-magic-sequence-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3dba021f00fd66ddc02422a6a153587a943a6fe8 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [124, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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-l5-s0/tests/check.py b/tasks/construct-mc-magic-sequence-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-mc-magic-sequence-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8c3599a16972234c93b7c9a530535dd8a31c13ae --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 128, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l5-s0/tests/run.py b/tasks/construct-mc-magic-sequence-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l5-s0/tests/test.sh b/tasks/construct-mc-magic-sequence-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-max-clique-l2-s1/environment/Dockerfile b/tasks/construct-mc-max-clique-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l2-s1/environment/instance.json b/tasks/construct-mc-max-clique-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e35aa9564eb88c30e1f2558907eb3405cefc9c59 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 7], [0, 8], [0, 10], [0, 11], [0, 17], [0, 18], [0, 20], [0, 21], [0, 23], [0, 25], [0, 26], [0, 30], [0, 31], [0, 33], [0, 34], [0, 35], [0, 36], [0, 38], [0, 39], [1, 2], [1, 4], [1, 6], [1, 7], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 20], [1, 21], [1, 27], [1, 31], [1, 35], [1, 38], [1, 39], [2, 3], [2, 10], [2, 11], [2, 15], [2, 18], [2, 20], [2, 21], [2, 23], [2, 26], [2, 28], [2, 29], [2, 33], [2, 36], [2, 37], [2, 38], [2, 39], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 14], [3, 19], [3, 21], [3, 23], [3, 25], [3, 27], [3, 30], [3, 31], [3, 37], [3, 38], [4, 6], [4, 13], [4, 14], [4, 15], [4, 18], [4, 19], [4, 20], [4, 21], [4, 23], [4, 27], [4, 28], [4, 30], [4, 31], [4, 34], [4, 35], [4, 37], [5, 6], [5, 9], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 31], [5, 34], [5, 35], [5, 37], [5, 39], [6, 7], [6, 9], [6, 11], [6, 12], [6, 13], [6, 15], [6, 17], [6, 20], [6, 21], [6, 22], [6, 23], [6, 25], [6, 27], [6, 28], [6, 29], [6, 32], [6, 35], [6, 37], [6, 39], [7, 9], [7, 10], [7, 12], [7, 13], [7, 16], [7, 17], [7, 18], [7, 21], [7, 25], [7, 26], [7, 30], [7, 31], [7, 37], [7, 38], [7, 39], [8, 9], [8, 10], [8, 11], [8, 12], [8, 15], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 29], [8, 30], [8, 31], [8, 33], [8, 36], [8, 37], [8, 38], [8, 39], [9, 10], [9, 11], [9, 12], [9, 16], [9, 21], [9, 23], [9, 24], [9, 25], [9, 29], [9, 31], [9, 33], [9, 34], [9, 36], [9, 39], [10, 12], [10, 13], [10, 15], [10, 16], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 25], [10, 27], [10, 29], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 20], [11, 22], [11, 23], [11, 25], [11, 29], [11, 30], [11, 34], [11, 37], [11, 39], [12, 13], [12, 15], [12, 16], [12, 17], [12, 18], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 28], [12, 29], [12, 31], [12, 32], [12, 33], [12, 36], [12, 37], [13, 15], [13, 18], [13, 19], [13, 20], [13, 22], [13, 26], [13, 27], [13, 29], [13, 30], [13, 35], [13, 38], [13, 39], [14, 16], [14, 17], [14, 18], [14, 22], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 31], [15, 17], [15, 21], [15, 22], [15, 24], [15, 26], [15, 27], [15, 29], [15, 30], [15, 34], [15, 35], [15, 36], [16, 17], [16, 19], [16, 20], [16, 21], [16, 24], [16, 25], [16, 26], [16, 27], [16, 30], [16, 31], [16, 33], [16, 37], [16, 38], [16, 39], [17, 20], [17, 21], [17, 23], [17, 24], [17, 32], [17, 33], [17, 36], [17, 37], [17, 38], [18, 19], [18, 20], [18, 21], [18, 22], [18, 26], [18, 30], [18, 33], [18, 35], [18, 38], [18, 39], [19, 22], [19, 24], [19, 25], [19, 27], [19, 31], [19, 33], [19, 34], [19, 37], [19, 39], [20, 23], [20, 26], [20, 28], [20, 30], [20, 32], [20, 35], [20, 36], [20, 37], [20, 39], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [22, 23], [22, 28], [22, 29], [22, 31], [22, 33], [22, 35], [22, 37], [22, 38], [23, 25], [23, 28], [23, 29], [23, 30], [23, 31], [23, 34], [23, 35], [23, 36], [23, 39], [24, 25], [24, 26], [24, 32], [24, 33], [24, 34], [24, 39], [25, 27], [25, 29], [25, 30], [25, 34], [25, 39], [26, 27], [26, 30], [26, 31], [26, 36], [26, 38], [26, 39], [27, 32], [27, 33], [27, 38], [27, 39], [28, 29], [28, 33], [28, 35], [28, 36], [28, 39], [29, 30], [29, 32], [29, 33], [29, 35], [29, 36], [29, 38], [29, 39], [30, 31], [30, 35], [30, 37], [30, 38], [31, 32], [31, 33], [31, 36], [31, 37], [32, 34], [32, 35], [32, 37], [32, 38], [32, 39], [33, 35], [33, 36], [33, 37], [35, 36], [35, 38], [35, 39], [36, 39], [37, 38]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s1/solution/solve.sh b/tasks/construct-mc-max-clique-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d67f4e131a1744e6d2127911dcae2746a4ee9932 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [8, 9, 10, 12, 21, 29, 33, 36]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l2-s1/tests/check.py b/tasks/construct-mc-max-clique-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l2-s1/tests/instance.json b/tasks/construct-mc-max-clique-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e35aa9564eb88c30e1f2558907eb3405cefc9c59 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 7], [0, 8], [0, 10], [0, 11], [0, 17], [0, 18], [0, 20], [0, 21], [0, 23], [0, 25], [0, 26], [0, 30], [0, 31], [0, 33], [0, 34], [0, 35], [0, 36], [0, 38], [0, 39], [1, 2], [1, 4], [1, 6], [1, 7], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 20], [1, 21], [1, 27], [1, 31], [1, 35], [1, 38], [1, 39], [2, 3], [2, 10], [2, 11], [2, 15], [2, 18], [2, 20], [2, 21], [2, 23], [2, 26], [2, 28], [2, 29], [2, 33], [2, 36], [2, 37], [2, 38], [2, 39], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 14], [3, 19], [3, 21], [3, 23], [3, 25], [3, 27], [3, 30], [3, 31], [3, 37], [3, 38], [4, 6], [4, 13], [4, 14], [4, 15], [4, 18], [4, 19], [4, 20], [4, 21], [4, 23], [4, 27], [4, 28], [4, 30], [4, 31], [4, 34], [4, 35], [4, 37], [5, 6], [5, 9], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 31], [5, 34], [5, 35], [5, 37], [5, 39], [6, 7], [6, 9], [6, 11], [6, 12], [6, 13], [6, 15], [6, 17], [6, 20], [6, 21], [6, 22], [6, 23], [6, 25], [6, 27], [6, 28], [6, 29], [6, 32], [6, 35], [6, 37], [6, 39], [7, 9], [7, 10], [7, 12], [7, 13], [7, 16], [7, 17], [7, 18], [7, 21], [7, 25], [7, 26], [7, 30], [7, 31], [7, 37], [7, 38], [7, 39], [8, 9], [8, 10], [8, 11], [8, 12], [8, 15], [8, 17], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 29], [8, 30], [8, 31], [8, 33], [8, 36], [8, 37], [8, 38], [8, 39], [9, 10], [9, 11], [9, 12], [9, 16], [9, 21], [9, 23], [9, 24], [9, 25], [9, 29], [9, 31], [9, 33], [9, 34], [9, 36], [9, 39], [10, 12], [10, 13], [10, 15], [10, 16], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 25], [10, 27], [10, 29], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 20], [11, 22], [11, 23], [11, 25], [11, 29], [11, 30], [11, 34], [11, 37], [11, 39], [12, 13], [12, 15], [12, 16], [12, 17], [12, 18], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 28], [12, 29], [12, 31], [12, 32], [12, 33], [12, 36], [12, 37], [13, 15], [13, 18], [13, 19], [13, 20], [13, 22], [13, 26], [13, 27], [13, 29], [13, 30], [13, 35], [13, 38], [13, 39], [14, 16], [14, 17], [14, 18], [14, 22], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 31], [15, 17], [15, 21], [15, 22], [15, 24], [15, 26], [15, 27], [15, 29], [15, 30], [15, 34], [15, 35], [15, 36], [16, 17], [16, 19], [16, 20], [16, 21], [16, 24], [16, 25], [16, 26], [16, 27], [16, 30], [16, 31], [16, 33], [16, 37], [16, 38], [16, 39], [17, 20], [17, 21], [17, 23], [17, 24], [17, 32], [17, 33], [17, 36], [17, 37], [17, 38], [18, 19], [18, 20], [18, 21], [18, 22], [18, 26], [18, 30], [18, 33], [18, 35], [18, 38], [18, 39], [19, 22], [19, 24], [19, 25], [19, 27], [19, 31], [19, 33], [19, 34], [19, 37], [19, 39], [20, 23], [20, 26], [20, 28], [20, 30], [20, 32], [20, 35], [20, 36], [20, 37], [20, 39], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [22, 23], [22, 28], [22, 29], [22, 31], [22, 33], [22, 35], [22, 37], [22, 38], [23, 25], [23, 28], [23, 29], [23, 30], [23, 31], [23, 34], [23, 35], [23, 36], [23, 39], [24, 25], [24, 26], [24, 32], [24, 33], [24, 34], [24, 39], [25, 27], [25, 29], [25, 30], [25, 34], [25, 39], [26, 27], [26, 30], [26, 31], [26, 36], [26, 38], [26, 39], [27, 32], [27, 33], [27, 38], [27, 39], [28, 29], [28, 33], [28, 35], [28, 36], [28, 39], [29, 30], [29, 32], [29, 33], [29, 35], [29, 36], [29, 38], [29, 39], [30, 31], [30, 35], [30, 37], [30, 38], [31, 32], [31, 33], [31, 36], [31, 37], [32, 34], [32, 35], [32, 37], [32, 38], [32, 39], [33, 35], [33, 36], [33, 37], [35, 36], [35, 38], [35, 39], [36, 39], [37, 38]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s1/tests/run.py b/tasks/construct-mc-max-clique-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l2-s1/tests/test.sh b/tasks/construct-mc-max-clique-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l2-s6/environment/Dockerfile b/tasks/construct-mc-max-clique-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l2-s6/environment/instance.json b/tasks/construct-mc-max-clique-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a26298ecea9cd4f23ed0d47834f106413592710 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 1], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 18], [0, 19], [0, 23], [0, 27], [0, 28], [0, 29], [0, 30], [0, 34], [0, 37], [1, 2], [1, 4], [1, 5], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 17], [1, 18], [1, 19], [1, 24], [1, 27], [1, 30], [1, 31], [1, 33], [1, 34], [1, 36], [2, 7], [2, 8], [2, 11], [2, 12], [2, 16], [2, 17], [2, 23], [2, 24], [2, 25], [2, 26], [2, 29], [2, 30], [2, 31], [2, 32], [2, 34], [2, 38], [2, 39], [3, 4], [3, 5], [3, 7], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 18], [3, 19], [3, 20], [3, 25], [3, 28], [3, 31], [3, 35], [3, 36], [3, 37], [3, 38], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 25], [4, 27], [4, 31], [4, 32], [4, 33], [4, 36], [4, 37], [4, 38], [5, 7], [5, 10], [5, 11], [5, 12], [5, 13], [5, 16], [5, 17], [5, 20], [5, 21], [5, 23], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 18], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 30], [6, 31], [6, 33], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 21], [7, 23], [7, 24], [7, 25], [7, 27], [7, 29], [7, 31], [7, 34], [7, 35], [7, 36], [7, 38], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 17], [8, 20], [8, 22], [8, 23], [8, 25], [8, 27], [8, 30], [8, 31], [8, 33], [8, 37], [8, 38], [8, 39], [9, 10], [9, 12], [9, 19], [9, 21], [9, 24], [9, 31], [9, 33], [9, 34], [9, 36], [9, 37], [9, 39], [10, 12], [10, 13], [10, 14], [10, 17], [10, 20], [10, 21], [10, 25], [10, 29], [10, 30], [10, 31], [10, 33], [10, 35], [10, 36], [10, 37], [11, 12], [11, 14], [11, 18], [11, 20], [11, 21], [11, 23], [11, 24], [11, 28], [11, 31], [11, 33], [11, 35], [12, 13], [12, 14], [12, 20], [12, 23], [12, 26], [12, 27], [12, 30], [12, 34], [12, 36], [12, 38], [12, 39], [13, 14], [13, 15], [13, 17], [13, 18], [13, 19], [13, 23], [13, 24], [13, 29], [13, 30], [13, 34], [13, 37], [13, 38], [14, 16], [14, 18], [14, 19], [14, 20], [14, 23], [14, 25], [14, 26], [14, 28], [14, 30], [14, 32], [14, 37], [15, 16], [15, 17], [15, 20], [15, 22], [15, 23], [15, 24], [15, 27], [15, 30], [15, 32], [15, 33], [15, 34], [15, 36], [15, 37], [15, 39], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [16, 24], [16, 30], [16, 33], [17, 19], [17, 21], [17, 22], [17, 23], [17, 24], [17, 26], [17, 27], [17, 28], [17, 29], [17, 31], [17, 33], [17, 34], [17, 37], [17, 38], [18, 19], [18, 23], [18, 25], [18, 27], [18, 28], [18, 34], [18, 36], [18, 37], [18, 38], [19, 22], [19, 23], [19, 25], [19, 26], [19, 29], [19, 31], [19, 32], [19, 33], [19, 37], [19, 38], [19, 39], [20, 22], [20, 23], [20, 25], [20, 27], [20, 29], [20, 31], [20, 35], [20, 36], [20, 38], [20, 39], [21, 22], [21, 25], [21, 27], [21, 28], [21, 31], [21, 33], [21, 34], [21, 36], [22, 23], [22, 24], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 33], [22, 34], [22, 38], [22, 39], [23, 25], [23, 27], [23, 29], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [24, 27], [24, 28], [24, 30], [24, 34], [24, 35], [24, 37], [24, 38], [24, 39], [25, 28], [25, 29], [25, 30], [25, 31], [25, 34], [25, 35], [25, 38], [26, 27], [26, 29], [26, 31], [26, 37], [27, 29], [27, 30], [27, 31], [27, 32], [27, 37], [27, 38], [28, 30], [28, 31], [28, 32], [28, 33], [28, 36], [28, 37], [28, 38], [28, 39], [29, 32], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 33], [30, 34], [30, 38], [31, 33], [31, 36], [31, 38], [31, 39], [32, 33], [32, 35], [32, 36], [32, 39], [33, 34], [33, 35], [33, 37], [33, 38], [34, 36], [34, 37], [34, 39], [35, 36], [35, 38], [36, 39], [38, 39]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s6/solution/solve.sh b/tasks/construct-mc-max-clique-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5939c33cb0ad5286185c44e9ab78bdaea3403c49 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [6, 8, 22, 23, 30, 31, 33, 38]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l2-s6/tests/check.py b/tasks/construct-mc-max-clique-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s6/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l2-s6/tests/instance.json b/tasks/construct-mc-max-clique-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a26298ecea9cd4f23ed0d47834f106413592710 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "k": 8, "edges": [[0, 1], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 18], [0, 19], [0, 23], [0, 27], [0, 28], [0, 29], [0, 30], [0, 34], [0, 37], [1, 2], [1, 4], [1, 5], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 17], [1, 18], [1, 19], [1, 24], [1, 27], [1, 30], [1, 31], [1, 33], [1, 34], [1, 36], [2, 7], [2, 8], [2, 11], [2, 12], [2, 16], [2, 17], [2, 23], [2, 24], [2, 25], [2, 26], [2, 29], [2, 30], [2, 31], [2, 32], [2, 34], [2, 38], [2, 39], [3, 4], [3, 5], [3, 7], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 18], [3, 19], [3, 20], [3, 25], [3, 28], [3, 31], [3, 35], [3, 36], [3, 37], [3, 38], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 25], [4, 27], [4, 31], [4, 32], [4, 33], [4, 36], [4, 37], [4, 38], [5, 7], [5, 10], [5, 11], [5, 12], [5, 13], [5, 16], [5, 17], [5, 20], [5, 21], [5, 23], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 18], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 30], [6, 31], [6, 33], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 21], [7, 23], [7, 24], [7, 25], [7, 27], [7, 29], [7, 31], [7, 34], [7, 35], [7, 36], [7, 38], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 17], [8, 20], [8, 22], [8, 23], [8, 25], [8, 27], [8, 30], [8, 31], [8, 33], [8, 37], [8, 38], [8, 39], [9, 10], [9, 12], [9, 19], [9, 21], [9, 24], [9, 31], [9, 33], [9, 34], [9, 36], [9, 37], [9, 39], [10, 12], [10, 13], [10, 14], [10, 17], [10, 20], [10, 21], [10, 25], [10, 29], [10, 30], [10, 31], [10, 33], [10, 35], [10, 36], [10, 37], [11, 12], [11, 14], [11, 18], [11, 20], [11, 21], [11, 23], [11, 24], [11, 28], [11, 31], [11, 33], [11, 35], [12, 13], [12, 14], [12, 20], [12, 23], [12, 26], [12, 27], [12, 30], [12, 34], [12, 36], [12, 38], [12, 39], [13, 14], [13, 15], [13, 17], [13, 18], [13, 19], [13, 23], [13, 24], [13, 29], [13, 30], [13, 34], [13, 37], [13, 38], [14, 16], [14, 18], [14, 19], [14, 20], [14, 23], [14, 25], [14, 26], [14, 28], [14, 30], [14, 32], [14, 37], [15, 16], [15, 17], [15, 20], [15, 22], [15, 23], [15, 24], [15, 27], [15, 30], [15, 32], [15, 33], [15, 34], [15, 36], [15, 37], [15, 39], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [16, 24], [16, 30], [16, 33], [17, 19], [17, 21], [17, 22], [17, 23], [17, 24], [17, 26], [17, 27], [17, 28], [17, 29], [17, 31], [17, 33], [17, 34], [17, 37], [17, 38], [18, 19], [18, 23], [18, 25], [18, 27], [18, 28], [18, 34], [18, 36], [18, 37], [18, 38], [19, 22], [19, 23], [19, 25], [19, 26], [19, 29], [19, 31], [19, 32], [19, 33], [19, 37], [19, 38], [19, 39], [20, 22], [20, 23], [20, 25], [20, 27], [20, 29], [20, 31], [20, 35], [20, 36], [20, 38], [20, 39], [21, 22], [21, 25], [21, 27], [21, 28], [21, 31], [21, 33], [21, 34], [21, 36], [22, 23], [22, 24], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 33], [22, 34], [22, 38], [22, 39], [23, 25], [23, 27], [23, 29], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [24, 27], [24, 28], [24, 30], [24, 34], [24, 35], [24, 37], [24, 38], [24, 39], [25, 28], [25, 29], [25, 30], [25, 31], [25, 34], [25, 35], [25, 38], [26, 27], [26, 29], [26, 31], [26, 37], [27, 29], [27, 30], [27, 31], [27, 32], [27, 37], [27, 38], [28, 30], [28, 31], [28, 32], [28, 33], [28, 36], [28, 37], [28, 38], [28, 39], [29, 32], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [30, 31], [30, 33], [30, 34], [30, 38], [31, 33], [31, 36], [31, 38], [31, 39], [32, 33], [32, 35], [32, 36], [32, 39], [33, 34], [33, 35], [33, 37], [33, 38], [34, 36], [34, 37], [34, 39], [35, 36], [35, 38], [36, 39], [38, 39]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l2-s6/tests/run.py b/tasks/construct-mc-max-clique-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l2-s6/tests/test.sh b/tasks/construct-mc-max-clique-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l6-s9/environment/Dockerfile b/tasks/construct-mc-max-clique-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l6-s9/environment/instance.json b/tasks/construct-mc-max-clique-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..404bc8c9488d8d2ba7f859c709dff328687e5659 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 13, "edges": [[0, 2], [0, 4], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 14], [0, 16], [0, 17], [0, 20], [0, 21], [0, 24], [0, 27], [0, 29], [0, 30], [0, 35], [0, 38], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 54], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 66], [0, 67], [0, 68], [0, 69], [0, 71], [0, 72], [0, 74], [0, 78], [0, 81], [0, 82], [0, 84], [0, 94], [0, 95], [0, 96], [0, 97], [0, 98], [0, 99], [0, 102], [0, 104], [0, 105], [0, 106], [0, 110], [0, 111], [0, 112], [0, 114], [0, 115], [0, 118], [1, 2], [1, 4], [1, 7], [1, 9], [1, 10], [1, 13], [1, 16], [1, 23], [1, 24], [1, 27], [1, 28], [1, 29], [1, 32], [1, 33], [1, 35], [1, 38], [1, 39], [1, 40], [1, 41], [1, 44], [1, 49], [1, 51], [1, 52], [1, 53], [1, 54], [1, 56], [1, 59], [1, 60], [1, 62], [1, 64], [1, 65], [1, 68], [1, 71], [1, 72], [1, 74], [1, 75], [1, 77], [1, 79], [1, 83], [1, 85], [1, 86], [1, 87], [1, 93], [1, 95], [1, 97], [1, 99], [1, 100], [1, 102], [1, 107], [1, 109], [1, 111], [1, 113], [1, 118], [1, 119], [2, 3], [2, 5], [2, 10], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 52], [2, 53], [2, 55], [2, 56], [2, 57], [2, 60], [2, 61], [2, 62], [2, 63], [2, 65], [2, 67], [2, 72], [2, 74], [2, 78], [2, 79], [2, 82], [2, 83], [2, 85], [2, 86], [2, 87], [2, 88], [2, 89], [2, 91], [2, 92], [2, 95], [2, 99], [2, 101], [2, 103], [2, 104], [2, 105], [2, 109], [2, 111], [2, 112], [2, 113], [2, 114], [2, 115], [2, 117], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 15], [3, 16], [3, 17], [3, 21], [3, 22], [3, 27], [3, 28], [3, 29], [3, 31], [3, 32], [3, 33], [3, 34], [3, 39], [3, 40], [3, 46], [3, 47], [3, 48], [3, 49], [3, 51], [3, 56], [3, 61], [3, 68], [3, 70], [3, 71], [3, 72], [3, 74], [3, 76], [3, 77], [3, 80], [3, 81], [3, 82], [3, 86], [3, 93], [3, 94], [3, 95], [3, 97], [3, 98], [3, 101], [3, 102], [3, 104], [3, 106], [3, 107], [3, 110], [3, 112], [3, 114], [3, 115], [3, 116], [3, 117], [3, 118], [3, 119], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 13], [4, 14], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 26], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 50], [4, 53], [4, 55], [4, 56], [4, 57], [4, 60], [4, 62], [4, 64], [4, 65], [4, 66], [4, 69], [4, 71], [4, 74], [4, 78], [4, 81], [4, 82], [4, 83], [4, 84], [4, 85], [4, 86], [4, 87], [4, 89], [4, 93], [4, 96], [4, 97], [4, 98], [4, 99], [4, 105], [4, 107], [4, 110], [4, 111], [4, 113], [4, 117], [4, 118], [4, 119], [5, 8], [5, 12], [5, 13], [5, 16], [5, 17], [5, 19], [5, 21], [5, 22], [5, 26], [5, 28], [5, 29], [5, 31], [5, 32], [5, 34], [5, 35], [5, 38], [5, 40], [5, 42], [5, 45], [5, 46], [5, 47], [5, 48], [5, 51], [5, 52], [5, 55], [5, 56], [5, 58], [5, 59], [5, 61], [5, 65], [5, 67], [5, 68], [5, 69], [5, 72], [5, 76], [5, 78], [5, 79], [5, 81], [5, 83], [5, 85], [5, 86], [5, 95], [5, 101], [5, 110], [5, 111], [5, 114], [5, 116], [5, 117], [5, 118], [5, 119], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 17], [6, 20], [6, 22], [6, 23], [6, 25], [6, 26], [6, 28], [6, 30], [6, 34], [6, 35], [6, 36], [6, 38], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 51], [6, 53], [6, 54], [6, 57], [6, 59], [6, 60], [6, 63], [6, 68], [6, 69], [6, 72], [6, 73], [6, 74], [6, 75], [6, 76], [6, 78], [6, 79], [6, 80], [6, 82], [6, 83], [6, 84], [6, 88], [6, 94], [6, 96], [6, 97], [6, 98], [6, 100], [6, 102], [6, 104], [6, 105], [6, 107], [6, 108], [6, 111], [6, 113], [6, 116], [6, 119], [7, 8], [7, 9], [7, 10], [7, 14], [7, 15], [7, 16], [7, 19], [7, 21], [7, 22], [7, 25], [7, 27], [7, 28], [7, 29], [7, 30], [7, 34], [7, 36], [7, 39], [7, 40], [7, 41], [7, 43], [7, 51], [7, 54], [7, 55], [7, 56], [7, 59], [7, 60], [7, 61], [7, 64], [7, 70], [7, 73], [7, 74], [7, 78], [7, 81], [7, 82], [7, 83], [7, 84], [7, 85], [7, 90], [7, 93], [7, 94], [7, 99], [7, 103], [7, 105], [7, 106], [7, 108], [7, 110], [7, 111], [7, 112], [7, 115], [7, 117], [7, 118], [7, 119], [8, 9], [8, 15], [8, 18], [8, 20], [8, 21], [8, 22], [8, 24], [8, 28], [8, 30], [8, 32], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 40], [8, 41], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 51], [8, 55], [8, 56], [8, 59], [8, 63], [8, 64], [8, 69], [8, 70], [8, 73], [8, 74], [8, 77], [8, 78], [8, 80], [8, 81], [8, 90], [8, 94], [8, 95], [8, 96], [8, 98], [8, 99], [8, 100], [8, 103], [8, 104], [8, 105], [8, 106], [8, 111], [8, 113], [8, 114], [8, 115], [8, 117], [8, 118], [9, 12], [9, 14], [9, 15], [9, 18], [9, 20], [9, 23], [9, 24], [9, 28], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 37], [9, 38], [9, 39], [9, 41], [9, 42], [9, 43], [9, 45], [9, 46], [9, 47], [9, 48], [9, 50], [9, 51], [9, 52], [9, 57], [9, 61], [9, 62], [9, 64], [9, 66], [9, 68], [9, 69], [9, 71], [9, 73], [9, 77], [9, 78], [9, 79], [9, 87], [9, 89], [9, 92], [9, 95], [9, 100], [9, 101], [9, 105], [9, 107], [9, 110], [9, 112], [9, 114], [9, 115], [9, 116], [9, 119], [10, 13], [10, 16], [10, 17], [10, 18], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 28], [10, 29], [10, 33], [10, 34], [10, 35], [10, 38], [10, 40], [10, 41], [10, 43], [10, 44], [10, 45], [10, 48], [10, 52], [10, 53], [10, 55], [10, 57], [10, 58], [10, 59], [10, 60], [10, 63], [10, 64], [10, 68], [10, 72], [10, 74], [10, 76], [10, 77], [10, 78], [10, 82], [10, 85], [10, 86], [10, 87], [10, 88], [10, 89], [10, 90], [10, 92], [10, 93], [10, 94], [10, 95], [10, 100], [10, 101], [10, 104], [10, 105], [10, 107], [10, 109], [10, 111], [10, 117], [10, 118], [10, 119], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 29], [11, 32], [11, 34], [11, 36], [11, 40], [11, 42], [11, 43], [11, 45], [11, 46], [11, 48], [11, 49], [11, 50], [11, 51], [11, 54], [11, 55], [11, 56], [11, 58], [11, 61], [11, 64], [11, 66], [11, 68], [11, 69], [11, 70], [11, 75], [11, 78], [11, 79], [11, 80], [11, 83], [11, 87], [11, 88], [11, 89], [11, 90], [11, 91], [11, 92], [11, 95], [11, 97], [11, 102], [11, 103], [11, 105], [11, 106], [11, 108], [11, 109], [11, 110], [11, 111], [11, 114], [12, 15], [12, 18], [12, 21], [12, 22], [12, 25], [12, 26], [12, 27], [12, 28], [12, 30], [12, 34], [12, 38], [12, 39], [12, 41], [12, 46], [12, 47], [12, 49], [12, 50], [12, 55], [12, 61], [12, 62], [12, 65], [12, 66], [12, 67], [12, 69], [12, 71], [12, 74], [12, 76], [12, 83], [12, 84], [12, 85], [12, 86], [12, 87], [12, 88], [12, 89], [12, 90], [12, 102], [12, 104], [12, 107], [12, 110], [12, 111], [12, 112], [12, 113], [12, 115], [12, 116], [12, 117], [12, 118], [13, 16], [13, 19], [13, 20], [13, 22], [13, 24], [13, 25], [13, 30], [13, 31], [13, 32], [13, 33], [13, 36], [13, 37], [13, 39], [13, 40], [13, 41], [13, 43], [13, 50], [13, 52], [13, 53], [13, 54], [13, 56], [13, 57], [13, 60], [13, 64], [13, 68], [13, 69], [13, 70], [13, 72], [13, 77], [13, 79], [13, 80], [13, 83], [13, 84], [13, 85], [13, 87], [13, 91], [13, 96], [13, 97], [13, 98], [13, 99], [13, 101], [13, 105], [13, 106], [13, 107], [13, 111], [13, 112], [13, 114], [13, 116], [14, 15], [14, 17], [14, 18], [14, 19], [14, 20], [14, 23], [14, 25], [14, 26], [14, 28], [14, 30], [14, 33], [14, 34], [14, 35], [14, 37], [14, 38], [14, 39], [14, 42], [14, 43], [14, 45], [14, 46], [14, 47], [14, 50], [14, 51], [14, 54], [14, 56], [14, 57], [14, 58], [14, 60], [14, 64], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 74], [14, 75], [14, 76], [14, 77], [14, 79], [14, 80], [14, 81], [14, 82], [14, 84], [14, 86], [14, 87], [14, 88], [14, 90], [14, 92], [14, 94], [14, 95], [14, 96], [14, 97], [14, 98], [14, 99], [14, 100], [14, 102], [14, 103], [14, 104], [14, 105], [14, 107], [14, 108], [14, 112], [14, 114], [14, 117], [15, 16], [15, 17], [15, 19], [15, 22], [15, 24], [15, 27], [15, 29], [15, 30], [15, 34], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 45], [15, 48], [15, 49], [15, 50], [15, 51], [15, 54], [15, 55], [15, 56], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 67], [15, 68], [15, 70], [15, 71], [15, 73], [15, 74], [15, 80], [15, 83], [15, 84], [15, 87], [15, 88], [15, 90], [15, 91], [15, 92], [15, 95], [15, 96], [15, 98], [15, 99], [15, 100], [15, 104], [15, 106], [15, 107], [15, 108], [15, 110], [15, 113], [15, 115], [16, 19], [16, 20], [16, 22], [16, 25], [16, 27], [16, 29], [16, 32], [16, 35], [16, 40], [16, 41], [16, 42], [16, 44], [16, 46], [16, 52], [16, 53], [16, 57], [16, 60], [16, 61], [16, 62], [16, 64], [16, 67], [16, 68], [16, 69], [16, 72], [16, 73], [16, 75], [16, 77], [16, 78], [16, 79], [16, 81], [16, 82], [16, 83], [16, 85], [16, 86], [16, 88], [16, 90], [16, 91], [16, 92], [16, 93], [16, 98], [16, 101], [16, 103], [16, 104], [16, 105], [16, 107], [16, 108], [16, 109], [16, 111], [16, 113], [16, 116], [16, 117], [16, 118], [17, 18], [17, 21], [17, 22], [17, 23], [17, 25], [17, 30], [17, 31], [17, 32], [17, 34], [17, 35], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 46], [17, 47], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 55], [17, 56], [17, 58], [17, 61], [17, 63], [17, 65], [17, 67], [17, 68], [17, 70], [17, 71], [17, 73], [17, 74], [17, 75], [17, 76], [17, 77], [17, 83], [17, 85], [17, 86], [17, 88], [17, 91], [17, 92], [17, 94], [17, 97], [17, 98], [17, 100], [17, 101], [17, 102], [17, 103], [17, 109], [17, 110], [17, 111], [17, 112], [17, 115], [17, 117], [18, 19], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 33], [18, 34], [18, 35], [18, 36], [18, 39], [18, 40], [18, 44], [18, 46], [18, 48], [18, 53], [18, 55], [18, 56], [18, 58], [18, 59], [18, 60], [18, 63], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 75], [18, 77], [18, 80], [18, 81], [18, 82], [18, 83], [18, 88], [18, 89], [18, 90], [18, 91], [18, 97], [18, 98], [18, 101], [18, 103], [18, 108], [18, 109], [18, 110], [18, 113], [18, 115], [18, 117], [18, 118], [19, 20], [19, 21], [19, 23], [19, 24], [19, 27], [19, 31], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 46], [19, 49], [19, 50], [19, 51], [19, 53], [19, 54], [19, 58], [19, 63], [19, 64], [19, 66], [19, 67], [19, 69], [19, 70], [19, 71], [19, 74], [19, 76], [19, 79], [19, 81], [19, 86], [19, 88], [19, 89], [19, 90], [19, 91], [19, 93], [19, 94], [19, 95], [19, 98], [19, 100], [19, 105], [19, 106], [19, 107], [19, 108], [19, 109], [19, 111], [19, 112], [19, 115], [19, 117], [19, 119], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 28], [20, 29], [20, 30], [20, 31], [20, 35], [20, 37], [20, 40], [20, 42], [20, 44], [20, 47], [20, 49], [20, 50], [20, 51], [20, 53], [20, 54], [20, 58], [20, 59], [20, 60], [20, 65], [20, 66], [20, 68], [20, 69], [20, 70], [20, 71], [20, 73], [20, 75], [20, 76], [20, 78], [20, 81], [20, 82], [20, 83], [20, 84], [20, 86], [20, 87], [20, 88], [20, 91], [20, 94], [20, 95], [20, 96], [20, 100], [20, 105], [20, 106], [20, 107], [20, 108], [20, 109], [20, 110], [20, 111], [20, 116], [20, 117], [20, 118], [21, 22], [21, 27], [21, 28], [21, 29], [21, 31], [21, 32], [21, 33], [21, 38], [21, 39], [21, 42], [21, 45], [21, 46], [21, 47], [21, 50], [21, 52], [21, 55], [21, 57], [21, 61], [21, 62], [21, 63], [21, 69], [21, 71], [21, 73], [21, 74], [21, 78], [21, 81], [21, 83], [21, 84], [21, 87], [21, 88], [21, 92], [21, 94], [21, 97], [21, 98], [21, 99], [21, 102], [21, 103], [21, 104], [21, 107], [21, 109], [21, 110], [21, 115], [21, 116], [21, 118], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 31], [22, 32], [22, 33], [22, 35], [22, 37], [22, 38], [22, 39], [22, 42], [22, 45], [22, 47], [22, 48], [22, 52], [22, 54], [22, 57], [22, 58], [22, 61], [22, 62], [22, 65], [22, 68], [22, 70], [22, 73], [22, 75], [22, 79], [22, 81], [22, 82], [22, 86], [22, 89], [22, 90], [22, 92], [22, 97], [22, 98], [22, 100], [22, 103], [22, 107], [22, 109], [22, 111], [22, 116], [22, 117], [22, 118], [23, 24], [23, 25], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 37], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 47], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 64], [23, 65], [23, 73], [23, 75], [23, 76], [23, 79], [23, 80], [23, 82], [23, 83], [23, 86], [23, 87], [23, 88], [23, 94], [23, 97], [23, 98], [23, 101], [23, 102], [23, 104], [23, 105], [23, 106], [23, 108], [23, 109], [23, 110], [23, 111], [23, 112], [23, 113], [23, 114], [23, 115], [23, 116], [23, 117], [23, 118], [23, 119], [24, 27], [24, 28], [24, 30], [24, 33], [24, 34], [24, 37], [24, 38], [24, 40], [24, 41], [24, 42], [24, 43], [24, 44], [24, 47], [24, 48], [24, 49], [24, 50], [24, 53], [24, 57], [24, 59], [24, 60], [24, 62], [24, 64], [24, 66], [24, 67], [24, 68], [24, 69], [24, 71], [24, 72], [24, 73], [24, 74], [24, 76], [24, 78], [24, 80], [24, 81], [24, 83], [24, 84], [24, 85], [24, 86], [24, 87], [24, 88], [24, 89], [24, 90], [24, 91], [24, 93], [24, 95], [24, 97], [24, 98], [24, 99], [24, 100], [24, 101], [24, 102], [24, 106], [24, 107], [24, 108], [24, 109], [24, 110], [24, 116], [24, 118], [25, 27], [25, 28], [25, 30], [25, 31], [25, 32], [25, 34], [25, 35], [25, 41], [25, 42], [25, 43], [25, 46], [25, 52], [25, 53], [25, 54], [25, 55], [25, 58], [25, 59], [25, 62], [25, 63], [25, 64], [25, 65], [25, 69], [25, 70], [25, 72], [25, 74], [25, 80], [25, 82], [25, 87], [25, 88], [25, 90], [25, 91], [25, 92], [25, 93], [25, 95], [25, 97], [25, 102], [25, 103], [25, 105], [25, 106], [25, 107], [25, 109], [25, 111], [25, 114], [25, 116], [25, 117], [25, 118], [25, 119], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [26, 42], [26, 45], [26, 46], [26, 51], [26, 53], [26, 55], [26, 56], [26, 58], [26, 59], [26, 68], [26, 70], [26, 71], [26, 72], [26, 75], [26, 76], [26, 78], [26, 80], [26, 82], [26, 83], [26, 84], [26, 86], [26, 88], [26, 89], [26, 90], [26, 91], [26, 92], [26, 93], [26, 99], [26, 101], [26, 105], [26, 107], [26, 108], [26, 109], [26, 111], [26, 114], [26, 116], [26, 118], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 35], [27, 37], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 48], [27, 49], [27, 50], [27, 53], [27, 54], [27, 61], [27, 64], [27, 65], [27, 66], [27, 67], [27, 70], [27, 71], [27, 72], [27, 73], [27, 74], [27, 75], [27, 76], [27, 77], [27, 79], [27, 80], [27, 81], [27, 83], [27, 85], [27, 87], [27, 89], [27, 90], [27, 94], [27, 95], [27, 96], [27, 97], [27, 99], [27, 102], [27, 103], [27, 105], [27, 108], [27, 109], [27, 111], [27, 114], [27, 115], [28, 30], [28, 33], [28, 36], [28, 37], [28, 39], [28, 41], [28, 42], [28, 44], [28, 45], [28, 53], [28, 56], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 65], [28, 66], [28, 68], [28, 73], [28, 74], [28, 75], [28, 76], [28, 78], [28, 79], [28, 80], [28, 82], [28, 83], [28, 85], [28, 86], [28, 87], [28, 88], [28, 90], [28, 91], [28, 95], [28, 97], [28, 98], [28, 99], [28, 104], [28, 107], [28, 108], [28, 110], [28, 111], [28, 115], [28, 118], [28, 119], [29, 30], [29, 31], [29, 35], [29, 37], [29, 39], [29, 42], [29, 43], [29, 46], [29, 52], [29, 53], [29, 56], [29, 58], [29, 59], [29, 60], [29, 64], [29, 67], [29, 68], [29, 70], [29, 71], [29, 75], [29, 77], [29, 78], [29, 80], [29, 84], [29, 85], [29, 90], [29, 91], [29, 93], [29, 94], [29, 95], [29, 97], [29, 100], [29, 102], [29, 106], [29, 113], [29, 115], [30, 32], [30, 33], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 46], [30, 48], [30, 49], [30, 53], [30, 54], [30, 59], [30, 61], [30, 62], [30, 63], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 78], [30, 79], [30, 83], [30, 85], [30, 88], [30, 89], [30, 90], [30, 91], [30, 93], [30, 94], [30, 95], [30, 97], [30, 100], [30, 101], [30, 102], [30, 103], [30, 105], [30, 106], [30, 107], [30, 109], [30, 110], [30, 115], [30, 116], [31, 32], [31, 35], [31, 36], [31, 37], [31, 41], [31, 42], [31, 43], [31, 44], [31, 46], [31, 48], [31, 50], [31, 51], [31, 52], [31, 53], [31, 54], [31, 57], [31, 58], [31, 59], [31, 61], [31, 62], [31, 63], [31, 64], [31, 66], [31, 70], [31, 72], [31, 75], [31, 77], [31, 78], [31, 82], [31, 83], [31, 89], [31, 93], [31, 95], [31, 100], [31, 103], [31, 106], [31, 109], [31, 110], [31, 111], [31, 112], [31, 113], [31, 116], [32, 34], [32, 35], [32, 39], [32, 41], [32, 45], [32, 47], [32, 54], [32, 55], [32, 57], [32, 58], [32, 60], [32, 64], [32, 69], [32, 75], [32, 77], [32, 78], [32, 82], [32, 84], [32, 87], [32, 88], [32, 90], [32, 95], [32, 97], [32, 98], [32, 99], [32, 100], [32, 103], [32, 104], [32, 106], [32, 109], [32, 110], [32, 111], [32, 112], [32, 114], [32, 116], [32, 118], [32, 119], [33, 35], [33, 37], [33, 40], [33, 41], [33, 43], [33, 46], [33, 48], [33, 49], [33, 55], [33, 57], [33, 59], [33, 60], [33, 61], [33, 62], [33, 64], [33, 65], [33, 66], [33, 67], [33, 68], [33, 69], [33, 70], [33, 76], [33, 77], [33, 78], [33, 79], [33, 83], [33, 84], [33, 86], [33, 87], [33, 91], [33, 93], [33, 96], [33, 97], [33, 99], [33, 101], [33, 102], [33, 105], [33, 106], [33, 109], [33, 110], [33, 111], [33, 112], [33, 113], [33, 114], [33, 115], [33, 119], [34, 36], [34, 38], [34, 39], [34, 41], [34, 42], [34, 44], [34, 48], [34, 51], [34, 54], [34, 55], [34, 58], [34, 59], [34, 61], [34, 63], [34, 65], [34, 71], [34, 73], [34, 76], [34, 77], [34, 79], [34, 82], [34, 85], [34, 92], [34, 96], [34, 97], [34, 98], [34, 99], [34, 104], [34, 107], [34, 109], [34, 110], [34, 111], [34, 112], [34, 115], [34, 118], [35, 36], [35, 37], [35, 38], [35, 39], [35, 41], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 54], [35, 55], [35, 56], [35, 57], [35, 60], [35, 62], [35, 66], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [35, 78], [35, 79], [35, 80], [35, 82], [35, 88], [35, 89], [35, 90], [35, 92], [35, 93], [35, 94], [35, 95], [35, 96], [35, 98], [35, 100], [35, 110], [35, 112], [35, 113], [35, 115], [35, 116], [35, 117], [36, 37], [36, 38], [36, 40], [36, 44], [36, 48], [36, 54], [36, 56], [36, 58], [36, 60], [36, 62], [36, 65], [36, 67], [36, 71], [36, 73], [36, 75], [36, 76], [36, 80], [36, 84], [36, 86], [36, 87], [36, 88], [36, 89], [36, 91], [36, 92], [36, 93], [36, 95], [36, 97], [36, 101], [36, 102], [36, 103], [36, 104], [36, 109], [36, 112], [36, 113], [36, 115], [36, 116], [36, 117], [36, 119], [37, 38], [37, 40], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 49], [37, 50], [37, 51], [37, 52], [37, 53], [37, 54], [37, 55], [37, 56], [37, 64], [37, 65], [37, 69], [37, 73], [37, 74], [37, 77], [37, 81], [37, 84], [37, 86], [37, 89], [37, 90], [37, 91], [37, 99], [37, 100], [37, 102], [37, 105], [37, 107], [37, 111], [37, 112], [37, 113], [37, 116], [37, 117], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 47], [38, 51], [38, 54], [38, 55], [38, 57], [38, 59], [38, 60], [38, 61], [38, 64], [38, 65], [38, 67], [38, 70], [38, 73], [38, 74], [38, 75], [38, 81], [38, 82], [38, 84], [38, 86], [38, 96], [38, 97], [38, 99], [38, 101], [38, 102], [38, 108], [38, 109], [38, 110], [38, 112], [38, 113], [38, 114], [38, 115], [38, 116], [38, 117], [38, 119], [39, 41], [39, 42], [39, 43], [39, 44], [39, 45], [39, 46], [39, 50], [39, 51], [39, 52], [39, 55], [39, 62], [39, 64], [39, 66], [39, 67], [39, 68], [39, 69], [39, 71], [39, 72], [39, 79], [39, 81], [39, 86], [39, 88], [39, 90], [39, 92], [39, 93], [39, 96], [39, 97], [39, 98], [39, 99], [39, 102], [39, 104], [39, 107], [39, 108], [39, 109], [39, 111], [39, 113], [39, 115], [39, 116], [39, 117], [39, 118], [40, 41], [40, 44], [40, 47], [40, 49], [40, 51], [40, 52], [40, 53], [40, 54], [40, 57], [40, 59], [40, 60], [40, 61], [40, 64], [40, 65], [40, 68], [40, 69], [40, 74], [40, 76], [40, 77], [40, 78], [40, 79], [40, 83], [40, 84], [40, 86], [40, 88], [40, 91], [40, 92], [40, 93], [40, 95], [40, 99], [40, 100], [40, 101], [40, 109], [40, 110], [40, 111], [40, 115], [41, 49], [41, 51], [41, 52], [41, 53], [41, 56], [41, 59], [41, 60], [41, 61], [41, 62], [41, 64], [41, 65], [41, 67], [41, 69], [41, 70], [41, 72], [41, 75], [41, 77], [41, 79], [41, 80], [41, 81], [41, 82], [41, 83], [41, 85], [41, 86], [41, 91], [41, 94], [41, 95], [41, 96], [41, 97], [41, 98], [41, 99], [41, 101], [41, 105], [41, 106], [41, 108], [41, 109], [41, 111], [41, 112], [41, 113], [41, 115], [41, 117], [41, 119], [42, 43], [42, 44], [42, 47], [42, 49], [42, 51], [42, 52], [42, 53], [42, 56], [42, 57], [42, 58], [42, 61], [42, 63], [42, 64], [42, 67], [42, 68], [42, 69], [42, 72], [42, 74], [42, 75], [42, 76], [42, 77], [42, 78], [42, 79], [42, 80], [42, 85], [42, 86], [42, 87], [42, 89], [42, 90], [42, 92], [42, 95], [42, 96], [42, 98], [42, 99], [42, 101], [42, 102], [42, 104], [42, 105], [42, 106], [42, 109], [42, 112], [42, 117], [42, 118], [43, 45], [43, 48], [43, 49], [43, 50], [43, 51], [43, 54], [43, 55], [43, 56], [43, 61], [43, 65], [43, 66], [43, 67], [43, 70], [43, 71], [43, 73], [43, 75], [43, 76], [43, 78], [43, 79], [43, 80], [43, 81], [43, 84], [43, 86], [43, 88], [43, 89], [43, 90], [43, 91], [43, 92], [43, 94], [43, 95], [43, 96], [43, 100], [43, 103], [43, 104], [43, 107], [43, 109], [43, 110], [43, 111], [43, 112], [43, 117], [43, 118], [43, 119], [44, 47], [44, 49], [44, 51], [44, 52], [44, 56], [44, 62], [44, 64], [44, 65], [44, 66], [44, 67], [44, 69], [44, 70], [44, 77], [44, 79], [44, 81], [44, 84], [44, 86], [44, 88], [44, 89], [44, 92], [44, 94], [44, 95], [44, 97], [44, 98], [44, 99], [44, 100], [44, 104], [44, 105], [44, 108], [44, 109], [44, 110], [44, 111], [44, 112], [44, 113], [44, 117], [44, 118], [45, 51], [45, 57], [45, 59], [45, 61], [45, 63], [45, 64], [45, 68], [45, 69], [45, 71], [45, 72], [45, 74], [45, 75], [45, 78], [45, 79], [45, 81], [45, 82], [45, 84], [45, 86], [45, 87], [45, 88], [45, 89], [45, 90], [45, 91], [45, 92], [45, 93], [45, 94], [45, 95], [45, 98], [45, 101], [45, 102], [45, 103], [45, 104], [45, 106], [45, 107], [45, 108], [45, 110], [45, 111], [45, 112], [45, 114], [45, 115], [46, 51], [46, 52], [46, 53], [46, 55], [46, 56], [46, 60], [46, 62], [46, 64], [46, 66], [46, 67], [46, 69], [46, 70], [46, 71], [46, 72], [46, 76], [46, 77], [46, 78], [46, 82], [46, 85], [46, 86], [46, 89], [46, 91], [46, 93], [46, 95], [46, 96], [46, 97], [46, 103], [46, 104], [46, 110], [46, 111], [46, 113], [46, 114], [46, 116], [46, 117], [46, 118], [46, 119], [47, 49], [47, 51], [47, 53], [47, 54], [47, 56], [47, 58], [47, 59], [47, 60], [47, 61], [47, 65], [47, 69], [47, 72], [47, 74], [47, 75], [47, 76], [47, 77], [47, 78], [47, 79], [47, 80], [47, 85], [47, 88], [47, 89], [47, 91], [47, 94], [47, 95], [47, 98], [47, 99], [47, 101], [47, 103], [47, 110], [47, 113], [47, 114], [47, 118], [47, 119], [48, 49], [48, 53], [48, 55], [48, 56], [48, 62], [48, 63], [48, 67], [48, 68], [48, 69], [48, 72], [48, 73], [48, 78], [48, 80], [48, 81], [48, 82], [48, 86], [48, 88], [48, 89], [48, 97], [48, 100], [48, 107], [48, 108], [48, 109], [48, 111], [48, 112], [48, 117], [48, 118], [48, 119], [49, 50], [49, 51], [49, 53], [49, 57], [49, 61], [49, 63], [49, 64], [49, 65], [49, 66], [49, 70], [49, 71], [49, 73], [49, 75], [49, 77], [49, 78], [49, 82], [49, 83], [49, 86], [49, 87], [49, 88], [49, 90], [49, 91], [49, 99], [49, 100], [49, 101], [49, 104], [49, 106], [49, 108], [49, 110], [49, 111], [49, 112], [49, 115], [49, 118], [49, 119], [50, 51], [50, 52], [50, 54], [50, 56], [50, 58], [50, 59], [50, 64], [50, 67], [50, 69], [50, 70], [50, 71], [50, 73], [50, 76], [50, 77], [50, 78], [50, 79], [50, 82], [50, 83], [50, 84], [50, 85], [50, 87], [50, 90], [50, 91], [50, 92], [50, 93], [50, 96], [50, 98], [50, 99], [50, 101], [50, 102], [50, 103], [50, 112], [50, 113], [50, 115], [50, 117], [50, 118], [51, 52], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 60], [51, 61], [51, 63], [51, 66], [51, 67], [51, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [51, 75], [51, 77], [51, 78], [51, 79], [51, 80], [51, 82], [51, 83], [51, 84], [51, 86], [51, 90], [51, 96], [51, 98], [51, 99], [51, 114], [51, 116], [51, 117], [51, 118], [51, 119], [52, 56], [52, 60], [52, 65], [52, 66], [52, 67], [52, 69], [52, 73], [52, 74], [52, 75], [52, 76], [52, 77], [52, 79], [52, 80], [52, 82], [52, 84], [52, 86], [52, 87], [52, 90], [52, 91], [52, 93], [52, 94], [52, 96], [52, 97], [52, 98], [52, 100], [52, 102], [52, 106], [52, 107], [52, 108], [52, 110], [52, 111], [52, 114], [52, 116], [52, 117], [53, 55], [53, 59], [53, 60], [53, 61], [53, 63], [53, 65], [53, 66], [53, 67], [53, 70], [53, 72], [53, 75], [53, 78], [53, 81], [53, 83], [53, 85], [53, 87], [53, 88], [53, 89], [53, 90], [53, 91], [53, 93], [53, 95], [53, 98], [53, 101], [53, 103], [53, 104], [53, 105], [53, 106], [53, 107], [53, 109], [53, 111], [53, 112], [53, 115], [53, 116], [54, 57], [54, 61], [54, 64], [54, 65], [54, 66], [54, 71], [54, 74], [54, 77], [54, 80], [54, 83], [54, 86], [54, 87], [54, 88], [54, 91], [54, 93], [54, 95], [54, 96], [54, 97], [54, 98], [54, 101], [54, 102], [54, 104], [54, 105], [54, 107], [54, 108], [54, 109], [54, 116], [54, 117], [54, 119], [55, 56], [55, 57], [55, 58], [55, 62], [55, 63], [55, 65], [55, 66], [55, 67], [55, 68], [55, 70], [55, 73], [55, 74], [55, 75], [55, 78], [55, 81], [55, 83], [55, 84], [55, 87], [55, 88], [55, 90], [55, 93], [55, 94], [55, 95], [55, 97], [55, 98], [55, 101], [55, 103], [55, 104], [55, 108], [55, 112], [55, 113], [55, 114], [55, 115], [55, 116], [55, 118], [55, 119], [56, 57], [56, 58], [56, 59], [56, 60], [56, 62], [56, 65], [56, 66], [56, 67], [56, 68], [56, 71], [56, 72], [56, 73], [56, 75], [56, 80], [56, 81], [56, 82], [56, 85], [56, 86], [56, 87], [56, 93], [56, 94], [56, 96], [56, 97], [56, 98], [56, 99], [56, 100], [56, 101], [56, 102], [56, 103], [56, 104], [56, 105], [56, 106], [56, 109], [56, 112], [56, 113], [56, 114], [56, 115], [56, 116], [57, 61], [57, 62], [57, 64], [57, 66], [57, 67], [57, 68], [57, 69], [57, 70], [57, 72], [57, 73], [57, 75], [57, 77], [57, 79], [57, 81], [57, 84], [57, 85], [57, 87], [57, 88], [57, 96], [57, 98], [57, 99], [57, 101], [57, 102], [57, 104], [57, 107], [57, 110], [57, 113], [57, 115], [57, 118], [57, 119], [58, 60], [58, 61], [58, 63], [58, 66], [58, 68], [58, 70], [58, 71], [58, 74], [58, 75], [58, 76], [58, 77], [58, 78], [58, 79], [58, 80], [58, 81], [58, 82], [58, 84], [58, 85], [58, 87], [58, 89], [58, 92], [58, 93], [58, 95], [58, 102], [58, 103], [58, 104], [58, 108], [58, 113], [58, 114], [58, 115], [58, 116], [58, 118], [58, 119], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 67], [59, 69], [59, 74], [59, 76], [59, 78], [59, 81], [59, 84], [59, 85], [59, 88], [59, 89], [59, 96], [59, 97], [59, 98], [59, 99], [59, 102], [59, 103], [59, 105], [59, 109], [59, 110], [59, 111], [59, 114], [59, 115], [59, 118], [59, 119], [60, 62], [60, 65], [60, 66], [60, 67], [60, 70], [60, 73], [60, 74], [60, 75], [60, 76], [60, 77], [60, 80], [60, 84], [60, 86], [60, 87], [60, 90], [60, 91], [60, 96], [60, 100], [60, 102], [60, 103], [60, 104], [60, 105], [60, 106], [60, 107], [60, 109], [60, 111], [60, 112], [60, 113], [60, 117], [61, 62], [61, 63], [61, 64], [61, 65], [61, 67], [61, 69], [61, 71], [61, 72], [61, 73], [61, 75], [61, 77], [61, 79], [61, 83], [61, 86], [61, 88], [61, 89], [61, 90], [61, 91], [61, 92], [61, 94], [61, 96], [61, 98], [61, 100], [61, 101], [61, 102], [61, 103], [61, 105], [61, 107], [61, 109], [61, 110], [61, 111], [61, 113], [61, 114], [61, 115], [61, 117], [61, 118], [61, 119], [62, 63], [62, 67], [62, 68], [62, 69], [62, 70], [62, 71], [62, 73], [62, 74], [62, 76], [62, 77], [62, 78], [62, 79], [62, 84], [62, 86], [62, 88], [62, 91], [62, 92], [62, 94], [62, 96], [62, 98], [62, 99], [62, 101], [62, 103], [62, 104], [62, 106], [62, 108], [62, 110], [62, 111], [62, 112], [62, 113], [62, 116], [62, 117], [63, 68], [63, 69], [63, 70], [63, 72], [63, 73], [63, 74], [63, 75], [63, 76], [63, 77], [63, 78], [63, 79], [63, 81], [63, 83], [63, 84], [63, 86], [63, 89], [63, 90], [63, 91], [63, 92], [63, 95], [63, 98], [63, 101], [63, 102], [63, 105], [63, 107], [63, 108], [63, 110], [63, 113], [63, 115], [63, 117], [63, 118], [64, 67], [64, 68], [64, 71], [64, 72], [64, 74], [64, 75], [64, 76], [64, 77], [64, 78], [64, 79], [64, 82], [64, 85], [64, 86], [64, 87], [64, 88], [64, 89], [64, 90], [64, 91], [64, 92], [64, 93], [64, 96], [64, 98], [64, 100], [64, 104], [64, 105], [64, 106], [64, 109], [64, 110], [64, 111], [64, 113], [64, 114], [64, 116], [64, 119], [65, 68], [65, 69], [65, 70], [65, 71], [65, 73], [65, 76], [65, 77], [65, 78], [65, 80], [65, 82], [65, 83], [65, 84], [65, 85], [65, 86], [65, 88], [65, 91], [65, 92], [65, 93], [65, 96], [65, 97], [65, 100], [65, 101], [65, 108], [65, 109], [65, 111], [65, 113], [65, 115], [65, 116], [65, 117], [65, 118], [66, 69], [66, 71], [66, 75], [66, 76], [66, 81], [66, 85], [66, 88], [66, 89], [66, 92], [66, 93], [66, 97], [66, 100], [66, 101], [66, 103], [66, 109], [66, 111], [66, 112], [66, 115], [66, 116], [66, 117], [66, 118], [66, 119], [67, 69], [67, 70], [67, 75], [67, 79], [67, 80], [67, 81], [67, 82], [67, 83], [67, 85], [67, 86], [67, 90], [67, 91], [67, 92], [67, 94], [67, 97], [67, 98], [67, 99], [67, 101], [67, 103], [67, 104], [67, 105], [67, 107], [67, 108], [67, 111], [67, 114], [67, 116], [67, 117], [67, 118], [67, 119], [68, 69], [68, 71], [68, 72], [68, 74], [68, 77], [68, 79], [68, 80], [68, 82], [68, 83], [68, 88], [68, 91], [68, 92], [68, 93], [68, 94], [68, 95], [68, 96], [68, 98], [68, 101], [68, 104], [68, 105], [68, 109], [68, 110], [68, 114], [68, 115], [68, 116], [69, 70], [69, 77], [69, 79], [69, 80], [69, 83], [69, 85], [69, 86], [69, 87], [69, 91], [69, 92], [69, 94], [69, 95], [69, 98], [69, 99], [69, 100], [69, 104], [69, 105], [69, 107], [69, 108], [69, 115], [69, 116], [69, 118], [69, 119], [70, 75], [70, 76], [70, 77], [70, 79], [70, 81], [70, 83], [70, 84], [70, 87], [70, 90], [70, 91], [70, 92], [70, 93], [70, 96], [70, 97], [70, 99], [70, 101], [70, 106], [70, 107], [70, 110], [70, 111], [70, 115], [70, 117], [70, 118], [71, 74], [71, 77], [71, 79], [71, 80], [71, 82], [71, 84], [71, 89], [71, 90], [71, 93], [71, 94], [71, 95], [71, 101], [71, 103], [71, 105], [71, 106], [71, 107], [71, 108], [71, 110], [71, 112], [71, 114], [71, 117], [71, 118], [72, 75], [72, 77], [72, 78], [72, 79], [72, 80], [72, 82], [72, 86], [72, 88], [72, 89], [72, 90], [72, 92], [72, 93], [72, 96], [72, 97], [72, 98], [72, 100], [72, 103], [72, 104], [72, 107], [72, 111], [72, 112], [72, 113], [72, 115], [72, 116], [73, 78], [73, 81], [73, 84], [73, 86], [73, 88], [73, 90], [73, 91], [73, 93], [73, 96], [73, 98], [73, 103], [73, 108], [73, 109], [73, 111], [73, 112], [73, 114], [73, 116], [73, 117], [73, 119], [74, 77], [74, 78], [74, 79], [74, 80], [74, 87], [74, 88], [74, 89], [74, 91], [74, 92], [74, 93], [74, 94], [74, 95], [74, 97], [74, 99], [74, 101], [74, 102], [74, 106], [74, 108], [74, 109], [74, 110], [74, 111], [74, 113], [74, 117], [75, 77], [75, 78], [75, 82], [75, 86], [75, 87], [75, 88], [75, 89], [75, 90], [75, 91], [75, 93], [75, 96], [75, 97], [75, 99], [75, 100], [75, 101], [75, 102], [75, 105], [75, 106], [75, 107], [75, 111], [75, 112], [75, 114], [75, 115], [75, 117], [75, 118], [76, 79], [76, 81], [76, 82], [76, 85], [76, 87], [76, 88], [76, 89], [76, 91], [76, 92], [76, 97], [76, 99], [76, 100], [76, 103], [76, 104], [76, 108], [76, 112], [76, 114], [76, 115], [76, 116], [76, 117], [77, 78], [77, 79], [77, 81], [77, 83], [77, 84], [77, 85], [77, 87], [77, 90], [77, 93], [77, 96], [77, 98], [77, 101], [77, 102], [77, 103], [77, 106], [77, 107], [77, 108], [77, 111], [77, 112], [77, 113], [77, 117], [77, 118], [78, 79], [78, 83], [78, 84], [78, 86], [78, 95], [78, 100], [78, 101], [78, 106], [78, 107], [78, 109], [78, 110], [78, 114], [79, 80], [79, 84], [79, 85], [79, 87], [79, 88], [79, 92], [79, 93], [79, 94], [79, 98], [79, 99], [79, 101], [79, 105], [79, 107], [79, 108], [79, 112], [79, 117], [80, 82], [80, 84], [80, 85], [80, 86], [80, 88], [80, 91], [80, 92], [80, 93], [80, 94], [80, 95], [80, 96], [80, 97], [80, 100], [80, 101], [80, 102], [80, 103], [80, 105], [80, 106], [80, 108], [80, 110], [80, 112], [80, 114], [80, 115], [80, 118], [81, 83], [81, 84], [81, 87], [81, 89], [81, 90], [81, 91], [81, 93], [81, 94], [81, 95], [81, 96], [81, 97], [81, 98], [81, 101], [81, 103], [81, 107], [81, 108], [81, 109], [81, 110], [81, 112], [81, 113], [81, 115], [81, 119], [82, 83], [82, 84], [82, 88], [82, 89], [82, 91], [82, 95], [82, 96], [82, 97], [82, 98], [82, 99], [82, 100], [82, 102], [82, 103], [82, 108], [82, 109], [82, 111], [82, 112], [82, 114], [82, 117], [83, 84], [83, 85], [83, 86], [83, 88], [83, 91], [83, 92], [83, 93], [83, 95], [83, 101], [83, 104], [83, 105], [83, 106], [83, 110], [83, 111], [83, 114], [83, 115], [84, 85], [84, 86], [84, 90], [84, 92], [84, 93], [84, 94], [84, 99], [84, 101], [84, 102], [84, 103], [84, 104], [84, 107], [84, 108], [84, 109], [84, 112], [84, 115], [84, 116], [85, 87], [85, 88], [85, 89], [85, 91], [85, 92], [85, 95], [85, 97], [85, 98], [85, 99], [85, 100], [85, 104], [85, 106], [85, 109], [85, 112], [85, 114], [85, 116], [85, 118], [85, 119], [86, 88], [86, 89], [86, 90], [86, 91], [86, 93], [86, 94], [86, 97], [86, 98], [86, 99], [86, 101], [86, 102], [86, 108], [86, 109], [86, 110], [86, 112], [86, 113], [86, 114], [86, 116], [86, 117], [86, 118], [86, 119], [87, 89], [87, 92], [87, 94], [87, 97], [87, 98], [87, 99], [87, 104], [87, 108], [87, 112], [87, 113], [87, 114], [87, 115], [87, 117], [87, 118], [87, 119], [88, 91], [88, 92], [88, 93], [88, 94], [88, 96], [88, 97], [88, 101], [88, 106], [88, 107], [88, 108], [88, 109], [88, 110], [88, 111], [88, 112], [88, 115], [88, 116], [88, 117], [88, 118], [88, 119], [89, 90], [89, 91], [89, 93], [89, 94], [89, 95], [89, 97], [89, 98], [89, 99], [89, 100], [89, 106], [89, 112], [89, 113], [89, 115], [89, 118], [89, 119], [90, 91], [90, 92], [90, 95], [90, 96], [90, 97], [90, 103], [90, 105], [90, 107], [90, 108], [90, 109], [90, 111], [90, 112], [90, 113], [90, 114], [90, 115], [91, 92], [91, 95], [91, 96], [91, 98], [91, 99], [91, 100], [91, 101], [91, 103], [91, 107], [91, 108], [91, 113], [91, 114], [91, 117], [91, 118], [92, 94], [92, 95], [92, 99], [92, 100], [92, 101], [92, 103], [92, 104], [92, 106], [92, 107], [92, 110], [92, 111], [92, 113], [92, 116], [92, 118], [93, 96], [93, 97], [93, 98], [93, 100], [93, 103], [93, 104], [93, 105], [93, 109], [93, 110], [93, 113], [93, 114], [93, 115], [93, 117], [93, 118], [94, 96], [94, 98], [94, 99], [94, 101], [94, 103], [94, 104], [94, 106], [94, 107], [94, 108], [94, 109], [94, 110], [94, 116], [94, 118], [95, 99], [95, 100], [95, 101], [95, 102], [95, 103], [95, 106], [95, 108], [95, 109], [95, 110], [95, 111], [95, 112], [95, 113], [95, 114], [95, 117], [95, 119], [96, 97], [96, 99], [96, 100], [96, 108], [96, 109], [96, 110], [96, 111], [96, 112], [96, 113], [96, 117], [96, 118], [97, 98], [97, 99], [97, 100], [97, 102], [97, 103], [97, 105], [97, 106], [97, 108], [97, 111], [97, 113], [97, 116], [97, 119], [98, 99], [98, 102], [98, 107], [98, 109], [98, 110], [98, 112], [98, 113], [98, 117], [98, 118], [98, 119], [99, 100], [99, 102], [99, 103], [99, 105], [99, 107], [99, 108], [99, 109], [99, 112], [99, 116], [99, 118], [99, 119], [100, 101], [100, 102], [100, 103], [100, 104], [100, 105], [100, 106], [100, 107], [100, 112], [100, 113], [100, 115], [100, 116], [100, 119], [101, 103], [101, 104], [101, 105], [101, 106], [101, 108], [101, 110], [101, 111], [101, 114], [101, 115], [101, 118], [101, 119], [102, 103], [102, 104], [102, 109], [102, 110], [102, 111], [102, 113], [102, 116], [103, 104], [103, 107], [103, 108], [103, 111], [103, 115], [103, 116], [103, 117], [103, 119], [104, 106], [104, 113], [104, 114], [104, 115], [104, 117], [104, 118], [104, 119], [105, 107], [105, 108], [105, 110], [105, 114], [105, 116], [105, 117], [105, 118], [105, 119], [106, 107], [106, 108], [106, 111], [106, 112], [106, 114], [106, 115], [106, 117], [106, 118], [106, 119], [107, 108], [107, 110], [107, 111], [107, 112], [107, 113], [107, 116], [107, 117], [107, 118], [107, 119], [108, 110], [108, 111], [108, 112], [108, 113], [109, 111], [109, 116], [109, 117], [109, 118], [109, 119], [110, 112], [110, 113], [110, 114], [110, 115], [110, 116], [110, 117], [111, 112], [111, 113], [111, 115], [111, 119], [112, 114], [112, 115], [112, 116], [112, 117], [113, 115], [113, 117], [113, 118], [114, 115], [114, 116], [114, 118], [115, 116], [115, 117], [115, 118], [116, 118], [116, 119], [117, 118], [117, 119]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l6-s9/solution/solve.sh b/tasks/construct-mc-max-clique-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..14881f57f8f805cf530215b1663657bcf31f4967 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [2, 17, 23, 40, 49, 53, 61, 65, 83, 88, 101, 111, 115]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l6-s9/tests/check.py b/tasks/construct-mc-max-clique-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l6-s9/tests/instance.json b/tasks/construct-mc-max-clique-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..404bc8c9488d8d2ba7f859c709dff328687e5659 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 120, "k": 13, "edges": [[0, 2], [0, 4], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 14], [0, 16], [0, 17], [0, 20], [0, 21], [0, 24], [0, 27], [0, 29], [0, 30], [0, 35], [0, 38], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 54], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 66], [0, 67], [0, 68], [0, 69], [0, 71], [0, 72], [0, 74], [0, 78], [0, 81], [0, 82], [0, 84], [0, 94], [0, 95], [0, 96], [0, 97], [0, 98], [0, 99], [0, 102], [0, 104], [0, 105], [0, 106], [0, 110], [0, 111], [0, 112], [0, 114], [0, 115], [0, 118], [1, 2], [1, 4], [1, 7], [1, 9], [1, 10], [1, 13], [1, 16], [1, 23], [1, 24], [1, 27], [1, 28], [1, 29], [1, 32], [1, 33], [1, 35], [1, 38], [1, 39], [1, 40], [1, 41], [1, 44], [1, 49], [1, 51], [1, 52], [1, 53], [1, 54], [1, 56], [1, 59], [1, 60], [1, 62], [1, 64], [1, 65], [1, 68], [1, 71], [1, 72], [1, 74], [1, 75], [1, 77], [1, 79], [1, 83], [1, 85], [1, 86], [1, 87], [1, 93], [1, 95], [1, 97], [1, 99], [1, 100], [1, 102], [1, 107], [1, 109], [1, 111], [1, 113], [1, 118], [1, 119], [2, 3], [2, 5], [2, 10], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 52], [2, 53], [2, 55], [2, 56], [2, 57], [2, 60], [2, 61], [2, 62], [2, 63], [2, 65], [2, 67], [2, 72], [2, 74], [2, 78], [2, 79], [2, 82], [2, 83], [2, 85], [2, 86], [2, 87], [2, 88], [2, 89], [2, 91], [2, 92], [2, 95], [2, 99], [2, 101], [2, 103], [2, 104], [2, 105], [2, 109], [2, 111], [2, 112], [2, 113], [2, 114], [2, 115], [2, 117], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 15], [3, 16], [3, 17], [3, 21], [3, 22], [3, 27], [3, 28], [3, 29], [3, 31], [3, 32], [3, 33], [3, 34], [3, 39], [3, 40], [3, 46], [3, 47], [3, 48], [3, 49], [3, 51], [3, 56], [3, 61], [3, 68], [3, 70], [3, 71], [3, 72], [3, 74], [3, 76], [3, 77], [3, 80], [3, 81], [3, 82], [3, 86], [3, 93], [3, 94], [3, 95], [3, 97], [3, 98], [3, 101], [3, 102], [3, 104], [3, 106], [3, 107], [3, 110], [3, 112], [3, 114], [3, 115], [3, 116], [3, 117], [3, 118], [3, 119], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 13], [4, 14], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 26], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 50], [4, 53], [4, 55], [4, 56], [4, 57], [4, 60], [4, 62], [4, 64], [4, 65], [4, 66], [4, 69], [4, 71], [4, 74], [4, 78], [4, 81], [4, 82], [4, 83], [4, 84], [4, 85], [4, 86], [4, 87], [4, 89], [4, 93], [4, 96], [4, 97], [4, 98], [4, 99], [4, 105], [4, 107], [4, 110], [4, 111], [4, 113], [4, 117], [4, 118], [4, 119], [5, 8], [5, 12], [5, 13], [5, 16], [5, 17], [5, 19], [5, 21], [5, 22], [5, 26], [5, 28], [5, 29], [5, 31], [5, 32], [5, 34], [5, 35], [5, 38], [5, 40], [5, 42], [5, 45], [5, 46], [5, 47], [5, 48], [5, 51], [5, 52], [5, 55], [5, 56], [5, 58], [5, 59], [5, 61], [5, 65], [5, 67], [5, 68], [5, 69], [5, 72], [5, 76], [5, 78], [5, 79], [5, 81], [5, 83], [5, 85], [5, 86], [5, 95], [5, 101], [5, 110], [5, 111], [5, 114], [5, 116], [5, 117], [5, 118], [5, 119], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 17], [6, 20], [6, 22], [6, 23], [6, 25], [6, 26], [6, 28], [6, 30], [6, 34], [6, 35], [6, 36], [6, 38], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 51], [6, 53], [6, 54], [6, 57], [6, 59], [6, 60], [6, 63], [6, 68], [6, 69], [6, 72], [6, 73], [6, 74], [6, 75], [6, 76], [6, 78], [6, 79], [6, 80], [6, 82], [6, 83], [6, 84], [6, 88], [6, 94], [6, 96], [6, 97], [6, 98], [6, 100], [6, 102], [6, 104], [6, 105], [6, 107], [6, 108], [6, 111], [6, 113], [6, 116], [6, 119], [7, 8], [7, 9], [7, 10], [7, 14], [7, 15], [7, 16], [7, 19], [7, 21], [7, 22], [7, 25], [7, 27], [7, 28], [7, 29], [7, 30], [7, 34], [7, 36], [7, 39], [7, 40], [7, 41], [7, 43], [7, 51], [7, 54], [7, 55], [7, 56], [7, 59], [7, 60], [7, 61], [7, 64], [7, 70], [7, 73], [7, 74], [7, 78], [7, 81], [7, 82], [7, 83], [7, 84], [7, 85], [7, 90], [7, 93], [7, 94], [7, 99], [7, 103], [7, 105], [7, 106], [7, 108], [7, 110], [7, 111], [7, 112], [7, 115], [7, 117], [7, 118], [7, 119], [8, 9], [8, 15], [8, 18], [8, 20], [8, 21], [8, 22], [8, 24], [8, 28], [8, 30], [8, 32], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 40], [8, 41], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 51], [8, 55], [8, 56], [8, 59], [8, 63], [8, 64], [8, 69], [8, 70], [8, 73], [8, 74], [8, 77], [8, 78], [8, 80], [8, 81], [8, 90], [8, 94], [8, 95], [8, 96], [8, 98], [8, 99], [8, 100], [8, 103], [8, 104], [8, 105], [8, 106], [8, 111], [8, 113], [8, 114], [8, 115], [8, 117], [8, 118], [9, 12], [9, 14], [9, 15], [9, 18], [9, 20], [9, 23], [9, 24], [9, 28], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 37], [9, 38], [9, 39], [9, 41], [9, 42], [9, 43], [9, 45], [9, 46], [9, 47], [9, 48], [9, 50], [9, 51], [9, 52], [9, 57], [9, 61], [9, 62], [9, 64], [9, 66], [9, 68], [9, 69], [9, 71], [9, 73], [9, 77], [9, 78], [9, 79], [9, 87], [9, 89], [9, 92], [9, 95], [9, 100], [9, 101], [9, 105], [9, 107], [9, 110], [9, 112], [9, 114], [9, 115], [9, 116], [9, 119], [10, 13], [10, 16], [10, 17], [10, 18], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 28], [10, 29], [10, 33], [10, 34], [10, 35], [10, 38], [10, 40], [10, 41], [10, 43], [10, 44], [10, 45], [10, 48], [10, 52], [10, 53], [10, 55], [10, 57], [10, 58], [10, 59], [10, 60], [10, 63], [10, 64], [10, 68], [10, 72], [10, 74], [10, 76], [10, 77], [10, 78], [10, 82], [10, 85], [10, 86], [10, 87], [10, 88], [10, 89], [10, 90], [10, 92], [10, 93], [10, 94], [10, 95], [10, 100], [10, 101], [10, 104], [10, 105], [10, 107], [10, 109], [10, 111], [10, 117], [10, 118], [10, 119], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 29], [11, 32], [11, 34], [11, 36], [11, 40], [11, 42], [11, 43], [11, 45], [11, 46], [11, 48], [11, 49], [11, 50], [11, 51], [11, 54], [11, 55], [11, 56], [11, 58], [11, 61], [11, 64], [11, 66], [11, 68], [11, 69], [11, 70], [11, 75], [11, 78], [11, 79], [11, 80], [11, 83], [11, 87], [11, 88], [11, 89], [11, 90], [11, 91], [11, 92], [11, 95], [11, 97], [11, 102], [11, 103], [11, 105], [11, 106], [11, 108], [11, 109], [11, 110], [11, 111], [11, 114], [12, 15], [12, 18], [12, 21], [12, 22], [12, 25], [12, 26], [12, 27], [12, 28], [12, 30], [12, 34], [12, 38], [12, 39], [12, 41], [12, 46], [12, 47], [12, 49], [12, 50], [12, 55], [12, 61], [12, 62], [12, 65], [12, 66], [12, 67], [12, 69], [12, 71], [12, 74], [12, 76], [12, 83], [12, 84], [12, 85], [12, 86], [12, 87], [12, 88], [12, 89], [12, 90], [12, 102], [12, 104], [12, 107], [12, 110], [12, 111], [12, 112], [12, 113], [12, 115], [12, 116], [12, 117], [12, 118], [13, 16], [13, 19], [13, 20], [13, 22], [13, 24], [13, 25], [13, 30], [13, 31], [13, 32], [13, 33], [13, 36], [13, 37], [13, 39], [13, 40], [13, 41], [13, 43], [13, 50], [13, 52], [13, 53], [13, 54], [13, 56], [13, 57], [13, 60], [13, 64], [13, 68], [13, 69], [13, 70], [13, 72], [13, 77], [13, 79], [13, 80], [13, 83], [13, 84], [13, 85], [13, 87], [13, 91], [13, 96], [13, 97], [13, 98], [13, 99], [13, 101], [13, 105], [13, 106], [13, 107], [13, 111], [13, 112], [13, 114], [13, 116], [14, 15], [14, 17], [14, 18], [14, 19], [14, 20], [14, 23], [14, 25], [14, 26], [14, 28], [14, 30], [14, 33], [14, 34], [14, 35], [14, 37], [14, 38], [14, 39], [14, 42], [14, 43], [14, 45], [14, 46], [14, 47], [14, 50], [14, 51], [14, 54], [14, 56], [14, 57], [14, 58], [14, 60], [14, 64], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 74], [14, 75], [14, 76], [14, 77], [14, 79], [14, 80], [14, 81], [14, 82], [14, 84], [14, 86], [14, 87], [14, 88], [14, 90], [14, 92], [14, 94], [14, 95], [14, 96], [14, 97], [14, 98], [14, 99], [14, 100], [14, 102], [14, 103], [14, 104], [14, 105], [14, 107], [14, 108], [14, 112], [14, 114], [14, 117], [15, 16], [15, 17], [15, 19], [15, 22], [15, 24], [15, 27], [15, 29], [15, 30], [15, 34], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 45], [15, 48], [15, 49], [15, 50], [15, 51], [15, 54], [15, 55], [15, 56], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 67], [15, 68], [15, 70], [15, 71], [15, 73], [15, 74], [15, 80], [15, 83], [15, 84], [15, 87], [15, 88], [15, 90], [15, 91], [15, 92], [15, 95], [15, 96], [15, 98], [15, 99], [15, 100], [15, 104], [15, 106], [15, 107], [15, 108], [15, 110], [15, 113], [15, 115], [16, 19], [16, 20], [16, 22], [16, 25], [16, 27], [16, 29], [16, 32], [16, 35], [16, 40], [16, 41], [16, 42], [16, 44], [16, 46], [16, 52], [16, 53], [16, 57], [16, 60], [16, 61], [16, 62], [16, 64], [16, 67], [16, 68], [16, 69], [16, 72], [16, 73], [16, 75], [16, 77], [16, 78], [16, 79], [16, 81], [16, 82], [16, 83], [16, 85], [16, 86], [16, 88], [16, 90], [16, 91], [16, 92], [16, 93], [16, 98], [16, 101], [16, 103], [16, 104], [16, 105], [16, 107], [16, 108], [16, 109], [16, 111], [16, 113], [16, 116], [16, 117], [16, 118], [17, 18], [17, 21], [17, 22], [17, 23], [17, 25], [17, 30], [17, 31], [17, 32], [17, 34], [17, 35], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 46], [17, 47], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 55], [17, 56], [17, 58], [17, 61], [17, 63], [17, 65], [17, 67], [17, 68], [17, 70], [17, 71], [17, 73], [17, 74], [17, 75], [17, 76], [17, 77], [17, 83], [17, 85], [17, 86], [17, 88], [17, 91], [17, 92], [17, 94], [17, 97], [17, 98], [17, 100], [17, 101], [17, 102], [17, 103], [17, 109], [17, 110], [17, 111], [17, 112], [17, 115], [17, 117], [18, 19], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 33], [18, 34], [18, 35], [18, 36], [18, 39], [18, 40], [18, 44], [18, 46], [18, 48], [18, 53], [18, 55], [18, 56], [18, 58], [18, 59], [18, 60], [18, 63], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 75], [18, 77], [18, 80], [18, 81], [18, 82], [18, 83], [18, 88], [18, 89], [18, 90], [18, 91], [18, 97], [18, 98], [18, 101], [18, 103], [18, 108], [18, 109], [18, 110], [18, 113], [18, 115], [18, 117], [18, 118], [19, 20], [19, 21], [19, 23], [19, 24], [19, 27], [19, 31], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 46], [19, 49], [19, 50], [19, 51], [19, 53], [19, 54], [19, 58], [19, 63], [19, 64], [19, 66], [19, 67], [19, 69], [19, 70], [19, 71], [19, 74], [19, 76], [19, 79], [19, 81], [19, 86], [19, 88], [19, 89], [19, 90], [19, 91], [19, 93], [19, 94], [19, 95], [19, 98], [19, 100], [19, 105], [19, 106], [19, 107], [19, 108], [19, 109], [19, 111], [19, 112], [19, 115], [19, 117], [19, 119], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 28], [20, 29], [20, 30], [20, 31], [20, 35], [20, 37], [20, 40], [20, 42], [20, 44], [20, 47], [20, 49], [20, 50], [20, 51], [20, 53], [20, 54], [20, 58], [20, 59], [20, 60], [20, 65], [20, 66], [20, 68], [20, 69], [20, 70], [20, 71], [20, 73], [20, 75], [20, 76], [20, 78], [20, 81], [20, 82], [20, 83], [20, 84], [20, 86], [20, 87], [20, 88], [20, 91], [20, 94], [20, 95], [20, 96], [20, 100], [20, 105], [20, 106], [20, 107], [20, 108], [20, 109], [20, 110], [20, 111], [20, 116], [20, 117], [20, 118], [21, 22], [21, 27], [21, 28], [21, 29], [21, 31], [21, 32], [21, 33], [21, 38], [21, 39], [21, 42], [21, 45], [21, 46], [21, 47], [21, 50], [21, 52], [21, 55], [21, 57], [21, 61], [21, 62], [21, 63], [21, 69], [21, 71], [21, 73], [21, 74], [21, 78], [21, 81], [21, 83], [21, 84], [21, 87], [21, 88], [21, 92], [21, 94], [21, 97], [21, 98], [21, 99], [21, 102], [21, 103], [21, 104], [21, 107], [21, 109], [21, 110], [21, 115], [21, 116], [21, 118], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 31], [22, 32], [22, 33], [22, 35], [22, 37], [22, 38], [22, 39], [22, 42], [22, 45], [22, 47], [22, 48], [22, 52], [22, 54], [22, 57], [22, 58], [22, 61], [22, 62], [22, 65], [22, 68], [22, 70], [22, 73], [22, 75], [22, 79], [22, 81], [22, 82], [22, 86], [22, 89], [22, 90], [22, 92], [22, 97], [22, 98], [22, 100], [22, 103], [22, 107], [22, 109], [22, 111], [22, 116], [22, 117], [22, 118], [23, 24], [23, 25], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 37], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 47], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 64], [23, 65], [23, 73], [23, 75], [23, 76], [23, 79], [23, 80], [23, 82], [23, 83], [23, 86], [23, 87], [23, 88], [23, 94], [23, 97], [23, 98], [23, 101], [23, 102], [23, 104], [23, 105], [23, 106], [23, 108], [23, 109], [23, 110], [23, 111], [23, 112], [23, 113], [23, 114], [23, 115], [23, 116], [23, 117], [23, 118], [23, 119], [24, 27], [24, 28], [24, 30], [24, 33], [24, 34], [24, 37], [24, 38], [24, 40], [24, 41], [24, 42], [24, 43], [24, 44], [24, 47], [24, 48], [24, 49], [24, 50], [24, 53], [24, 57], [24, 59], [24, 60], [24, 62], [24, 64], [24, 66], [24, 67], [24, 68], [24, 69], [24, 71], [24, 72], [24, 73], [24, 74], [24, 76], [24, 78], [24, 80], [24, 81], [24, 83], [24, 84], [24, 85], [24, 86], [24, 87], [24, 88], [24, 89], [24, 90], [24, 91], [24, 93], [24, 95], [24, 97], [24, 98], [24, 99], [24, 100], [24, 101], [24, 102], [24, 106], [24, 107], [24, 108], [24, 109], [24, 110], [24, 116], [24, 118], [25, 27], [25, 28], [25, 30], [25, 31], [25, 32], [25, 34], [25, 35], [25, 41], [25, 42], [25, 43], [25, 46], [25, 52], [25, 53], [25, 54], [25, 55], [25, 58], [25, 59], [25, 62], [25, 63], [25, 64], [25, 65], [25, 69], [25, 70], [25, 72], [25, 74], [25, 80], [25, 82], [25, 87], [25, 88], [25, 90], [25, 91], [25, 92], [25, 93], [25, 95], [25, 97], [25, 102], [25, 103], [25, 105], [25, 106], [25, 107], [25, 109], [25, 111], [25, 114], [25, 116], [25, 117], [25, 118], [25, 119], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [26, 42], [26, 45], [26, 46], [26, 51], [26, 53], [26, 55], [26, 56], [26, 58], [26, 59], [26, 68], [26, 70], [26, 71], [26, 72], [26, 75], [26, 76], [26, 78], [26, 80], [26, 82], [26, 83], [26, 84], [26, 86], [26, 88], [26, 89], [26, 90], [26, 91], [26, 92], [26, 93], [26, 99], [26, 101], [26, 105], [26, 107], [26, 108], [26, 109], [26, 111], [26, 114], [26, 116], [26, 118], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 35], [27, 37], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 48], [27, 49], [27, 50], [27, 53], [27, 54], [27, 61], [27, 64], [27, 65], [27, 66], [27, 67], [27, 70], [27, 71], [27, 72], [27, 73], [27, 74], [27, 75], [27, 76], [27, 77], [27, 79], [27, 80], [27, 81], [27, 83], [27, 85], [27, 87], [27, 89], [27, 90], [27, 94], [27, 95], [27, 96], [27, 97], [27, 99], [27, 102], [27, 103], [27, 105], [27, 108], [27, 109], [27, 111], [27, 114], [27, 115], [28, 30], [28, 33], [28, 36], [28, 37], [28, 39], [28, 41], [28, 42], [28, 44], [28, 45], [28, 53], [28, 56], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 65], [28, 66], [28, 68], [28, 73], [28, 74], [28, 75], [28, 76], [28, 78], [28, 79], [28, 80], [28, 82], [28, 83], [28, 85], [28, 86], [28, 87], [28, 88], [28, 90], [28, 91], [28, 95], [28, 97], [28, 98], [28, 99], [28, 104], [28, 107], [28, 108], [28, 110], [28, 111], [28, 115], [28, 118], [28, 119], [29, 30], [29, 31], [29, 35], [29, 37], [29, 39], [29, 42], [29, 43], [29, 46], [29, 52], [29, 53], [29, 56], [29, 58], [29, 59], [29, 60], [29, 64], [29, 67], [29, 68], [29, 70], [29, 71], [29, 75], [29, 77], [29, 78], [29, 80], [29, 84], [29, 85], [29, 90], [29, 91], [29, 93], [29, 94], [29, 95], [29, 97], [29, 100], [29, 102], [29, 106], [29, 113], [29, 115], [30, 32], [30, 33], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 46], [30, 48], [30, 49], [30, 53], [30, 54], [30, 59], [30, 61], [30, 62], [30, 63], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 78], [30, 79], [30, 83], [30, 85], [30, 88], [30, 89], [30, 90], [30, 91], [30, 93], [30, 94], [30, 95], [30, 97], [30, 100], [30, 101], [30, 102], [30, 103], [30, 105], [30, 106], [30, 107], [30, 109], [30, 110], [30, 115], [30, 116], [31, 32], [31, 35], [31, 36], [31, 37], [31, 41], [31, 42], [31, 43], [31, 44], [31, 46], [31, 48], [31, 50], [31, 51], [31, 52], [31, 53], [31, 54], [31, 57], [31, 58], [31, 59], [31, 61], [31, 62], [31, 63], [31, 64], [31, 66], [31, 70], [31, 72], [31, 75], [31, 77], [31, 78], [31, 82], [31, 83], [31, 89], [31, 93], [31, 95], [31, 100], [31, 103], [31, 106], [31, 109], [31, 110], [31, 111], [31, 112], [31, 113], [31, 116], [32, 34], [32, 35], [32, 39], [32, 41], [32, 45], [32, 47], [32, 54], [32, 55], [32, 57], [32, 58], [32, 60], [32, 64], [32, 69], [32, 75], [32, 77], [32, 78], [32, 82], [32, 84], [32, 87], [32, 88], [32, 90], [32, 95], [32, 97], [32, 98], [32, 99], [32, 100], [32, 103], [32, 104], [32, 106], [32, 109], [32, 110], [32, 111], [32, 112], [32, 114], [32, 116], [32, 118], [32, 119], [33, 35], [33, 37], [33, 40], [33, 41], [33, 43], [33, 46], [33, 48], [33, 49], [33, 55], [33, 57], [33, 59], [33, 60], [33, 61], [33, 62], [33, 64], [33, 65], [33, 66], [33, 67], [33, 68], [33, 69], [33, 70], [33, 76], [33, 77], [33, 78], [33, 79], [33, 83], [33, 84], [33, 86], [33, 87], [33, 91], [33, 93], [33, 96], [33, 97], [33, 99], [33, 101], [33, 102], [33, 105], [33, 106], [33, 109], [33, 110], [33, 111], [33, 112], [33, 113], [33, 114], [33, 115], [33, 119], [34, 36], [34, 38], [34, 39], [34, 41], [34, 42], [34, 44], [34, 48], [34, 51], [34, 54], [34, 55], [34, 58], [34, 59], [34, 61], [34, 63], [34, 65], [34, 71], [34, 73], [34, 76], [34, 77], [34, 79], [34, 82], [34, 85], [34, 92], [34, 96], [34, 97], [34, 98], [34, 99], [34, 104], [34, 107], [34, 109], [34, 110], [34, 111], [34, 112], [34, 115], [34, 118], [35, 36], [35, 37], [35, 38], [35, 39], [35, 41], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 54], [35, 55], [35, 56], [35, 57], [35, 60], [35, 62], [35, 66], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [35, 78], [35, 79], [35, 80], [35, 82], [35, 88], [35, 89], [35, 90], [35, 92], [35, 93], [35, 94], [35, 95], [35, 96], [35, 98], [35, 100], [35, 110], [35, 112], [35, 113], [35, 115], [35, 116], [35, 117], [36, 37], [36, 38], [36, 40], [36, 44], [36, 48], [36, 54], [36, 56], [36, 58], [36, 60], [36, 62], [36, 65], [36, 67], [36, 71], [36, 73], [36, 75], [36, 76], [36, 80], [36, 84], [36, 86], [36, 87], [36, 88], [36, 89], [36, 91], [36, 92], [36, 93], [36, 95], [36, 97], [36, 101], [36, 102], [36, 103], [36, 104], [36, 109], [36, 112], [36, 113], [36, 115], [36, 116], [36, 117], [36, 119], [37, 38], [37, 40], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 49], [37, 50], [37, 51], [37, 52], [37, 53], [37, 54], [37, 55], [37, 56], [37, 64], [37, 65], [37, 69], [37, 73], [37, 74], [37, 77], [37, 81], [37, 84], [37, 86], [37, 89], [37, 90], [37, 91], [37, 99], [37, 100], [37, 102], [37, 105], [37, 107], [37, 111], [37, 112], [37, 113], [37, 116], [37, 117], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 47], [38, 51], [38, 54], [38, 55], [38, 57], [38, 59], [38, 60], [38, 61], [38, 64], [38, 65], [38, 67], [38, 70], [38, 73], [38, 74], [38, 75], [38, 81], [38, 82], [38, 84], [38, 86], [38, 96], [38, 97], [38, 99], [38, 101], [38, 102], [38, 108], [38, 109], [38, 110], [38, 112], [38, 113], [38, 114], [38, 115], [38, 116], [38, 117], [38, 119], [39, 41], [39, 42], [39, 43], [39, 44], [39, 45], [39, 46], [39, 50], [39, 51], [39, 52], [39, 55], [39, 62], [39, 64], [39, 66], [39, 67], [39, 68], [39, 69], [39, 71], [39, 72], [39, 79], [39, 81], [39, 86], [39, 88], [39, 90], [39, 92], [39, 93], [39, 96], [39, 97], [39, 98], [39, 99], [39, 102], [39, 104], [39, 107], [39, 108], [39, 109], [39, 111], [39, 113], [39, 115], [39, 116], [39, 117], [39, 118], [40, 41], [40, 44], [40, 47], [40, 49], [40, 51], [40, 52], [40, 53], [40, 54], [40, 57], [40, 59], [40, 60], [40, 61], [40, 64], [40, 65], [40, 68], [40, 69], [40, 74], [40, 76], [40, 77], [40, 78], [40, 79], [40, 83], [40, 84], [40, 86], [40, 88], [40, 91], [40, 92], [40, 93], [40, 95], [40, 99], [40, 100], [40, 101], [40, 109], [40, 110], [40, 111], [40, 115], [41, 49], [41, 51], [41, 52], [41, 53], [41, 56], [41, 59], [41, 60], [41, 61], [41, 62], [41, 64], [41, 65], [41, 67], [41, 69], [41, 70], [41, 72], [41, 75], [41, 77], [41, 79], [41, 80], [41, 81], [41, 82], [41, 83], [41, 85], [41, 86], [41, 91], [41, 94], [41, 95], [41, 96], [41, 97], [41, 98], [41, 99], [41, 101], [41, 105], [41, 106], [41, 108], [41, 109], [41, 111], [41, 112], [41, 113], [41, 115], [41, 117], [41, 119], [42, 43], [42, 44], [42, 47], [42, 49], [42, 51], [42, 52], [42, 53], [42, 56], [42, 57], [42, 58], [42, 61], [42, 63], [42, 64], [42, 67], [42, 68], [42, 69], [42, 72], [42, 74], [42, 75], [42, 76], [42, 77], [42, 78], [42, 79], [42, 80], [42, 85], [42, 86], [42, 87], [42, 89], [42, 90], [42, 92], [42, 95], [42, 96], [42, 98], [42, 99], [42, 101], [42, 102], [42, 104], [42, 105], [42, 106], [42, 109], [42, 112], [42, 117], [42, 118], [43, 45], [43, 48], [43, 49], [43, 50], [43, 51], [43, 54], [43, 55], [43, 56], [43, 61], [43, 65], [43, 66], [43, 67], [43, 70], [43, 71], [43, 73], [43, 75], [43, 76], [43, 78], [43, 79], [43, 80], [43, 81], [43, 84], [43, 86], [43, 88], [43, 89], [43, 90], [43, 91], [43, 92], [43, 94], [43, 95], [43, 96], [43, 100], [43, 103], [43, 104], [43, 107], [43, 109], [43, 110], [43, 111], [43, 112], [43, 117], [43, 118], [43, 119], [44, 47], [44, 49], [44, 51], [44, 52], [44, 56], [44, 62], [44, 64], [44, 65], [44, 66], [44, 67], [44, 69], [44, 70], [44, 77], [44, 79], [44, 81], [44, 84], [44, 86], [44, 88], [44, 89], [44, 92], [44, 94], [44, 95], [44, 97], [44, 98], [44, 99], [44, 100], [44, 104], [44, 105], [44, 108], [44, 109], [44, 110], [44, 111], [44, 112], [44, 113], [44, 117], [44, 118], [45, 51], [45, 57], [45, 59], [45, 61], [45, 63], [45, 64], [45, 68], [45, 69], [45, 71], [45, 72], [45, 74], [45, 75], [45, 78], [45, 79], [45, 81], [45, 82], [45, 84], [45, 86], [45, 87], [45, 88], [45, 89], [45, 90], [45, 91], [45, 92], [45, 93], [45, 94], [45, 95], [45, 98], [45, 101], [45, 102], [45, 103], [45, 104], [45, 106], [45, 107], [45, 108], [45, 110], [45, 111], [45, 112], [45, 114], [45, 115], [46, 51], [46, 52], [46, 53], [46, 55], [46, 56], [46, 60], [46, 62], [46, 64], [46, 66], [46, 67], [46, 69], [46, 70], [46, 71], [46, 72], [46, 76], [46, 77], [46, 78], [46, 82], [46, 85], [46, 86], [46, 89], [46, 91], [46, 93], [46, 95], [46, 96], [46, 97], [46, 103], [46, 104], [46, 110], [46, 111], [46, 113], [46, 114], [46, 116], [46, 117], [46, 118], [46, 119], [47, 49], [47, 51], [47, 53], [47, 54], [47, 56], [47, 58], [47, 59], [47, 60], [47, 61], [47, 65], [47, 69], [47, 72], [47, 74], [47, 75], [47, 76], [47, 77], [47, 78], [47, 79], [47, 80], [47, 85], [47, 88], [47, 89], [47, 91], [47, 94], [47, 95], [47, 98], [47, 99], [47, 101], [47, 103], [47, 110], [47, 113], [47, 114], [47, 118], [47, 119], [48, 49], [48, 53], [48, 55], [48, 56], [48, 62], [48, 63], [48, 67], [48, 68], [48, 69], [48, 72], [48, 73], [48, 78], [48, 80], [48, 81], [48, 82], [48, 86], [48, 88], [48, 89], [48, 97], [48, 100], [48, 107], [48, 108], [48, 109], [48, 111], [48, 112], [48, 117], [48, 118], [48, 119], [49, 50], [49, 51], [49, 53], [49, 57], [49, 61], [49, 63], [49, 64], [49, 65], [49, 66], [49, 70], [49, 71], [49, 73], [49, 75], [49, 77], [49, 78], [49, 82], [49, 83], [49, 86], [49, 87], [49, 88], [49, 90], [49, 91], [49, 99], [49, 100], [49, 101], [49, 104], [49, 106], [49, 108], [49, 110], [49, 111], [49, 112], [49, 115], [49, 118], [49, 119], [50, 51], [50, 52], [50, 54], [50, 56], [50, 58], [50, 59], [50, 64], [50, 67], [50, 69], [50, 70], [50, 71], [50, 73], [50, 76], [50, 77], [50, 78], [50, 79], [50, 82], [50, 83], [50, 84], [50, 85], [50, 87], [50, 90], [50, 91], [50, 92], [50, 93], [50, 96], [50, 98], [50, 99], [50, 101], [50, 102], [50, 103], [50, 112], [50, 113], [50, 115], [50, 117], [50, 118], [51, 52], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 60], [51, 61], [51, 63], [51, 66], [51, 67], [51, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [51, 75], [51, 77], [51, 78], [51, 79], [51, 80], [51, 82], [51, 83], [51, 84], [51, 86], [51, 90], [51, 96], [51, 98], [51, 99], [51, 114], [51, 116], [51, 117], [51, 118], [51, 119], [52, 56], [52, 60], [52, 65], [52, 66], [52, 67], [52, 69], [52, 73], [52, 74], [52, 75], [52, 76], [52, 77], [52, 79], [52, 80], [52, 82], [52, 84], [52, 86], [52, 87], [52, 90], [52, 91], [52, 93], [52, 94], [52, 96], [52, 97], [52, 98], [52, 100], [52, 102], [52, 106], [52, 107], [52, 108], [52, 110], [52, 111], [52, 114], [52, 116], [52, 117], [53, 55], [53, 59], [53, 60], [53, 61], [53, 63], [53, 65], [53, 66], [53, 67], [53, 70], [53, 72], [53, 75], [53, 78], [53, 81], [53, 83], [53, 85], [53, 87], [53, 88], [53, 89], [53, 90], [53, 91], [53, 93], [53, 95], [53, 98], [53, 101], [53, 103], [53, 104], [53, 105], [53, 106], [53, 107], [53, 109], [53, 111], [53, 112], [53, 115], [53, 116], [54, 57], [54, 61], [54, 64], [54, 65], [54, 66], [54, 71], [54, 74], [54, 77], [54, 80], [54, 83], [54, 86], [54, 87], [54, 88], [54, 91], [54, 93], [54, 95], [54, 96], [54, 97], [54, 98], [54, 101], [54, 102], [54, 104], [54, 105], [54, 107], [54, 108], [54, 109], [54, 116], [54, 117], [54, 119], [55, 56], [55, 57], [55, 58], [55, 62], [55, 63], [55, 65], [55, 66], [55, 67], [55, 68], [55, 70], [55, 73], [55, 74], [55, 75], [55, 78], [55, 81], [55, 83], [55, 84], [55, 87], [55, 88], [55, 90], [55, 93], [55, 94], [55, 95], [55, 97], [55, 98], [55, 101], [55, 103], [55, 104], [55, 108], [55, 112], [55, 113], [55, 114], [55, 115], [55, 116], [55, 118], [55, 119], [56, 57], [56, 58], [56, 59], [56, 60], [56, 62], [56, 65], [56, 66], [56, 67], [56, 68], [56, 71], [56, 72], [56, 73], [56, 75], [56, 80], [56, 81], [56, 82], [56, 85], [56, 86], [56, 87], [56, 93], [56, 94], [56, 96], [56, 97], [56, 98], [56, 99], [56, 100], [56, 101], [56, 102], [56, 103], [56, 104], [56, 105], [56, 106], [56, 109], [56, 112], [56, 113], [56, 114], [56, 115], [56, 116], [57, 61], [57, 62], [57, 64], [57, 66], [57, 67], [57, 68], [57, 69], [57, 70], [57, 72], [57, 73], [57, 75], [57, 77], [57, 79], [57, 81], [57, 84], [57, 85], [57, 87], [57, 88], [57, 96], [57, 98], [57, 99], [57, 101], [57, 102], [57, 104], [57, 107], [57, 110], [57, 113], [57, 115], [57, 118], [57, 119], [58, 60], [58, 61], [58, 63], [58, 66], [58, 68], [58, 70], [58, 71], [58, 74], [58, 75], [58, 76], [58, 77], [58, 78], [58, 79], [58, 80], [58, 81], [58, 82], [58, 84], [58, 85], [58, 87], [58, 89], [58, 92], [58, 93], [58, 95], [58, 102], [58, 103], [58, 104], [58, 108], [58, 113], [58, 114], [58, 115], [58, 116], [58, 118], [58, 119], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 67], [59, 69], [59, 74], [59, 76], [59, 78], [59, 81], [59, 84], [59, 85], [59, 88], [59, 89], [59, 96], [59, 97], [59, 98], [59, 99], [59, 102], [59, 103], [59, 105], [59, 109], [59, 110], [59, 111], [59, 114], [59, 115], [59, 118], [59, 119], [60, 62], [60, 65], [60, 66], [60, 67], [60, 70], [60, 73], [60, 74], [60, 75], [60, 76], [60, 77], [60, 80], [60, 84], [60, 86], [60, 87], [60, 90], [60, 91], [60, 96], [60, 100], [60, 102], [60, 103], [60, 104], [60, 105], [60, 106], [60, 107], [60, 109], [60, 111], [60, 112], [60, 113], [60, 117], [61, 62], [61, 63], [61, 64], [61, 65], [61, 67], [61, 69], [61, 71], [61, 72], [61, 73], [61, 75], [61, 77], [61, 79], [61, 83], [61, 86], [61, 88], [61, 89], [61, 90], [61, 91], [61, 92], [61, 94], [61, 96], [61, 98], [61, 100], [61, 101], [61, 102], [61, 103], [61, 105], [61, 107], [61, 109], [61, 110], [61, 111], [61, 113], [61, 114], [61, 115], [61, 117], [61, 118], [61, 119], [62, 63], [62, 67], [62, 68], [62, 69], [62, 70], [62, 71], [62, 73], [62, 74], [62, 76], [62, 77], [62, 78], [62, 79], [62, 84], [62, 86], [62, 88], [62, 91], [62, 92], [62, 94], [62, 96], [62, 98], [62, 99], [62, 101], [62, 103], [62, 104], [62, 106], [62, 108], [62, 110], [62, 111], [62, 112], [62, 113], [62, 116], [62, 117], [63, 68], [63, 69], [63, 70], [63, 72], [63, 73], [63, 74], [63, 75], [63, 76], [63, 77], [63, 78], [63, 79], [63, 81], [63, 83], [63, 84], [63, 86], [63, 89], [63, 90], [63, 91], [63, 92], [63, 95], [63, 98], [63, 101], [63, 102], [63, 105], [63, 107], [63, 108], [63, 110], [63, 113], [63, 115], [63, 117], [63, 118], [64, 67], [64, 68], [64, 71], [64, 72], [64, 74], [64, 75], [64, 76], [64, 77], [64, 78], [64, 79], [64, 82], [64, 85], [64, 86], [64, 87], [64, 88], [64, 89], [64, 90], [64, 91], [64, 92], [64, 93], [64, 96], [64, 98], [64, 100], [64, 104], [64, 105], [64, 106], [64, 109], [64, 110], [64, 111], [64, 113], [64, 114], [64, 116], [64, 119], [65, 68], [65, 69], [65, 70], [65, 71], [65, 73], [65, 76], [65, 77], [65, 78], [65, 80], [65, 82], [65, 83], [65, 84], [65, 85], [65, 86], [65, 88], [65, 91], [65, 92], [65, 93], [65, 96], [65, 97], [65, 100], [65, 101], [65, 108], [65, 109], [65, 111], [65, 113], [65, 115], [65, 116], [65, 117], [65, 118], [66, 69], [66, 71], [66, 75], [66, 76], [66, 81], [66, 85], [66, 88], [66, 89], [66, 92], [66, 93], [66, 97], [66, 100], [66, 101], [66, 103], [66, 109], [66, 111], [66, 112], [66, 115], [66, 116], [66, 117], [66, 118], [66, 119], [67, 69], [67, 70], [67, 75], [67, 79], [67, 80], [67, 81], [67, 82], [67, 83], [67, 85], [67, 86], [67, 90], [67, 91], [67, 92], [67, 94], [67, 97], [67, 98], [67, 99], [67, 101], [67, 103], [67, 104], [67, 105], [67, 107], [67, 108], [67, 111], [67, 114], [67, 116], [67, 117], [67, 118], [67, 119], [68, 69], [68, 71], [68, 72], [68, 74], [68, 77], [68, 79], [68, 80], [68, 82], [68, 83], [68, 88], [68, 91], [68, 92], [68, 93], [68, 94], [68, 95], [68, 96], [68, 98], [68, 101], [68, 104], [68, 105], [68, 109], [68, 110], [68, 114], [68, 115], [68, 116], [69, 70], [69, 77], [69, 79], [69, 80], [69, 83], [69, 85], [69, 86], [69, 87], [69, 91], [69, 92], [69, 94], [69, 95], [69, 98], [69, 99], [69, 100], [69, 104], [69, 105], [69, 107], [69, 108], [69, 115], [69, 116], [69, 118], [69, 119], [70, 75], [70, 76], [70, 77], [70, 79], [70, 81], [70, 83], [70, 84], [70, 87], [70, 90], [70, 91], [70, 92], [70, 93], [70, 96], [70, 97], [70, 99], [70, 101], [70, 106], [70, 107], [70, 110], [70, 111], [70, 115], [70, 117], [70, 118], [71, 74], [71, 77], [71, 79], [71, 80], [71, 82], [71, 84], [71, 89], [71, 90], [71, 93], [71, 94], [71, 95], [71, 101], [71, 103], [71, 105], [71, 106], [71, 107], [71, 108], [71, 110], [71, 112], [71, 114], [71, 117], [71, 118], [72, 75], [72, 77], [72, 78], [72, 79], [72, 80], [72, 82], [72, 86], [72, 88], [72, 89], [72, 90], [72, 92], [72, 93], [72, 96], [72, 97], [72, 98], [72, 100], [72, 103], [72, 104], [72, 107], [72, 111], [72, 112], [72, 113], [72, 115], [72, 116], [73, 78], [73, 81], [73, 84], [73, 86], [73, 88], [73, 90], [73, 91], [73, 93], [73, 96], [73, 98], [73, 103], [73, 108], [73, 109], [73, 111], [73, 112], [73, 114], [73, 116], [73, 117], [73, 119], [74, 77], [74, 78], [74, 79], [74, 80], [74, 87], [74, 88], [74, 89], [74, 91], [74, 92], [74, 93], [74, 94], [74, 95], [74, 97], [74, 99], [74, 101], [74, 102], [74, 106], [74, 108], [74, 109], [74, 110], [74, 111], [74, 113], [74, 117], [75, 77], [75, 78], [75, 82], [75, 86], [75, 87], [75, 88], [75, 89], [75, 90], [75, 91], [75, 93], [75, 96], [75, 97], [75, 99], [75, 100], [75, 101], [75, 102], [75, 105], [75, 106], [75, 107], [75, 111], [75, 112], [75, 114], [75, 115], [75, 117], [75, 118], [76, 79], [76, 81], [76, 82], [76, 85], [76, 87], [76, 88], [76, 89], [76, 91], [76, 92], [76, 97], [76, 99], [76, 100], [76, 103], [76, 104], [76, 108], [76, 112], [76, 114], [76, 115], [76, 116], [76, 117], [77, 78], [77, 79], [77, 81], [77, 83], [77, 84], [77, 85], [77, 87], [77, 90], [77, 93], [77, 96], [77, 98], [77, 101], [77, 102], [77, 103], [77, 106], [77, 107], [77, 108], [77, 111], [77, 112], [77, 113], [77, 117], [77, 118], [78, 79], [78, 83], [78, 84], [78, 86], [78, 95], [78, 100], [78, 101], [78, 106], [78, 107], [78, 109], [78, 110], [78, 114], [79, 80], [79, 84], [79, 85], [79, 87], [79, 88], [79, 92], [79, 93], [79, 94], [79, 98], [79, 99], [79, 101], [79, 105], [79, 107], [79, 108], [79, 112], [79, 117], [80, 82], [80, 84], [80, 85], [80, 86], [80, 88], [80, 91], [80, 92], [80, 93], [80, 94], [80, 95], [80, 96], [80, 97], [80, 100], [80, 101], [80, 102], [80, 103], [80, 105], [80, 106], [80, 108], [80, 110], [80, 112], [80, 114], [80, 115], [80, 118], [81, 83], [81, 84], [81, 87], [81, 89], [81, 90], [81, 91], [81, 93], [81, 94], [81, 95], [81, 96], [81, 97], [81, 98], [81, 101], [81, 103], [81, 107], [81, 108], [81, 109], [81, 110], [81, 112], [81, 113], [81, 115], [81, 119], [82, 83], [82, 84], [82, 88], [82, 89], [82, 91], [82, 95], [82, 96], [82, 97], [82, 98], [82, 99], [82, 100], [82, 102], [82, 103], [82, 108], [82, 109], [82, 111], [82, 112], [82, 114], [82, 117], [83, 84], [83, 85], [83, 86], [83, 88], [83, 91], [83, 92], [83, 93], [83, 95], [83, 101], [83, 104], [83, 105], [83, 106], [83, 110], [83, 111], [83, 114], [83, 115], [84, 85], [84, 86], [84, 90], [84, 92], [84, 93], [84, 94], [84, 99], [84, 101], [84, 102], [84, 103], [84, 104], [84, 107], [84, 108], [84, 109], [84, 112], [84, 115], [84, 116], [85, 87], [85, 88], [85, 89], [85, 91], [85, 92], [85, 95], [85, 97], [85, 98], [85, 99], [85, 100], [85, 104], [85, 106], [85, 109], [85, 112], [85, 114], [85, 116], [85, 118], [85, 119], [86, 88], [86, 89], [86, 90], [86, 91], [86, 93], [86, 94], [86, 97], [86, 98], [86, 99], [86, 101], [86, 102], [86, 108], [86, 109], [86, 110], [86, 112], [86, 113], [86, 114], [86, 116], [86, 117], [86, 118], [86, 119], [87, 89], [87, 92], [87, 94], [87, 97], [87, 98], [87, 99], [87, 104], [87, 108], [87, 112], [87, 113], [87, 114], [87, 115], [87, 117], [87, 118], [87, 119], [88, 91], [88, 92], [88, 93], [88, 94], [88, 96], [88, 97], [88, 101], [88, 106], [88, 107], [88, 108], [88, 109], [88, 110], [88, 111], [88, 112], [88, 115], [88, 116], [88, 117], [88, 118], [88, 119], [89, 90], [89, 91], [89, 93], [89, 94], [89, 95], [89, 97], [89, 98], [89, 99], [89, 100], [89, 106], [89, 112], [89, 113], [89, 115], [89, 118], [89, 119], [90, 91], [90, 92], [90, 95], [90, 96], [90, 97], [90, 103], [90, 105], [90, 107], [90, 108], [90, 109], [90, 111], [90, 112], [90, 113], [90, 114], [90, 115], [91, 92], [91, 95], [91, 96], [91, 98], [91, 99], [91, 100], [91, 101], [91, 103], [91, 107], [91, 108], [91, 113], [91, 114], [91, 117], [91, 118], [92, 94], [92, 95], [92, 99], [92, 100], [92, 101], [92, 103], [92, 104], [92, 106], [92, 107], [92, 110], [92, 111], [92, 113], [92, 116], [92, 118], [93, 96], [93, 97], [93, 98], [93, 100], [93, 103], [93, 104], [93, 105], [93, 109], [93, 110], [93, 113], [93, 114], [93, 115], [93, 117], [93, 118], [94, 96], [94, 98], [94, 99], [94, 101], [94, 103], [94, 104], [94, 106], [94, 107], [94, 108], [94, 109], [94, 110], [94, 116], [94, 118], [95, 99], [95, 100], [95, 101], [95, 102], [95, 103], [95, 106], [95, 108], [95, 109], [95, 110], [95, 111], [95, 112], [95, 113], [95, 114], [95, 117], [95, 119], [96, 97], [96, 99], [96, 100], [96, 108], [96, 109], [96, 110], [96, 111], [96, 112], [96, 113], [96, 117], [96, 118], [97, 98], [97, 99], [97, 100], [97, 102], [97, 103], [97, 105], [97, 106], [97, 108], [97, 111], [97, 113], [97, 116], [97, 119], [98, 99], [98, 102], [98, 107], [98, 109], [98, 110], [98, 112], [98, 113], [98, 117], [98, 118], [98, 119], [99, 100], [99, 102], [99, 103], [99, 105], [99, 107], [99, 108], [99, 109], [99, 112], [99, 116], [99, 118], [99, 119], [100, 101], [100, 102], [100, 103], [100, 104], [100, 105], [100, 106], [100, 107], [100, 112], [100, 113], [100, 115], [100, 116], [100, 119], [101, 103], [101, 104], [101, 105], [101, 106], [101, 108], [101, 110], [101, 111], [101, 114], [101, 115], [101, 118], [101, 119], [102, 103], [102, 104], [102, 109], [102, 110], [102, 111], [102, 113], [102, 116], [103, 104], [103, 107], [103, 108], [103, 111], [103, 115], [103, 116], [103, 117], [103, 119], [104, 106], [104, 113], [104, 114], [104, 115], [104, 117], [104, 118], [104, 119], [105, 107], [105, 108], [105, 110], [105, 114], [105, 116], [105, 117], [105, 118], [105, 119], [106, 107], [106, 108], [106, 111], [106, 112], [106, 114], [106, 115], [106, 117], [106, 118], [106, 119], [107, 108], [107, 110], [107, 111], [107, 112], [107, 113], [107, 116], [107, 117], [107, 118], [107, 119], [108, 110], [108, 111], [108, 112], [108, 113], [109, 111], [109, 116], [109, 117], [109, 118], [109, 119], [110, 112], [110, 113], [110, 114], [110, 115], [110, 116], [110, 117], [111, 112], [111, 113], [111, 115], [111, 119], [112, 114], [112, 115], [112, 116], [112, 117], [113, 115], [113, 117], [113, 118], [114, 115], [114, 116], [114, 118], [115, 116], [115, 117], [115, 118], [116, 118], [116, 119], [117, 118], [117, 119]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l6-s9/tests/run.py b/tasks/construct-mc-max-clique-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l6-s9/tests/test.sh b/tasks/construct-mc-max-clique-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l5-s2/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l5-s2/environment/instance.json b/tasks/construct-mc-max-independent-set-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72a32a445165bacde52b0f0fa23f6cb80461e275 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 12], [0, 13], [0, 15], [0, 26], [0, 27], [0, 41], [0, 47], [0, 49], [0, 52], [0, 53], [0, 54], [0, 57], [0, 58], [0, 61], [0, 64], [0, 66], [0, 73], [0, 79], [0, 80], [0, 82], [1, 7], [1, 9], [1, 15], [1, 16], [1, 17], [1, 27], [1, 31], [1, 32], [1, 33], [1, 37], [1, 42], [1, 43], [1, 45], [1, 49], [1, 50], [1, 52], [1, 54], [1, 61], [1, 62], [1, 63], [1, 68], [1, 69], [1, 75], [1, 81], [1, 84], [1, 89], [2, 3], [2, 7], [2, 11], [2, 16], [2, 17], [2, 23], [2, 27], [2, 28], [2, 30], [2, 32], [2, 35], [2, 42], [2, 44], [2, 45], [2, 49], [2, 51], [2, 52], [2, 58], [2, 59], [2, 60], [2, 62], [2, 63], [2, 70], [2, 74], [2, 77], [2, 78], [2, 84], [2, 87], [3, 4], [3, 7], [3, 8], [3, 13], [3, 15], [3, 21], [3, 32], [3, 35], [3, 36], [3, 40], [3, 41], [3, 43], [3, 46], [3, 48], [3, 49], [3, 50], [3, 51], [3, 53], [3, 55], [3, 58], [3, 59], [3, 60], [3, 61], [3, 68], [3, 69], [3, 89], [4, 9], [4, 10], [4, 11], [4, 12], [4, 18], [4, 19], [4, 20], [4, 22], [4, 24], [4, 28], [4, 29], [4, 31], [4, 33], [4, 34], [4, 36], [4, 37], [4, 42], [4, 43], [4, 47], [4, 50], [4, 51], [4, 53], [4, 56], [4, 62], [4, 64], [4, 66], [4, 68], [4, 71], [4, 73], [4, 83], [4, 85], [5, 11], [5, 12], [5, 13], [5, 16], [5, 29], [5, 30], [5, 38], [5, 42], [5, 49], [5, 53], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 63], [5, 65], [5, 69], [5, 74], [5, 79], [5, 82], [5, 86], [5, 87], [5, 88], [5, 89], [6, 13], [6, 14], [6, 16], [6, 25], [6, 38], [6, 40], [6, 49], [6, 51], [6, 61], [6, 63], [6, 71], [6, 72], [6, 73], [6, 76], [6, 77], [6, 78], [6, 85], [6, 86], [6, 87], [6, 88], [6, 89], [7, 8], [7, 11], [7, 12], [7, 14], [7, 16], [7, 18], [7, 23], [7, 24], [7, 29], [7, 31], [7, 33], [7, 37], [7, 40], [7, 41], [7, 43], [7, 44], [7, 46], [7, 53], [7, 55], [7, 57], [7, 58], [7, 59], [7, 68], [7, 69], [7, 72], [7, 74], [7, 80], [7, 87], [8, 9], [8, 10], [8, 19], [8, 21], [8, 23], [8, 25], [8, 31], [8, 36], [8, 41], [8, 52], [8, 59], [8, 63], [8, 64], [8, 68], [8, 73], [8, 74], [8, 75], [8, 82], [8, 88], [8, 89], [9, 11], [9, 13], [9, 15], [9, 18], [9, 21], [9, 23], [9, 30], [9, 39], [9, 42], [9, 44], [9, 46], [9, 47], [9, 52], [9, 53], [9, 56], [9, 57], [9, 59], [9, 60], [9, 71], [9, 73], [9, 77], [9, 86], [9, 89], [10, 11], [10, 20], [10, 24], [10, 26], [10, 28], [10, 30], [10, 33], [10, 35], [10, 36], [10, 41], [10, 42], [10, 44], [10, 47], [10, 48], [10, 52], [10, 53], [10, 54], [10, 55], [10, 61], [10, 62], [10, 64], [10, 66], [10, 68], [10, 71], [10, 72], [10, 77], [10, 78], [10, 83], [10, 87], [11, 15], [11, 16], [11, 31], [11, 32], [11, 38], [11, 49], [11, 51], [11, 56], [11, 57], [11, 66], [11, 68], [11, 74], [11, 79], [11, 89], [12, 15], [12, 16], [12, 20], [12, 33], [12, 37], [12, 38], [12, 41], [12, 42], [12, 47], [12, 49], [12, 50], [12, 57], [12, 60], [12, 61], [12, 62], [12, 64], [12, 69], [12, 72], [12, 74], [12, 78], [12, 81], [12, 84], [12, 89], [13, 15], [13, 17], [13, 20], [13, 21], [13, 25], [13, 28], [13, 29], [13, 31], [13, 33], [13, 34], [13, 35], [13, 41], [13, 44], [13, 46], [13, 47], [13, 50], [13, 52], [13, 55], [13, 62], [13, 66], [13, 67], [13, 69], [13, 72], [13, 76], [13, 80], [13, 86], [14, 18], [14, 19], [14, 21], [14, 23], [14, 25], [14, 27], [14, 31], [14, 36], [14, 41], [14, 45], [14, 47], [14, 51], [14, 52], [14, 54], [14, 58], [14, 60], [14, 65], [14, 73], [14, 74], [14, 76], [14, 80], [14, 85], [14, 86], [14, 87], [15, 18], [15, 22], [15, 25], [15, 26], [15, 29], [15, 32], [15, 35], [15, 37], [15, 40], [15, 43], [15, 50], [15, 55], [15, 59], [15, 71], [15, 78], [15, 84], [15, 88], [16, 20], [16, 21], [16, 22], [16, 24], [16, 28], [16, 41], [16, 42], [16, 43], [16, 45], [16, 49], [16, 50], [16, 53], [16, 57], [16, 61], [16, 65], [16, 69], [16, 72], [16, 76], [16, 84], [17, 18], [17, 21], [17, 24], [17, 28], [17, 29], [17, 30], [17, 36], [17, 39], [17, 49], [17, 51], [17, 53], [17, 59], [17, 63], [17, 64], [17, 67], [17, 68], [17, 71], [17, 72], [17, 74], [17, 79], [17, 80], [17, 83], [17, 86], [17, 89], [18, 19], [18, 20], [18, 23], [18, 27], [18, 31], [18, 34], [18, 38], [18, 44], [18, 47], [18, 48], [18, 52], [18, 61], [18, 63], [18, 73], [18, 74], [18, 76], [18, 78], [18, 81], [18, 82], [18, 83], [18, 84], [18, 85], [18, 87], [18, 88], [19, 20], [19, 21], [19, 23], [19, 24], [19, 32], [19, 36], [19, 37], [19, 39], [19, 40], [19, 41], [19, 45], [19, 50], [19, 54], [19, 58], [19, 65], [19, 66], [19, 68], [19, 77], [19, 82], [19, 83], [19, 89], [20, 29], [20, 30], [20, 35], [20, 42], [20, 43], [20, 44], [20, 46], [20, 47], [20, 48], [20, 49], [20, 51], [20, 54], [20, 60], [20, 63], [20, 66], [20, 68], [20, 74], [20, 77], [20, 79], [20, 80], [20, 81], [20, 82], [21, 22], [21, 26], [21, 33], [21, 35], [21, 36], [21, 39], [21, 42], [21, 45], [21, 48], [21, 50], [21, 52], [21, 54], [21, 56], [21, 57], [21, 58], [21, 65], [21, 68], [21, 71], [21, 76], [21, 77], [21, 80], [21, 86], [21, 88], [21, 89], [22, 24], [22, 27], [22, 28], [22, 31], [22, 35], [22, 43], [22, 46], [22, 50], [22, 54], [22, 55], [22, 58], [22, 62], [22, 69], [22, 70], [22, 72], [22, 75], [22, 79], [22, 81], [23, 25], [23, 26], [23, 27], [23, 29], [23, 34], [23, 40], [23, 41], [23, 42], [23, 43], [23, 53], [23, 55], [23, 58], [23, 61], [23, 62], [23, 63], [23, 67], [23, 72], [23, 78], [23, 81], [23, 83], [24, 25], [24, 27], [24, 30], [24, 37], [24, 45], [24, 46], [24, 50], [24, 54], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 70], [24, 71], [24, 75], [24, 78], [24, 83], [24, 85], [24, 87], [24, 88], [25, 27], [25, 31], [25, 32], [25, 40], [25, 48], [25, 52], [25, 60], [25, 67], [25, 71], [25, 89], [26, 32], [26, 38], [26, 40], [26, 41], [26, 45], [26, 47], [26, 48], [26, 51], [26, 52], [26, 59], [26, 61], [26, 69], [26, 70], [26, 73], [26, 75], [26, 88], [27, 36], [27, 37], [27, 38], [27, 44], [27, 49], [27, 52], [27, 54], [27, 56], [27, 57], [27, 61], [27, 64], [27, 65], [27, 66], [27, 67], [27, 70], [27, 78], [27, 80], [27, 82], [27, 84], [27, 89], [28, 32], [28, 40], [28, 42], [28, 43], [28, 45], [28, 46], [28, 49], [28, 57], [28, 68], [28, 71], [28, 72], [28, 74], [28, 76], [28, 78], [28, 80], [28, 81], [28, 82], [28, 85], [28, 87], [29, 32], [29, 35], [29, 38], [29, 39], [29, 43], [29, 45], [29, 48], [29, 51], [29, 54], [29, 55], [29, 59], [29, 63], [29, 64], [29, 67], [29, 69], [29, 73], [29, 74], [29, 80], [29, 88], [30, 34], [30, 35], [30, 41], [30, 42], [30, 44], [30, 54], [30, 55], [30, 57], [30, 58], [30, 62], [30, 64], [30, 65], [30, 66], [30, 68], [30, 71], [30, 73], [30, 74], [30, 82], [31, 33], [31, 35], [31, 37], [31, 40], [31, 41], [31, 49], [31, 50], [31, 51], [31, 54], [31, 59], [31, 63], [31, 64], [31, 68], [31, 71], [31, 72], [31, 73], [31, 76], [31, 80], [31, 84], [31, 85], [31, 86], [31, 87], [32, 47], [32, 48], [32, 51], [32, 55], [32, 57], [32, 58], [32, 60], [32, 64], [32, 66], [32, 67], [32, 68], [32, 70], [32, 74], [32, 78], [32, 84], [32, 86], [33, 34], [33, 39], [33, 40], [33, 45], [33, 49], [33, 54], [33, 57], [33, 61], [33, 62], [33, 63], [33, 64], [33, 67], [33, 69], [33, 74], [33, 77], [33, 78], [33, 85], [34, 36], [34, 38], [34, 40], [34, 43], [34, 45], [34, 46], [34, 47], [34, 49], [34, 50], [34, 54], [34, 61], [34, 64], [34, 69], [34, 72], [34, 78], [34, 79], [34, 88], [34, 89], [35, 39], [35, 40], [35, 42], [35, 43], [35, 45], [35, 49], [35, 62], [35, 67], [35, 71], [35, 74], [35, 75], [35, 77], [35, 84], [35, 88], [35, 89], [36, 44], [36, 47], [36, 49], [36, 56], [36, 61], [36, 62], [36, 65], [36, 66], [36, 80], [36, 81], [36, 87], [37, 38], [37, 39], [37, 40], [37, 49], [37, 68], [37, 74], [37, 75], [37, 76], [37, 78], [37, 80], [37, 81], [37, 83], [37, 85], [38, 44], [38, 45], [38, 46], [38, 47], [38, 50], [38, 55], [38, 56], [38, 61], [38, 65], [38, 67], [38, 69], [38, 71], [38, 77], [38, 79], [38, 81], [38, 82], [38, 83], [38, 86], [38, 89], [39, 41], [39, 48], [39, 49], [39, 50], [39, 51], [39, 52], [39, 67], [39, 74], [39, 75], [39, 77], [39, 81], [39, 86], [39, 88], [40, 44], [40, 49], [40, 50], [40, 51], [40, 53], [40, 59], [40, 60], [40, 65], [40, 71], [40, 75], [40, 78], [40, 84], [40, 86], [41, 45], [41, 46], [41, 53], [41, 54], [41, 55], [41, 59], [41, 61], [41, 64], [41, 71], [41, 81], [41, 84], [41, 86], [41, 88], [42, 44], [42, 45], [42, 47], [42, 50], [42, 59], [42, 60], [42, 61], [42, 67], [42, 68], [42, 70], [42, 71], [42, 82], [42, 83], [42, 85], [42, 89], [43, 45], [43, 46], [43, 48], [43, 50], [43, 59], [43, 66], [43, 68], [43, 71], [43, 74], [43, 80], [43, 81], [43, 82], [43, 85], [43, 88], [44, 45], [44, 49], [44, 50], [44, 54], [44, 58], [44, 69], [44, 79], [44, 84], [45, 47], [45, 55], [45, 62], [45, 64], [45, 67], [45, 69], [45, 70], [45, 72], [45, 73], [45, 74], [45, 81], [45, 82], [45, 85], [45, 87], [45, 89], [46, 53], [46, 55], [46, 58], [46, 59], [46, 63], [46, 68], [46, 69], [46, 71], [46, 73], [46, 74], [46, 76], [46, 78], [46, 88], [47, 48], [47, 53], [47, 55], [47, 56], [47, 57], [47, 58], [47, 63], [47, 66], [47, 72], [47, 80], [47, 82], [47, 86], [48, 52], [48, 56], [48, 57], [48, 59], [48, 62], [48, 68], [48, 70], [48, 73], [48, 74], [48, 75], [48, 78], [48, 79], [48, 83], [48, 84], [48, 87], [48, 89], [49, 52], [49, 53], [49, 56], [49, 64], [49, 70], [49, 71], [49, 74], [49, 76], [49, 82], [49, 84], [49, 87], [49, 88], [50, 51], [50, 52], [50, 57], [50, 59], [50, 64], [50, 65], [50, 67], [50, 70], [50, 72], [50, 79], [50, 81], [50, 82], [50, 85], [50, 87], [51, 52], [51, 53], [51, 54], [51, 56], [51, 60], [51, 63], [51, 65], [51, 71], [51, 74], [51, 77], [51, 79], [51, 81], [52, 55], [52, 58], [52, 59], [52, 63], [52, 64], [52, 67], [52, 69], [52, 71], [52, 72], [52, 73], [52, 79], [52, 85], [52, 86], [52, 89], [53, 56], [53, 58], [53, 59], [53, 61], [53, 65], [53, 66], [53, 67], [53, 71], [53, 74], [53, 75], [53, 78], [53, 82], [53, 83], [53, 88], [54, 55], [54, 59], [54, 63], [54, 64], [54, 66], [54, 67], [54, 68], [54, 70], [54, 71], [54, 73], [54, 84], [54, 85], [54, 86], [54, 87], [55, 65], [55, 79], [55, 86], [55, 88], [56, 57], [56, 59], [56, 64], [56, 67], [56, 68], [56, 80], [56, 82], [56, 83], [57, 63], [57, 64], [57, 66], [57, 67], [57, 69], [57, 71], [57, 79], [57, 81], [57, 83], [57, 84], [57, 86], [58, 60], [58, 61], [58, 73], [58, 75], [58, 79], [58, 83], [58, 86], [59, 62], [59, 65], [59, 68], [59, 70], [59, 72], [59, 75], [59, 81], [59, 83], [59, 84], [59, 89], [60, 61], [60, 65], [60, 67], [60, 70], [60, 74], [60, 76], [60, 82], [60, 86], [60, 89], [61, 62], [61, 63], [61, 75], [61, 76], [61, 83], [61, 89], [62, 67], [62, 68], [62, 70], [62, 76], [62, 80], [62, 81], [62, 82], [62, 88], [63, 65], [63, 71], [63, 78], [63, 79], [63, 81], [63, 83], [64, 73], [64, 74], [64, 76], [64, 84], [64, 85], [65, 67], [65, 71], [65, 72], [65, 77], [65, 79], [65, 82], [65, 84], [66, 67], [66, 68], [66, 84], [66, 86], [67, 68], [67, 69], [67, 72], [67, 81], [67, 83], [67, 84], [68, 73], [68, 75], [68, 79], [68, 81], [68, 82], [68, 85], [69, 70], [69, 72], [69, 73], [69, 76], [69, 79], [69, 81], [69, 83], [69, 87], [70, 73], [70, 75], [70, 76], [70, 81], [70, 87], [70, 89], [71, 75], [71, 82], [71, 87], [71, 88], [72, 74], [72, 77], [72, 79], [72, 81], [72, 84], [72, 86], [72, 88], [73, 74], [73, 77], [73, 79], [73, 88], [74, 83], [74, 85], [74, 89], [75, 76], [75, 77], [75, 82], [75, 86], [75, 87], [76, 79], [76, 82], [76, 89], [77, 82], [77, 88], [77, 89], [78, 81], [78, 82], [78, 84], [78, 88], [79, 82], [79, 85], [81, 82], [81, 84], [83, 86], [83, 88], [84, 86], [85, 86], [86, 88], [86, 89], [87, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s2/solution/solve.sh b/tasks/construct-mc-max-independent-set-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79cf20984ca0bd1cf39e61b623f4f6f5cebeeadf --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [1, 3, 11, 12, 22, 25, 26, 34, 39, 44, 65, 76, 80, 83, 85, 87]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l5-s2/tests/check.py b/tasks/construct-mc-max-independent-set-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l5-s2/tests/instance.json b/tasks/construct-mc-max-independent-set-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72a32a445165bacde52b0f0fa23f6cb80461e275 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 12], [0, 13], [0, 15], [0, 26], [0, 27], [0, 41], [0, 47], [0, 49], [0, 52], [0, 53], [0, 54], [0, 57], [0, 58], [0, 61], [0, 64], [0, 66], [0, 73], [0, 79], [0, 80], [0, 82], [1, 7], [1, 9], [1, 15], [1, 16], [1, 17], [1, 27], [1, 31], [1, 32], [1, 33], [1, 37], [1, 42], [1, 43], [1, 45], [1, 49], [1, 50], [1, 52], [1, 54], [1, 61], [1, 62], [1, 63], [1, 68], [1, 69], [1, 75], [1, 81], [1, 84], [1, 89], [2, 3], [2, 7], [2, 11], [2, 16], [2, 17], [2, 23], [2, 27], [2, 28], [2, 30], [2, 32], [2, 35], [2, 42], [2, 44], [2, 45], [2, 49], [2, 51], [2, 52], [2, 58], [2, 59], [2, 60], [2, 62], [2, 63], [2, 70], [2, 74], [2, 77], [2, 78], [2, 84], [2, 87], [3, 4], [3, 7], [3, 8], [3, 13], [3, 15], [3, 21], [3, 32], [3, 35], [3, 36], [3, 40], [3, 41], [3, 43], [3, 46], [3, 48], [3, 49], [3, 50], [3, 51], [3, 53], [3, 55], [3, 58], [3, 59], [3, 60], [3, 61], [3, 68], [3, 69], [3, 89], [4, 9], [4, 10], [4, 11], [4, 12], [4, 18], [4, 19], [4, 20], [4, 22], [4, 24], [4, 28], [4, 29], [4, 31], [4, 33], [4, 34], [4, 36], [4, 37], [4, 42], [4, 43], [4, 47], [4, 50], [4, 51], [4, 53], [4, 56], [4, 62], [4, 64], [4, 66], [4, 68], [4, 71], [4, 73], [4, 83], [4, 85], [5, 11], [5, 12], [5, 13], [5, 16], [5, 29], [5, 30], [5, 38], [5, 42], [5, 49], [5, 53], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 63], [5, 65], [5, 69], [5, 74], [5, 79], [5, 82], [5, 86], [5, 87], [5, 88], [5, 89], [6, 13], [6, 14], [6, 16], [6, 25], [6, 38], [6, 40], [6, 49], [6, 51], [6, 61], [6, 63], [6, 71], [6, 72], [6, 73], [6, 76], [6, 77], [6, 78], [6, 85], [6, 86], [6, 87], [6, 88], [6, 89], [7, 8], [7, 11], [7, 12], [7, 14], [7, 16], [7, 18], [7, 23], [7, 24], [7, 29], [7, 31], [7, 33], [7, 37], [7, 40], [7, 41], [7, 43], [7, 44], [7, 46], [7, 53], [7, 55], [7, 57], [7, 58], [7, 59], [7, 68], [7, 69], [7, 72], [7, 74], [7, 80], [7, 87], [8, 9], [8, 10], [8, 19], [8, 21], [8, 23], [8, 25], [8, 31], [8, 36], [8, 41], [8, 52], [8, 59], [8, 63], [8, 64], [8, 68], [8, 73], [8, 74], [8, 75], [8, 82], [8, 88], [8, 89], [9, 11], [9, 13], [9, 15], [9, 18], [9, 21], [9, 23], [9, 30], [9, 39], [9, 42], [9, 44], [9, 46], [9, 47], [9, 52], [9, 53], [9, 56], [9, 57], [9, 59], [9, 60], [9, 71], [9, 73], [9, 77], [9, 86], [9, 89], [10, 11], [10, 20], [10, 24], [10, 26], [10, 28], [10, 30], [10, 33], [10, 35], [10, 36], [10, 41], [10, 42], [10, 44], [10, 47], [10, 48], [10, 52], [10, 53], [10, 54], [10, 55], [10, 61], [10, 62], [10, 64], [10, 66], [10, 68], [10, 71], [10, 72], [10, 77], [10, 78], [10, 83], [10, 87], [11, 15], [11, 16], [11, 31], [11, 32], [11, 38], [11, 49], [11, 51], [11, 56], [11, 57], [11, 66], [11, 68], [11, 74], [11, 79], [11, 89], [12, 15], [12, 16], [12, 20], [12, 33], [12, 37], [12, 38], [12, 41], [12, 42], [12, 47], [12, 49], [12, 50], [12, 57], [12, 60], [12, 61], [12, 62], [12, 64], [12, 69], [12, 72], [12, 74], [12, 78], [12, 81], [12, 84], [12, 89], [13, 15], [13, 17], [13, 20], [13, 21], [13, 25], [13, 28], [13, 29], [13, 31], [13, 33], [13, 34], [13, 35], [13, 41], [13, 44], [13, 46], [13, 47], [13, 50], [13, 52], [13, 55], [13, 62], [13, 66], [13, 67], [13, 69], [13, 72], [13, 76], [13, 80], [13, 86], [14, 18], [14, 19], [14, 21], [14, 23], [14, 25], [14, 27], [14, 31], [14, 36], [14, 41], [14, 45], [14, 47], [14, 51], [14, 52], [14, 54], [14, 58], [14, 60], [14, 65], [14, 73], [14, 74], [14, 76], [14, 80], [14, 85], [14, 86], [14, 87], [15, 18], [15, 22], [15, 25], [15, 26], [15, 29], [15, 32], [15, 35], [15, 37], [15, 40], [15, 43], [15, 50], [15, 55], [15, 59], [15, 71], [15, 78], [15, 84], [15, 88], [16, 20], [16, 21], [16, 22], [16, 24], [16, 28], [16, 41], [16, 42], [16, 43], [16, 45], [16, 49], [16, 50], [16, 53], [16, 57], [16, 61], [16, 65], [16, 69], [16, 72], [16, 76], [16, 84], [17, 18], [17, 21], [17, 24], [17, 28], [17, 29], [17, 30], [17, 36], [17, 39], [17, 49], [17, 51], [17, 53], [17, 59], [17, 63], [17, 64], [17, 67], [17, 68], [17, 71], [17, 72], [17, 74], [17, 79], [17, 80], [17, 83], [17, 86], [17, 89], [18, 19], [18, 20], [18, 23], [18, 27], [18, 31], [18, 34], [18, 38], [18, 44], [18, 47], [18, 48], [18, 52], [18, 61], [18, 63], [18, 73], [18, 74], [18, 76], [18, 78], [18, 81], [18, 82], [18, 83], [18, 84], [18, 85], [18, 87], [18, 88], [19, 20], [19, 21], [19, 23], [19, 24], [19, 32], [19, 36], [19, 37], [19, 39], [19, 40], [19, 41], [19, 45], [19, 50], [19, 54], [19, 58], [19, 65], [19, 66], [19, 68], [19, 77], [19, 82], [19, 83], [19, 89], [20, 29], [20, 30], [20, 35], [20, 42], [20, 43], [20, 44], [20, 46], [20, 47], [20, 48], [20, 49], [20, 51], [20, 54], [20, 60], [20, 63], [20, 66], [20, 68], [20, 74], [20, 77], [20, 79], [20, 80], [20, 81], [20, 82], [21, 22], [21, 26], [21, 33], [21, 35], [21, 36], [21, 39], [21, 42], [21, 45], [21, 48], [21, 50], [21, 52], [21, 54], [21, 56], [21, 57], [21, 58], [21, 65], [21, 68], [21, 71], [21, 76], [21, 77], [21, 80], [21, 86], [21, 88], [21, 89], [22, 24], [22, 27], [22, 28], [22, 31], [22, 35], [22, 43], [22, 46], [22, 50], [22, 54], [22, 55], [22, 58], [22, 62], [22, 69], [22, 70], [22, 72], [22, 75], [22, 79], [22, 81], [23, 25], [23, 26], [23, 27], [23, 29], [23, 34], [23, 40], [23, 41], [23, 42], [23, 43], [23, 53], [23, 55], [23, 58], [23, 61], [23, 62], [23, 63], [23, 67], [23, 72], [23, 78], [23, 81], [23, 83], [24, 25], [24, 27], [24, 30], [24, 37], [24, 45], [24, 46], [24, 50], [24, 54], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 70], [24, 71], [24, 75], [24, 78], [24, 83], [24, 85], [24, 87], [24, 88], [25, 27], [25, 31], [25, 32], [25, 40], [25, 48], [25, 52], [25, 60], [25, 67], [25, 71], [25, 89], [26, 32], [26, 38], [26, 40], [26, 41], [26, 45], [26, 47], [26, 48], [26, 51], [26, 52], [26, 59], [26, 61], [26, 69], [26, 70], [26, 73], [26, 75], [26, 88], [27, 36], [27, 37], [27, 38], [27, 44], [27, 49], [27, 52], [27, 54], [27, 56], [27, 57], [27, 61], [27, 64], [27, 65], [27, 66], [27, 67], [27, 70], [27, 78], [27, 80], [27, 82], [27, 84], [27, 89], [28, 32], [28, 40], [28, 42], [28, 43], [28, 45], [28, 46], [28, 49], [28, 57], [28, 68], [28, 71], [28, 72], [28, 74], [28, 76], [28, 78], [28, 80], [28, 81], [28, 82], [28, 85], [28, 87], [29, 32], [29, 35], [29, 38], [29, 39], [29, 43], [29, 45], [29, 48], [29, 51], [29, 54], [29, 55], [29, 59], [29, 63], [29, 64], [29, 67], [29, 69], [29, 73], [29, 74], [29, 80], [29, 88], [30, 34], [30, 35], [30, 41], [30, 42], [30, 44], [30, 54], [30, 55], [30, 57], [30, 58], [30, 62], [30, 64], [30, 65], [30, 66], [30, 68], [30, 71], [30, 73], [30, 74], [30, 82], [31, 33], [31, 35], [31, 37], [31, 40], [31, 41], [31, 49], [31, 50], [31, 51], [31, 54], [31, 59], [31, 63], [31, 64], [31, 68], [31, 71], [31, 72], [31, 73], [31, 76], [31, 80], [31, 84], [31, 85], [31, 86], [31, 87], [32, 47], [32, 48], [32, 51], [32, 55], [32, 57], [32, 58], [32, 60], [32, 64], [32, 66], [32, 67], [32, 68], [32, 70], [32, 74], [32, 78], [32, 84], [32, 86], [33, 34], [33, 39], [33, 40], [33, 45], [33, 49], [33, 54], [33, 57], [33, 61], [33, 62], [33, 63], [33, 64], [33, 67], [33, 69], [33, 74], [33, 77], [33, 78], [33, 85], [34, 36], [34, 38], [34, 40], [34, 43], [34, 45], [34, 46], [34, 47], [34, 49], [34, 50], [34, 54], [34, 61], [34, 64], [34, 69], [34, 72], [34, 78], [34, 79], [34, 88], [34, 89], [35, 39], [35, 40], [35, 42], [35, 43], [35, 45], [35, 49], [35, 62], [35, 67], [35, 71], [35, 74], [35, 75], [35, 77], [35, 84], [35, 88], [35, 89], [36, 44], [36, 47], [36, 49], [36, 56], [36, 61], [36, 62], [36, 65], [36, 66], [36, 80], [36, 81], [36, 87], [37, 38], [37, 39], [37, 40], [37, 49], [37, 68], [37, 74], [37, 75], [37, 76], [37, 78], [37, 80], [37, 81], [37, 83], [37, 85], [38, 44], [38, 45], [38, 46], [38, 47], [38, 50], [38, 55], [38, 56], [38, 61], [38, 65], [38, 67], [38, 69], [38, 71], [38, 77], [38, 79], [38, 81], [38, 82], [38, 83], [38, 86], [38, 89], [39, 41], [39, 48], [39, 49], [39, 50], [39, 51], [39, 52], [39, 67], [39, 74], [39, 75], [39, 77], [39, 81], [39, 86], [39, 88], [40, 44], [40, 49], [40, 50], [40, 51], [40, 53], [40, 59], [40, 60], [40, 65], [40, 71], [40, 75], [40, 78], [40, 84], [40, 86], [41, 45], [41, 46], [41, 53], [41, 54], [41, 55], [41, 59], [41, 61], [41, 64], [41, 71], [41, 81], [41, 84], [41, 86], [41, 88], [42, 44], [42, 45], [42, 47], [42, 50], [42, 59], [42, 60], [42, 61], [42, 67], [42, 68], [42, 70], [42, 71], [42, 82], [42, 83], [42, 85], [42, 89], [43, 45], [43, 46], [43, 48], [43, 50], [43, 59], [43, 66], [43, 68], [43, 71], [43, 74], [43, 80], [43, 81], [43, 82], [43, 85], [43, 88], [44, 45], [44, 49], [44, 50], [44, 54], [44, 58], [44, 69], [44, 79], [44, 84], [45, 47], [45, 55], [45, 62], [45, 64], [45, 67], [45, 69], [45, 70], [45, 72], [45, 73], [45, 74], [45, 81], [45, 82], [45, 85], [45, 87], [45, 89], [46, 53], [46, 55], [46, 58], [46, 59], [46, 63], [46, 68], [46, 69], [46, 71], [46, 73], [46, 74], [46, 76], [46, 78], [46, 88], [47, 48], [47, 53], [47, 55], [47, 56], [47, 57], [47, 58], [47, 63], [47, 66], [47, 72], [47, 80], [47, 82], [47, 86], [48, 52], [48, 56], [48, 57], [48, 59], [48, 62], [48, 68], [48, 70], [48, 73], [48, 74], [48, 75], [48, 78], [48, 79], [48, 83], [48, 84], [48, 87], [48, 89], [49, 52], [49, 53], [49, 56], [49, 64], [49, 70], [49, 71], [49, 74], [49, 76], [49, 82], [49, 84], [49, 87], [49, 88], [50, 51], [50, 52], [50, 57], [50, 59], [50, 64], [50, 65], [50, 67], [50, 70], [50, 72], [50, 79], [50, 81], [50, 82], [50, 85], [50, 87], [51, 52], [51, 53], [51, 54], [51, 56], [51, 60], [51, 63], [51, 65], [51, 71], [51, 74], [51, 77], [51, 79], [51, 81], [52, 55], [52, 58], [52, 59], [52, 63], [52, 64], [52, 67], [52, 69], [52, 71], [52, 72], [52, 73], [52, 79], [52, 85], [52, 86], [52, 89], [53, 56], [53, 58], [53, 59], [53, 61], [53, 65], [53, 66], [53, 67], [53, 71], [53, 74], [53, 75], [53, 78], [53, 82], [53, 83], [53, 88], [54, 55], [54, 59], [54, 63], [54, 64], [54, 66], [54, 67], [54, 68], [54, 70], [54, 71], [54, 73], [54, 84], [54, 85], [54, 86], [54, 87], [55, 65], [55, 79], [55, 86], [55, 88], [56, 57], [56, 59], [56, 64], [56, 67], [56, 68], [56, 80], [56, 82], [56, 83], [57, 63], [57, 64], [57, 66], [57, 67], [57, 69], [57, 71], [57, 79], [57, 81], [57, 83], [57, 84], [57, 86], [58, 60], [58, 61], [58, 73], [58, 75], [58, 79], [58, 83], [58, 86], [59, 62], [59, 65], [59, 68], [59, 70], [59, 72], [59, 75], [59, 81], [59, 83], [59, 84], [59, 89], [60, 61], [60, 65], [60, 67], [60, 70], [60, 74], [60, 76], [60, 82], [60, 86], [60, 89], [61, 62], [61, 63], [61, 75], [61, 76], [61, 83], [61, 89], [62, 67], [62, 68], [62, 70], [62, 76], [62, 80], [62, 81], [62, 82], [62, 88], [63, 65], [63, 71], [63, 78], [63, 79], [63, 81], [63, 83], [64, 73], [64, 74], [64, 76], [64, 84], [64, 85], [65, 67], [65, 71], [65, 72], [65, 77], [65, 79], [65, 82], [65, 84], [66, 67], [66, 68], [66, 84], [66, 86], [67, 68], [67, 69], [67, 72], [67, 81], [67, 83], [67, 84], [68, 73], [68, 75], [68, 79], [68, 81], [68, 82], [68, 85], [69, 70], [69, 72], [69, 73], [69, 76], [69, 79], [69, 81], [69, 83], [69, 87], [70, 73], [70, 75], [70, 76], [70, 81], [70, 87], [70, 89], [71, 75], [71, 82], [71, 87], [71, 88], [72, 74], [72, 77], [72, 79], [72, 81], [72, 84], [72, 86], [72, 88], [73, 74], [73, 77], [73, 79], [73, 88], [74, 83], [74, 85], [74, 89], [75, 76], [75, 77], [75, 82], [75, 86], [75, 87], [76, 79], [76, 82], [76, 89], [77, 82], [77, 88], [77, 89], [78, 81], [78, 82], [78, 84], [78, 88], [79, 82], [79, 85], [81, 82], [81, 84], [83, 86], [83, 88], [84, 86], [85, 86], [86, 88], [86, 89], [87, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s2/tests/run.py b/tasks/construct-mc-max-independent-set-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l5-s2/tests/test.sh b/tasks/construct-mc-max-independent-set-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l5-s5/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-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-mc-max-independent-set-l5-s5/environment/instance.json b/tasks/construct-mc-max-independent-set-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91092b4f613ef033707321c450203a327cc40123 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 1], [0, 2], [0, 6], [0, 7], [0, 8], [0, 11], [0, 18], [0, 20], [0, 21], [0, 33], [0, 34], [0, 38], [0, 46], [0, 47], [0, 49], [0, 60], [0, 63], [0, 66], [0, 72], [0, 77], [0, 81], [0, 82], [0, 84], [1, 5], [1, 6], [1, 10], [1, 11], [1, 13], [1, 14], [1, 20], [1, 23], [1, 24], [1, 25], [1, 40], [1, 42], [1, 51], [1, 52], [1, 53], [1, 58], [1, 59], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 68], [1, 75], [1, 77], [1, 78], [1, 85], [1, 86], [1, 87], [2, 5], [2, 7], [2, 10], [2, 12], [2, 15], [2, 16], [2, 19], [2, 23], [2, 28], [2, 30], [2, 31], [2, 33], [2, 34], [2, 36], [2, 39], [2, 48], [2, 49], [2, 52], [2, 54], [2, 66], [2, 68], [2, 69], [2, 70], [2, 77], [2, 78], [2, 80], [2, 81], [2, 82], [2, 84], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 11], [3, 16], [3, 17], [3, 21], [3, 23], [3, 28], [3, 29], [3, 33], [3, 40], [3, 42], [3, 44], [3, 52], [3, 54], [3, 55], [3, 58], [3, 59], [3, 60], [3, 62], [3, 65], [3, 66], [3, 68], [3, 78], [3, 83], [3, 84], [3, 85], [3, 86], [3, 89], [4, 7], [4, 23], [4, 24], [4, 25], [4, 30], [4, 31], [4, 33], [4, 37], [4, 38], [4, 39], [4, 48], [4, 52], [4, 55], [4, 59], [4, 63], [4, 65], [4, 75], [4, 77], [4, 81], [4, 82], [4, 83], [4, 86], [4, 88], [5, 8], [5, 9], [5, 11], [5, 14], [5, 21], [5, 23], [5, 24], [5, 26], [5, 29], [5, 30], [5, 34], [5, 43], [5, 44], [5, 46], [5, 47], [5, 53], [5, 55], [5, 57], [5, 59], [5, 60], [5, 65], [5, 66], [5, 69], [5, 70], [6, 15], [6, 16], [6, 18], [6, 23], [6, 24], [6, 28], [6, 34], [6, 37], [6, 38], [6, 40], [6, 46], [6, 49], [6, 51], [6, 52], [6, 54], [6, 60], [6, 61], [6, 62], [6, 65], [6, 66], [6, 68], [6, 69], [6, 74], [6, 84], [6, 87], [7, 13], [7, 14], [7, 15], [7, 16], [7, 19], [7, 32], [7, 33], [7, 36], [7, 38], [7, 41], [7, 42], [7, 43], [7, 49], [7, 63], [7, 64], [7, 67], [7, 76], [7, 77], [7, 81], [7, 84], [7, 89], [8, 12], [8, 15], [8, 16], [8, 21], [8, 26], [8, 36], [8, 39], [8, 44], [8, 45], [8, 48], [8, 51], [8, 58], [8, 60], [8, 62], [8, 63], [8, 65], [8, 69], [8, 75], [8, 79], [8, 82], [8, 87], [9, 10], [9, 11], [9, 15], [9, 17], [9, 22], [9, 26], [9, 27], [9, 32], [9, 39], [9, 41], [9, 49], [9, 52], [9, 53], [9, 58], [9, 67], [9, 74], [9, 75], [9, 77], [9, 78], [9, 80], [9, 81], [9, 84], [10, 14], [10, 17], [10, 21], [10, 24], [10, 26], [10, 27], [10, 32], [10, 34], [10, 35], [10, 36], [10, 37], [10, 40], [10, 43], [10, 46], [10, 47], [10, 48], [10, 49], [10, 52], [10, 56], [10, 58], [10, 62], [10, 67], [10, 70], [10, 74], [10, 75], [10, 77], [10, 78], [10, 80], [10, 82], [11, 12], [11, 14], [11, 17], [11, 21], [11, 23], [11, 30], [11, 31], [11, 32], [11, 33], [11, 37], [11, 41], [11, 44], [11, 47], [11, 48], [11, 49], [11, 51], [11, 54], [11, 57], [11, 60], [11, 63], [11, 66], [11, 71], [11, 75], [11, 84], [12, 17], [12, 19], [12, 22], [12, 23], [12, 24], [12, 25], [12, 37], [12, 43], [12, 44], [12, 49], [12, 56], [12, 60], [12, 67], [12, 72], [12, 73], [12, 76], [12, 77], [12, 81], [12, 84], [12, 85], [12, 86], [13, 18], [13, 19], [13, 27], [13, 28], [13, 29], [13, 30], [13, 33], [13, 34], [13, 35], [13, 36], [13, 40], [13, 41], [13, 42], [13, 53], [13, 57], [13, 62], [13, 65], [13, 67], [13, 71], [13, 76], [13, 78], [13, 81], [13, 83], [13, 87], [14, 27], [14, 29], [14, 32], [14, 34], [14, 36], [14, 37], [14, 44], [14, 51], [14, 53], [14, 56], [14, 58], [14, 59], [14, 61], [14, 62], [14, 63], [14, 65], [14, 67], [14, 69], [14, 71], [14, 79], [14, 80], [14, 85], [15, 18], [15, 19], [15, 24], [15, 25], [15, 33], [15, 36], [15, 37], [15, 38], [15, 40], [15, 46], [15, 55], [15, 57], [15, 59], [15, 68], [15, 72], [15, 73], [15, 80], [15, 81], [15, 82], [15, 88], [15, 89], [16, 28], [16, 35], [16, 38], [16, 40], [16, 42], [16, 45], [16, 47], [16, 49], [16, 50], [16, 52], [16, 64], [16, 67], [16, 70], [16, 71], [16, 79], [16, 81], [16, 84], [16, 87], [17, 21], [17, 22], [17, 25], [17, 26], [17, 27], [17, 28], [17, 31], [17, 34], [17, 37], [17, 46], [17, 52], [17, 53], [17, 59], [17, 63], [17, 70], [17, 78], [17, 81], [17, 85], [17, 86], [17, 87], [17, 88], [17, 89], [18, 19], [18, 22], [18, 23], [18, 28], [18, 29], [18, 32], [18, 36], [18, 42], [18, 43], [18, 51], [18, 55], [18, 56], [18, 64], [18, 70], [18, 72], [18, 76], [18, 79], [19, 20], [19, 31], [19, 34], [19, 46], [19, 50], [19, 51], [19, 53], [19, 62], [19, 63], [19, 64], [19, 68], [19, 69], [19, 73], [19, 79], [19, 80], [19, 81], [19, 85], [19, 89], [20, 24], [20, 25], [20, 31], [20, 32], [20, 35], [20, 40], [20, 44], [20, 48], [20, 53], [20, 55], [20, 60], [20, 61], [20, 65], [20, 68], [20, 69], [20, 71], [20, 72], [20, 78], [20, 80], [20, 87], [21, 22], [21, 26], [21, 29], [21, 39], [21, 44], [21, 49], [21, 56], [21, 63], [21, 67], [21, 74], [21, 81], [21, 86], [22, 24], [22, 29], [22, 31], [22, 44], [22, 45], [22, 50], [22, 51], [22, 53], [22, 54], [22, 56], [22, 59], [22, 61], [22, 66], [22, 67], [22, 70], [22, 77], [22, 78], [22, 81], [22, 82], [22, 83], [22, 89], [23, 24], [23, 38], [23, 39], [23, 41], [23, 51], [23, 55], [23, 60], [23, 67], [23, 68], [23, 84], [24, 44], [24, 48], [24, 49], [24, 52], [24, 60], [24, 61], [24, 63], [24, 68], [24, 70], [24, 73], [24, 74], [24, 81], [24, 82], [24, 85], [25, 26], [25, 33], [25, 35], [25, 39], [25, 43], [25, 44], [25, 55], [25, 57], [25, 58], [25, 59], [25, 65], [25, 72], [25, 73], [25, 77], [25, 82], [26, 27], [26, 31], [26, 38], [26, 42], [26, 45], [26, 46], [26, 48], [26, 56], [26, 58], [26, 59], [26, 62], [26, 66], [26, 70], [26, 71], [26, 72], [26, 73], [26, 74], [26, 79], [26, 80], [26, 83], [26, 87], [27, 32], [27, 36], [27, 42], [27, 46], [27, 47], [27, 55], [27, 56], [27, 59], [27, 61], [27, 62], [27, 68], [27, 70], [27, 72], [27, 74], [27, 78], [27, 79], [27, 82], [27, 87], [27, 89], [28, 31], [28, 34], [28, 36], [28, 47], [28, 49], [28, 51], [28, 54], [28, 56], [28, 57], [28, 58], [28, 64], [28, 67], [28, 77], [28, 81], [28, 83], [28, 84], [28, 88], [28, 89], [29, 31], [29, 34], [29, 48], [29, 49], [29, 56], [29, 58], [29, 59], [29, 60], [29, 63], [29, 64], [29, 67], [29, 70], [29, 71], [29, 73], [29, 75], [29, 77], [29, 84], [29, 85], [29, 86], [29, 88], [30, 31], [30, 33], [30, 40], [30, 48], [30, 53], [30, 60], [30, 61], [30, 64], [30, 65], [30, 66], [30, 71], [30, 72], [30, 75], [30, 76], [30, 86], [31, 33], [31, 35], [31, 41], [31, 42], [31, 43], [31, 44], [31, 49], [31, 50], [31, 57], [31, 59], [31, 64], [31, 70], [31, 72], [31, 77], [31, 79], [31, 89], [32, 34], [32, 38], [32, 44], [32, 48], [32, 57], [32, 63], [32, 69], [32, 74], [32, 75], [32, 81], [32, 83], [32, 88], [32, 89], [33, 38], [33, 40], [33, 41], [33, 42], [33, 44], [33, 48], [33, 56], [33, 79], [33, 82], [33, 84], [33, 88], [34, 39], [34, 42], [34, 47], [34, 48], [34, 67], [34, 68], [34, 78], [34, 79], [34, 84], [34, 85], [34, 86], [34, 87], [35, 38], [35, 41], [35, 43], [35, 48], [35, 50], [35, 52], [35, 55], [35, 58], [35, 64], [35, 65], [35, 67], [35, 71], [35, 72], [35, 79], [35, 84], [35, 85], [36, 40], [36, 43], [36, 46], [36, 48], [36, 50], [36, 51], [36, 52], [36, 53], [36, 54], [36, 56], [36, 57], [36, 60], [36, 64], [36, 69], [36, 79], [36, 81], [36, 85], [37, 38], [37, 41], [37, 46], [37, 47], [37, 51], [37, 57], [37, 58], [37, 63], [37, 64], [37, 66], [37, 68], [37, 70], [37, 73], [37, 74], [37, 78], [37, 85], [37, 86], [38, 40], [38, 41], [38, 42], [38, 45], [38, 55], [38, 58], [38, 63], [38, 74], [38, 78], [38, 81], [38, 82], [38, 85], [38, 88], [39, 43], [39, 55], [39, 57], [39, 60], [39, 64], [39, 66], [39, 69], [39, 70], [39, 72], [39, 75], [39, 77], [39, 78], [39, 84], [40, 42], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 63], [40, 64], [40, 69], [40, 70], [40, 71], [40, 73], [40, 75], [40, 86], [41, 43], [41, 51], [41, 53], [41, 54], [41, 56], [41, 57], [41, 58], [41, 60], [41, 62], [41, 68], [41, 73], [42, 48], [42, 50], [42, 51], [42, 58], [42, 62], [42, 70], [42, 74], [42, 77], [42, 85], [43, 45], [43, 48], [43, 49], [43, 60], [43, 63], [43, 65], [43, 66], [43, 72], [43, 78], [43, 81], [43, 83], [43, 85], [43, 88], [44, 45], [44, 47], [44, 53], [44, 61], [44, 62], [44, 68], [44, 72], [44, 74], [44, 78], [44, 79], [44, 84], [44, 87], [45, 47], [45, 55], [45, 56], [45, 60], [45, 63], [45, 70], [45, 73], [45, 78], [45, 79], [45, 83], [45, 84], [46, 49], [46, 57], [46, 60], [46, 63], [46, 70], [46, 74], [46, 76], [46, 78], [46, 81], [46, 88], [47, 48], [47, 54], [47, 58], [47, 59], [47, 60], [47, 63], [47, 65], [47, 67], [47, 69], [47, 70], [47, 78], [47, 79], [47, 81], [47, 83], [47, 85], [47, 87], [48, 51], [48, 52], [48, 53], [48, 55], [48, 68], [48, 69], [48, 75], [48, 76], [48, 77], [48, 84], [49, 55], [49, 58], [49, 62], [49, 65], [49, 81], [49, 82], [49, 88], [50, 53], [50, 56], [50, 58], [50, 60], [50, 67], [50, 68], [50, 69], [50, 73], [50, 75], [50, 80], [50, 81], [50, 88], [50, 89], [51, 57], [51, 59], [51, 65], [51, 67], [51, 77], [51, 83], [51, 87], [52, 59], [52, 61], [52, 64], [52, 65], [52, 66], [52, 68], [52, 69], [52, 70], [52, 71], [52, 75], [52, 79], [52, 85], [52, 87], [52, 88], [53, 55], [53, 60], [53, 61], [53, 68], [53, 79], [53, 84], [53, 85], [54, 59], [54, 65], [54, 68], [54, 70], [54, 82], [54, 84], [54, 86], [54, 88], [55, 58], [55, 61], [55, 69], [55, 70], [55, 75], [55, 76], [55, 77], [55, 78], [55, 83], [56, 63], [56, 65], [56, 75], [56, 78], [56, 81], [56, 82], [57, 60], [57, 69], [57, 74], [57, 76], [57, 81], [57, 82], [57, 84], [57, 86], [57, 88], [58, 65], [58, 66], [58, 68], [58, 73], [58, 74], [58, 79], [58, 82], [59, 63], [59, 65], [59, 68], [59, 80], [59, 82], [59, 85], [59, 89], [60, 64], [60, 67], [60, 70], [60, 83], [60, 84], [60, 86], [60, 89], [61, 62], [61, 64], [61, 67], [61, 70], [61, 74], [61, 78], [61, 80], [61, 81], [61, 82], [61, 83], [61, 89], [62, 64], [62, 67], [62, 70], [62, 78], [62, 79], [62, 87], [63, 64], [63, 66], [63, 70], [63, 75], [63, 84], [63, 86], [63, 88], [64, 65], [64, 67], [64, 75], [64, 79], [64, 81], [64, 82], [64, 84], [64, 85], [64, 89], [65, 69], [65, 70], [65, 71], [65, 74], [65, 75], [65, 77], [65, 80], [65, 87], [66, 67], [66, 71], [66, 73], [66, 76], [66, 78], [66, 81], [66, 84], [66, 85], [66, 87], [67, 72], [67, 81], [67, 88], [68, 69], [68, 75], [68, 79], [68, 80], [68, 83], [68, 84], [68, 86], [68, 88], [69, 70], [69, 72], [70, 74], [70, 75], [70, 81], [71, 73], [71, 74], [71, 75], [71, 78], [71, 80], [71, 81], [71, 83], [72, 73], [72, 75], [72, 82], [72, 84], [73, 76], [73, 82], [73, 83], [73, 85], [73, 86], [73, 87], [73, 88], [74, 79], [74, 80], [74, 81], [74, 83], [74, 85], [74, 88], [75, 83], [75, 84], [76, 83], [76, 86], [76, 87], [76, 89], [77, 79], [77, 81], [77, 82], [78, 80], [78, 82], [78, 84], [78, 86], [78, 87], [78, 88], [78, 89], [79, 81], [79, 82], [79, 84], [79, 85], [79, 88], [80, 81], [80, 82], [80, 86], [80, 87], [81, 86], [81, 87], [81, 89], [82, 83], [82, 84], [82, 87], [82, 89], [85, 88], [85, 89], [86, 87], [87, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s5/solution/solve.sh b/tasks/construct-mc-max-independent-set-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6365e2b22379a1627479bd5e7c2f5e26813fc4be --- /dev/null +++ b/tasks/construct-mc-max-independent-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' +{"independent_set": [21, 24, 33, 34, 35, 45, 46, 53, 54, 62, 66, 69, 75, 77, 80, 89]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l5-s5/tests/check.py b/tasks/construct-mc-max-independent-set-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l5-s5/tests/instance.json b/tasks/construct-mc-max-independent-set-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91092b4f613ef033707321c450203a327cc40123 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 16, "edges": [[0, 1], [0, 2], [0, 6], [0, 7], [0, 8], [0, 11], [0, 18], [0, 20], [0, 21], [0, 33], [0, 34], [0, 38], [0, 46], [0, 47], [0, 49], [0, 60], [0, 63], [0, 66], [0, 72], [0, 77], [0, 81], [0, 82], [0, 84], [1, 5], [1, 6], [1, 10], [1, 11], [1, 13], [1, 14], [1, 20], [1, 23], [1, 24], [1, 25], [1, 40], [1, 42], [1, 51], [1, 52], [1, 53], [1, 58], [1, 59], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 68], [1, 75], [1, 77], [1, 78], [1, 85], [1, 86], [1, 87], [2, 5], [2, 7], [2, 10], [2, 12], [2, 15], [2, 16], [2, 19], [2, 23], [2, 28], [2, 30], [2, 31], [2, 33], [2, 34], [2, 36], [2, 39], [2, 48], [2, 49], [2, 52], [2, 54], [2, 66], [2, 68], [2, 69], [2, 70], [2, 77], [2, 78], [2, 80], [2, 81], [2, 82], [2, 84], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 11], [3, 16], [3, 17], [3, 21], [3, 23], [3, 28], [3, 29], [3, 33], [3, 40], [3, 42], [3, 44], [3, 52], [3, 54], [3, 55], [3, 58], [3, 59], [3, 60], [3, 62], [3, 65], [3, 66], [3, 68], [3, 78], [3, 83], [3, 84], [3, 85], [3, 86], [3, 89], [4, 7], [4, 23], [4, 24], [4, 25], [4, 30], [4, 31], [4, 33], [4, 37], [4, 38], [4, 39], [4, 48], [4, 52], [4, 55], [4, 59], [4, 63], [4, 65], [4, 75], [4, 77], [4, 81], [4, 82], [4, 83], [4, 86], [4, 88], [5, 8], [5, 9], [5, 11], [5, 14], [5, 21], [5, 23], [5, 24], [5, 26], [5, 29], [5, 30], [5, 34], [5, 43], [5, 44], [5, 46], [5, 47], [5, 53], [5, 55], [5, 57], [5, 59], [5, 60], [5, 65], [5, 66], [5, 69], [5, 70], [6, 15], [6, 16], [6, 18], [6, 23], [6, 24], [6, 28], [6, 34], [6, 37], [6, 38], [6, 40], [6, 46], [6, 49], [6, 51], [6, 52], [6, 54], [6, 60], [6, 61], [6, 62], [6, 65], [6, 66], [6, 68], [6, 69], [6, 74], [6, 84], [6, 87], [7, 13], [7, 14], [7, 15], [7, 16], [7, 19], [7, 32], [7, 33], [7, 36], [7, 38], [7, 41], [7, 42], [7, 43], [7, 49], [7, 63], [7, 64], [7, 67], [7, 76], [7, 77], [7, 81], [7, 84], [7, 89], [8, 12], [8, 15], [8, 16], [8, 21], [8, 26], [8, 36], [8, 39], [8, 44], [8, 45], [8, 48], [8, 51], [8, 58], [8, 60], [8, 62], [8, 63], [8, 65], [8, 69], [8, 75], [8, 79], [8, 82], [8, 87], [9, 10], [9, 11], [9, 15], [9, 17], [9, 22], [9, 26], [9, 27], [9, 32], [9, 39], [9, 41], [9, 49], [9, 52], [9, 53], [9, 58], [9, 67], [9, 74], [9, 75], [9, 77], [9, 78], [9, 80], [9, 81], [9, 84], [10, 14], [10, 17], [10, 21], [10, 24], [10, 26], [10, 27], [10, 32], [10, 34], [10, 35], [10, 36], [10, 37], [10, 40], [10, 43], [10, 46], [10, 47], [10, 48], [10, 49], [10, 52], [10, 56], [10, 58], [10, 62], [10, 67], [10, 70], [10, 74], [10, 75], [10, 77], [10, 78], [10, 80], [10, 82], [11, 12], [11, 14], [11, 17], [11, 21], [11, 23], [11, 30], [11, 31], [11, 32], [11, 33], [11, 37], [11, 41], [11, 44], [11, 47], [11, 48], [11, 49], [11, 51], [11, 54], [11, 57], [11, 60], [11, 63], [11, 66], [11, 71], [11, 75], [11, 84], [12, 17], [12, 19], [12, 22], [12, 23], [12, 24], [12, 25], [12, 37], [12, 43], [12, 44], [12, 49], [12, 56], [12, 60], [12, 67], [12, 72], [12, 73], [12, 76], [12, 77], [12, 81], [12, 84], [12, 85], [12, 86], [13, 18], [13, 19], [13, 27], [13, 28], [13, 29], [13, 30], [13, 33], [13, 34], [13, 35], [13, 36], [13, 40], [13, 41], [13, 42], [13, 53], [13, 57], [13, 62], [13, 65], [13, 67], [13, 71], [13, 76], [13, 78], [13, 81], [13, 83], [13, 87], [14, 27], [14, 29], [14, 32], [14, 34], [14, 36], [14, 37], [14, 44], [14, 51], [14, 53], [14, 56], [14, 58], [14, 59], [14, 61], [14, 62], [14, 63], [14, 65], [14, 67], [14, 69], [14, 71], [14, 79], [14, 80], [14, 85], [15, 18], [15, 19], [15, 24], [15, 25], [15, 33], [15, 36], [15, 37], [15, 38], [15, 40], [15, 46], [15, 55], [15, 57], [15, 59], [15, 68], [15, 72], [15, 73], [15, 80], [15, 81], [15, 82], [15, 88], [15, 89], [16, 28], [16, 35], [16, 38], [16, 40], [16, 42], [16, 45], [16, 47], [16, 49], [16, 50], [16, 52], [16, 64], [16, 67], [16, 70], [16, 71], [16, 79], [16, 81], [16, 84], [16, 87], [17, 21], [17, 22], [17, 25], [17, 26], [17, 27], [17, 28], [17, 31], [17, 34], [17, 37], [17, 46], [17, 52], [17, 53], [17, 59], [17, 63], [17, 70], [17, 78], [17, 81], [17, 85], [17, 86], [17, 87], [17, 88], [17, 89], [18, 19], [18, 22], [18, 23], [18, 28], [18, 29], [18, 32], [18, 36], [18, 42], [18, 43], [18, 51], [18, 55], [18, 56], [18, 64], [18, 70], [18, 72], [18, 76], [18, 79], [19, 20], [19, 31], [19, 34], [19, 46], [19, 50], [19, 51], [19, 53], [19, 62], [19, 63], [19, 64], [19, 68], [19, 69], [19, 73], [19, 79], [19, 80], [19, 81], [19, 85], [19, 89], [20, 24], [20, 25], [20, 31], [20, 32], [20, 35], [20, 40], [20, 44], [20, 48], [20, 53], [20, 55], [20, 60], [20, 61], [20, 65], [20, 68], [20, 69], [20, 71], [20, 72], [20, 78], [20, 80], [20, 87], [21, 22], [21, 26], [21, 29], [21, 39], [21, 44], [21, 49], [21, 56], [21, 63], [21, 67], [21, 74], [21, 81], [21, 86], [22, 24], [22, 29], [22, 31], [22, 44], [22, 45], [22, 50], [22, 51], [22, 53], [22, 54], [22, 56], [22, 59], [22, 61], [22, 66], [22, 67], [22, 70], [22, 77], [22, 78], [22, 81], [22, 82], [22, 83], [22, 89], [23, 24], [23, 38], [23, 39], [23, 41], [23, 51], [23, 55], [23, 60], [23, 67], [23, 68], [23, 84], [24, 44], [24, 48], [24, 49], [24, 52], [24, 60], [24, 61], [24, 63], [24, 68], [24, 70], [24, 73], [24, 74], [24, 81], [24, 82], [24, 85], [25, 26], [25, 33], [25, 35], [25, 39], [25, 43], [25, 44], [25, 55], [25, 57], [25, 58], [25, 59], [25, 65], [25, 72], [25, 73], [25, 77], [25, 82], [26, 27], [26, 31], [26, 38], [26, 42], [26, 45], [26, 46], [26, 48], [26, 56], [26, 58], [26, 59], [26, 62], [26, 66], [26, 70], [26, 71], [26, 72], [26, 73], [26, 74], [26, 79], [26, 80], [26, 83], [26, 87], [27, 32], [27, 36], [27, 42], [27, 46], [27, 47], [27, 55], [27, 56], [27, 59], [27, 61], [27, 62], [27, 68], [27, 70], [27, 72], [27, 74], [27, 78], [27, 79], [27, 82], [27, 87], [27, 89], [28, 31], [28, 34], [28, 36], [28, 47], [28, 49], [28, 51], [28, 54], [28, 56], [28, 57], [28, 58], [28, 64], [28, 67], [28, 77], [28, 81], [28, 83], [28, 84], [28, 88], [28, 89], [29, 31], [29, 34], [29, 48], [29, 49], [29, 56], [29, 58], [29, 59], [29, 60], [29, 63], [29, 64], [29, 67], [29, 70], [29, 71], [29, 73], [29, 75], [29, 77], [29, 84], [29, 85], [29, 86], [29, 88], [30, 31], [30, 33], [30, 40], [30, 48], [30, 53], [30, 60], [30, 61], [30, 64], [30, 65], [30, 66], [30, 71], [30, 72], [30, 75], [30, 76], [30, 86], [31, 33], [31, 35], [31, 41], [31, 42], [31, 43], [31, 44], [31, 49], [31, 50], [31, 57], [31, 59], [31, 64], [31, 70], [31, 72], [31, 77], [31, 79], [31, 89], [32, 34], [32, 38], [32, 44], [32, 48], [32, 57], [32, 63], [32, 69], [32, 74], [32, 75], [32, 81], [32, 83], [32, 88], [32, 89], [33, 38], [33, 40], [33, 41], [33, 42], [33, 44], [33, 48], [33, 56], [33, 79], [33, 82], [33, 84], [33, 88], [34, 39], [34, 42], [34, 47], [34, 48], [34, 67], [34, 68], [34, 78], [34, 79], [34, 84], [34, 85], [34, 86], [34, 87], [35, 38], [35, 41], [35, 43], [35, 48], [35, 50], [35, 52], [35, 55], [35, 58], [35, 64], [35, 65], [35, 67], [35, 71], [35, 72], [35, 79], [35, 84], [35, 85], [36, 40], [36, 43], [36, 46], [36, 48], [36, 50], [36, 51], [36, 52], [36, 53], [36, 54], [36, 56], [36, 57], [36, 60], [36, 64], [36, 69], [36, 79], [36, 81], [36, 85], [37, 38], [37, 41], [37, 46], [37, 47], [37, 51], [37, 57], [37, 58], [37, 63], [37, 64], [37, 66], [37, 68], [37, 70], [37, 73], [37, 74], [37, 78], [37, 85], [37, 86], [38, 40], [38, 41], [38, 42], [38, 45], [38, 55], [38, 58], [38, 63], [38, 74], [38, 78], [38, 81], [38, 82], [38, 85], [38, 88], [39, 43], [39, 55], [39, 57], [39, 60], [39, 64], [39, 66], [39, 69], [39, 70], [39, 72], [39, 75], [39, 77], [39, 78], [39, 84], [40, 42], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 63], [40, 64], [40, 69], [40, 70], [40, 71], [40, 73], [40, 75], [40, 86], [41, 43], [41, 51], [41, 53], [41, 54], [41, 56], [41, 57], [41, 58], [41, 60], [41, 62], [41, 68], [41, 73], [42, 48], [42, 50], [42, 51], [42, 58], [42, 62], [42, 70], [42, 74], [42, 77], [42, 85], [43, 45], [43, 48], [43, 49], [43, 60], [43, 63], [43, 65], [43, 66], [43, 72], [43, 78], [43, 81], [43, 83], [43, 85], [43, 88], [44, 45], [44, 47], [44, 53], [44, 61], [44, 62], [44, 68], [44, 72], [44, 74], [44, 78], [44, 79], [44, 84], [44, 87], [45, 47], [45, 55], [45, 56], [45, 60], [45, 63], [45, 70], [45, 73], [45, 78], [45, 79], [45, 83], [45, 84], [46, 49], [46, 57], [46, 60], [46, 63], [46, 70], [46, 74], [46, 76], [46, 78], [46, 81], [46, 88], [47, 48], [47, 54], [47, 58], [47, 59], [47, 60], [47, 63], [47, 65], [47, 67], [47, 69], [47, 70], [47, 78], [47, 79], [47, 81], [47, 83], [47, 85], [47, 87], [48, 51], [48, 52], [48, 53], [48, 55], [48, 68], [48, 69], [48, 75], [48, 76], [48, 77], [48, 84], [49, 55], [49, 58], [49, 62], [49, 65], [49, 81], [49, 82], [49, 88], [50, 53], [50, 56], [50, 58], [50, 60], [50, 67], [50, 68], [50, 69], [50, 73], [50, 75], [50, 80], [50, 81], [50, 88], [50, 89], [51, 57], [51, 59], [51, 65], [51, 67], [51, 77], [51, 83], [51, 87], [52, 59], [52, 61], [52, 64], [52, 65], [52, 66], [52, 68], [52, 69], [52, 70], [52, 71], [52, 75], [52, 79], [52, 85], [52, 87], [52, 88], [53, 55], [53, 60], [53, 61], [53, 68], [53, 79], [53, 84], [53, 85], [54, 59], [54, 65], [54, 68], [54, 70], [54, 82], [54, 84], [54, 86], [54, 88], [55, 58], [55, 61], [55, 69], [55, 70], [55, 75], [55, 76], [55, 77], [55, 78], [55, 83], [56, 63], [56, 65], [56, 75], [56, 78], [56, 81], [56, 82], [57, 60], [57, 69], [57, 74], [57, 76], [57, 81], [57, 82], [57, 84], [57, 86], [57, 88], [58, 65], [58, 66], [58, 68], [58, 73], [58, 74], [58, 79], [58, 82], [59, 63], [59, 65], [59, 68], [59, 80], [59, 82], [59, 85], [59, 89], [60, 64], [60, 67], [60, 70], [60, 83], [60, 84], [60, 86], [60, 89], [61, 62], [61, 64], [61, 67], [61, 70], [61, 74], [61, 78], [61, 80], [61, 81], [61, 82], [61, 83], [61, 89], [62, 64], [62, 67], [62, 70], [62, 78], [62, 79], [62, 87], [63, 64], [63, 66], [63, 70], [63, 75], [63, 84], [63, 86], [63, 88], [64, 65], [64, 67], [64, 75], [64, 79], [64, 81], [64, 82], [64, 84], [64, 85], [64, 89], [65, 69], [65, 70], [65, 71], [65, 74], [65, 75], [65, 77], [65, 80], [65, 87], [66, 67], [66, 71], [66, 73], [66, 76], [66, 78], [66, 81], [66, 84], [66, 85], [66, 87], [67, 72], [67, 81], [67, 88], [68, 69], [68, 75], [68, 79], [68, 80], [68, 83], [68, 84], [68, 86], [68, 88], [69, 70], [69, 72], [70, 74], [70, 75], [70, 81], [71, 73], [71, 74], [71, 75], [71, 78], [71, 80], [71, 81], [71, 83], [72, 73], [72, 75], [72, 82], [72, 84], [73, 76], [73, 82], [73, 83], [73, 85], [73, 86], [73, 87], [73, 88], [74, 79], [74, 80], [74, 81], [74, 83], [74, 85], [74, 88], [75, 83], [75, 84], [76, 83], [76, 86], [76, 87], [76, 89], [77, 79], [77, 81], [77, 82], [78, 80], [78, 82], [78, 84], [78, 86], [78, 87], [78, 88], [78, 89], [79, 81], [79, 82], [79, 84], [79, 85], [79, 88], [80, 81], [80, 82], [80, 86], [80, 87], [81, 86], [81, 87], [81, 89], [82, 83], [82, 84], [82, 87], [82, 89], [85, 88], [85, 89], [86, 87], [87, 89]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l5-s5/tests/run.py b/tasks/construct-mc-max-independent-set-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-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-mc-max-independent-set-l5-s5/tests/test.sh b/tasks/construct-mc-max-independent-set-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-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-mc-non-transitive-dice-l5-s2/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l5-s2/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4addd221adaa9fce583e2556aacac110357f518 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "m": 7, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l5-s2/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..918f17182b43aee14c0a3a76171d945e1724d262 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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' +{"dice": [[0, 0, 1, 9, 9, 9, 10], [0, 5, 6, 6, 7, 8, 11], [1, 2, 2, 3, 10, 11, 13], [0, 1, 7, 7, 9, 9, 12], [0, 0, 5, 6, 10, 10, 11], [0, 2, 6, 6, 9, 9, 9], [3, 4, 5, 5, 7, 7, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l5-s2/tests/check.py b/tasks/construct-mc-non-transitive-dice-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s2/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-l5-s2/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4addd221adaa9fce583e2556aacac110357f518 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "m": 7, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l5-s2/tests/run.py b/tasks/construct-mc-non-transitive-dice-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l5-s2/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-number-partitioning-l1-s0/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l1-s0/environment/instance.json b/tasks/construct-mc-number-partitioning-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0092e8b334cf67745856d5766c2c09afa874679c --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l1-s0/solution/solve.sh b/tasks/construct-mc-number-partitioning-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e880db5676fdb382101bdbbc7e9113013590ca3f --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 2, 3, 4, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l1-s0/tests/check.py b/tasks/construct-mc-number-partitioning-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s0/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l1-s0/tests/instance.json b/tasks/construct-mc-number-partitioning-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0092e8b334cf67745856d5766c2c09afa874679c --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l1-s0/tests/run.py b/tasks/construct-mc-number-partitioning-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l1-s0/tests/test.sh b/tasks/construct-mc-number-partitioning-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l1-s7/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l1-s7/environment/instance.json b/tasks/construct-mc-number-partitioning-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..522031bd98670057427e22b1d98e47c6e6591c5c --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l1-s7/solution/solve.sh b/tasks/construct-mc-number-partitioning-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5c921da5220c7e3fa9a3f7173dc4fa2930cf5d31 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [0, 1, 2, 3, 4, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l1-s7/tests/check.py b/tasks/construct-mc-number-partitioning-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s7/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l1-s7/tests/instance.json b/tasks/construct-mc-number-partitioning-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..522031bd98670057427e22b1d98e47c6e6591c5c --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l1-s7/tests/run.py b/tasks/construct-mc-number-partitioning-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l1-s7/tests/test.sh b/tasks/construct-mc-number-partitioning-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s1/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s1/environment/instance.json b/tasks/construct-mc-number-partitioning-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e7ea2acdf11ed326933338822fb2709268f4d423 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 69, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s1/solution/solve.sh b/tasks/construct-mc-number-partitioning-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ba4fb47b21c7e30739d825798eeef79821bf074 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"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, 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-l5-s1/tests/check.py b/tasks/construct-mc-number-partitioning-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s1/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-l5-s1/tests/instance.json b/tasks/construct-mc-number-partitioning-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e7ea2acdf11ed326933338822fb2709268f4d423 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 69, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s1/tests/run.py b/tasks/construct-mc-number-partitioning-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s1/tests/test.sh b/tasks/construct-mc-number-partitioning-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s6/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s6/environment/instance.json b/tasks/construct-mc-number-partitioning-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a29748171c68837a46ba0c363ea6a9bfae080964 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s6/solution/solve.sh b/tasks/construct-mc-number-partitioning-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..244777e16659feb9ce39dc812d426878205099d0 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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": [0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l5-s6/tests/check.py b/tasks/construct-mc-number-partitioning-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-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-l5-s6/tests/instance.json b/tasks/construct-mc-number-partitioning-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a29748171c68837a46ba0c363ea6a9bfae080964 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s6/tests/run.py b/tasks/construct-mc-number-partitioning-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s6/tests/test.sh b/tasks/construct-mc-number-partitioning-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s8/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s8/environment/instance.json b/tasks/construct-mc-number-partitioning-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2fbe46e7ecbe116911cf17ce8caf46a2dfd7029d --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 68, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s8/solution/solve.sh b/tasks/construct-mc-number-partitioning-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb74fc15e034e9b13dc7f81f93cc9db27885c738 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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": [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, 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-l5-s8/tests/check.py b/tasks/construct-mc-number-partitioning-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s8/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-l5-s8/tests/instance.json b/tasks/construct-mc-number-partitioning-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2fbe46e7ecbe116911cf17ce8caf46a2dfd7029d --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 68, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l5-s8/tests/run.py b/tasks/construct-mc-number-partitioning-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l5-s8/tests/test.sh b/tasks/construct-mc-number-partitioning-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-ortholatin-l3-s0/environment/Dockerfile b/tasks/construct-mc-ortholatin-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ortholatin-l3-s0/environment/instance.json b/tasks/construct-mc-ortholatin-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64320cbb64481fc888bb0cc32d0c4831c193a780 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l3-s0/solution/solve.sh b/tasks/construct-mc-ortholatin-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ee633a9f35e5537d5b2e500bd64b4ba19510277 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [[0, 6, 2, 3, 4, 5, 1, 7, 8, 9], [1, 7, 8, 9, 0, 6, 2, 3, 4, 5], [7, 8, 4, 0, 6, 2, 3, 9, 5, 1], [8, 9, 5, 1, 2, 3, 4, 0, 6, 7], [9, 0, 1, 7, 8, 4, 5, 6, 2, 3], [5, 1, 7, 8, 9, 0, 6, 2, 3, 4], [6, 2, 3, 4, 5, 1, 7, 8, 9, 0], [2, 3, 9, 5, 1, 7, 8, 4, 0, 6], [3, 4, 0, 6, 7, 8, 9, 5, 1, 2], [4, 5, 6, 2, 3, 9, 0, 1, 7, 8]], "Y": [[5, 0, 6, 7, 9, 2, 8, 4, 1, 3], [3, 1, 4, 8, 2, 6, 5, 0, 7, 9], [6, 3, 1, 4, 8, 7, 2, 9, 0, 5], [2, 5, 3, 6, 1, 4, 0, 8, 9, 7], [7, 9, 0, 5, 6, 3, 4, 2, 8, 1], [8, 2, 9, 0, 4, 1, 7, 3, 5, 6], [1, 4, 8, 2, 5, 9, 3, 7, 6, 0], [0, 6, 2, 1, 7, 8, 9, 5, 3, 4], [9, 8, 7, 3, 0, 5, 1, 6, 4, 2], [4, 7, 5, 9, 3, 0, 6, 1, 2, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l3-s0/tests/check.py b/tasks/construct-mc-ortholatin-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/tests/check.py @@ -0,0 +1,25 @@ +"""Pair of orthogonal Latin squares of order n (MathConstraint ortholatin, CC-BY-4.0).""" +from run import Invalid, int_list + + +def _square(v, n, name): + if not isinstance(v, list) or len(v) != n: + raise Invalid(f"{name} must be a list of {n} rows") + S = [int_list(r, n, 0, n - 1, f"{name} row") for r in v] + full = list(range(n)) + for i in range(n): + if sorted(S[i]) != full: + raise Invalid(f"{name}: row {i} is not a permutation of 0..{n - 1}") + if sorted(S[r][i] for r in range(n)) != full: + raise Invalid(f"{name}: column {i} is not a permutation of 0..{n - 1}") + return S + + +def check(inst, ans): + n = inst["n"] + X = _square(ans.get("X"), n, "X") + Y = _square(ans.get("Y"), n, "Y") + pairs = {(X[i][j], Y[i][j]) for i in range(n) for j in range(n)} + if len(pairs) != n * n: + raise Invalid("X and Y are not orthogonal (some ordered pair repeats)") + return None, {} diff --git a/tasks/construct-mc-ortholatin-l3-s0/tests/instance.json b/tasks/construct-mc-ortholatin-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64320cbb64481fc888bb0cc32d0c4831c193a780 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l3-s0/tests/run.py b/tasks/construct-mc-ortholatin-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ortholatin-l3-s0/tests/test.sh b/tasks/construct-mc-ortholatin-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-chromatic-girth-l3-s0/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-chromatic-girth-l3-s0/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0cae8648e6011de56ecdfc99a3b1e34d6f66ef08 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 23, "required_edges": [], "max_chromatic_number": 3, "min_edges": 44, "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-l3-s0/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c76aa1ee224363a33a489f0520963eb8382cca3a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 20], [0, 21], [0, 22], [1, 17], [1, 18], [1, 19], [2, 15], [2, 16], [2, 19], [2, 22], [3, 13], [3, 14], [3, 19], [3, 21], [4, 11], [4, 12], [4, 18], [4, 20], [5, 10], [5, 12], [5, 16], [5, 21], [6, 9], [6, 12], [6, 14], [6, 15], [7, 8], [7, 11], [7, 13], [7, 15], [8, 10], [8, 14], [8, 22], [9, 10], [9, 11], [9, 19], [10, 20], [11, 21], [12, 17], [13, 16], [13, 17], [14, 18], [15, 20], [16, 18], [17, 22]], "coloring": [0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 2, 2, 1, 2, 1, 2, 1, 0, 2, 2, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0cae8648e6011de56ecdfc99a3b1e34d6f66ef08 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 23, "required_edges": [], "max_chromatic_number": 3, "min_edges": 44, "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-l3-s0/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0efcab3d04e84123d20ec898ee8830a2638d0ad6 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [[5, 6], [3, 8], [0, 9], [3, 7], [3, 9], [4, 9]], "max_degree": 6, "min_degree": 4, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..12ba5a6b930dcf86d462ed6efd022d8b7214a34e --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0efcab3d04e84123d20ec898ee8830a2638d0ad6 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [[5, 6], [3, 8], [0, 9], [3, 7], [3, 9], [4, 9]], "max_degree": 6, "min_degree": 4, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s2/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s2/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8eb7b99321c93b9d222bb5cc9dc16dcd85d4ec6e --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [[3, 6], [1, 4], [0, 2], [3, 8], [1, 3], [7, 8], [5, 6]], "max_independent_set": 2, "min_connectivity": 2, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s2/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..266b10696d549d81ec1db10a95e1067a0f575ccd --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-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' +{"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, 4], [2, 5], [2, 6], [2, 7], [2, 8], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-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-independent-connectivity-l1-s2/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8eb7b99321c93b9d222bb5cc9dc16dcd85d4ec6e --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 9, "required_edges": [[3, 6], [1, 4], [0, 2], [3, 8], [1, 3], [7, 8], [5, 6]], "max_independent_set": 2, "min_connectivity": 2, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/environment/Dockerfile b/tasks/construct-mc-pysms-min-degree-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/environment/instance.json b/tasks/construct-mc-pysms-min-degree-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d8b3db2e3e50f45eb0fed3dff91cd197786db696 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 13, "required_edges": [], "min_degree": 6, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/solution/solve.sh b/tasks/construct-mc-pysms-min-degree-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4cafa9813841741ebbf193085ce3e45b85fa4e68 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [9, 11], [9, 12], [10, 11], [10, 12], [11, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/tests/check.py b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/tests/instance.json b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d8b3db2e3e50f45eb0fed3dff91cd197786db696 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 13, "required_edges": [], "min_degree": 6, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/tests/run.py b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-degree-l4-s0/tests/test.sh b/tasks/construct-mc-pysms-min-degree-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-ramsey-l1-s3/environment/Dockerfile b/tasks/construct-mc-ramsey-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l1-s3/environment/instance.json b/tasks/construct-mc-ramsey-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e42b98d5ab39c2b8fc3ee9c1e5d0c1964ca8a1d6 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "r": 4, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s3/solution/solve.sh b/tasks/construct-mc-ramsey-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..88922d11a5ef2128237794cdf1c7d4f42a478ede --- /dev/null +++ b/tasks/construct-mc-ramsey-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": [1, 0, 0, 1, 1, 0, 0, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l1-s3/tests/check.py b/tasks/construct-mc-ramsey-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s3/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l1-s3/tests/instance.json b/tasks/construct-mc-ramsey-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e42b98d5ab39c2b8fc3ee9c1e5d0c1964ca8a1d6 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "r": 4, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s3/tests/run.py b/tasks/construct-mc-ramsey-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l1-s3/tests/test.sh b/tasks/construct-mc-ramsey-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l1-s4/environment/Dockerfile b/tasks/construct-mc-ramsey-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l1-s4/environment/instance.json b/tasks/construct-mc-ramsey-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4593ea5429ca8f3552b4e145c095db6650f41bf2 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "r": 3, "s": 3, "fixed": [["colors", 3, 1], ["colors", 9, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s4/solution/solve.sh b/tasks/construct-mc-ramsey-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..785c1e78489f87a5c57f1ac662d92e371d3abc46 --- /dev/null +++ b/tasks/construct-mc-ramsey-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, 1, 0, 1, 1, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l1-s4/tests/check.py b/tasks/construct-mc-ramsey-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s4/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l1-s4/tests/instance.json b/tasks/construct-mc-ramsey-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4593ea5429ca8f3552b4e145c095db6650f41bf2 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "r": 3, "s": 3, "fixed": [["colors", 3, 1], ["colors", 9, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l1-s4/tests/run.py b/tasks/construct-mc-ramsey-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l1-s4/tests/test.sh b/tasks/construct-mc-ramsey-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-social-golfers-l4-s1/environment/Dockerfile b/tasks/construct-mc-social-golfers-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l4-s1/environment/instance.json b/tasks/construct-mc-social-golfers-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3400326b43f867af87bae35dc44b4a352cfe511a --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 7, "group_size": 3, "n_weeks": 5, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l4-s1/solution/solve.sh b/tasks/construct-mc-social-golfers-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb4fb6aef13da17d8fc0df60df435c898e872044 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"schedule": [[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6], [3, 5, 6, 5, 4, 6, 5, 4, 6, 1, 3, 0, 1, 0, 2, 2, 4, 1, 3, 2, 0], [1, 2, 3, 1, 2, 4, 4, 5, 6, 5, 6, 0, 3, 5, 2, 1, 3, 0, 0, 6, 4], [1, 3, 4, 4, 5, 6, 5, 6, 3, 4, 6, 5, 1, 2, 0, 2, 3, 0, 2, 1, 0], [3, 4, 5, 6, 3, 4, 5, 6, 3, 4, 5, 6, 1, 2, 0, 1, 0, 2, 0, 2, 1]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l4-s1/tests/check.py b/tasks/construct-mc-social-golfers-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s1/tests/check.py @@ -0,0 +1,25 @@ +"""Social golfer problem (MathConstraint social_golfers, CSPLib prob010, CC-BY-4.0): each week partition +the g*s players into g groups of size s; no two players share a group in more than one week.""" +from run import Invalid, int_list + + +def check(inst, ans): + g, s, w = inst["n_groups"], inst["group_size"], inst["n_weeks"] + P = g * s + sched = ans.get("schedule") + if not isinstance(sched, list) or len(sched) != w: + raise Invalid(f"schedule must be a list of {w} weeks") + met = set() + for wk, row in enumerate(sched): + row = int_list(row, P, 0, g - 1, f"week {wk}") + groups = [[p for p in range(P) if row[p] == grp] for grp in range(g)] + for grp, mem in enumerate(groups): + if len(mem) != s: + raise Invalid(f"week {wk}: group {grp} has {len(mem)} players, need {s}") + for i in range(s): + for j in range(i + 1, s): + pr = (mem[i], mem[j]) + if pr in met: + raise Invalid(f"players {pr} play together in more than one week") + met.add(pr) + return None, {} diff --git a/tasks/construct-mc-social-golfers-l4-s1/tests/instance.json b/tasks/construct-mc-social-golfers-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3400326b43f867af87bae35dc44b4a352cfe511a --- /dev/null +++ b/tasks/construct-mc-social-golfers-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 7, "group_size": 3, "n_weeks": 5, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l4-s1/tests/run.py b/tasks/construct-mc-social-golfers-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l4-s1/tests/test.sh b/tasks/construct-mc-social-golfers-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-van-der-waerden-l1-s1/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l1-s1/environment/instance.json b/tasks/construct-mc-van-der-waerden-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48a79635724859883ac121ffd0fed42b5e87ea77 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 3, "n": 7, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l1-s1/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e3e7e5ad611c2a47fbcd96942d0844a170f710f8 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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' +{"colors": [0, 1, 1, 0, 0, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l1-s1/tests/check.py b/tasks/construct-mc-van-der-waerden-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l1-s1/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l1-s1/tests/instance.json b/tasks/construct-mc-van-der-waerden-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48a79635724859883ac121ffd0fed42b5e87ea77 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 3, "n": 7, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l1-s1/tests/run.py b/tasks/construct-mc-van-der-waerden-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l1-s1/tests/test.sh b/tasks/construct-mc-van-der-waerden-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l5-s0/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l5-s0/environment/instance.json b/tasks/construct-mc-van-der-waerden-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a512a05f1411f777878f39b8adaffc5cead4ce8d --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 120, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s0/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4e8330d8497c217388b4661f80ecdbb120ea91cd --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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' +{"colors": [0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l5-s0/tests/check.py b/tasks/construct-mc-van-der-waerden-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-mc-van-der-waerden-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a512a05f1411f777878f39b8adaffc5cead4ce8d --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 120, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s0/tests/run.py b/tasks/construct-mc-van-der-waerden-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l5-s0/tests/test.sh b/tasks/construct-mc-van-der-waerden-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l5-s7/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l5-s7/environment/instance.json b/tasks/construct-mc-van-der-waerden-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..523c9d8e3a06f7672890a73e63a0cc03cc88ad97 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 55, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s7/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..43354e16af493b012f013f2208a19bbad98b54b8 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 1, 3, 1, 3, 3, 0, 0, 2, 1, 0, 0, 3, 1, 1, 2, 2, 0, 2, 0, 0, 1, 0, 2, 3, 3, 0, 2, 3, 2, 3, 1, 2, 2, 3, 1, 0, 1, 1, 3, 1, 3, 3, 0, 0, 2, 1, 0, 0, 3, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l5-s7/tests/check.py b/tasks/construct-mc-van-der-waerden-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/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-l5-s7/tests/instance.json b/tasks/construct-mc-van-der-waerden-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..523c9d8e3a06f7672890a73e63a0cc03cc88ad97 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 55, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l5-s7/tests/run.py b/tasks/construct-mc-van-der-waerden-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l5-s7/tests/test.sh b/tasks/construct-mc-van-der-waerden-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l4-s9/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l4-s9/environment/instance.json b/tasks/construct-mc-vertex-cover-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..174e0cbd83449a0ea3ea0bfd1d6045afcab705a0 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 41, "edges": [[0, 6], [0, 7], [0, 10], [0, 12], [0, 14], [0, 16], [0, 24], [0, 25], [0, 26], [0, 31], [0, 34], [0, 46], [0, 56], [1, 6], [1, 8], [1, 11], [1, 12], [1, 13], [1, 17], [1, 28], [1, 32], [1, 33], [1, 35], [1, 36], [1, 43], [1, 56], [1, 59], [2, 5], [2, 6], [2, 15], [2, 24], [2, 27], [2, 31], [2, 34], [2, 35], [2, 39], [2, 40], [2, 46], [2, 47], [3, 4], [3, 9], [3, 12], [3, 25], [3, 26], [3, 28], [3, 34], [3, 39], [3, 40], [3, 41], [3, 44], [3, 51], [3, 58], [4, 5], [4, 16], [4, 17], [4, 18], [4, 27], [4, 37], [4, 38], [4, 39], [4, 40], [4, 46], [4, 47], [4, 49], [4, 51], [4, 52], [5, 8], [5, 11], [5, 13], [5, 14], [5, 18], [5, 19], [5, 24], [5, 28], [5, 41], [5, 43], [5, 46], [5, 49], [5, 53], [5, 58], [6, 13], [6, 15], [6, 17], [6, 21], [6, 27], [6, 38], [6, 44], [6, 45], [6, 49], [6, 52], [6, 57], [7, 8], [7, 12], [7, 17], [7, 18], [7, 21], [7, 28], [7, 36], [7, 45], [7, 50], [7, 58], [8, 9], [8, 20], [8, 22], [8, 26], [9, 12], [9, 16], [9, 19], [9, 30], [9, 34], [9, 36], [9, 39], [9, 42], [9, 43], [9, 44], [10, 12], [10, 20], [10, 22], [10, 25], [10, 29], [10, 46], [10, 49], [10, 51], [10, 53], [11, 18], [11, 22], [11, 28], [11, 36], [11, 37], [11, 40], [11, 47], [11, 50], [11, 54], [11, 56], [12, 13], [12, 14], [12, 18], [12, 19], [12, 23], [12, 29], [12, 40], [12, 54], [13, 18], [13, 20], [13, 22], [13, 31], [13, 38], [13, 59], [14, 23], [14, 27], [14, 29], [14, 31], [14, 32], [14, 35], [14, 36], [14, 44], [14, 56], [14, 58], [15, 16], [15, 20], [15, 22], [15, 25], [15, 33], [15, 34], [15, 39], [15, 41], [15, 46], [15, 52], [15, 53], [15, 56], [16, 18], [16, 28], [16, 31], [16, 37], [16, 39], [16, 43], [16, 46], [16, 47], [16, 59], [17, 25], [17, 26], [17, 40], [17, 42], [17, 51], [18, 31], [18, 35], [18, 36], [18, 43], [18, 46], [18, 58], [18, 59], [19, 20], [19, 25], [19, 40], [19, 51], [20, 23], [20, 26], [20, 28], [20, 35], [20, 36], [20, 41], [20, 43], [20, 46], [20, 51], [21, 26], [21, 27], [21, 37], [21, 40], [21, 44], [21, 51], [22, 24], [22, 26], [22, 29], [22, 34], [22, 40], [22, 41], [22, 46], [22, 49], [22, 55], [23, 26], [23, 28], [23, 31], [23, 32], [23, 33], [23, 37], [23, 38], [23, 41], [23, 46], [23, 50], [23, 57], [23, 58], [23, 59], [24, 27], [24, 28], [24, 42], [24, 44], [24, 59], [25, 27], [25, 38], [25, 46], [25, 48], [25, 53], [26, 32], [26, 33], [26, 34], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [27, 30], [27, 34], [27, 36], [27, 38], [27, 42], [27, 48], [27, 49], [27, 50], [27, 54], [28, 29], [28, 30], [28, 35], [28, 40], [28, 41], [28, 49], [28, 54], [29, 37], [29, 49], [30, 53], [31, 32], [31, 36], [31, 41], [31, 45], [31, 49], [31, 52], [32, 36], [32, 39], [32, 49], [32, 51], [33, 37], [33, 40], [33, 42], [33, 46], [33, 51], [33, 56], [33, 58], [34, 39], [34, 47], [34, 49], [34, 56], [34, 57], [35, 37], [35, 51], [35, 59], [36, 42], [36, 46], [36, 50], [36, 54], [36, 56], [36, 57], [36, 58], [36, 59], [37, 39], [37, 42], [37, 44], [37, 47], [37, 48], [37, 56], [38, 43], [38, 45], [38, 46], [38, 50], [39, 47], [39, 51], [39, 52], [39, 59], [40, 41], [40, 45], [40, 54], [40, 55], [41, 43], [41, 45], [41, 49], [41, 57], [41, 59], [42, 45], [42, 49], [42, 51], [42, 52], [42, 53], [43, 56], [43, 59], [44, 53], [44, 59], [45, 51], [45, 52], [46, 48], [46, 51], [46, 55], [48, 53], [48, 59], [49, 56], [49, 58], [51, 54], [51, 56], [51, 57], [51, 59], [52, 53], [53, 54]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l4-s9/solution/solve.sh b/tasks/construct-mc-vertex-cover-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..58b7f00808699148d14d7a7c141a47681b814d96 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 31, 34, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 49, 51, 53, 56, 57, 58, 59]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l4-s9/tests/check.py b/tasks/construct-mc-vertex-cover-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l4-s9/tests/instance.json b/tasks/construct-mc-vertex-cover-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..174e0cbd83449a0ea3ea0bfd1d6045afcab705a0 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 41, "edges": [[0, 6], [0, 7], [0, 10], [0, 12], [0, 14], [0, 16], [0, 24], [0, 25], [0, 26], [0, 31], [0, 34], [0, 46], [0, 56], [1, 6], [1, 8], [1, 11], [1, 12], [1, 13], [1, 17], [1, 28], [1, 32], [1, 33], [1, 35], [1, 36], [1, 43], [1, 56], [1, 59], [2, 5], [2, 6], [2, 15], [2, 24], [2, 27], [2, 31], [2, 34], [2, 35], [2, 39], [2, 40], [2, 46], [2, 47], [3, 4], [3, 9], [3, 12], [3, 25], [3, 26], [3, 28], [3, 34], [3, 39], [3, 40], [3, 41], [3, 44], [3, 51], [3, 58], [4, 5], [4, 16], [4, 17], [4, 18], [4, 27], [4, 37], [4, 38], [4, 39], [4, 40], [4, 46], [4, 47], [4, 49], [4, 51], [4, 52], [5, 8], [5, 11], [5, 13], [5, 14], [5, 18], [5, 19], [5, 24], [5, 28], [5, 41], [5, 43], [5, 46], [5, 49], [5, 53], [5, 58], [6, 13], [6, 15], [6, 17], [6, 21], [6, 27], [6, 38], [6, 44], [6, 45], [6, 49], [6, 52], [6, 57], [7, 8], [7, 12], [7, 17], [7, 18], [7, 21], [7, 28], [7, 36], [7, 45], [7, 50], [7, 58], [8, 9], [8, 20], [8, 22], [8, 26], [9, 12], [9, 16], [9, 19], [9, 30], [9, 34], [9, 36], [9, 39], [9, 42], [9, 43], [9, 44], [10, 12], [10, 20], [10, 22], [10, 25], [10, 29], [10, 46], [10, 49], [10, 51], [10, 53], [11, 18], [11, 22], [11, 28], [11, 36], [11, 37], [11, 40], [11, 47], [11, 50], [11, 54], [11, 56], [12, 13], [12, 14], [12, 18], [12, 19], [12, 23], [12, 29], [12, 40], [12, 54], [13, 18], [13, 20], [13, 22], [13, 31], [13, 38], [13, 59], [14, 23], [14, 27], [14, 29], [14, 31], [14, 32], [14, 35], [14, 36], [14, 44], [14, 56], [14, 58], [15, 16], [15, 20], [15, 22], [15, 25], [15, 33], [15, 34], [15, 39], [15, 41], [15, 46], [15, 52], [15, 53], [15, 56], [16, 18], [16, 28], [16, 31], [16, 37], [16, 39], [16, 43], [16, 46], [16, 47], [16, 59], [17, 25], [17, 26], [17, 40], [17, 42], [17, 51], [18, 31], [18, 35], [18, 36], [18, 43], [18, 46], [18, 58], [18, 59], [19, 20], [19, 25], [19, 40], [19, 51], [20, 23], [20, 26], [20, 28], [20, 35], [20, 36], [20, 41], [20, 43], [20, 46], [20, 51], [21, 26], [21, 27], [21, 37], [21, 40], [21, 44], [21, 51], [22, 24], [22, 26], [22, 29], [22, 34], [22, 40], [22, 41], [22, 46], [22, 49], [22, 55], [23, 26], [23, 28], [23, 31], [23, 32], [23, 33], [23, 37], [23, 38], [23, 41], [23, 46], [23, 50], [23, 57], [23, 58], [23, 59], [24, 27], [24, 28], [24, 42], [24, 44], [24, 59], [25, 27], [25, 38], [25, 46], [25, 48], [25, 53], [26, 32], [26, 33], [26, 34], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [27, 30], [27, 34], [27, 36], [27, 38], [27, 42], [27, 48], [27, 49], [27, 50], [27, 54], [28, 29], [28, 30], [28, 35], [28, 40], [28, 41], [28, 49], [28, 54], [29, 37], [29, 49], [30, 53], [31, 32], [31, 36], [31, 41], [31, 45], [31, 49], [31, 52], [32, 36], [32, 39], [32, 49], [32, 51], [33, 37], [33, 40], [33, 42], [33, 46], [33, 51], [33, 56], [33, 58], [34, 39], [34, 47], [34, 49], [34, 56], [34, 57], [35, 37], [35, 51], [35, 59], [36, 42], [36, 46], [36, 50], [36, 54], [36, 56], [36, 57], [36, 58], [36, 59], [37, 39], [37, 42], [37, 44], [37, 47], [37, 48], [37, 56], [38, 43], [38, 45], [38, 46], [38, 50], [39, 47], [39, 51], [39, 52], [39, 59], [40, 41], [40, 45], [40, 54], [40, 55], [41, 43], [41, 45], [41, 49], [41, 57], [41, 59], [42, 45], [42, 49], [42, 51], [42, 52], [42, 53], [43, 56], [43, 59], [44, 53], [44, 59], [45, 51], [45, 52], [46, 48], [46, 51], [46, 55], [48, 53], [48, 59], [49, 56], [49, 58], [51, 54], [51, 56], [51, 57], [51, 59], [52, 53], [53, 54]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l4-s9/tests/run.py b/tasks/construct-mc-vertex-cover-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l4-s9/tests/test.sh b/tasks/construct-mc-vertex-cover-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l4-s0/environment/Dockerfile b/tasks/construct-nppc-3col-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l4-s0/environment/instance.json b/tasks/construct-nppc-3col-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d9fe28642676def8ce48ffb054a9eb771dd6dd8 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 14], [0, 18], [0, 22], [0, 28], [1, 3], [1, 8], [1, 10], [1, 12], [1, 13], [1, 14], [1, 19], [1, 23], [2, 17], [2, 24], [3, 22], [3, 27], [4, 17], [4, 22], [4, 25], [4, 26], [5, 11], [5, 12], [5, 14], [5, 16], [5, 18], [6, 12], [6, 18], [6, 22], [6, 25], [6, 29], [7, 12], [7, 13], [8, 10], [8, 13], [8, 20], [8, 22], [8, 24], [9, 12], [9, 14], [9, 19], [9, 28], [10, 17], [10, 26], [10, 28], [10, 29], [11, 19], [11, 25], [11, 29], [12, 19], [12, 20], [12, 23], [12, 25], [12, 27], [13, 17], [13, 21], [14, 17], [14, 19], [14, 22], [14, 25], [14, 27], [16, 24], [16, 28], [17, 26], [17, 27], [18, 19], [18, 20], [18, 21], [19, 21], [19, 28], [20, 21], [20, 22], [20, 25], [20, 26], [20, 29], [21, 27], [21, 28], [22, 28], [23, 29], [26, 29], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s0/solution/solve.sh b/tasks/construct-nppc-3col-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a1a6b0ddd7fd92defb42a18b23000d3d042293d --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [0, 1, 2, 2, 0, 1, 0, 1, 2, 1, 0, 2, 2, 0, 2, 2, 0, 1, 2, 0, 0, 1, 1, 0, 1, 1, 2, 0, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l4-s0/tests/check.py b/tasks/construct-nppc-3col-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s0/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l4-s0/tests/instance.json b/tasks/construct-nppc-3col-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d9fe28642676def8ce48ffb054a9eb771dd6dd8 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 14], [0, 18], [0, 22], [0, 28], [1, 3], [1, 8], [1, 10], [1, 12], [1, 13], [1, 14], [1, 19], [1, 23], [2, 17], [2, 24], [3, 22], [3, 27], [4, 17], [4, 22], [4, 25], [4, 26], [5, 11], [5, 12], [5, 14], [5, 16], [5, 18], [6, 12], [6, 18], [6, 22], [6, 25], [6, 29], [7, 12], [7, 13], [8, 10], [8, 13], [8, 20], [8, 22], [8, 24], [9, 12], [9, 14], [9, 19], [9, 28], [10, 17], [10, 26], [10, 28], [10, 29], [11, 19], [11, 25], [11, 29], [12, 19], [12, 20], [12, 23], [12, 25], [12, 27], [13, 17], [13, 21], [14, 17], [14, 19], [14, 22], [14, 25], [14, 27], [16, 24], [16, 28], [17, 26], [17, 27], [18, 19], [18, 20], [18, 21], [19, 21], [19, 28], [20, 21], [20, 22], [20, 25], [20, 26], [20, 29], [21, 27], [21, 28], [22, 28], [23, 29], [26, 29], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s0/tests/run.py b/tasks/construct-nppc-3col-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l4-s0/tests/test.sh b/tasks/construct-nppc-3col-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l4-s7/environment/Dockerfile b/tasks/construct-nppc-3col-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l4-s7/environment/instance.json b/tasks/construct-nppc-3col-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef5fa0fc6327e8596176657761de45f4dc4145f5 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 8], [0, 11], [0, 13], [0, 14], [0, 18], [0, 28], [1, 3], [1, 5], [1, 9], [1, 16], [1, 18], [1, 22], [1, 28], [2, 4], [2, 20], [2, 26], [2, 29], [3, 13], [3, 14], [3, 15], [3, 19], [3, 24], [3, 28], [4, 26], [5, 11], [5, 14], [5, 15], [5, 24], [6, 9], [6, 11], [6, 14], [6, 15], [6, 18], [6, 26], [6, 29], [7, 8], [7, 21], [7, 22], [8, 20], [9, 21], [9, 22], [9, 23], [9, 27], [10, 11], [10, 19], [10, 28], [11, 20], [11, 21], [11, 26], [11, 27], [12, 26], [12, 27], [13, 16], [13, 21], [13, 27], [13, 28], [14, 20], [14, 21], [14, 23], [14, 24], [14, 27], [16, 17], [16, 24], [17, 18], [17, 29], [18, 23], [18, 24], [19, 25], [21, 23], [21, 24], [22, 23], [22, 24], [22, 26], [22, 29], [23, 25], [23, 27], [24, 28], [25, 29], [26, 27], [27, 28]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s7/solution/solve.sh b/tasks/construct-nppc-3col-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..df4db46298023d8b24f56bf670d5a39bbf65784f --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [1, 2, 1, 1, 0, 1, 1, 2, 0, 0, 2, 0, 0, 2, 0, 2, 0, 1, 0, 0, 2, 1, 1, 2, 2, 1, 2, 1, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l4-s7/tests/check.py b/tasks/construct-nppc-3col-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s7/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l4-s7/tests/instance.json b/tasks/construct-nppc-3col-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef5fa0fc6327e8596176657761de45f4dc4145f5 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 8], [0, 11], [0, 13], [0, 14], [0, 18], [0, 28], [1, 3], [1, 5], [1, 9], [1, 16], [1, 18], [1, 22], [1, 28], [2, 4], [2, 20], [2, 26], [2, 29], [3, 13], [3, 14], [3, 15], [3, 19], [3, 24], [3, 28], [4, 26], [5, 11], [5, 14], [5, 15], [5, 24], [6, 9], [6, 11], [6, 14], [6, 15], [6, 18], [6, 26], [6, 29], [7, 8], [7, 21], [7, 22], [8, 20], [9, 21], [9, 22], [9, 23], [9, 27], [10, 11], [10, 19], [10, 28], [11, 20], [11, 21], [11, 26], [11, 27], [12, 26], [12, 27], [13, 16], [13, 21], [13, 27], [13, 28], [14, 20], [14, 21], [14, 23], [14, 24], [14, 27], [16, 17], [16, 24], [17, 18], [17, 29], [18, 23], [18, 24], [19, 25], [21, 23], [21, 24], [22, 23], [22, 24], [22, 26], [22, 29], [23, 25], [23, 27], [24, 28], [25, 29], [26, 27], [27, 28]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s7/tests/run.py b/tasks/construct-nppc-3col-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l4-s7/tests/test.sh b/tasks/construct-nppc-3col-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l2-s2/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l2-s2/environment/instance.json b/tasks/construct-nppc-bandwidth-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9e5effbd9c1bed1a67b627dde60d36ad606894c --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 4], [1, 2], [2, 3], [3, 4], [3, 5], [3, 7], [4, 5], [5, 6]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s2/solution/solve.sh b/tasks/construct-nppc-bandwidth-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7b8e36f8333f25bd211414a830cc7c481cafd9fc --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [7, 3, 1, 2, 4, 5, 6, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l2-s2/tests/check.py b/tasks/construct-nppc-bandwidth-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s2/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l2-s2/tests/instance.json b/tasks/construct-nppc-bandwidth-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9e5effbd9c1bed1a67b627dde60d36ad606894c --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 4], [1, 2], [2, 3], [3, 4], [3, 5], [3, 7], [4, 5], [5, 6]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s2/tests/run.py b/tasks/construct-nppc-bandwidth-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l2-s2/tests/test.sh b/tasks/construct-nppc-bandwidth-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l2-s5/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l2-s5/environment/instance.json b/tasks/construct-nppc-bandwidth-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e9d4c18bb96a99d39f82fd985a27e27c81d090a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 1], [1, 3], [2, 4], [3, 6], [4, 5], [4, 7], [5, 6], [6, 7]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s5/solution/solve.sh b/tasks/construct-nppc-bandwidth-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3d5709a32d6dfaaa06d21cd5966badba74e8c0cd --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [4, 6, 0, 7, 1, 3, 5, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l2-s5/tests/check.py b/tasks/construct-nppc-bandwidth-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s5/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l2-s5/tests/instance.json b/tasks/construct-nppc-bandwidth-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e9d4c18bb96a99d39f82fd985a27e27c81d090a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "bandwidth": 3, "edges": [[0, 1], [1, 3], [2, 4], [3, 6], [4, 5], [4, 7], [5, 6], [6, 7]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l2-s5/tests/run.py b/tasks/construct-nppc-bandwidth-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l2-s5/tests/test.sh b/tasks/construct-nppc-bandwidth-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-dominating-set-l3-s2/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l3-s2/environment/instance.json b/tasks/construct-nppc-dominating-set-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d5d5835a2c9212ac54a8eef1c54410a31fb1711e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 50, "k": 20, "edges": [[0, 2], [0, 6], [0, 9], [0, 10], [0, 11], [0, 14], [0, 22], [0, 26], [0, 30], [0, 36], [0, 39], [0, 43], [0, 47], [1, 2], [1, 5], [1, 6], [1, 11], [1, 12], [1, 13], [1, 14], [1, 18], [1, 21], [1, 23], [1, 25], [1, 30], [1, 33], [1, 34], [1, 35], [1, 37], [1, 38], [1, 42], [2, 3], [2, 4], [2, 15], [2, 16], [2, 18], [2, 19], [2, 21], [2, 25], [2, 26], [2, 32], [2, 34], [2, 42], [2, 44], [2, 46], [3, 6], [3, 9], [3, 16], [3, 17], [3, 20], [3, 22], [3, 27], [3, 29], [3, 35], [3, 36], [3, 39], [3, 48], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 15], [4, 24], [4, 27], [4, 28], [4, 29], [4, 32], [4, 34], [4, 35], [4, 37], [4, 40], [4, 41], [4, 43], [5, 7], [5, 9], [5, 14], [5, 20], [5, 21], [5, 22], [5, 26], [5, 27], [5, 28], [5, 30], [5, 32], [5, 34], [5, 39], [5, 41], [5, 45], [5, 47], [6, 8], [6, 9], [6, 13], [6, 16], [6, 21], [6, 23], [6, 26], [6, 29], [6, 31], [6, 32], [6, 36], [6, 38], [6, 45], [7, 11], [7, 23], [7, 29], [7, 30], [7, 32], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 46], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 21], [8, 24], [8, 28], [8, 38], [8, 43], [8, 46], [8, 47], [8, 48], [9, 11], [9, 18], [9, 19], [9, 23], [9, 26], [9, 33], [9, 37], [9, 41], [9, 42], [9, 46], [9, 47], [9, 49], [10, 11], [10, 13], [10, 17], [10, 24], [10, 28], [10, 32], [10, 37], [10, 41], [10, 42], [10, 45], [10, 46], [10, 48], [11, 14], [11, 18], [11, 20], [11, 22], [11, 25], [11, 27], [11, 31], [11, 32], [11, 33], [11, 39], [11, 40], [11, 41], [11, 43], [11, 47], [11, 48], [12, 13], [12, 19], [12, 25], [12, 27], [12, 30], [12, 31], [12, 33], [12, 38], [12, 41], [12, 47], [13, 14], [13, 15], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 25], [13, 29], [13, 34], [13, 35], [13, 37], [13, 40], [13, 41], [13, 43], [13, 45], [13, 46], [13, 48], [14, 17], [14, 21], [14, 23], [14, 25], [14, 30], [14, 31], [14, 32], [14, 37], [14, 39], [14, 40], [14, 43], [14, 44], [14, 45], [14, 46], [15, 16], [15, 17], [15, 18], [15, 26], [15, 31], [15, 37], [15, 38], [15, 40], [15, 41], [15, 48], [16, 19], [16, 24], [16, 27], [16, 32], [16, 39], [16, 40], [16, 44], [16, 45], [16, 47], [17, 20], [17, 23], [17, 28], [17, 30], [17, 31], [17, 37], [17, 40], [17, 42], [17, 44], [17, 48], [18, 26], [18, 28], [18, 34], [18, 35], [18, 40], [18, 47], [18, 48], [19, 26], [19, 34], [19, 38], [19, 41], [19, 45], [19, 47], [19, 49], [20, 23], [20, 29], [20, 30], [20, 32], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 47], [21, 22], [21, 24], [21, 27], [21, 29], [21, 30], [21, 32], [21, 36], [21, 41], [21, 44], [21, 46], [21, 47], [22, 25], [22, 27], [22, 29], [22, 30], [22, 32], [22, 45], [22, 47], [23, 25], [23, 26], [23, 28], [23, 30], [23, 31], [23, 33], [23, 38], [23, 42], [23, 44], [23, 45], [24, 27], [24, 35], [24, 36], [24, 37], [24, 39], [24, 41], [24, 42], [24, 43], [24, 46], [25, 26], [25, 30], [25, 32], [25, 33], [25, 40], [25, 44], [25, 47], [25, 48], [26, 28], [26, 33], [26, 35], [26, 37], [26, 40], [26, 46], [27, 28], [27, 32], [27, 36], [27, 38], [27, 48], [28, 32], [28, 33], [28, 40], [28, 41], [28, 42], [28, 43], [28, 46], [29, 33], [29, 36], [29, 37], [29, 38], [29, 46], [29, 49], [30, 34], [30, 35], [30, 37], [30, 41], [30, 43], [30, 48], [30, 49], [31, 36], [31, 37], [31, 41], [31, 42], [31, 47], [31, 48], [31, 49], [32, 35], [32, 37], [32, 42], [32, 46], [33, 34], [33, 43], [33, 49], [34, 38], [34, 39], [34, 42], [34, 44], [34, 45], [34, 46], [35, 36], [35, 37], [35, 41], [35, 43], [35, 45], [36, 37], [36, 41], [36, 42], [36, 45], [36, 46], [36, 47], [36, 49], [37, 38], [37, 39], [37, 40], [37, 48], [38, 46], [38, 47], [39, 44], [39, 46], [39, 48], [40, 41], [40, 45], [40, 46], [40, 48], [41, 42], [41, 46], [41, 48], [41, 49], [42, 44], [42, 46], [42, 47], [43, 46], [43, 48], [43, 49], [44, 48], [45, 46], [45, 48], [45, 49], [46, 47], [46, 48], [46, 49]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l3-s2/solution/solve.sh b/tasks/construct-nppc-dominating-set-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..574aaa835f7ea79e5954c7e0c9692e03c16f1b49 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [0, 1, 5, 6, 8, 12, 13, 19, 23, 28, 30, 32, 36, 37, 39, 40, 41, 43, 44, 46]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l3-s2/tests/check.py b/tasks/construct-nppc-dominating-set-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s2/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l3-s2/tests/instance.json b/tasks/construct-nppc-dominating-set-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d5d5835a2c9212ac54a8eef1c54410a31fb1711e --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 50, "k": 20, "edges": [[0, 2], [0, 6], [0, 9], [0, 10], [0, 11], [0, 14], [0, 22], [0, 26], [0, 30], [0, 36], [0, 39], [0, 43], [0, 47], [1, 2], [1, 5], [1, 6], [1, 11], [1, 12], [1, 13], [1, 14], [1, 18], [1, 21], [1, 23], [1, 25], [1, 30], [1, 33], [1, 34], [1, 35], [1, 37], [1, 38], [1, 42], [2, 3], [2, 4], [2, 15], [2, 16], [2, 18], [2, 19], [2, 21], [2, 25], [2, 26], [2, 32], [2, 34], [2, 42], [2, 44], [2, 46], [3, 6], [3, 9], [3, 16], [3, 17], [3, 20], [3, 22], [3, 27], [3, 29], [3, 35], [3, 36], [3, 39], [3, 48], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 15], [4, 24], [4, 27], [4, 28], [4, 29], [4, 32], [4, 34], [4, 35], [4, 37], [4, 40], [4, 41], [4, 43], [5, 7], [5, 9], [5, 14], [5, 20], [5, 21], [5, 22], [5, 26], [5, 27], [5, 28], [5, 30], [5, 32], [5, 34], [5, 39], [5, 41], [5, 45], [5, 47], [6, 8], [6, 9], [6, 13], [6, 16], [6, 21], [6, 23], [6, 26], [6, 29], [6, 31], [6, 32], [6, 36], [6, 38], [6, 45], [7, 11], [7, 23], [7, 29], [7, 30], [7, 32], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 46], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 21], [8, 24], [8, 28], [8, 38], [8, 43], [8, 46], [8, 47], [8, 48], [9, 11], [9, 18], [9, 19], [9, 23], [9, 26], [9, 33], [9, 37], [9, 41], [9, 42], [9, 46], [9, 47], [9, 49], [10, 11], [10, 13], [10, 17], [10, 24], [10, 28], [10, 32], [10, 37], [10, 41], [10, 42], [10, 45], [10, 46], [10, 48], [11, 14], [11, 18], [11, 20], [11, 22], [11, 25], [11, 27], [11, 31], [11, 32], [11, 33], [11, 39], [11, 40], [11, 41], [11, 43], [11, 47], [11, 48], [12, 13], [12, 19], [12, 25], [12, 27], [12, 30], [12, 31], [12, 33], [12, 38], [12, 41], [12, 47], [13, 14], [13, 15], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 25], [13, 29], [13, 34], [13, 35], [13, 37], [13, 40], [13, 41], [13, 43], [13, 45], [13, 46], [13, 48], [14, 17], [14, 21], [14, 23], [14, 25], [14, 30], [14, 31], [14, 32], [14, 37], [14, 39], [14, 40], [14, 43], [14, 44], [14, 45], [14, 46], [15, 16], [15, 17], [15, 18], [15, 26], [15, 31], [15, 37], [15, 38], [15, 40], [15, 41], [15, 48], [16, 19], [16, 24], [16, 27], [16, 32], [16, 39], [16, 40], [16, 44], [16, 45], [16, 47], [17, 20], [17, 23], [17, 28], [17, 30], [17, 31], [17, 37], [17, 40], [17, 42], [17, 44], [17, 48], [18, 26], [18, 28], [18, 34], [18, 35], [18, 40], [18, 47], [18, 48], [19, 26], [19, 34], [19, 38], [19, 41], [19, 45], [19, 47], [19, 49], [20, 23], [20, 29], [20, 30], [20, 32], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 47], [21, 22], [21, 24], [21, 27], [21, 29], [21, 30], [21, 32], [21, 36], [21, 41], [21, 44], [21, 46], [21, 47], [22, 25], [22, 27], [22, 29], [22, 30], [22, 32], [22, 45], [22, 47], [23, 25], [23, 26], [23, 28], [23, 30], [23, 31], [23, 33], [23, 38], [23, 42], [23, 44], [23, 45], [24, 27], [24, 35], [24, 36], [24, 37], [24, 39], [24, 41], [24, 42], [24, 43], [24, 46], [25, 26], [25, 30], [25, 32], [25, 33], [25, 40], [25, 44], [25, 47], [25, 48], [26, 28], [26, 33], [26, 35], [26, 37], [26, 40], [26, 46], [27, 28], [27, 32], [27, 36], [27, 38], [27, 48], [28, 32], [28, 33], [28, 40], [28, 41], [28, 42], [28, 43], [28, 46], [29, 33], [29, 36], [29, 37], [29, 38], [29, 46], [29, 49], [30, 34], [30, 35], [30, 37], [30, 41], [30, 43], [30, 48], [30, 49], [31, 36], [31, 37], [31, 41], [31, 42], [31, 47], [31, 48], [31, 49], [32, 35], [32, 37], [32, 42], [32, 46], [33, 34], [33, 43], [33, 49], [34, 38], [34, 39], [34, 42], [34, 44], [34, 45], [34, 46], [35, 36], [35, 37], [35, 41], [35, 43], [35, 45], [36, 37], [36, 41], [36, 42], [36, 45], [36, 46], [36, 47], [36, 49], [37, 38], [37, 39], [37, 40], [37, 48], [38, 46], [38, 47], [39, 44], [39, 46], [39, 48], [40, 41], [40, 45], [40, 46], [40, 48], [41, 42], [41, 46], [41, 48], [41, 49], [42, 44], [42, 46], [42, 47], [43, 46], [43, 48], [43, 49], [44, 48], [45, 46], [45, 48], [45, 49], [46, 47], [46, 48], [46, 49]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l3-s2/tests/run.py b/tasks/construct-nppc-dominating-set-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l3-s2/tests/test.sh b/tasks/construct-nppc-dominating-set-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l3-s5/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l3-s5/environment/instance.json b/tasks/construct-nppc-dominating-set-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d97861139737aad4901dcdc6f83bb2d0aa37a856 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 50, "k": 20, "edges": [[0, 2], [0, 4], [0, 5], [0, 8], [0, 10], [0, 19], [0, 20], [0, 22], [0, 23], [0, 25], [0, 27], [0, 28], [0, 31], [0, 35], [0, 36], [0, 38], [0, 39], [0, 40], [0, 42], [0, 49], [1, 6], [1, 9], [1, 10], [1, 13], [1, 17], [1, 19], [1, 23], [1, 27], [1, 36], [1, 37], [1, 39], [1, 41], [1, 47], [2, 5], [2, 17], [2, 20], [2, 24], [2, 28], [2, 31], [2, 37], [2, 42], [2, 43], [2, 45], [3, 4], [3, 8], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 24], [3, 27], [3, 35], [3, 40], [3, 41], [3, 44], [3, 47], [4, 6], [4, 16], [4, 22], [4, 25], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 37], [4, 42], [4, 43], [4, 45], [5, 6], [5, 11], [5, 23], [5, 25], [5, 26], [5, 31], [5, 34], [5, 35], [5, 36], [5, 45], [5, 46], [6, 12], [6, 13], [6, 17], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 40], [6, 49], [7, 11], [7, 14], [7, 16], [7, 17], [7, 20], [7, 30], [7, 33], [7, 35], [7, 36], [7, 41], [7, 44], [7, 48], [8, 9], [8, 10], [8, 13], [8, 16], [8, 23], [8, 29], [8, 31], [8, 33], [8, 34], [8, 41], [8, 43], [8, 47], [8, 48], [9, 11], [9, 15], [9, 19], [9, 22], [9, 26], [9, 27], [9, 31], [9, 32], [9, 34], [9, 36], [9, 45], [9, 48], [9, 49], [10, 12], [10, 15], [10, 17], [10, 27], [10, 32], [10, 36], [10, 38], [10, 39], [10, 46], [11, 12], [11, 17], [11, 20], [11, 23], [11, 24], [11, 25], [11, 33], [11, 34], [11, 36], [11, 40], [11, 42], [11, 45], [11, 49], [12, 14], [12, 20], [12, 22], [12, 26], [12, 31], [12, 32], [12, 34], [12, 36], [12, 37], [12, 38], [12, 47], [13, 14], [13, 16], [13, 22], [13, 23], [13, 28], [13, 29], [13, 32], [13, 34], [13, 36], [13, 44], [13, 48], [14, 15], [14, 18], [14, 19], [14, 20], [14, 22], [14, 23], [14, 26], [14, 30], [14, 32], [14, 34], [14, 42], [14, 48], [15, 22], [15, 26], [15, 27], [15, 28], [15, 33], [15, 34], [15, 35], [15, 36], [15, 39], [15, 40], [16, 17], [16, 24], [16, 30], [16, 34], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [17, 18], [17, 21], [17, 29], [17, 30], [17, 35], [17, 43], [17, 46], [18, 24], [18, 34], [18, 35], [18, 37], [18, 38], [18, 43], [18, 47], [18, 49], [19, 22], [19, 27], [19, 32], [19, 33], [19, 37], [19, 44], [19, 47], [20, 21], [20, 23], [20, 29], [20, 32], [20, 33], [20, 43], [20, 47], [21, 22], [21, 30], [21, 31], [21, 33], [21, 34], [21, 35], [21, 39], [21, 41], [22, 23], [22, 29], [22, 34], [22, 39], [22, 41], [22, 47], [22, 48], [23, 24], [23, 25], [23, 29], [23, 30], [23, 32], [23, 36], [23, 37], [23, 40], [23, 42], [23, 48], [24, 26], [24, 31], [24, 32], [24, 34], [24, 35], [24, 40], [24, 41], [24, 46], [24, 48], [24, 49], [25, 27], [25, 31], [25, 35], [25, 37], [25, 39], [25, 46], [26, 31], [26, 33], [26, 34], [26, 35], [26, 36], [26, 41], [26, 43], [26, 47], [26, 49], [27, 28], [27, 33], [27, 34], [27, 35], [27, 38], [27, 42], [27, 45], [27, 46], [28, 32], [28, 34], [28, 36], [28, 39], [28, 43], [28, 44], [28, 47], [28, 48], [29, 30], [29, 32], [29, 33], [29, 34], [29, 35], [29, 38], [29, 41], [29, 49], [30, 31], [30, 32], [30, 38], [30, 43], [30, 45], [30, 46], [31, 32], [31, 34], [31, 40], [31, 44], [31, 45], [31, 46], [31, 49], [32, 33], [32, 35], [32, 38], [32, 47], [33, 34], [33, 37], [33, 38], [33, 40], [33, 45], [33, 48], [33, 49], [34, 37], [34, 41], [34, 43], [34, 44], [34, 45], [34, 49], [35, 38], [35, 39], [35, 40], [35, 41], [35, 44], [35, 48], [36, 39], [36, 44], [37, 39], [37, 40], [37, 47], [37, 49], [38, 41], [38, 46], [38, 48], [39, 45], [39, 46], [39, 49], [40, 44], [40, 45], [40, 46], [40, 48], [41, 42], [41, 47], [41, 48], [42, 46], [42, 47], [42, 49], [43, 47], [44, 48], [45, 46]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l3-s5/solution/solve.sh b/tasks/construct-nppc-dominating-set-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5508ab1e85baea38e05776e642ede20aabe597be --- /dev/null +++ b/tasks/construct-nppc-dominating-set-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' +{"dominating_set": [1, 2, 4, 5, 9, 10, 11, 12, 13, 16, 17, 19, 20, 23, 26, 28, 33, 34, 42, 48]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l3-s5/tests/check.py b/tasks/construct-nppc-dominating-set-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-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-l3-s5/tests/instance.json b/tasks/construct-nppc-dominating-set-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d97861139737aad4901dcdc6f83bb2d0aa37a856 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 50, "k": 20, "edges": [[0, 2], [0, 4], [0, 5], [0, 8], [0, 10], [0, 19], [0, 20], [0, 22], [0, 23], [0, 25], [0, 27], [0, 28], [0, 31], [0, 35], [0, 36], [0, 38], [0, 39], [0, 40], [0, 42], [0, 49], [1, 6], [1, 9], [1, 10], [1, 13], [1, 17], [1, 19], [1, 23], [1, 27], [1, 36], [1, 37], [1, 39], [1, 41], [1, 47], [2, 5], [2, 17], [2, 20], [2, 24], [2, 28], [2, 31], [2, 37], [2, 42], [2, 43], [2, 45], [3, 4], [3, 8], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 24], [3, 27], [3, 35], [3, 40], [3, 41], [3, 44], [3, 47], [4, 6], [4, 16], [4, 22], [4, 25], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 37], [4, 42], [4, 43], [4, 45], [5, 6], [5, 11], [5, 23], [5, 25], [5, 26], [5, 31], [5, 34], [5, 35], [5, 36], [5, 45], [5, 46], [6, 12], [6, 13], [6, 17], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 40], [6, 49], [7, 11], [7, 14], [7, 16], [7, 17], [7, 20], [7, 30], [7, 33], [7, 35], [7, 36], [7, 41], [7, 44], [7, 48], [8, 9], [8, 10], [8, 13], [8, 16], [8, 23], [8, 29], [8, 31], [8, 33], [8, 34], [8, 41], [8, 43], [8, 47], [8, 48], [9, 11], [9, 15], [9, 19], [9, 22], [9, 26], [9, 27], [9, 31], [9, 32], [9, 34], [9, 36], [9, 45], [9, 48], [9, 49], [10, 12], [10, 15], [10, 17], [10, 27], [10, 32], [10, 36], [10, 38], [10, 39], [10, 46], [11, 12], [11, 17], [11, 20], [11, 23], [11, 24], [11, 25], [11, 33], [11, 34], [11, 36], [11, 40], [11, 42], [11, 45], [11, 49], [12, 14], [12, 20], [12, 22], [12, 26], [12, 31], [12, 32], [12, 34], [12, 36], [12, 37], [12, 38], [12, 47], [13, 14], [13, 16], [13, 22], [13, 23], [13, 28], [13, 29], [13, 32], [13, 34], [13, 36], [13, 44], [13, 48], [14, 15], [14, 18], [14, 19], [14, 20], [14, 22], [14, 23], [14, 26], [14, 30], [14, 32], [14, 34], [14, 42], [14, 48], [15, 22], [15, 26], [15, 27], [15, 28], [15, 33], [15, 34], [15, 35], [15, 36], [15, 39], [15, 40], [16, 17], [16, 24], [16, 30], [16, 34], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [17, 18], [17, 21], [17, 29], [17, 30], [17, 35], [17, 43], [17, 46], [18, 24], [18, 34], [18, 35], [18, 37], [18, 38], [18, 43], [18, 47], [18, 49], [19, 22], [19, 27], [19, 32], [19, 33], [19, 37], [19, 44], [19, 47], [20, 21], [20, 23], [20, 29], [20, 32], [20, 33], [20, 43], [20, 47], [21, 22], [21, 30], [21, 31], [21, 33], [21, 34], [21, 35], [21, 39], [21, 41], [22, 23], [22, 29], [22, 34], [22, 39], [22, 41], [22, 47], [22, 48], [23, 24], [23, 25], [23, 29], [23, 30], [23, 32], [23, 36], [23, 37], [23, 40], [23, 42], [23, 48], [24, 26], [24, 31], [24, 32], [24, 34], [24, 35], [24, 40], [24, 41], [24, 46], [24, 48], [24, 49], [25, 27], [25, 31], [25, 35], [25, 37], [25, 39], [25, 46], [26, 31], [26, 33], [26, 34], [26, 35], [26, 36], [26, 41], [26, 43], [26, 47], [26, 49], [27, 28], [27, 33], [27, 34], [27, 35], [27, 38], [27, 42], [27, 45], [27, 46], [28, 32], [28, 34], [28, 36], [28, 39], [28, 43], [28, 44], [28, 47], [28, 48], [29, 30], [29, 32], [29, 33], [29, 34], [29, 35], [29, 38], [29, 41], [29, 49], [30, 31], [30, 32], [30, 38], [30, 43], [30, 45], [30, 46], [31, 32], [31, 34], [31, 40], [31, 44], [31, 45], [31, 46], [31, 49], [32, 33], [32, 35], [32, 38], [32, 47], [33, 34], [33, 37], [33, 38], [33, 40], [33, 45], [33, 48], [33, 49], [34, 37], [34, 41], [34, 43], [34, 44], [34, 45], [34, 49], [35, 38], [35, 39], [35, 40], [35, 41], [35, 44], [35, 48], [36, 39], [36, 44], [37, 39], [37, 40], [37, 47], [37, 49], [38, 41], [38, 46], [38, 48], [39, 45], [39, 46], [39, 49], [40, 44], [40, 45], [40, 46], [40, 48], [41, 42], [41, 47], [41, 48], [42, 46], [42, 47], [42, 49], [43, 47], [44, 48], [45, 46]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l3-s5/tests/run.py b/tasks/construct-nppc-dominating-set-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l3-s5/tests/test.sh b/tasks/construct-nppc-dominating-set-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l3-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l6-s3/environment/Dockerfile b/tasks/construct-nppc-independent-set-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l6-s3/environment/instance.json b/tasks/construct-nppc-independent-set-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7d8577047e0fa9a8eadb1881f3be4b6f0d62c7e --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 3], [0, 4], [0, 11], [0, 26], [0, 30], [0, 33], [0, 38], [0, 51], [0, 53], [0, 58], [0, 62], [0, 63], [0, 64], [0, 65], [0, 67], [0, 86], [0, 89], [0, 94], [1, 4], [1, 5], [1, 14], [1, 17], [1, 19], [1, 22], [1, 28], [1, 29], [1, 40], [1, 41], [1, 42], [1, 43], [1, 46], [1, 48], [1, 55], [1, 59], [1, 60], [1, 63], [1, 66], [1, 68], [1, 69], [1, 71], [1, 75], [1, 76], [1, 81], [1, 82], [1, 85], [1, 87], [1, 89], [1, 95], [2, 3], [2, 4], [2, 5], [2, 10], [2, 17], [2, 21], [2, 22], [2, 24], [2, 25], [2, 32], [2, 35], [2, 37], [2, 46], [2, 49], [2, 51], [2, 55], [2, 58], [2, 60], [2, 69], [2, 71], [2, 73], [2, 75], [2, 79], [2, 81], [2, 83], [2, 86], [2, 88], [2, 89], [2, 92], [2, 93], [2, 99], [3, 5], [3, 10], [3, 16], [3, 17], [3, 31], [3, 33], [3, 40], [3, 43], [3, 78], [3, 84], [3, 87], [4, 5], [4, 9], [4, 10], [4, 14], [4, 16], [4, 17], [4, 29], [4, 30], [4, 33], [4, 35], [4, 40], [4, 42], [4, 46], [4, 48], [4, 52], [4, 54], [4, 55], [4, 59], [4, 60], [4, 63], [4, 69], [4, 72], [4, 73], [4, 75], [4, 83], [4, 86], [4, 94], [4, 95], [4, 96], [5, 9], [5, 12], [5, 13], [5, 15], [5, 19], [5, 28], [5, 31], [5, 38], [5, 39], [5, 44], [5, 50], [5, 52], [5, 53], [5, 55], [5, 57], [5, 58], [5, 61], [5, 63], [5, 68], [5, 69], [5, 70], [5, 74], [5, 79], [5, 80], [5, 81], [5, 83], [5, 84], [5, 99], [6, 7], [6, 10], [6, 11], [6, 16], [6, 17], [6, 20], [6, 21], [6, 22], [6, 28], [6, 34], [6, 36], [6, 37], [6, 39], [6, 40], [6, 43], [6, 50], [6, 54], [6, 71], [6, 75], [6, 76], [6, 97], [7, 8], [7, 17], [7, 21], [7, 23], [7, 26], [7, 29], [7, 31], [7, 34], [7, 37], [7, 40], [7, 46], [7, 47], [7, 52], [7, 57], [7, 59], [7, 60], [7, 65], [7, 67], [7, 68], [7, 70], [7, 71], [7, 77], [7, 78], [7, 89], [7, 90], [7, 91], [7, 95], [7, 98], [8, 9], [8, 21], [8, 36], [8, 39], [8, 42], [8, 45], [8, 47], [8, 48], [8, 49], [8, 50], [8, 52], [8, 53], [8, 54], [8, 67], [8, 71], [8, 77], [8, 91], [8, 98], [9, 12], [9, 16], [9, 22], [9, 24], [9, 28], [9, 30], [9, 40], [9, 45], [9, 50], [9, 70], [9, 80], [9, 87], [9, 90], [9, 95], [9, 96], [10, 11], [10, 16], [10, 22], [10, 23], [10, 25], [10, 28], [10, 29], [10, 30], [10, 49], [10, 50], [10, 51], [10, 54], [10, 67], [10, 74], [10, 77], [10, 78], [10, 82], [10, 85], [10, 86], [10, 93], [10, 99], [11, 14], [11, 20], [11, 22], [11, 24], [11, 27], [11, 30], [11, 35], [11, 36], [11, 39], [11, 40], [11, 52], [11, 54], [11, 55], [11, 56], [11, 57], [11, 59], [11, 63], [11, 75], [11, 76], [11, 78], [11, 79], [11, 83], [11, 85], [11, 86], [11, 88], [11, 89], [11, 92], [11, 95], [12, 13], [12, 14], [12, 15], [12, 18], [12, 19], [12, 21], [12, 23], [12, 35], [12, 37], [12, 39], [12, 41], [12, 48], [12, 52], [12, 53], [12, 55], [12, 56], [12, 59], [12, 66], [12, 75], [12, 78], [12, 80], [12, 95], [12, 96], [13, 18], [13, 21], [13, 26], [13, 31], [13, 32], [13, 37], [13, 38], [13, 39], [13, 45], [13, 57], [13, 58], [13, 60], [13, 62], [13, 69], [13, 70], [13, 72], [13, 74], [13, 75], [13, 77], [13, 91], [14, 17], [14, 18], [14, 21], [14, 22], [14, 26], [14, 40], [14, 43], [14, 49], [14, 52], [14, 64], [14, 73], [14, 75], [14, 80], [14, 86], [14, 87], [15, 16], [15, 26], [15, 36], [15, 44], [15, 45], [15, 52], [15, 54], [15, 65], [15, 69], [15, 76], [15, 87], [15, 94], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 31], [16, 36], [16, 49], [16, 51], [16, 53], [16, 54], [16, 59], [16, 60], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 71], [16, 75], [16, 78], [16, 79], [16, 99], [17, 20], [17, 21], [17, 25], [17, 28], [17, 30], [17, 32], [17, 37], [17, 39], [17, 45], [17, 47], [17, 48], [17, 49], [17, 51], [17, 58], [17, 61], [17, 66], [17, 67], [17, 71], [17, 72], [17, 76], [17, 85], [17, 87], [17, 88], [17, 92], [17, 95], [17, 97], [17, 98], [18, 19], [18, 22], [18, 28], [18, 29], [18, 30], [18, 32], [18, 38], [18, 41], [18, 42], [18, 45], [18, 48], [18, 49], [18, 51], [18, 53], [18, 56], [18, 57], [18, 58], [18, 61], [18, 66], [18, 77], [18, 78], [18, 79], [18, 84], [18, 86], [18, 91], [18, 92], [18, 95], [18, 96], [18, 97], [19, 21], [19, 22], [19, 33], [19, 39], [19, 42], [19, 45], [19, 46], [19, 52], [19, 54], [19, 57], [19, 63], [19, 65], [19, 74], [19, 75], [19, 97], [20, 25], [20, 28], [20, 38], [20, 39], [20, 44], [20, 48], [20, 50], [20, 53], [20, 54], [20, 62], [20, 63], [20, 66], [20, 67], [20, 74], [20, 78], [20, 81], [20, 82], [20, 86], [20, 89], [20, 93], [20, 95], [20, 98], [21, 28], [21, 32], [21, 34], [21, 42], [21, 46], [21, 50], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 71], [21, 72], [21, 78], [21, 86], [21, 87], [21, 92], [21, 97], [21, 98], [22, 26], [22, 27], [22, 28], [22, 29], [22, 31], [22, 43], [22, 44], [22, 45], [22, 50], [22, 54], [22, 55], [22, 56], [22, 60], [22, 65], [22, 69], [22, 72], [22, 74], [22, 75], [22, 77], [22, 78], [22, 85], [22, 87], [22, 89], [22, 91], [22, 96], [22, 98], [22, 99], [23, 24], [23, 26], [23, 28], [23, 31], [23, 33], [23, 37], [23, 39], [23, 42], [23, 44], [23, 49], [23, 62], [23, 65], [23, 74], [23, 76], [23, 86], [23, 92], [23, 94], [23, 97], [24, 27], [24, 34], [24, 38], [24, 39], [24, 40], [24, 41], [24, 44], [24, 49], [24, 53], [24, 56], [24, 59], [24, 61], [24, 62], [24, 64], [24, 66], [24, 67], [24, 68], [24, 72], [24, 73], [24, 74], [24, 76], [24, 78], [24, 79], [24, 82], [24, 84], [24, 86], [24, 87], [24, 93], [24, 94], [24, 99], [25, 28], [25, 36], [25, 49], [25, 53], [25, 60], [25, 73], [25, 78], [25, 79], [25, 84], [25, 85], [25, 95], [25, 96], [26, 29], [26, 30], [26, 36], [26, 37], [26, 40], [26, 46], [26, 51], [26, 55], [26, 58], [26, 67], [26, 76], [26, 82], [26, 86], [26, 87], [26, 91], [26, 94], [26, 98], [27, 30], [27, 37], [27, 40], [27, 45], [27, 51], [27, 52], [27, 53], [27, 54], [27, 59], [27, 60], [27, 63], [27, 64], [27, 65], [27, 69], [27, 71], [27, 75], [27, 95], [27, 97], [28, 30], [28, 34], [28, 39], [28, 42], [28, 44], [28, 48], [28, 52], [28, 59], [28, 61], [28, 63], [28, 64], [28, 76], [28, 79], [28, 83], [28, 92], [28, 97], [28, 98], [29, 33], [29, 34], [29, 36], [29, 37], [29, 42], [29, 43], [29, 46], [29, 50], [29, 53], [29, 57], [29, 62], [29, 69], [29, 86], [29, 87], [29, 89], [29, 90], [29, 96], [29, 97], [30, 33], [30, 43], [30, 51], [30, 52], [30, 56], [30, 58], [30, 60], [30, 63], [30, 65], [30, 67], [30, 70], [30, 72], [30, 73], [30, 74], [30, 75], [30, 77], [30, 82], [30, 88], [30, 95], [30, 98], [31, 33], [31, 36], [31, 38], [31, 40], [31, 48], [31, 49], [31, 51], [31, 60], [31, 70], [31, 72], [31, 74], [31, 79], [31, 81], [31, 88], [31, 94], [31, 96], [32, 37], [32, 40], [32, 42], [32, 46], [32, 53], [32, 71], [32, 75], [32, 78], [32, 80], [32, 84], [32, 85], [32, 89], [32, 90], [32, 94], [32, 96], [33, 38], [33, 39], [33, 46], [33, 54], [33, 55], [33, 56], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 76], [33, 77], [33, 88], [33, 91], [33, 96], [34, 37], [34, 39], [34, 40], [34, 43], [34, 44], [34, 45], [34, 46], [34, 50], [34, 51], [34, 62], [34, 66], [34, 74], [34, 75], [34, 76], [34, 78], [34, 79], [34, 83], [34, 87], [34, 89], [34, 90], [34, 91], [34, 93], [34, 99], [35, 37], [35, 40], [35, 42], [35, 44], [35, 45], [35, 50], [35, 52], [35, 60], [35, 62], [35, 71], [35, 75], [35, 76], [35, 86], [35, 89], [35, 90], [35, 92], [35, 96], [36, 42], [36, 44], [36, 45], [36, 51], [36, 53], [36, 55], [36, 56], [36, 60], [36, 69], [36, 81], [36, 85], [36, 88], [36, 96], [36, 98], [37, 38], [37, 43], [37, 46], [37, 51], [37, 52], [37, 55], [37, 59], [37, 63], [37, 68], [37, 71], [37, 72], [37, 77], [37, 78], [37, 80], [37, 82], [37, 92], [38, 42], [38, 50], [38, 54], [38, 57], [38, 59], [38, 60], [38, 64], [38, 65], [38, 69], [38, 70], [38, 71], [38, 75], [38, 77], [38, 85], [38, 86], [38, 87], [39, 41], [39, 43], [39, 48], [39, 53], [39, 62], [39, 65], [39, 69], [39, 75], [39, 77], [39, 78], [39, 82], [39, 89], [39, 91], [39, 93], [39, 97], [40, 41], [40, 48], [40, 50], [40, 56], [40, 58], [40, 59], [40, 64], [40, 65], [40, 67], [40, 80], [40, 81], [40, 92], [41, 45], [41, 46], [41, 49], [41, 53], [41, 73], [41, 74], [41, 76], [41, 78], [41, 85], [41, 87], [42, 45], [42, 46], [42, 50], [42, 51], [42, 52], [42, 53], [42, 55], [42, 57], [42, 59], [42, 61], [42, 62], [42, 63], [42, 65], [42, 67], [42, 71], [42, 72], [42, 74], [42, 78], [42, 82], [42, 83], [42, 90], [42, 92], [42, 96], [43, 45], [43, 53], [43, 55], [43, 57], [43, 60], [43, 63], [43, 66], [43, 67], [43, 69], [43, 82], [43, 84], [43, 92], [43, 94], [44, 46], [44, 47], [44, 48], [44, 53], [44, 54], [44, 60], [44, 61], [44, 62], [44, 68], [44, 69], [44, 70], [44, 74], [44, 77], [44, 78], [44, 82], [44, 85], [44, 88], [44, 94], [44, 97], [44, 98], [45, 47], [45, 50], [45, 51], [45, 53], [45, 60], [45, 63], [45, 75], [45, 79], [45, 80], [45, 86], [45, 94], [45, 97], [45, 98], [45, 99], [46, 48], [46, 52], [46, 56], [46, 57], [46, 58], [46, 61], [46, 62], [46, 64], [46, 65], [46, 66], [46, 69], [46, 74], [46, 78], [46, 80], [46, 85], [46, 89], [46, 90], [46, 91], [46, 94], [47, 49], [47, 53], [47, 57], [47, 64], [47, 74], [47, 76], [47, 80], [47, 84], [47, 87], [47, 90], [47, 92], [47, 94], [47, 95], [48, 49], [48, 51], [48, 54], [48, 59], [48, 60], [48, 62], [48, 71], [48, 79], [48, 84], [48, 86], [48, 90], [49, 57], [49, 58], [49, 59], [49, 67], [49, 78], [49, 88], [49, 91], [50, 63], [50, 66], [50, 68], [50, 69], [50, 70], [50, 71], [50, 78], [50, 85], [50, 88], [50, 90], [50, 92], [50, 98], [50, 99], [51, 52], [51, 57], [51, 59], [51, 65], [51, 79], [51, 81], [51, 83], [51, 85], [51, 88], [51, 89], [51, 97], [51, 98], [52, 54], [52, 59], [52, 63], [52, 64], [52, 65], [52, 66], [52, 73], [52, 78], [52, 82], [52, 86], [52, 91], [52, 95], [52, 96], [52, 98], [52, 99], [53, 55], [53, 57], [53, 61], [53, 65], [53, 70], [53, 77], [53, 80], [53, 82], [53, 83], [53, 92], [54, 62], [54, 68], [54, 73], [54, 91], [54, 93], [55, 57], [55, 68], [55, 74], [55, 79], [55, 90], [55, 95], [56, 62], [56, 63], [56, 64], [56, 65], [56, 68], [56, 73], [56, 74], [56, 75], [56, 78], [56, 87], [56, 89], [56, 92], [56, 96], [56, 97], [57, 58], [57, 63], [57, 65], [57, 67], [57, 68], [57, 75], [57, 76], [57, 78], [57, 80], [57, 81], [57, 83], [57, 84], [57, 86], [57, 89], [57, 90], [57, 92], [57, 96], [57, 97], [58, 59], [58, 64], [58, 68], [58, 76], [58, 77], [58, 79], [58, 90], [58, 92], [58, 96], [59, 60], [59, 71], [59, 72], [59, 74], [59, 75], [59, 80], [59, 82], [59, 83], [60, 63], [60, 64], [60, 65], [60, 66], [60, 71], [60, 73], [60, 74], [60, 83], [60, 86], [60, 87], [60, 91], [60, 94], [60, 95], [60, 96], [60, 98], [61, 62], [61, 65], [61, 68], [61, 69], [61, 70], [61, 71], [61, 78], [61, 92], [62, 63], [62, 66], [62, 68], [62, 69], [62, 72], [62, 80], [62, 81], [62, 88], [62, 89], [62, 91], [62, 94], [63, 67], [63, 74], [63, 90], [63, 92], [63, 97], [64, 79], [64, 81], [64, 87], [64, 89], [64, 92], [64, 95], [64, 97], [64, 98], [64, 99], [65, 66], [65, 68], [65, 70], [65, 72], [65, 73], [65, 78], [65, 81], [65, 82], [65, 91], [65, 97], [66, 68], [66, 74], [66, 78], [66, 86], [66, 92], [66, 95], [66, 96], [67, 68], [67, 74], [67, 75], [67, 80], [67, 87], [67, 94], [67, 95], [68, 73], [68, 78], [68, 80], [68, 81], [68, 87], [68, 91], [68, 93], [68, 94], [68, 98], [69, 70], [69, 76], [69, 80], [69, 82], [69, 84], [69, 89], [69, 97], [70, 71], [70, 74], [70, 78], [70, 79], [70, 90], [70, 91], [70, 92], [70, 98], [71, 77], [71, 80], [71, 84], [71, 94], [71, 96], [71, 98], [72, 77], [72, 78], [72, 79], [72, 89], [73, 82], [73, 85], [73, 86], [73, 89], [73, 90], [73, 97], [74, 79], [74, 86], [74, 87], [74, 90], [74, 94], [74, 97], [74, 99], [75, 77], [75, 79], [75, 80], [75, 81], [75, 84], [75, 85], [75, 86], [75, 93], [75, 99], [76, 77], [76, 86], [76, 87], [76, 94], [77, 81], [77, 82], [77, 88], [77, 89], [77, 94], [77, 96], [78, 79], [78, 83], [78, 89], [78, 90], [78, 93], [78, 94], [78, 95], [79, 81], [79, 84], [79, 86], [79, 88], [79, 96], [79, 97], [80, 82], [80, 84], [80, 86], [80, 88], [80, 92], [80, 93], [80, 95], [80, 98], [80, 99], [81, 89], [81, 90], [81, 96], [81, 97], [82, 84], [82, 92], [82, 95], [82, 96], [83, 90], [83, 94], [83, 95], [83, 97], [84, 87], [84, 93], [84, 94], [84, 98], [85, 88], [85, 89], [85, 92], [85, 94], [85, 96], [86, 90], [86, 92], [86, 97], [87, 89], [87, 95], [87, 96], [88, 89], [88, 95], [89, 90], [89, 92], [89, 98], [90, 91], [90, 93], [90, 94], [91, 94], [92, 96], [93, 97], [94, 99], [95, 96], [95, 98], [96, 97]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s3/solution/solve.sh b/tasks/construct-nppc-independent-set-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0da27d9a659a58919ee86167a7e115ccf871cbe4 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [3, 6, 9, 14, 15, 19, 23, 25, 27, 29, 32, 35, 38, 41, 47, 48, 55, 56, 58, 61, 66, 67, 72, 81, 82, 83, 88, 93, 98, 99]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l6-s3/tests/check.py b/tasks/construct-nppc-independent-set-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s3/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l6-s3/tests/instance.json b/tasks/construct-nppc-independent-set-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7d8577047e0fa9a8eadb1881f3be4b6f0d62c7e --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 3], [0, 4], [0, 11], [0, 26], [0, 30], [0, 33], [0, 38], [0, 51], [0, 53], [0, 58], [0, 62], [0, 63], [0, 64], [0, 65], [0, 67], [0, 86], [0, 89], [0, 94], [1, 4], [1, 5], [1, 14], [1, 17], [1, 19], [1, 22], [1, 28], [1, 29], [1, 40], [1, 41], [1, 42], [1, 43], [1, 46], [1, 48], [1, 55], [1, 59], [1, 60], [1, 63], [1, 66], [1, 68], [1, 69], [1, 71], [1, 75], [1, 76], [1, 81], [1, 82], [1, 85], [1, 87], [1, 89], [1, 95], [2, 3], [2, 4], [2, 5], [2, 10], [2, 17], [2, 21], [2, 22], [2, 24], [2, 25], [2, 32], [2, 35], [2, 37], [2, 46], [2, 49], [2, 51], [2, 55], [2, 58], [2, 60], [2, 69], [2, 71], [2, 73], [2, 75], [2, 79], [2, 81], [2, 83], [2, 86], [2, 88], [2, 89], [2, 92], [2, 93], [2, 99], [3, 5], [3, 10], [3, 16], [3, 17], [3, 31], [3, 33], [3, 40], [3, 43], [3, 78], [3, 84], [3, 87], [4, 5], [4, 9], [4, 10], [4, 14], [4, 16], [4, 17], [4, 29], [4, 30], [4, 33], [4, 35], [4, 40], [4, 42], [4, 46], [4, 48], [4, 52], [4, 54], [4, 55], [4, 59], [4, 60], [4, 63], [4, 69], [4, 72], [4, 73], [4, 75], [4, 83], [4, 86], [4, 94], [4, 95], [4, 96], [5, 9], [5, 12], [5, 13], [5, 15], [5, 19], [5, 28], [5, 31], [5, 38], [5, 39], [5, 44], [5, 50], [5, 52], [5, 53], [5, 55], [5, 57], [5, 58], [5, 61], [5, 63], [5, 68], [5, 69], [5, 70], [5, 74], [5, 79], [5, 80], [5, 81], [5, 83], [5, 84], [5, 99], [6, 7], [6, 10], [6, 11], [6, 16], [6, 17], [6, 20], [6, 21], [6, 22], [6, 28], [6, 34], [6, 36], [6, 37], [6, 39], [6, 40], [6, 43], [6, 50], [6, 54], [6, 71], [6, 75], [6, 76], [6, 97], [7, 8], [7, 17], [7, 21], [7, 23], [7, 26], [7, 29], [7, 31], [7, 34], [7, 37], [7, 40], [7, 46], [7, 47], [7, 52], [7, 57], [7, 59], [7, 60], [7, 65], [7, 67], [7, 68], [7, 70], [7, 71], [7, 77], [7, 78], [7, 89], [7, 90], [7, 91], [7, 95], [7, 98], [8, 9], [8, 21], [8, 36], [8, 39], [8, 42], [8, 45], [8, 47], [8, 48], [8, 49], [8, 50], [8, 52], [8, 53], [8, 54], [8, 67], [8, 71], [8, 77], [8, 91], [8, 98], [9, 12], [9, 16], [9, 22], [9, 24], [9, 28], [9, 30], [9, 40], [9, 45], [9, 50], [9, 70], [9, 80], [9, 87], [9, 90], [9, 95], [9, 96], [10, 11], [10, 16], [10, 22], [10, 23], [10, 25], [10, 28], [10, 29], [10, 30], [10, 49], [10, 50], [10, 51], [10, 54], [10, 67], [10, 74], [10, 77], [10, 78], [10, 82], [10, 85], [10, 86], [10, 93], [10, 99], [11, 14], [11, 20], [11, 22], [11, 24], [11, 27], [11, 30], [11, 35], [11, 36], [11, 39], [11, 40], [11, 52], [11, 54], [11, 55], [11, 56], [11, 57], [11, 59], [11, 63], [11, 75], [11, 76], [11, 78], [11, 79], [11, 83], [11, 85], [11, 86], [11, 88], [11, 89], [11, 92], [11, 95], [12, 13], [12, 14], [12, 15], [12, 18], [12, 19], [12, 21], [12, 23], [12, 35], [12, 37], [12, 39], [12, 41], [12, 48], [12, 52], [12, 53], [12, 55], [12, 56], [12, 59], [12, 66], [12, 75], [12, 78], [12, 80], [12, 95], [12, 96], [13, 18], [13, 21], [13, 26], [13, 31], [13, 32], [13, 37], [13, 38], [13, 39], [13, 45], [13, 57], [13, 58], [13, 60], [13, 62], [13, 69], [13, 70], [13, 72], [13, 74], [13, 75], [13, 77], [13, 91], [14, 17], [14, 18], [14, 21], [14, 22], [14, 26], [14, 40], [14, 43], [14, 49], [14, 52], [14, 64], [14, 73], [14, 75], [14, 80], [14, 86], [14, 87], [15, 16], [15, 26], [15, 36], [15, 44], [15, 45], [15, 52], [15, 54], [15, 65], [15, 69], [15, 76], [15, 87], [15, 94], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 31], [16, 36], [16, 49], [16, 51], [16, 53], [16, 54], [16, 59], [16, 60], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 71], [16, 75], [16, 78], [16, 79], [16, 99], [17, 20], [17, 21], [17, 25], [17, 28], [17, 30], [17, 32], [17, 37], [17, 39], [17, 45], [17, 47], [17, 48], [17, 49], [17, 51], [17, 58], [17, 61], [17, 66], [17, 67], [17, 71], [17, 72], [17, 76], [17, 85], [17, 87], [17, 88], [17, 92], [17, 95], [17, 97], [17, 98], [18, 19], [18, 22], [18, 28], [18, 29], [18, 30], [18, 32], [18, 38], [18, 41], [18, 42], [18, 45], [18, 48], [18, 49], [18, 51], [18, 53], [18, 56], [18, 57], [18, 58], [18, 61], [18, 66], [18, 77], [18, 78], [18, 79], [18, 84], [18, 86], [18, 91], [18, 92], [18, 95], [18, 96], [18, 97], [19, 21], [19, 22], [19, 33], [19, 39], [19, 42], [19, 45], [19, 46], [19, 52], [19, 54], [19, 57], [19, 63], [19, 65], [19, 74], [19, 75], [19, 97], [20, 25], [20, 28], [20, 38], [20, 39], [20, 44], [20, 48], [20, 50], [20, 53], [20, 54], [20, 62], [20, 63], [20, 66], [20, 67], [20, 74], [20, 78], [20, 81], [20, 82], [20, 86], [20, 89], [20, 93], [20, 95], [20, 98], [21, 28], [21, 32], [21, 34], [21, 42], [21, 46], [21, 50], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 71], [21, 72], [21, 78], [21, 86], [21, 87], [21, 92], [21, 97], [21, 98], [22, 26], [22, 27], [22, 28], [22, 29], [22, 31], [22, 43], [22, 44], [22, 45], [22, 50], [22, 54], [22, 55], [22, 56], [22, 60], [22, 65], [22, 69], [22, 72], [22, 74], [22, 75], [22, 77], [22, 78], [22, 85], [22, 87], [22, 89], [22, 91], [22, 96], [22, 98], [22, 99], [23, 24], [23, 26], [23, 28], [23, 31], [23, 33], [23, 37], [23, 39], [23, 42], [23, 44], [23, 49], [23, 62], [23, 65], [23, 74], [23, 76], [23, 86], [23, 92], [23, 94], [23, 97], [24, 27], [24, 34], [24, 38], [24, 39], [24, 40], [24, 41], [24, 44], [24, 49], [24, 53], [24, 56], [24, 59], [24, 61], [24, 62], [24, 64], [24, 66], [24, 67], [24, 68], [24, 72], [24, 73], [24, 74], [24, 76], [24, 78], [24, 79], [24, 82], [24, 84], [24, 86], [24, 87], [24, 93], [24, 94], [24, 99], [25, 28], [25, 36], [25, 49], [25, 53], [25, 60], [25, 73], [25, 78], [25, 79], [25, 84], [25, 85], [25, 95], [25, 96], [26, 29], [26, 30], [26, 36], [26, 37], [26, 40], [26, 46], [26, 51], [26, 55], [26, 58], [26, 67], [26, 76], [26, 82], [26, 86], [26, 87], [26, 91], [26, 94], [26, 98], [27, 30], [27, 37], [27, 40], [27, 45], [27, 51], [27, 52], [27, 53], [27, 54], [27, 59], [27, 60], [27, 63], [27, 64], [27, 65], [27, 69], [27, 71], [27, 75], [27, 95], [27, 97], [28, 30], [28, 34], [28, 39], [28, 42], [28, 44], [28, 48], [28, 52], [28, 59], [28, 61], [28, 63], [28, 64], [28, 76], [28, 79], [28, 83], [28, 92], [28, 97], [28, 98], [29, 33], [29, 34], [29, 36], [29, 37], [29, 42], [29, 43], [29, 46], [29, 50], [29, 53], [29, 57], [29, 62], [29, 69], [29, 86], [29, 87], [29, 89], [29, 90], [29, 96], [29, 97], [30, 33], [30, 43], [30, 51], [30, 52], [30, 56], [30, 58], [30, 60], [30, 63], [30, 65], [30, 67], [30, 70], [30, 72], [30, 73], [30, 74], [30, 75], [30, 77], [30, 82], [30, 88], [30, 95], [30, 98], [31, 33], [31, 36], [31, 38], [31, 40], [31, 48], [31, 49], [31, 51], [31, 60], [31, 70], [31, 72], [31, 74], [31, 79], [31, 81], [31, 88], [31, 94], [31, 96], [32, 37], [32, 40], [32, 42], [32, 46], [32, 53], [32, 71], [32, 75], [32, 78], [32, 80], [32, 84], [32, 85], [32, 89], [32, 90], [32, 94], [32, 96], [33, 38], [33, 39], [33, 46], [33, 54], [33, 55], [33, 56], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 76], [33, 77], [33, 88], [33, 91], [33, 96], [34, 37], [34, 39], [34, 40], [34, 43], [34, 44], [34, 45], [34, 46], [34, 50], [34, 51], [34, 62], [34, 66], [34, 74], [34, 75], [34, 76], [34, 78], [34, 79], [34, 83], [34, 87], [34, 89], [34, 90], [34, 91], [34, 93], [34, 99], [35, 37], [35, 40], [35, 42], [35, 44], [35, 45], [35, 50], [35, 52], [35, 60], [35, 62], [35, 71], [35, 75], [35, 76], [35, 86], [35, 89], [35, 90], [35, 92], [35, 96], [36, 42], [36, 44], [36, 45], [36, 51], [36, 53], [36, 55], [36, 56], [36, 60], [36, 69], [36, 81], [36, 85], [36, 88], [36, 96], [36, 98], [37, 38], [37, 43], [37, 46], [37, 51], [37, 52], [37, 55], [37, 59], [37, 63], [37, 68], [37, 71], [37, 72], [37, 77], [37, 78], [37, 80], [37, 82], [37, 92], [38, 42], [38, 50], [38, 54], [38, 57], [38, 59], [38, 60], [38, 64], [38, 65], [38, 69], [38, 70], [38, 71], [38, 75], [38, 77], [38, 85], [38, 86], [38, 87], [39, 41], [39, 43], [39, 48], [39, 53], [39, 62], [39, 65], [39, 69], [39, 75], [39, 77], [39, 78], [39, 82], [39, 89], [39, 91], [39, 93], [39, 97], [40, 41], [40, 48], [40, 50], [40, 56], [40, 58], [40, 59], [40, 64], [40, 65], [40, 67], [40, 80], [40, 81], [40, 92], [41, 45], [41, 46], [41, 49], [41, 53], [41, 73], [41, 74], [41, 76], [41, 78], [41, 85], [41, 87], [42, 45], [42, 46], [42, 50], [42, 51], [42, 52], [42, 53], [42, 55], [42, 57], [42, 59], [42, 61], [42, 62], [42, 63], [42, 65], [42, 67], [42, 71], [42, 72], [42, 74], [42, 78], [42, 82], [42, 83], [42, 90], [42, 92], [42, 96], [43, 45], [43, 53], [43, 55], [43, 57], [43, 60], [43, 63], [43, 66], [43, 67], [43, 69], [43, 82], [43, 84], [43, 92], [43, 94], [44, 46], [44, 47], [44, 48], [44, 53], [44, 54], [44, 60], [44, 61], [44, 62], [44, 68], [44, 69], [44, 70], [44, 74], [44, 77], [44, 78], [44, 82], [44, 85], [44, 88], [44, 94], [44, 97], [44, 98], [45, 47], [45, 50], [45, 51], [45, 53], [45, 60], [45, 63], [45, 75], [45, 79], [45, 80], [45, 86], [45, 94], [45, 97], [45, 98], [45, 99], [46, 48], [46, 52], [46, 56], [46, 57], [46, 58], [46, 61], [46, 62], [46, 64], [46, 65], [46, 66], [46, 69], [46, 74], [46, 78], [46, 80], [46, 85], [46, 89], [46, 90], [46, 91], [46, 94], [47, 49], [47, 53], [47, 57], [47, 64], [47, 74], [47, 76], [47, 80], [47, 84], [47, 87], [47, 90], [47, 92], [47, 94], [47, 95], [48, 49], [48, 51], [48, 54], [48, 59], [48, 60], [48, 62], [48, 71], [48, 79], [48, 84], [48, 86], [48, 90], [49, 57], [49, 58], [49, 59], [49, 67], [49, 78], [49, 88], [49, 91], [50, 63], [50, 66], [50, 68], [50, 69], [50, 70], [50, 71], [50, 78], [50, 85], [50, 88], [50, 90], [50, 92], [50, 98], [50, 99], [51, 52], [51, 57], [51, 59], [51, 65], [51, 79], [51, 81], [51, 83], [51, 85], [51, 88], [51, 89], [51, 97], [51, 98], [52, 54], [52, 59], [52, 63], [52, 64], [52, 65], [52, 66], [52, 73], [52, 78], [52, 82], [52, 86], [52, 91], [52, 95], [52, 96], [52, 98], [52, 99], [53, 55], [53, 57], [53, 61], [53, 65], [53, 70], [53, 77], [53, 80], [53, 82], [53, 83], [53, 92], [54, 62], [54, 68], [54, 73], [54, 91], [54, 93], [55, 57], [55, 68], [55, 74], [55, 79], [55, 90], [55, 95], [56, 62], [56, 63], [56, 64], [56, 65], [56, 68], [56, 73], [56, 74], [56, 75], [56, 78], [56, 87], [56, 89], [56, 92], [56, 96], [56, 97], [57, 58], [57, 63], [57, 65], [57, 67], [57, 68], [57, 75], [57, 76], [57, 78], [57, 80], [57, 81], [57, 83], [57, 84], [57, 86], [57, 89], [57, 90], [57, 92], [57, 96], [57, 97], [58, 59], [58, 64], [58, 68], [58, 76], [58, 77], [58, 79], [58, 90], [58, 92], [58, 96], [59, 60], [59, 71], [59, 72], [59, 74], [59, 75], [59, 80], [59, 82], [59, 83], [60, 63], [60, 64], [60, 65], [60, 66], [60, 71], [60, 73], [60, 74], [60, 83], [60, 86], [60, 87], [60, 91], [60, 94], [60, 95], [60, 96], [60, 98], [61, 62], [61, 65], [61, 68], [61, 69], [61, 70], [61, 71], [61, 78], [61, 92], [62, 63], [62, 66], [62, 68], [62, 69], [62, 72], [62, 80], [62, 81], [62, 88], [62, 89], [62, 91], [62, 94], [63, 67], [63, 74], [63, 90], [63, 92], [63, 97], [64, 79], [64, 81], [64, 87], [64, 89], [64, 92], [64, 95], [64, 97], [64, 98], [64, 99], [65, 66], [65, 68], [65, 70], [65, 72], [65, 73], [65, 78], [65, 81], [65, 82], [65, 91], [65, 97], [66, 68], [66, 74], [66, 78], [66, 86], [66, 92], [66, 95], [66, 96], [67, 68], [67, 74], [67, 75], [67, 80], [67, 87], [67, 94], [67, 95], [68, 73], [68, 78], [68, 80], [68, 81], [68, 87], [68, 91], [68, 93], [68, 94], [68, 98], [69, 70], [69, 76], [69, 80], [69, 82], [69, 84], [69, 89], [69, 97], [70, 71], [70, 74], [70, 78], [70, 79], [70, 90], [70, 91], [70, 92], [70, 98], [71, 77], [71, 80], [71, 84], [71, 94], [71, 96], [71, 98], [72, 77], [72, 78], [72, 79], [72, 89], [73, 82], [73, 85], [73, 86], [73, 89], [73, 90], [73, 97], [74, 79], [74, 86], [74, 87], [74, 90], [74, 94], [74, 97], [74, 99], [75, 77], [75, 79], [75, 80], [75, 81], [75, 84], [75, 85], [75, 86], [75, 93], [75, 99], [76, 77], [76, 86], [76, 87], [76, 94], [77, 81], [77, 82], [77, 88], [77, 89], [77, 94], [77, 96], [78, 79], [78, 83], [78, 89], [78, 90], [78, 93], [78, 94], [78, 95], [79, 81], [79, 84], [79, 86], [79, 88], [79, 96], [79, 97], [80, 82], [80, 84], [80, 86], [80, 88], [80, 92], [80, 93], [80, 95], [80, 98], [80, 99], [81, 89], [81, 90], [81, 96], [81, 97], [82, 84], [82, 92], [82, 95], [82, 96], [83, 90], [83, 94], [83, 95], [83, 97], [84, 87], [84, 93], [84, 94], [84, 98], [85, 88], [85, 89], [85, 92], [85, 94], [85, 96], [86, 90], [86, 92], [86, 97], [87, 89], [87, 95], [87, 96], [88, 89], [88, 95], [89, 90], [89, 92], [89, 98], [90, 91], [90, 93], [90, 94], [91, 94], [92, 96], [93, 97], [94, 99], [95, 96], [95, 98], [96, 97]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s3/tests/run.py b/tasks/construct-nppc-independent-set-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l6-s3/tests/test.sh b/tasks/construct-nppc-independent-set-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l6-s4/environment/Dockerfile b/tasks/construct-nppc-independent-set-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l6-s4/environment/instance.json b/tasks/construct-nppc-independent-set-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2cc41c3288dcbeae35b3ce3f48cf3193ff76b977 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 4], [0, 9], [0, 12], [0, 14], [0, 17], [0, 27], [0, 31], [0, 33], [0, 46], [0, 47], [0, 56], [0, 57], [0, 58], [0, 68], [0, 72], [0, 73], [0, 74], [0, 75], [0, 84], [0, 85], [0, 92], [1, 3], [1, 4], [1, 5], [1, 11], [1, 16], [1, 36], [1, 37], [1, 46], [1, 56], [1, 57], [1, 58], [1, 64], [1, 68], [1, 79], [1, 83], [1, 92], [1, 96], [1, 97], [2, 4], [2, 5], [2, 17], [2, 25], [2, 26], [2, 31], [2, 32], [2, 34], [2, 36], [2, 39], [2, 42], [2, 43], [2, 44], [2, 46], [2, 49], [2, 50], [2, 52], [2, 56], [2, 57], [2, 62], [2, 66], [2, 69], [2, 73], [2, 77], [2, 78], [2, 89], [2, 90], [2, 95], [2, 96], [2, 98], [2, 99], [3, 5], [3, 6], [3, 10], [3, 15], [3, 26], [3, 31], [3, 36], [3, 39], [3, 40], [3, 41], [3, 47], [3, 50], [3, 51], [3, 57], [3, 58], [3, 63], [3, 65], [3, 69], [3, 72], [3, 77], [3, 80], [3, 82], [3, 83], [3, 86], [3, 88], [3, 89], [3, 90], [3, 95], [3, 97], [4, 5], [4, 6], [4, 13], [4, 14], [4, 19], [4, 20], [4, 23], [4, 24], [4, 25], [4, 27], [4, 28], [4, 37], [4, 40], [4, 45], [4, 50], [4, 54], [4, 55], [4, 58], [4, 59], [4, 64], [4, 67], [4, 71], [4, 72], [4, 80], [4, 81], [4, 83], [4, 85], [4, 91], [4, 92], [4, 96], [4, 97], [5, 7], [5, 11], [5, 13], [5, 15], [5, 18], [5, 22], [5, 24], [5, 25], [5, 29], [5, 31], [5, 36], [5, 40], [5, 41], [5, 45], [5, 51], [5, 56], [5, 62], [5, 63], [5, 68], [5, 72], [5, 77], [5, 87], [5, 89], [5, 90], [6, 16], [6, 18], [6, 24], [6, 26], [6, 27], [6, 29], [6, 30], [6, 31], [6, 40], [6, 42], [6, 44], [6, 48], [6, 54], [6, 58], [6, 63], [6, 65], [6, 67], [6, 70], [6, 72], [6, 76], [6, 78], [6, 79], [6, 84], [6, 87], [6, 91], [6, 92], [6, 98], [7, 11], [7, 12], [7, 16], [7, 19], [7, 24], [7, 44], [7, 53], [7, 58], [7, 63], [7, 66], [7, 68], [7, 69], [7, 92], [7, 99], [8, 13], [8, 24], [8, 27], [8, 28], [8, 33], [8, 39], [8, 40], [8, 44], [8, 48], [8, 53], [8, 58], [8, 59], [8, 61], [8, 63], [8, 75], [8, 79], [8, 85], [8, 87], [8, 88], [8, 98], [9, 16], [9, 17], [9, 25], [9, 26], [9, 27], [9, 28], [9, 36], [9, 38], [9, 45], [9, 47], [9, 48], [9, 58], [9, 59], [9, 61], [9, 63], [9, 64], [9, 65], [9, 77], [9, 78], [9, 83], [9, 88], [9, 91], [9, 93], [9, 96], [10, 12], [10, 16], [10, 18], [10, 19], [10, 28], [10, 33], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 53], [10, 56], [10, 63], [10, 67], [10, 69], [10, 72], [10, 81], [10, 88], [10, 98], [10, 99], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 24], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 46], [11, 49], [11, 50], [11, 54], [11, 56], [11, 60], [11, 61], [11, 63], [11, 65], [11, 70], [11, 77], [11, 83], [11, 86], [11, 89], [11, 92], [11, 95], [11, 98], [12, 13], [12, 14], [12, 18], [12, 21], [12, 22], [12, 25], [12, 28], [12, 36], [12, 37], [12, 39], [12, 40], [12, 42], [12, 43], [12, 45], [12, 49], [12, 53], [12, 66], [12, 69], [12, 70], [12, 73], [12, 74], [12, 76], [12, 78], [12, 80], [12, 81], [12, 82], [12, 88], [12, 92], [12, 95], [12, 97], [13, 23], [13, 24], [13, 26], [13, 28], [13, 30], [13, 32], [13, 33], [13, 35], [13, 38], [13, 41], [13, 42], [13, 43], [13, 46], [13, 56], [13, 58], [13, 61], [13, 62], [13, 64], [13, 68], [13, 77], [13, 80], [13, 85], [13, 86], [13, 87], [13, 91], [13, 92], [13, 93], [13, 95], [13, 96], [13, 98], [14, 15], [14, 16], [14, 22], [14, 23], [14, 24], [14, 26], [14, 30], [14, 34], [14, 36], [14, 37], [14, 39], [14, 41], [14, 42], [14, 45], [14, 47], [14, 49], [14, 50], [14, 51], [14, 52], [14, 57], [14, 59], [14, 61], [14, 62], [14, 64], [14, 66], [14, 69], [14, 70], [14, 78], [14, 81], [14, 82], [14, 95], [15, 22], [15, 23], [15, 24], [15, 30], [15, 32], [15, 34], [15, 38], [15, 40], [15, 42], [15, 43], [15, 46], [15, 47], [15, 52], [15, 59], [15, 61], [15, 62], [15, 63], [15, 64], [15, 68], [15, 70], [15, 71], [15, 78], [15, 79], [15, 85], [15, 86], [15, 87], [15, 88], [15, 90], [15, 91], [15, 94], [15, 98], [15, 99], [16, 17], [16, 18], [16, 20], [16, 21], [16, 23], [16, 26], [16, 27], [16, 31], [16, 33], [16, 34], [16, 36], [16, 38], [16, 42], [16, 44], [16, 47], [16, 48], [16, 49], [16, 51], [16, 53], [16, 54], [16, 57], [16, 66], [16, 67], [16, 74], [16, 79], [16, 80], [16, 86], [16, 89], [16, 93], [16, 98], [17, 19], [17, 26], [17, 27], [17, 31], [17, 35], [17, 36], [17, 39], [17, 40], [17, 43], [17, 45], [17, 50], [17, 51], [17, 52], [17, 54], [17, 55], [17, 56], [17, 64], [17, 65], [17, 69], [17, 73], [17, 76], [17, 77], [17, 78], [17, 79], [17, 86], [17, 88], [17, 96], [17, 97], [17, 99], [18, 19], [18, 26], [18, 29], [18, 30], [18, 35], [18, 41], [18, 42], [18, 44], [18, 47], [18, 49], [18, 54], [18, 56], [18, 65], [18, 67], [18, 73], [18, 74], [18, 75], [18, 79], [18, 81], [19, 20], [19, 25], [19, 26], [19, 27], [19, 29], [19, 42], [19, 43], [19, 46], [19, 56], [19, 57], [19, 61], [19, 64], [19, 68], [19, 69], [19, 71], [19, 74], [19, 75], [19, 76], [19, 78], [19, 80], [19, 88], [19, 89], [19, 92], [19, 95], [20, 22], [20, 29], [20, 36], [20, 37], [20, 46], [20, 53], [20, 59], [20, 61], [20, 64], [20, 67], [20, 69], [20, 73], [20, 75], [20, 81], [20, 83], [20, 85], [20, 88], [20, 92], [20, 97], [21, 25], [21, 28], [21, 35], [21, 37], [21, 41], [21, 42], [21, 47], [21, 51], [21, 57], [21, 68], [21, 74], [21, 78], [21, 80], [21, 87], [21, 92], [21, 96], [22, 24], [22, 26], [22, 27], [22, 44], [22, 45], [22, 46], [22, 48], [22, 51], [22, 60], [22, 64], [22, 67], [22, 68], [22, 69], [22, 74], [22, 77], [22, 88], [22, 94], [22, 95], [23, 28], [23, 31], [23, 33], [23, 34], [23, 36], [23, 41], [23, 44], [23, 50], [23, 53], [23, 56], [23, 58], [23, 72], [23, 75], [23, 82], [23, 93], [24, 29], [24, 36], [24, 37], [24, 38], [24, 41], [24, 43], [24, 44], [24, 45], [24, 51], [24, 58], [24, 59], [24, 64], [24, 77], [24, 82], [24, 85], [24, 98], [24, 99], [25, 27], [25, 36], [25, 40], [25, 41], [25, 43], [25, 45], [25, 47], [25, 50], [25, 53], [25, 58], [25, 61], [25, 64], [25, 68], [25, 69], [25, 79], [25, 88], [25, 99], [26, 27], [26, 28], [26, 33], [26, 37], [26, 39], [26, 43], [26, 61], [26, 66], [26, 68], [26, 69], [26, 74], [26, 84], [26, 92], [26, 93], [27, 30], [27, 31], [27, 35], [27, 37], [27, 38], [27, 40], [27, 41], [27, 45], [27, 47], [27, 49], [27, 54], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [27, 63], [27, 70], [27, 72], [27, 75], [27, 77], [27, 80], [27, 83], [27, 86], [27, 88], [27, 92], [27, 93], [27, 94], [27, 95], [27, 98], [27, 99], [28, 31], [28, 32], [28, 33], [28, 34], [28, 38], [28, 39], [28, 41], [28, 46], [28, 49], [28, 59], [28, 64], [28, 65], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 75], [28, 78], [28, 80], [28, 84], [28, 85], [28, 88], [28, 89], [28, 96], [28, 97], [28, 99], [29, 30], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 39], [29, 45], [29, 47], [29, 48], [29, 52], [29, 60], [29, 70], [29, 75], [29, 79], [29, 83], [29, 87], [29, 88], [29, 89], [29, 90], [29, 92], [29, 94], [29, 95], [29, 96], [29, 99], [30, 33], [30, 37], [30, 40], [30, 41], [30, 43], [30, 45], [30, 50], [30, 53], [30, 54], [30, 58], [30, 59], [30, 64], [30, 68], [30, 69], [30, 84], [30, 85], [30, 87], [30, 93], [30, 97], [30, 98], [30, 99], [31, 44], [31, 47], [31, 48], [31, 51], [31, 52], [31, 54], [31, 59], [31, 60], [31, 66], [31, 68], [31, 72], [31, 74], [31, 75], [31, 80], [31, 82], [31, 83], [31, 87], [31, 88], [31, 92], [31, 94], [31, 98], [32, 38], [32, 39], [32, 44], [32, 49], [32, 50], [32, 57], [32, 59], [32, 69], [32, 72], [32, 73], [32, 74], [32, 82], [32, 83], [32, 87], [32, 93], [32, 96], [32, 97], [32, 98], [33, 38], [33, 41], [33, 43], [33, 45], [33, 47], [33, 49], [33, 52], [33, 54], [33, 56], [33, 65], [33, 67], [33, 69], [33, 71], [33, 76], [33, 80], [33, 85], [33, 87], [33, 89], [33, 90], [33, 94], [33, 96], [33, 99], [34, 37], [34, 39], [34, 42], [34, 43], [34, 50], [34, 53], [34, 55], [34, 57], [34, 58], [34, 59], [34, 61], [34, 69], [34, 72], [34, 76], [34, 79], [34, 83], [34, 84], [34, 90], [34, 92], [34, 96], [34, 97], [34, 98], [35, 37], [35, 38], [35, 39], [35, 40], [35, 44], [35, 47], [35, 49], [35, 50], [35, 61], [35, 71], [35, 72], [35, 74], [35, 75], [35, 81], [35, 84], [35, 88], [35, 98], [35, 99], [36, 37], [36, 39], [36, 46], [36, 56], [36, 58], [36, 64], [36, 71], [36, 72], [36, 73], [36, 74], [36, 77], [36, 79], [36, 82], [36, 85], [36, 86], [36, 88], [36, 89], [36, 92], [36, 94], [36, 96], [37, 42], [37, 43], [37, 44], [37, 45], [37, 47], [37, 53], [37, 57], [37, 58], [37, 59], [37, 60], [37, 61], [37, 64], [37, 68], [37, 72], [37, 74], [37, 75], [37, 76], [37, 77], [37, 81], [37, 89], [37, 90], [37, 93], [37, 95], [37, 96], [37, 99], [38, 42], [38, 43], [38, 46], [38, 47], [38, 51], [38, 53], [38, 57], [38, 59], [38, 60], [38, 61], [38, 64], [38, 67], [38, 69], [38, 70], [38, 75], [38, 80], [38, 81], [38, 82], [38, 84], [38, 85], [38, 87], [38, 88], [38, 92], [39, 40], [39, 45], [39, 49], [39, 53], [39, 56], [39, 58], [39, 59], [39, 61], [39, 62], [39, 63], [39, 64], [39, 66], [39, 75], [39, 88], [39, 89], [39, 90], [39, 95], [39, 96], [39, 98], [39, 99], [40, 41], [40, 46], [40, 50], [40, 59], [40, 63], [40, 65], [40, 67], [40, 70], [40, 75], [40, 77], [40, 80], [40, 81], [40, 85], [40, 92], [40, 96], [40, 98], [41, 54], [41, 56], [41, 58], [41, 64], [41, 66], [41, 68], [41, 70], [41, 72], [41, 75], [41, 76], [41, 84], [41, 90], [41, 93], [41, 99], [42, 43], [42, 46], [42, 61], [42, 68], [42, 75], [42, 79], [42, 81], [42, 92], [42, 97], [42, 98], [43, 46], [43, 53], [43, 62], [43, 63], [43, 64], [43, 68], [43, 70], [43, 81], [43, 83], [43, 85], [43, 88], [43, 89], [44, 45], [44, 46], [44, 48], [44, 54], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 66], [44, 67], [44, 68], [44, 81], [44, 86], [44, 87], [44, 90], [44, 93], [44, 96], [45, 46], [45, 48], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 79], [45, 80], [45, 81], [45, 84], [45, 86], [45, 89], [45, 90], [45, 96], [46, 47], [46, 51], [46, 53], [46, 55], [46, 63], [46, 80], [46, 82], [46, 88], [46, 95], [46, 96], [47, 53], [47, 58], [47, 59], [47, 61], [47, 62], [47, 63], [47, 65], [47, 69], [47, 70], [47, 74], [47, 78], [47, 85], [47, 87], [47, 90], [47, 95], [47, 96], [47, 98], [48, 58], [48, 64], [48, 65], [48, 71], [48, 76], [48, 79], [48, 80], [48, 82], [48, 85], [48, 86], [48, 87], [48, 89], [48, 90], [48, 94], [49, 55], [49, 56], [49, 62], [49, 63], [49, 67], [49, 68], [49, 72], [49, 76], [49, 81], [49, 84], [49, 85], [49, 88], [49, 90], [49, 92], [50, 55], [50, 56], [50, 57], [50, 71], [50, 72], [50, 74], [50, 77], [50, 80], [50, 81], [50, 83], [50, 85], [50, 86], [50, 87], [50, 92], [51, 57], [51, 64], [51, 67], [51, 73], [51, 75], [51, 79], [51, 81], [51, 84], [51, 87], [51, 88], [51, 93], [51, 97], [51, 99], [52, 53], [52, 56], [52, 66], [52, 67], [52, 68], [52, 69], [52, 71], [52, 75], [52, 88], [52, 92], [53, 54], [53, 57], [53, 59], [53, 61], [53, 62], [53, 65], [53, 69], [53, 73], [53, 74], [53, 83], [53, 84], [53, 85], [53, 86], [53, 87], [53, 89], [53, 95], [53, 96], [53, 97], [54, 59], [54, 66], [54, 69], [54, 71], [54, 76], [54, 79], [54, 80], [54, 85], [54, 88], [54, 91], [54, 95], [54, 99], [55, 56], [55, 59], [55, 63], [55, 64], [55, 71], [55, 75], [55, 81], [55, 84], [55, 88], [55, 92], [55, 97], [56, 58], [56, 60], [56, 67], [56, 69], [56, 71], [56, 73], [56, 74], [56, 76], [56, 96], [56, 99], [57, 63], [57, 64], [57, 85], [57, 93], [57, 99], [58, 59], [58, 60], [58, 62], [58, 63], [58, 64], [58, 73], [58, 75], [58, 77], [58, 79], [58, 86], [58, 89], [58, 91], [58, 93], [58, 96], [58, 99], [59, 63], [59, 64], [59, 68], [59, 72], [59, 73], [59, 75], [59, 86], [59, 88], [59, 89], [59, 90], [59, 91], [59, 96], [59, 99], [60, 63], [60, 64], [60, 72], [60, 83], [60, 87], [60, 97], [61, 63], [61, 68], [61, 69], [61, 70], [61, 77], [61, 90], [61, 92], [61, 95], [61, 97], [62, 64], [62, 68], [62, 72], [62, 81], [62, 87], [62, 99], [63, 64], [63, 67], [63, 69], [63, 76], [63, 79], [63, 89], [63, 96], [63, 97], [64, 68], [64, 70], [64, 71], [64, 73], [64, 75], [64, 79], [64, 85], [64, 87], [64, 88], [64, 91], [64, 98], [65, 67], [65, 87], [65, 98], [66, 67], [66, 70], [66, 75], [66, 78], [66, 83], [66, 90], [66, 93], [67, 69], [67, 71], [67, 73], [67, 79], [67, 80], [67, 88], [67, 90], [67, 92], [67, 93], [67, 99], [68, 76], [68, 80], [68, 82], [68, 85], [68, 86], [68, 87], [68, 88], [68, 94], [68, 95], [69, 75], [69, 78], [69, 79], [69, 80], [69, 83], [69, 85], [69, 86], [69, 88], [69, 89], [69, 91], [69, 94], [69, 96], [69, 99], [70, 72], [70, 73], [70, 79], [70, 92], [70, 93], [70, 98], [71, 72], [71, 73], [71, 74], [71, 75], [71, 78], [71, 82], [71, 88], [71, 94], [71, 97], [72, 77], [72, 80], [72, 82], [72, 83], [72, 84], [72, 85], [72, 86], [72, 87], [72, 88], [72, 91], [73, 75], [73, 77], [73, 79], [73, 82], [73, 84], [73, 85], [73, 87], [73, 95], [74, 79], [74, 80], [74, 81], [74, 94], [74, 96], [74, 99], [75, 78], [75, 80], [75, 81], [75, 83], [75, 88], [75, 90], [75, 93], [75, 97], [75, 99], [76, 79], [76, 82], [76, 87], [76, 92], [76, 97], [76, 99], [77, 85], [77, 96], [77, 98], [78, 88], [78, 98], [78, 99], [79, 84], [79, 86], [79, 89], [79, 96], [79, 97], [79, 98], [80, 82], [81, 87], [81, 95], [81, 98], [82, 86], [82, 92], [82, 94], [82, 99], [83, 84], [83, 86], [83, 91], [83, 92], [83, 95], [84, 86], [84, 90], [84, 91], [84, 93], [84, 94], [84, 95], [84, 99], [85, 89], [85, 91], [85, 96], [86, 93], [87, 90], [87, 96], [87, 98], [88, 94], [88, 99], [89, 93], [89, 96], [89, 98], [90, 98], [91, 92], [91, 93], [91, 99], [92, 93], [92, 94], [92, 99], [93, 95], [95, 96], [95, 97], [97, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s4/solution/solve.sh b/tasks/construct-nppc-independent-set-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..260c44d5682151ffa7d54b3056551734a16e7d85 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [0, 1, 7, 8, 10, 20, 23, 25, 26, 30, 32, 35, 42, 51, 52, 55, 60, 62, 65, 70, 76, 77, 78, 80, 86, 89, 90, 91, 94, 95]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l6-s4/tests/check.py b/tasks/construct-nppc-independent-set-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s4/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l6-s4/tests/instance.json b/tasks/construct-nppc-independent-set-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2cc41c3288dcbeae35b3ce3f48cf3193ff76b977 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 30, "edges": [[0, 4], [0, 9], [0, 12], [0, 14], [0, 17], [0, 27], [0, 31], [0, 33], [0, 46], [0, 47], [0, 56], [0, 57], [0, 58], [0, 68], [0, 72], [0, 73], [0, 74], [0, 75], [0, 84], [0, 85], [0, 92], [1, 3], [1, 4], [1, 5], [1, 11], [1, 16], [1, 36], [1, 37], [1, 46], [1, 56], [1, 57], [1, 58], [1, 64], [1, 68], [1, 79], [1, 83], [1, 92], [1, 96], [1, 97], [2, 4], [2, 5], [2, 17], [2, 25], [2, 26], [2, 31], [2, 32], [2, 34], [2, 36], [2, 39], [2, 42], [2, 43], [2, 44], [2, 46], [2, 49], [2, 50], [2, 52], [2, 56], [2, 57], [2, 62], [2, 66], [2, 69], [2, 73], [2, 77], [2, 78], [2, 89], [2, 90], [2, 95], [2, 96], [2, 98], [2, 99], [3, 5], [3, 6], [3, 10], [3, 15], [3, 26], [3, 31], [3, 36], [3, 39], [3, 40], [3, 41], [3, 47], [3, 50], [3, 51], [3, 57], [3, 58], [3, 63], [3, 65], [3, 69], [3, 72], [3, 77], [3, 80], [3, 82], [3, 83], [3, 86], [3, 88], [3, 89], [3, 90], [3, 95], [3, 97], [4, 5], [4, 6], [4, 13], [4, 14], [4, 19], [4, 20], [4, 23], [4, 24], [4, 25], [4, 27], [4, 28], [4, 37], [4, 40], [4, 45], [4, 50], [4, 54], [4, 55], [4, 58], [4, 59], [4, 64], [4, 67], [4, 71], [4, 72], [4, 80], [4, 81], [4, 83], [4, 85], [4, 91], [4, 92], [4, 96], [4, 97], [5, 7], [5, 11], [5, 13], [5, 15], [5, 18], [5, 22], [5, 24], [5, 25], [5, 29], [5, 31], [5, 36], [5, 40], [5, 41], [5, 45], [5, 51], [5, 56], [5, 62], [5, 63], [5, 68], [5, 72], [5, 77], [5, 87], [5, 89], [5, 90], [6, 16], [6, 18], [6, 24], [6, 26], [6, 27], [6, 29], [6, 30], [6, 31], [6, 40], [6, 42], [6, 44], [6, 48], [6, 54], [6, 58], [6, 63], [6, 65], [6, 67], [6, 70], [6, 72], [6, 76], [6, 78], [6, 79], [6, 84], [6, 87], [6, 91], [6, 92], [6, 98], [7, 11], [7, 12], [7, 16], [7, 19], [7, 24], [7, 44], [7, 53], [7, 58], [7, 63], [7, 66], [7, 68], [7, 69], [7, 92], [7, 99], [8, 13], [8, 24], [8, 27], [8, 28], [8, 33], [8, 39], [8, 40], [8, 44], [8, 48], [8, 53], [8, 58], [8, 59], [8, 61], [8, 63], [8, 75], [8, 79], [8, 85], [8, 87], [8, 88], [8, 98], [9, 16], [9, 17], [9, 25], [9, 26], [9, 27], [9, 28], [9, 36], [9, 38], [9, 45], [9, 47], [9, 48], [9, 58], [9, 59], [9, 61], [9, 63], [9, 64], [9, 65], [9, 77], [9, 78], [9, 83], [9, 88], [9, 91], [9, 93], [9, 96], [10, 12], [10, 16], [10, 18], [10, 19], [10, 28], [10, 33], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 53], [10, 56], [10, 63], [10, 67], [10, 69], [10, 72], [10, 81], [10, 88], [10, 98], [10, 99], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 24], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 46], [11, 49], [11, 50], [11, 54], [11, 56], [11, 60], [11, 61], [11, 63], [11, 65], [11, 70], [11, 77], [11, 83], [11, 86], [11, 89], [11, 92], [11, 95], [11, 98], [12, 13], [12, 14], [12, 18], [12, 21], [12, 22], [12, 25], [12, 28], [12, 36], [12, 37], [12, 39], [12, 40], [12, 42], [12, 43], [12, 45], [12, 49], [12, 53], [12, 66], [12, 69], [12, 70], [12, 73], [12, 74], [12, 76], [12, 78], [12, 80], [12, 81], [12, 82], [12, 88], [12, 92], [12, 95], [12, 97], [13, 23], [13, 24], [13, 26], [13, 28], [13, 30], [13, 32], [13, 33], [13, 35], [13, 38], [13, 41], [13, 42], [13, 43], [13, 46], [13, 56], [13, 58], [13, 61], [13, 62], [13, 64], [13, 68], [13, 77], [13, 80], [13, 85], [13, 86], [13, 87], [13, 91], [13, 92], [13, 93], [13, 95], [13, 96], [13, 98], [14, 15], [14, 16], [14, 22], [14, 23], [14, 24], [14, 26], [14, 30], [14, 34], [14, 36], [14, 37], [14, 39], [14, 41], [14, 42], [14, 45], [14, 47], [14, 49], [14, 50], [14, 51], [14, 52], [14, 57], [14, 59], [14, 61], [14, 62], [14, 64], [14, 66], [14, 69], [14, 70], [14, 78], [14, 81], [14, 82], [14, 95], [15, 22], [15, 23], [15, 24], [15, 30], [15, 32], [15, 34], [15, 38], [15, 40], [15, 42], [15, 43], [15, 46], [15, 47], [15, 52], [15, 59], [15, 61], [15, 62], [15, 63], [15, 64], [15, 68], [15, 70], [15, 71], [15, 78], [15, 79], [15, 85], [15, 86], [15, 87], [15, 88], [15, 90], [15, 91], [15, 94], [15, 98], [15, 99], [16, 17], [16, 18], [16, 20], [16, 21], [16, 23], [16, 26], [16, 27], [16, 31], [16, 33], [16, 34], [16, 36], [16, 38], [16, 42], [16, 44], [16, 47], [16, 48], [16, 49], [16, 51], [16, 53], [16, 54], [16, 57], [16, 66], [16, 67], [16, 74], [16, 79], [16, 80], [16, 86], [16, 89], [16, 93], [16, 98], [17, 19], [17, 26], [17, 27], [17, 31], [17, 35], [17, 36], [17, 39], [17, 40], [17, 43], [17, 45], [17, 50], [17, 51], [17, 52], [17, 54], [17, 55], [17, 56], [17, 64], [17, 65], [17, 69], [17, 73], [17, 76], [17, 77], [17, 78], [17, 79], [17, 86], [17, 88], [17, 96], [17, 97], [17, 99], [18, 19], [18, 26], [18, 29], [18, 30], [18, 35], [18, 41], [18, 42], [18, 44], [18, 47], [18, 49], [18, 54], [18, 56], [18, 65], [18, 67], [18, 73], [18, 74], [18, 75], [18, 79], [18, 81], [19, 20], [19, 25], [19, 26], [19, 27], [19, 29], [19, 42], [19, 43], [19, 46], [19, 56], [19, 57], [19, 61], [19, 64], [19, 68], [19, 69], [19, 71], [19, 74], [19, 75], [19, 76], [19, 78], [19, 80], [19, 88], [19, 89], [19, 92], [19, 95], [20, 22], [20, 29], [20, 36], [20, 37], [20, 46], [20, 53], [20, 59], [20, 61], [20, 64], [20, 67], [20, 69], [20, 73], [20, 75], [20, 81], [20, 83], [20, 85], [20, 88], [20, 92], [20, 97], [21, 25], [21, 28], [21, 35], [21, 37], [21, 41], [21, 42], [21, 47], [21, 51], [21, 57], [21, 68], [21, 74], [21, 78], [21, 80], [21, 87], [21, 92], [21, 96], [22, 24], [22, 26], [22, 27], [22, 44], [22, 45], [22, 46], [22, 48], [22, 51], [22, 60], [22, 64], [22, 67], [22, 68], [22, 69], [22, 74], [22, 77], [22, 88], [22, 94], [22, 95], [23, 28], [23, 31], [23, 33], [23, 34], [23, 36], [23, 41], [23, 44], [23, 50], [23, 53], [23, 56], [23, 58], [23, 72], [23, 75], [23, 82], [23, 93], [24, 29], [24, 36], [24, 37], [24, 38], [24, 41], [24, 43], [24, 44], [24, 45], [24, 51], [24, 58], [24, 59], [24, 64], [24, 77], [24, 82], [24, 85], [24, 98], [24, 99], [25, 27], [25, 36], [25, 40], [25, 41], [25, 43], [25, 45], [25, 47], [25, 50], [25, 53], [25, 58], [25, 61], [25, 64], [25, 68], [25, 69], [25, 79], [25, 88], [25, 99], [26, 27], [26, 28], [26, 33], [26, 37], [26, 39], [26, 43], [26, 61], [26, 66], [26, 68], [26, 69], [26, 74], [26, 84], [26, 92], [26, 93], [27, 30], [27, 31], [27, 35], [27, 37], [27, 38], [27, 40], [27, 41], [27, 45], [27, 47], [27, 49], [27, 54], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [27, 63], [27, 70], [27, 72], [27, 75], [27, 77], [27, 80], [27, 83], [27, 86], [27, 88], [27, 92], [27, 93], [27, 94], [27, 95], [27, 98], [27, 99], [28, 31], [28, 32], [28, 33], [28, 34], [28, 38], [28, 39], [28, 41], [28, 46], [28, 49], [28, 59], [28, 64], [28, 65], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 75], [28, 78], [28, 80], [28, 84], [28, 85], [28, 88], [28, 89], [28, 96], [28, 97], [28, 99], [29, 30], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 39], [29, 45], [29, 47], [29, 48], [29, 52], [29, 60], [29, 70], [29, 75], [29, 79], [29, 83], [29, 87], [29, 88], [29, 89], [29, 90], [29, 92], [29, 94], [29, 95], [29, 96], [29, 99], [30, 33], [30, 37], [30, 40], [30, 41], [30, 43], [30, 45], [30, 50], [30, 53], [30, 54], [30, 58], [30, 59], [30, 64], [30, 68], [30, 69], [30, 84], [30, 85], [30, 87], [30, 93], [30, 97], [30, 98], [30, 99], [31, 44], [31, 47], [31, 48], [31, 51], [31, 52], [31, 54], [31, 59], [31, 60], [31, 66], [31, 68], [31, 72], [31, 74], [31, 75], [31, 80], [31, 82], [31, 83], [31, 87], [31, 88], [31, 92], [31, 94], [31, 98], [32, 38], [32, 39], [32, 44], [32, 49], [32, 50], [32, 57], [32, 59], [32, 69], [32, 72], [32, 73], [32, 74], [32, 82], [32, 83], [32, 87], [32, 93], [32, 96], [32, 97], [32, 98], [33, 38], [33, 41], [33, 43], [33, 45], [33, 47], [33, 49], [33, 52], [33, 54], [33, 56], [33, 65], [33, 67], [33, 69], [33, 71], [33, 76], [33, 80], [33, 85], [33, 87], [33, 89], [33, 90], [33, 94], [33, 96], [33, 99], [34, 37], [34, 39], [34, 42], [34, 43], [34, 50], [34, 53], [34, 55], [34, 57], [34, 58], [34, 59], [34, 61], [34, 69], [34, 72], [34, 76], [34, 79], [34, 83], [34, 84], [34, 90], [34, 92], [34, 96], [34, 97], [34, 98], [35, 37], [35, 38], [35, 39], [35, 40], [35, 44], [35, 47], [35, 49], [35, 50], [35, 61], [35, 71], [35, 72], [35, 74], [35, 75], [35, 81], [35, 84], [35, 88], [35, 98], [35, 99], [36, 37], [36, 39], [36, 46], [36, 56], [36, 58], [36, 64], [36, 71], [36, 72], [36, 73], [36, 74], [36, 77], [36, 79], [36, 82], [36, 85], [36, 86], [36, 88], [36, 89], [36, 92], [36, 94], [36, 96], [37, 42], [37, 43], [37, 44], [37, 45], [37, 47], [37, 53], [37, 57], [37, 58], [37, 59], [37, 60], [37, 61], [37, 64], [37, 68], [37, 72], [37, 74], [37, 75], [37, 76], [37, 77], [37, 81], [37, 89], [37, 90], [37, 93], [37, 95], [37, 96], [37, 99], [38, 42], [38, 43], [38, 46], [38, 47], [38, 51], [38, 53], [38, 57], [38, 59], [38, 60], [38, 61], [38, 64], [38, 67], [38, 69], [38, 70], [38, 75], [38, 80], [38, 81], [38, 82], [38, 84], [38, 85], [38, 87], [38, 88], [38, 92], [39, 40], [39, 45], [39, 49], [39, 53], [39, 56], [39, 58], [39, 59], [39, 61], [39, 62], [39, 63], [39, 64], [39, 66], [39, 75], [39, 88], [39, 89], [39, 90], [39, 95], [39, 96], [39, 98], [39, 99], [40, 41], [40, 46], [40, 50], [40, 59], [40, 63], [40, 65], [40, 67], [40, 70], [40, 75], [40, 77], [40, 80], [40, 81], [40, 85], [40, 92], [40, 96], [40, 98], [41, 54], [41, 56], [41, 58], [41, 64], [41, 66], [41, 68], [41, 70], [41, 72], [41, 75], [41, 76], [41, 84], [41, 90], [41, 93], [41, 99], [42, 43], [42, 46], [42, 61], [42, 68], [42, 75], [42, 79], [42, 81], [42, 92], [42, 97], [42, 98], [43, 46], [43, 53], [43, 62], [43, 63], [43, 64], [43, 68], [43, 70], [43, 81], [43, 83], [43, 85], [43, 88], [43, 89], [44, 45], [44, 46], [44, 48], [44, 54], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 66], [44, 67], [44, 68], [44, 81], [44, 86], [44, 87], [44, 90], [44, 93], [44, 96], [45, 46], [45, 48], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 79], [45, 80], [45, 81], [45, 84], [45, 86], [45, 89], [45, 90], [45, 96], [46, 47], [46, 51], [46, 53], [46, 55], [46, 63], [46, 80], [46, 82], [46, 88], [46, 95], [46, 96], [47, 53], [47, 58], [47, 59], [47, 61], [47, 62], [47, 63], [47, 65], [47, 69], [47, 70], [47, 74], [47, 78], [47, 85], [47, 87], [47, 90], [47, 95], [47, 96], [47, 98], [48, 58], [48, 64], [48, 65], [48, 71], [48, 76], [48, 79], [48, 80], [48, 82], [48, 85], [48, 86], [48, 87], [48, 89], [48, 90], [48, 94], [49, 55], [49, 56], [49, 62], [49, 63], [49, 67], [49, 68], [49, 72], [49, 76], [49, 81], [49, 84], [49, 85], [49, 88], [49, 90], [49, 92], [50, 55], [50, 56], [50, 57], [50, 71], [50, 72], [50, 74], [50, 77], [50, 80], [50, 81], [50, 83], [50, 85], [50, 86], [50, 87], [50, 92], [51, 57], [51, 64], [51, 67], [51, 73], [51, 75], [51, 79], [51, 81], [51, 84], [51, 87], [51, 88], [51, 93], [51, 97], [51, 99], [52, 53], [52, 56], [52, 66], [52, 67], [52, 68], [52, 69], [52, 71], [52, 75], [52, 88], [52, 92], [53, 54], [53, 57], [53, 59], [53, 61], [53, 62], [53, 65], [53, 69], [53, 73], [53, 74], [53, 83], [53, 84], [53, 85], [53, 86], [53, 87], [53, 89], [53, 95], [53, 96], [53, 97], [54, 59], [54, 66], [54, 69], [54, 71], [54, 76], [54, 79], [54, 80], [54, 85], [54, 88], [54, 91], [54, 95], [54, 99], [55, 56], [55, 59], [55, 63], [55, 64], [55, 71], [55, 75], [55, 81], [55, 84], [55, 88], [55, 92], [55, 97], [56, 58], [56, 60], [56, 67], [56, 69], [56, 71], [56, 73], [56, 74], [56, 76], [56, 96], [56, 99], [57, 63], [57, 64], [57, 85], [57, 93], [57, 99], [58, 59], [58, 60], [58, 62], [58, 63], [58, 64], [58, 73], [58, 75], [58, 77], [58, 79], [58, 86], [58, 89], [58, 91], [58, 93], [58, 96], [58, 99], [59, 63], [59, 64], [59, 68], [59, 72], [59, 73], [59, 75], [59, 86], [59, 88], [59, 89], [59, 90], [59, 91], [59, 96], [59, 99], [60, 63], [60, 64], [60, 72], [60, 83], [60, 87], [60, 97], [61, 63], [61, 68], [61, 69], [61, 70], [61, 77], [61, 90], [61, 92], [61, 95], [61, 97], [62, 64], [62, 68], [62, 72], [62, 81], [62, 87], [62, 99], [63, 64], [63, 67], [63, 69], [63, 76], [63, 79], [63, 89], [63, 96], [63, 97], [64, 68], [64, 70], [64, 71], [64, 73], [64, 75], [64, 79], [64, 85], [64, 87], [64, 88], [64, 91], [64, 98], [65, 67], [65, 87], [65, 98], [66, 67], [66, 70], [66, 75], [66, 78], [66, 83], [66, 90], [66, 93], [67, 69], [67, 71], [67, 73], [67, 79], [67, 80], [67, 88], [67, 90], [67, 92], [67, 93], [67, 99], [68, 76], [68, 80], [68, 82], [68, 85], [68, 86], [68, 87], [68, 88], [68, 94], [68, 95], [69, 75], [69, 78], [69, 79], [69, 80], [69, 83], [69, 85], [69, 86], [69, 88], [69, 89], [69, 91], [69, 94], [69, 96], [69, 99], [70, 72], [70, 73], [70, 79], [70, 92], [70, 93], [70, 98], [71, 72], [71, 73], [71, 74], [71, 75], [71, 78], [71, 82], [71, 88], [71, 94], [71, 97], [72, 77], [72, 80], [72, 82], [72, 83], [72, 84], [72, 85], [72, 86], [72, 87], [72, 88], [72, 91], [73, 75], [73, 77], [73, 79], [73, 82], [73, 84], [73, 85], [73, 87], [73, 95], [74, 79], [74, 80], [74, 81], [74, 94], [74, 96], [74, 99], [75, 78], [75, 80], [75, 81], [75, 83], [75, 88], [75, 90], [75, 93], [75, 97], [75, 99], [76, 79], [76, 82], [76, 87], [76, 92], [76, 97], [76, 99], [77, 85], [77, 96], [77, 98], [78, 88], [78, 98], [78, 99], [79, 84], [79, 86], [79, 89], [79, 96], [79, 97], [79, 98], [80, 82], [81, 87], [81, 95], [81, 98], [82, 86], [82, 92], [82, 94], [82, 99], [83, 84], [83, 86], [83, 91], [83, 92], [83, 95], [84, 86], [84, 90], [84, 91], [84, 93], [84, 94], [84, 95], [84, 99], [85, 89], [85, 91], [85, 96], [86, 93], [87, 90], [87, 96], [87, 98], [88, 94], [88, 99], [89, 93], [89, 96], [89, 98], [90, 98], [91, 92], [91, 93], [91, 99], [92, 93], [92, 94], [92, 99], [93, 95], [95, 96], [95, 97], [97, 99]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l6-s4/tests/run.py b/tasks/construct-nppc-independent-set-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l6-s4/tests/test.sh b/tasks/construct-nppc-independent-set-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l1-s1/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l1-s1/environment/instance.json b/tasks/construct-nppc-vertex-cover-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..76288ba803fdc6f39c89b5272964ab2f3d225f1f --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 3], [0, 4], [0, 5], [1, 4], [1, 7], [2, 4], [3, 4], [4, 5], [4, 6], [4, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s1/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f51f29830b0cd9cd24b5d6e9ebfb1cf1af349a3 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [0, 1, 4]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l1-s1/tests/check.py b/tasks/construct-nppc-vertex-cover-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l1-s1/tests/instance.json b/tasks/construct-nppc-vertex-cover-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..76288ba803fdc6f39c89b5272964ab2f3d225f1f --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 3], [0, 4], [0, 5], [1, 4], [1, 7], [2, 4], [3, 4], [4, 5], [4, 6], [4, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s1/tests/run.py b/tasks/construct-nppc-vertex-cover-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l1-s1/tests/test.sh b/tasks/construct-nppc-vertex-cover-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l1-s6/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l1-s6/environment/instance.json b/tasks/construct-nppc-vertex-cover-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1082879a030dfe867e25d4976ba5a0cd586aec4d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 2], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 6], [3, 4], [4, 5], [4, 6], [4, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s6/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3cd92f46e6f5e6a61e31950f8b15491e3764ab6d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [2, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l1-s6/tests/check.py b/tasks/construct-nppc-vertex-cover-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l1-s6/tests/instance.json b/tasks/construct-nppc-vertex-cover-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1082879a030dfe867e25d4976ba5a0cd586aec4d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 3, "edges": [[0, 2], [1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [2, 6], [3, 4], [4, 5], [4, 6], [4, 7]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l1-s6/tests/run.py b/tasks/construct-nppc-vertex-cover-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l1-s6/tests/test.sh b/tasks/construct-nppc-vertex-cover-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/environment/instance.json b/tasks/construct-nppc-vertex-cover-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b03eb3eb3c00dc3ab8d8e90bc5cc626154a1fb72 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "k": 40, "edges": [[0, 5], [0, 8], [0, 9], [0, 19], [0, 21], [0, 37], [0, 40], [0, 41], [0, 46], [0, 49], [0, 50], [0, 53], [0, 58], [0, 61], [0, 64], [0, 67], [0, 71], [0, 76], [0, 77], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 11], [1, 12], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 26], [1, 29], [1, 30], [1, 33], [1, 35], [1, 36], [1, 37], [1, 40], [1, 41], [1, 42], [1, 43], [1, 45], [1, 46], [1, 47], [1, 48], [1, 50], [1, 51], [1, 56], [1, 57], [1, 58], [1, 60], [1, 61], [1, 62], [1, 64], [1, 66], [1, 67], [1, 69], [1, 71], [1, 76], [1, 77], [1, 78], [1, 79], [2, 8], [2, 12], [2, 13], [2, 16], [2, 18], [2, 22], [2, 24], [2, 29], [2, 40], [2, 41], [2, 46], [2, 50], [2, 53], [2, 58], [2, 61], [2, 64], [2, 67], [2, 72], [2, 76], [2, 77], [2, 79], [3, 7], [3, 16], [3, 19], [3, 21], [3, 29], [3, 35], [3, 36], [3, 40], [3, 45], [3, 56], [3, 67], [3, 69], [3, 76], [4, 5], [4, 8], [4, 9], [4, 12], [4, 13], [4, 16], [4, 19], [4, 22], [4, 30], [4, 31], [4, 41], [4, 50], [4, 53], [4, 56], [4, 61], [4, 76], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [5, 25], [5, 26], [5, 29], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 40], [5, 41], [5, 43], [5, 45], [5, 46], [5, 48], [5, 49], [5, 51], [5, 54], [5, 55], [5, 56], [5, 58], [5, 60], [5, 61], [5, 63], [5, 64], [5, 67], [5, 69], [5, 71], [5, 72], [5, 73], [5, 74], [5, 76], [5, 77], [5, 79], [6, 7], [6, 8], [6, 9], [6, 12], [6, 19], [6, 21], [6, 22], [6, 24], [6, 29], [6, 30], [6, 31], [6, 35], [6, 40], [6, 41], [6, 45], [6, 50], [6, 53], [6, 54], [6, 58], [6, 61], [6, 69], [7, 8], [7, 10], [7, 12], [7, 14], [7, 16], [7, 17], [7, 18], [7, 19], [7, 22], [7, 25], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 36], [7, 41], [7, 43], [7, 45], [7, 46], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 62], [7, 65], [7, 67], [7, 68], [7, 69], [7, 71], [7, 72], [7, 74], [7, 75], [7, 76], [7, 77], [7, 79], [8, 9], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 19], [8, 20], [8, 24], [8, 25], [8, 27], [8, 32], [8, 33], [8, 35], [8, 37], [8, 39], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 45], [8, 47], [8, 49], [8, 50], [8, 51], [8, 53], [8, 55], [8, 58], [8, 59], [8, 61], [8, 65], [8, 67], [8, 69], [8, 70], [8, 71], [8, 72], [8, 73], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 79], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 41], [9, 45], [9, 46], [9, 47], [9, 48], [9, 50], [9, 52], [9, 53], [9, 54], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 61], [9, 63], [9, 65], [9, 66], [9, 67], [9, 69], [9, 70], [9, 71], [9, 72], [9, 73], [9, 75], [9, 77], [9, 79], [10, 19], [10, 30], [10, 31], [10, 35], [10, 36], [10, 40], [10, 41], [10, 43], [10, 50], [10, 53], [10, 67], [10, 69], [10, 72], [10, 76], [10, 77], [10, 79], [11, 19], [11, 35], [11, 36], [11, 37], [11, 40], [11, 45], [11, 50], [11, 56], [11, 58], [11, 59], [11, 61], [11, 67], [11, 72], [11, 76], [11, 77], [12, 13], [12, 16], [12, 19], [12, 20], [12, 21], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [12, 30], [12, 31], [12, 33], [12, 34], [12, 36], [12, 37], [12, 39], [12, 41], [12, 44], [12, 45], [12, 48], [12, 49], [12, 50], [12, 51], [12, 53], [12, 54], [12, 55], [12, 56], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 64], [12, 65], [12, 66], [12, 67], [12, 72], [12, 73], [12, 75], [12, 76], [12, 77], [12, 78], [12, 79], [13, 14], [13, 15], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 27], [13, 28], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 36], [13, 37], [13, 40], [13, 41], [13, 42], [13, 43], [13, 45], [13, 46], [13, 52], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 64], [13, 66], [13, 67], [13, 68], [13, 70], [13, 71], [13, 72], [13, 73], [13, 75], [13, 76], [13, 77], [13, 78], [13, 79], [14, 18], [14, 21], [14, 24], [14, 29], [14, 30], [14, 31], [14, 37], [14, 49], [14, 50], [14, 53], [14, 58], [14, 59], [14, 69], [14, 72], [14, 76], [15, 16], [15, 18], [15, 19], [15, 22], [15, 24], [15, 30], [15, 35], [15, 36], [15, 37], [15, 40], [15, 45], [15, 49], [15, 53], [15, 58], [15, 61], [15, 64], [15, 67], [15, 69], [15, 77], [15, 79], [16, 17], [16, 19], [16, 20], [16, 22], [16, 23], [16, 24], [16, 28], [16, 30], [16, 31], [16, 34], [16, 35], [16, 36], [16, 37], [16, 40], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 48], [16, 50], [16, 52], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 61], [16, 63], [16, 64], [16, 67], [16, 69], [16, 71], [16, 77], [16, 79], [17, 22], [17, 31], [17, 35], [17, 37], [17, 41], [17, 43], [17, 46], [17, 49], [17, 50], [17, 54], [17, 56], [17, 58], [17, 59], [17, 61], [17, 69], [17, 71], [17, 72], [17, 76], [17, 77], [18, 19], [18, 21], [18, 22], [18, 24], [18, 29], [18, 30], [18, 31], [18, 32], [18, 34], [18, 35], [18, 36], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 46], [18, 47], [18, 49], [18, 50], [18, 53], [18, 54], [18, 55], [18, 56], [18, 57], [18, 59], [18, 60], [18, 62], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 71], [18, 73], [18, 74], [18, 75], [18, 76], [18, 77], [18, 79], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 29], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 39], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 48], [19, 49], [19, 50], [19, 51], [19, 52], [19, 56], [19, 61], [19, 62], [19, 64], [19, 67], [19, 69], [19, 70], [19, 71], [19, 72], [19, 74], [19, 76], [19, 77], [19, 78], [19, 79], [20, 21], [20, 30], [20, 31], [20, 36], [20, 37], [20, 40], [20, 41], [20, 45], [20, 46], [20, 50], [20, 64], [20, 67], [20, 69], [20, 76], [20, 77], [20, 79], [21, 22], [21, 24], [21, 27], [21, 28], [21, 31], [21, 33], [21, 36], [21, 38], [21, 41], [21, 43], [21, 46], [21, 47], [21, 50], [21, 53], [21, 54], [21, 55], [21, 56], [21, 58], [21, 59], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 69], [21, 70], [21, 71], [21, 72], [21, 73], [21, 76], [21, 77], [21, 78], [21, 79], [22, 23], [22, 24], [22, 27], [22, 28], [22, 30], [22, 31], [22, 32], [22, 35], [22, 36], [22, 37], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 46], [22, 48], [22, 49], [22, 50], [22, 51], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [22, 59], [22, 61], [22, 62], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 71], [22, 72], [22, 74], [22, 77], [23, 31], [23, 35], [23, 36], [23, 37], [23, 46], [23, 49], [23, 53], [23, 54], [23, 64], [23, 69], [23, 71], [23, 77], [23, 79], [24, 26], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 37], [24, 40], [24, 42], [24, 43], [24, 44], [24, 45], [24, 46], [24, 48], [24, 49], [24, 50], [24, 52], [24, 53], [24, 54], [24, 56], [24, 57], [24, 58], [24, 59], [24, 61], [24, 62], [24, 66], [24, 68], [24, 70], [24, 72], [24, 75], [24, 76], [24, 77], [24, 79], [25, 29], [25, 35], [25, 36], [25, 37], [25, 40], [25, 41], [25, 43], [25, 45], [25, 49], [25, 50], [25, 53], [25, 58], [25, 59], [25, 67], [25, 72], [25, 77], [26, 29], [26, 30], [26, 37], [26, 41], [26, 49], [26, 50], [26, 54], [26, 56], [26, 58], [26, 59], [26, 67], [26, 69], [26, 72], [26, 77], [26, 79], [27, 29], [27, 35], [27, 36], [27, 45], [27, 46], [27, 50], [27, 58], [27, 59], [27, 61], [27, 64], [27, 67], [27, 69], [27, 71], [27, 77], [28, 31], [28, 36], [28, 37], [28, 40], [28, 41], [28, 49], [28, 50], [28, 58], [28, 61], [28, 67], [28, 69], [28, 71], [28, 76], [28, 79], [29, 32], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 43], [29, 46], [29, 47], [29, 48], [29, 49], [29, 50], [29, 51], [29, 52], [29, 53], [29, 54], [29, 56], [29, 57], [29, 58], [29, 59], [29, 60], [29, 62], [29, 63], [29, 64], [29, 65], [29, 67], [29, 69], [29, 70], [29, 71], [29, 72], [29, 75], [29, 76], [29, 77], [29, 78], [29, 79], [30, 32], [30, 33], [30, 34], [30, 35], [30, 38], [30, 40], [30, 43], [30, 45], [30, 49], [30, 51], [30, 53], [30, 55], [30, 58], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 67], [30, 68], [30, 69], [30, 71], [30, 73], [30, 74], [30, 75], [31, 36], [31, 37], [31, 38], [31, 39], [31, 40], [31, 41], [31, 43], [31, 44], [31, 45], [31, 46], [31, 49], [31, 52], [31, 53], [31, 54], [31, 56], [31, 59], [31, 60], [31, 62], [31, 64], [31, 65], [31, 66], [31, 68], [31, 70], [31, 71], [31, 72], [31, 76], [31, 77], [31, 78], [31, 79], [32, 36], [32, 37], [32, 43], [32, 50], [32, 53], [32, 54], [32, 58], [32, 59], [32, 61], [32, 67], [32, 69], [32, 77], [32, 79], [33, 41], [33, 43], [33, 50], [33, 58], [33, 64], [33, 69], [33, 72], [33, 76], [33, 77], [33, 79], [34, 36], [34, 37], [34, 41], [34, 45], [34, 50], [34, 53], [34, 54], [34, 59], [34, 64], [34, 67], [34, 69], [34, 71], [34, 72], [34, 77], [35, 36], [35, 37], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 45], [35, 46], [35, 49], [35, 50], [35, 51], [35, 52], [35, 53], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 61], [35, 62], [35, 65], [35, 67], [35, 68], [35, 69], [35, 70], [35, 72], [35, 73], [35, 74], [35, 76], [35, 79], [36, 37], [36, 40], [36, 41], [36, 43], [36, 44], [36, 45], [36, 46], [36, 48], [36, 49], [36, 50], [36, 54], [36, 55], [36, 56], [36, 58], [36, 59], [36, 60], [36, 63], [36, 64], [36, 66], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 73], [36, 74], [36, 75], [36, 76], [36, 77], [36, 78], [36, 79], [37, 42], [37, 43], [37, 45], [37, 47], [37, 48], [37, 49], [37, 50], [37, 51], [37, 53], [37, 55], [37, 56], [37, 59], [37, 60], [37, 62], [37, 67], [37, 68], [37, 69], [37, 71], [37, 73], [37, 76], [37, 79], [38, 40], [38, 41], [38, 46], [38, 53], [38, 56], [38, 58], [38, 59], [38, 61], [38, 64], [38, 67], [38, 76], [38, 77], [39, 41], [39, 43], [39, 53], [39, 54], [39, 58], [39, 61], [39, 76], [39, 77], [40, 41], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 64], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 74], [40, 76], [40, 77], [40, 79], [41, 44], [41, 46], [41, 48], [41, 50], [41, 51], [41, 53], [41, 54], [41, 56], [41, 58], [41, 59], [41, 60], [41, 61], [41, 63], [41, 64], [41, 65], [41, 66], [41, 69], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [41, 75], [41, 76], [41, 77], [41, 79], [42, 49], [42, 53], [42, 54], [42, 59], [42, 64], [42, 69], [43, 45], [43, 47], [43, 50], [43, 51], [43, 52], [43, 53], [43, 54], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 63], [43, 64], [43, 65], [43, 67], [43, 69], [43, 71], [43, 72], [43, 74], [43, 75], [43, 77], [44, 45], [44, 49], [44, 50], [44, 53], [44, 54], [44, 56], [44, 59], [44, 67], [44, 69], [44, 71], [44, 72], [45, 46], [45, 49], [45, 50], [45, 52], [45, 53], [45, 54], [45, 56], [45, 57], [45, 61], [45, 62], [45, 66], [45, 67], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [45, 75], [45, 76], [45, 77], [45, 79], [46, 47], [46, 49], [46, 50], [46, 51], [46, 52], [46, 53], [46, 54], [46, 56], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 64], [46, 66], [46, 67], [46, 68], [46, 69], [46, 71], [46, 72], [46, 74], [46, 76], [46, 77], [46, 79], [47, 49], [47, 54], [47, 58], [47, 59], [47, 61], [47, 64], [47, 69], [47, 71], [47, 72], [47, 76], [47, 79], [48, 50], [48, 53], [48, 56], [48, 58], [48, 61], [48, 71], [48, 76], [48, 79], [49, 50], [49, 52], [49, 54], [49, 56], [49, 58], [49, 59], [49, 60], [49, 61], [49, 64], [49, 65], [49, 69], [49, 70], [49, 72], [49, 75], [49, 76], [49, 77], [49, 78], [49, 79], [50, 55], [50, 56], [50, 58], [50, 59], [50, 61], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 73], [50, 75], [50, 76], [50, 77], [50, 78], [50, 79], [51, 54], [51, 58], [51, 59], [51, 64], [51, 67], [51, 71], [51, 72], [51, 76], [51, 77], [52, 54], [52, 58], [52, 61], [52, 64], [52, 67], [52, 71], [52, 72], [52, 77], [52, 79], [53, 55], [53, 56], [53, 58], [53, 59], [53, 60], [53, 64], [53, 66], [53, 67], [53, 69], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [53, 75], [53, 77], [53, 78], [53, 79], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 61], [54, 63], [54, 64], [54, 67], [54, 69], [54, 70], [54, 71], [54, 75], [54, 77], [54, 78], [54, 79], [55, 56], [55, 64], [55, 69], [55, 77], [55, 79], [56, 58], [56, 59], [56, 60], [56, 63], [56, 64], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 76], [56, 77], [56, 79], [57, 58], [57, 69], [57, 77], [58, 59], [58, 60], [58, 62], [58, 64], [58, 67], [58, 68], [58, 69], [58, 71], [58, 72], [58, 75], [58, 76], [58, 77], [58, 79], [59, 61], [59, 64], [59, 65], [59, 66], [59, 67], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 77], [60, 61], [60, 67], [60, 69], [60, 76], [60, 79], [61, 62], [61, 65], [61, 67], [61, 69], [61, 71], [61, 72], [61, 73], [61, 74], [61, 75], [61, 76], [61, 77], [61, 79], [62, 67], [62, 69], [62, 71], [62, 72], [62, 79], [63, 64], [63, 69], [63, 76], [63, 77], [64, 65], [64, 66], [64, 67], [64, 69], [64, 70], [64, 71], [64, 72], [64, 74], [64, 77], [64, 78], [64, 79], [65, 69], [65, 76], [65, 79], [66, 67], [66, 72], [66, 76], [66, 77], [67, 68], [67, 70], [67, 72], [67, 73], [67, 75], [67, 77], [68, 69], [68, 71], [68, 77], [69, 70], [69, 71], [69, 72], [69, 73], [69, 75], [69, 76], [69, 77], [69, 78], [69, 79], [70, 71], [70, 72], [70, 76], [71, 72], [71, 76], [71, 77], [71, 78], [71, 79], [72, 73], [72, 76], [72, 77], [72, 78], [72, 79], [73, 76], [73, 77], [73, 79], [74, 77], [74, 79], [76, 77], [76, 79], [78, 79]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d008fa98d48a3939a3a9fa248677b99e3c7a3206 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 5, 7, 8, 9, 12, 13, 16, 18, 19, 21, 22, 24, 29, 30, 31, 35, 36, 37, 40, 41, 43, 45, 46, 49, 50, 53, 54, 56, 58, 59, 61, 64, 67, 69, 71, 72, 76, 77, 79]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/tests/check.py b/tasks/construct-nppc-vertex-cover-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/tests/instance.json b/tasks/construct-nppc-vertex-cover-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b03eb3eb3c00dc3ab8d8e90bc5cc626154a1fb72 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 80, "k": 40, "edges": [[0, 5], [0, 8], [0, 9], [0, 19], [0, 21], [0, 37], [0, 40], [0, 41], [0, 46], [0, 49], [0, 50], [0, 53], [0, 58], [0, 61], [0, 64], [0, 67], [0, 71], [0, 76], [0, 77], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 11], [1, 12], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 26], [1, 29], [1, 30], [1, 33], [1, 35], [1, 36], [1, 37], [1, 40], [1, 41], [1, 42], [1, 43], [1, 45], [1, 46], [1, 47], [1, 48], [1, 50], [1, 51], [1, 56], [1, 57], [1, 58], [1, 60], [1, 61], [1, 62], [1, 64], [1, 66], [1, 67], [1, 69], [1, 71], [1, 76], [1, 77], [1, 78], [1, 79], [2, 8], [2, 12], [2, 13], [2, 16], [2, 18], [2, 22], [2, 24], [2, 29], [2, 40], [2, 41], [2, 46], [2, 50], [2, 53], [2, 58], [2, 61], [2, 64], [2, 67], [2, 72], [2, 76], [2, 77], [2, 79], [3, 7], [3, 16], [3, 19], [3, 21], [3, 29], [3, 35], [3, 36], [3, 40], [3, 45], [3, 56], [3, 67], [3, 69], [3, 76], [4, 5], [4, 8], [4, 9], [4, 12], [4, 13], [4, 16], [4, 19], [4, 22], [4, 30], [4, 31], [4, 41], [4, 50], [4, 53], [4, 56], [4, 61], [4, 76], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [5, 25], [5, 26], [5, 29], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 40], [5, 41], [5, 43], [5, 45], [5, 46], [5, 48], [5, 49], [5, 51], [5, 54], [5, 55], [5, 56], [5, 58], [5, 60], [5, 61], [5, 63], [5, 64], [5, 67], [5, 69], [5, 71], [5, 72], [5, 73], [5, 74], [5, 76], [5, 77], [5, 79], [6, 7], [6, 8], [6, 9], [6, 12], [6, 19], [6, 21], [6, 22], [6, 24], [6, 29], [6, 30], [6, 31], [6, 35], [6, 40], [6, 41], [6, 45], [6, 50], [6, 53], [6, 54], [6, 58], [6, 61], [6, 69], [7, 8], [7, 10], [7, 12], [7, 14], [7, 16], [7, 17], [7, 18], [7, 19], [7, 22], [7, 25], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 36], [7, 41], [7, 43], [7, 45], [7, 46], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 55], [7, 56], [7, 58], [7, 59], [7, 62], [7, 65], [7, 67], [7, 68], [7, 69], [7, 71], [7, 72], [7, 74], [7, 75], [7, 76], [7, 77], [7, 79], [8, 9], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 19], [8, 20], [8, 24], [8, 25], [8, 27], [8, 32], [8, 33], [8, 35], [8, 37], [8, 39], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 45], [8, 47], [8, 49], [8, 50], [8, 51], [8, 53], [8, 55], [8, 58], [8, 59], [8, 61], [8, 65], [8, 67], [8, 69], [8, 70], [8, 71], [8, 72], [8, 73], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 79], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 24], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 33], [9, 34], [9, 35], [9, 36], [9, 38], [9, 41], [9, 45], [9, 46], [9, 47], [9, 48], [9, 50], [9, 52], [9, 53], [9, 54], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 61], [9, 63], [9, 65], [9, 66], [9, 67], [9, 69], [9, 70], [9, 71], [9, 72], [9, 73], [9, 75], [9, 77], [9, 79], [10, 19], [10, 30], [10, 31], [10, 35], [10, 36], [10, 40], [10, 41], [10, 43], [10, 50], [10, 53], [10, 67], [10, 69], [10, 72], [10, 76], [10, 77], [10, 79], [11, 19], [11, 35], [11, 36], [11, 37], [11, 40], [11, 45], [11, 50], [11, 56], [11, 58], [11, 59], [11, 61], [11, 67], [11, 72], [11, 76], [11, 77], [12, 13], [12, 16], [12, 19], [12, 20], [12, 21], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [12, 30], [12, 31], [12, 33], [12, 34], [12, 36], [12, 37], [12, 39], [12, 41], [12, 44], [12, 45], [12, 48], [12, 49], [12, 50], [12, 51], [12, 53], [12, 54], [12, 55], [12, 56], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 64], [12, 65], [12, 66], [12, 67], [12, 72], [12, 73], [12, 75], [12, 76], [12, 77], [12, 78], [12, 79], [13, 14], [13, 15], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 27], [13, 28], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 36], [13, 37], [13, 40], [13, 41], [13, 42], [13, 43], [13, 45], [13, 46], [13, 52], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 64], [13, 66], [13, 67], [13, 68], [13, 70], [13, 71], [13, 72], [13, 73], [13, 75], [13, 76], [13, 77], [13, 78], [13, 79], [14, 18], [14, 21], [14, 24], [14, 29], [14, 30], [14, 31], [14, 37], [14, 49], [14, 50], [14, 53], [14, 58], [14, 59], [14, 69], [14, 72], [14, 76], [15, 16], [15, 18], [15, 19], [15, 22], [15, 24], [15, 30], [15, 35], [15, 36], [15, 37], [15, 40], [15, 45], [15, 49], [15, 53], [15, 58], [15, 61], [15, 64], [15, 67], [15, 69], [15, 77], [15, 79], [16, 17], [16, 19], [16, 20], [16, 22], [16, 23], [16, 24], [16, 28], [16, 30], [16, 31], [16, 34], [16, 35], [16, 36], [16, 37], [16, 40], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 48], [16, 50], [16, 52], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 61], [16, 63], [16, 64], [16, 67], [16, 69], [16, 71], [16, 77], [16, 79], [17, 22], [17, 31], [17, 35], [17, 37], [17, 41], [17, 43], [17, 46], [17, 49], [17, 50], [17, 54], [17, 56], [17, 58], [17, 59], [17, 61], [17, 69], [17, 71], [17, 72], [17, 76], [17, 77], [18, 19], [18, 21], [18, 22], [18, 24], [18, 29], [18, 30], [18, 31], [18, 32], [18, 34], [18, 35], [18, 36], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 46], [18, 47], [18, 49], [18, 50], [18, 53], [18, 54], [18, 55], [18, 56], [18, 57], [18, 59], [18, 60], [18, 62], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 71], [18, 73], [18, 74], [18, 75], [18, 76], [18, 77], [18, 79], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 29], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 39], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 48], [19, 49], [19, 50], [19, 51], [19, 52], [19, 56], [19, 61], [19, 62], [19, 64], [19, 67], [19, 69], [19, 70], [19, 71], [19, 72], [19, 74], [19, 76], [19, 77], [19, 78], [19, 79], [20, 21], [20, 30], [20, 31], [20, 36], [20, 37], [20, 40], [20, 41], [20, 45], [20, 46], [20, 50], [20, 64], [20, 67], [20, 69], [20, 76], [20, 77], [20, 79], [21, 22], [21, 24], [21, 27], [21, 28], [21, 31], [21, 33], [21, 36], [21, 38], [21, 41], [21, 43], [21, 46], [21, 47], [21, 50], [21, 53], [21, 54], [21, 55], [21, 56], [21, 58], [21, 59], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 69], [21, 70], [21, 71], [21, 72], [21, 73], [21, 76], [21, 77], [21, 78], [21, 79], [22, 23], [22, 24], [22, 27], [22, 28], [22, 30], [22, 31], [22, 32], [22, 35], [22, 36], [22, 37], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 46], [22, 48], [22, 49], [22, 50], [22, 51], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [22, 59], [22, 61], [22, 62], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 71], [22, 72], [22, 74], [22, 77], [23, 31], [23, 35], [23, 36], [23, 37], [23, 46], [23, 49], [23, 53], [23, 54], [23, 64], [23, 69], [23, 71], [23, 77], [23, 79], [24, 26], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 37], [24, 40], [24, 42], [24, 43], [24, 44], [24, 45], [24, 46], [24, 48], [24, 49], [24, 50], [24, 52], [24, 53], [24, 54], [24, 56], [24, 57], [24, 58], [24, 59], [24, 61], [24, 62], [24, 66], [24, 68], [24, 70], [24, 72], [24, 75], [24, 76], [24, 77], [24, 79], [25, 29], [25, 35], [25, 36], [25, 37], [25, 40], [25, 41], [25, 43], [25, 45], [25, 49], [25, 50], [25, 53], [25, 58], [25, 59], [25, 67], [25, 72], [25, 77], [26, 29], [26, 30], [26, 37], [26, 41], [26, 49], [26, 50], [26, 54], [26, 56], [26, 58], [26, 59], [26, 67], [26, 69], [26, 72], [26, 77], [26, 79], [27, 29], [27, 35], [27, 36], [27, 45], [27, 46], [27, 50], [27, 58], [27, 59], [27, 61], [27, 64], [27, 67], [27, 69], [27, 71], [27, 77], [28, 31], [28, 36], [28, 37], [28, 40], [28, 41], [28, 49], [28, 50], [28, 58], [28, 61], [28, 67], [28, 69], [28, 71], [28, 76], [28, 79], [29, 32], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 43], [29, 46], [29, 47], [29, 48], [29, 49], [29, 50], [29, 51], [29, 52], [29, 53], [29, 54], [29, 56], [29, 57], [29, 58], [29, 59], [29, 60], [29, 62], [29, 63], [29, 64], [29, 65], [29, 67], [29, 69], [29, 70], [29, 71], [29, 72], [29, 75], [29, 76], [29, 77], [29, 78], [29, 79], [30, 32], [30, 33], [30, 34], [30, 35], [30, 38], [30, 40], [30, 43], [30, 45], [30, 49], [30, 51], [30, 53], [30, 55], [30, 58], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 67], [30, 68], [30, 69], [30, 71], [30, 73], [30, 74], [30, 75], [31, 36], [31, 37], [31, 38], [31, 39], [31, 40], [31, 41], [31, 43], [31, 44], [31, 45], [31, 46], [31, 49], [31, 52], [31, 53], [31, 54], [31, 56], [31, 59], [31, 60], [31, 62], [31, 64], [31, 65], [31, 66], [31, 68], [31, 70], [31, 71], [31, 72], [31, 76], [31, 77], [31, 78], [31, 79], [32, 36], [32, 37], [32, 43], [32, 50], [32, 53], [32, 54], [32, 58], [32, 59], [32, 61], [32, 67], [32, 69], [32, 77], [32, 79], [33, 41], [33, 43], [33, 50], [33, 58], [33, 64], [33, 69], [33, 72], [33, 76], [33, 77], [33, 79], [34, 36], [34, 37], [34, 41], [34, 45], [34, 50], [34, 53], [34, 54], [34, 59], [34, 64], [34, 67], [34, 69], [34, 71], [34, 72], [34, 77], [35, 36], [35, 37], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 45], [35, 46], [35, 49], [35, 50], [35, 51], [35, 52], [35, 53], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 61], [35, 62], [35, 65], [35, 67], [35, 68], [35, 69], [35, 70], [35, 72], [35, 73], [35, 74], [35, 76], [35, 79], [36, 37], [36, 40], [36, 41], [36, 43], [36, 44], [36, 45], [36, 46], [36, 48], [36, 49], [36, 50], [36, 54], [36, 55], [36, 56], [36, 58], [36, 59], [36, 60], [36, 63], [36, 64], [36, 66], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 73], [36, 74], [36, 75], [36, 76], [36, 77], [36, 78], [36, 79], [37, 42], [37, 43], [37, 45], [37, 47], [37, 48], [37, 49], [37, 50], [37, 51], [37, 53], [37, 55], [37, 56], [37, 59], [37, 60], [37, 62], [37, 67], [37, 68], [37, 69], [37, 71], [37, 73], [37, 76], [37, 79], [38, 40], [38, 41], [38, 46], [38, 53], [38, 56], [38, 58], [38, 59], [38, 61], [38, 64], [38, 67], [38, 76], [38, 77], [39, 41], [39, 43], [39, 53], [39, 54], [39, 58], [39, 61], [39, 76], [39, 77], [40, 41], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 64], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 74], [40, 76], [40, 77], [40, 79], [41, 44], [41, 46], [41, 48], [41, 50], [41, 51], [41, 53], [41, 54], [41, 56], [41, 58], [41, 59], [41, 60], [41, 61], [41, 63], [41, 64], [41, 65], [41, 66], [41, 69], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [41, 75], [41, 76], [41, 77], [41, 79], [42, 49], [42, 53], [42, 54], [42, 59], [42, 64], [42, 69], [43, 45], [43, 47], [43, 50], [43, 51], [43, 52], [43, 53], [43, 54], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 63], [43, 64], [43, 65], [43, 67], [43, 69], [43, 71], [43, 72], [43, 74], [43, 75], [43, 77], [44, 45], [44, 49], [44, 50], [44, 53], [44, 54], [44, 56], [44, 59], [44, 67], [44, 69], [44, 71], [44, 72], [45, 46], [45, 49], [45, 50], [45, 52], [45, 53], [45, 54], [45, 56], [45, 57], [45, 61], [45, 62], [45, 66], [45, 67], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [45, 75], [45, 76], [45, 77], [45, 79], [46, 47], [46, 49], [46, 50], [46, 51], [46, 52], [46, 53], [46, 54], [46, 56], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 64], [46, 66], [46, 67], [46, 68], [46, 69], [46, 71], [46, 72], [46, 74], [46, 76], [46, 77], [46, 79], [47, 49], [47, 54], [47, 58], [47, 59], [47, 61], [47, 64], [47, 69], [47, 71], [47, 72], [47, 76], [47, 79], [48, 50], [48, 53], [48, 56], [48, 58], [48, 61], [48, 71], [48, 76], [48, 79], [49, 50], [49, 52], [49, 54], [49, 56], [49, 58], [49, 59], [49, 60], [49, 61], [49, 64], [49, 65], [49, 69], [49, 70], [49, 72], [49, 75], [49, 76], [49, 77], [49, 78], [49, 79], [50, 55], [50, 56], [50, 58], [50, 59], [50, 61], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 73], [50, 75], [50, 76], [50, 77], [50, 78], [50, 79], [51, 54], [51, 58], [51, 59], [51, 64], [51, 67], [51, 71], [51, 72], [51, 76], [51, 77], [52, 54], [52, 58], [52, 61], [52, 64], [52, 67], [52, 71], [52, 72], [52, 77], [52, 79], [53, 55], [53, 56], [53, 58], [53, 59], [53, 60], [53, 64], [53, 66], [53, 67], [53, 69], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [53, 75], [53, 77], [53, 78], [53, 79], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 61], [54, 63], [54, 64], [54, 67], [54, 69], [54, 70], [54, 71], [54, 75], [54, 77], [54, 78], [54, 79], [55, 56], [55, 64], [55, 69], [55, 77], [55, 79], [56, 58], [56, 59], [56, 60], [56, 63], [56, 64], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 76], [56, 77], [56, 79], [57, 58], [57, 69], [57, 77], [58, 59], [58, 60], [58, 62], [58, 64], [58, 67], [58, 68], [58, 69], [58, 71], [58, 72], [58, 75], [58, 76], [58, 77], [58, 79], [59, 61], [59, 64], [59, 65], [59, 66], [59, 67], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 77], [60, 61], [60, 67], [60, 69], [60, 76], [60, 79], [61, 62], [61, 65], [61, 67], [61, 69], [61, 71], [61, 72], [61, 73], [61, 74], [61, 75], [61, 76], [61, 77], [61, 79], [62, 67], [62, 69], [62, 71], [62, 72], [62, 79], [63, 64], [63, 69], [63, 76], [63, 77], [64, 65], [64, 66], [64, 67], [64, 69], [64, 70], [64, 71], [64, 72], [64, 74], [64, 77], [64, 78], [64, 79], [65, 69], [65, 76], [65, 79], [66, 67], [66, 72], [66, 76], [66, 77], [67, 68], [67, 70], [67, 72], [67, 73], [67, 75], [67, 77], [68, 69], [68, 71], [68, 77], [69, 70], [69, 71], [69, 72], [69, 73], [69, 75], [69, 76], [69, 77], [69, 78], [69, 79], [70, 71], [70, 72], [70, 76], [71, 72], [71, 76], [71, 77], [71, 78], [71, 79], [72, 73], [72, 76], [72, 77], [72, 78], [72, 79], [73, 76], [73, 77], [73, 79], [74, 77], [74, 79], [76, 77], [76, 79], [78, 79]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/tests/run.py b/tasks/construct-nppc-vertex-cover-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l5-s9/tests/test.sh b/tasks/construct-nppc-vertex-cover-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l2-s3/environment/Dockerfile b/tasks/construct-rg-graph-color-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l2-s3/environment/instance.json b/tasks/construct-rg-graph-color-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b01054ece7aff425316604283ba56f322c344195 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 1], [0, 7], [0, 8], [1, 4], [2, 6], [3, 8], [5, 6], [5, 7], [8, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s3/solution/solve.sh b/tasks/construct-rg-graph-color-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2590179b6ee07fd1c352a4b606a88be16e0a34a7 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 1, 1, 1, 1, 2, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l2-s3/tests/check.py b/tasks/construct-rg-graph-color-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s3/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-l2-s3/tests/instance.json b/tasks/construct-rg-graph-color-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b01054ece7aff425316604283ba56f322c344195 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 1], [0, 7], [0, 8], [1, 4], [2, 6], [3, 8], [5, 6], [5, 7], [8, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s3/tests/run.py b/tasks/construct-rg-graph-color-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l2-s3/tests/test.sh b/tasks/construct-rg-graph-color-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l6-s2/environment/Dockerfile b/tasks/construct-rg-graph-color-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l6-s2/environment/instance.json b/tasks/construct-rg-graph-color-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..47b95006820058a65cb9b0f67a9e1b6c8c080178 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 1], [0, 19], [0, 30], [0, 33], [0, 34], [1, 5], [1, 15], [1, 18], [1, 21], [2, 9], [2, 11], [2, 20], [2, 22], [2, 28], [2, 29], [4, 17], [4, 20], [4, 29], [5, 9], [5, 17], [5, 21], [5, 32], [5, 36], [6, 18], [6, 34], [7, 10], [7, 15], [7, 24], [7, 35], [8, 9], [10, 21], [11, 16], [11, 22], [11, 27], [11, 28], [12, 15], [12, 18], [13, 14], [13, 18], [13, 23], [14, 23], [14, 26], [14, 27], [14, 31], [15, 20], [15, 32], [16, 19], [16, 30], [16, 37], [17, 22], [17, 35], [17, 39], [18, 39], [19, 21], [19, 23], [20, 31], [20, 35], [21, 31], [23, 24], [23, 31], [23, 36], [23, 37], [24, 27], [26, 28], [28, 29], [28, 33], [30, 38], [31, 32], [35, 36], [35, 38], [36, 39], [37, 39]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s2/solution/solve.sh b/tasks/construct-rg-graph-color-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bdd4535a8eeddae29c07f146caa3cf7f68c34e47 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 3, 1, 2, 3, 2, 2, 3, 3, 3, 2, 1, 1, 1, 3, 2, 2, 1, 2, 2, 2, 3, 2, 2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l6-s2/tests/check.py b/tasks/construct-rg-graph-color-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s2/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-l6-s2/tests/instance.json b/tasks/construct-rg-graph-color-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..47b95006820058a65cb9b0f67a9e1b6c8c080178 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 1], [0, 19], [0, 30], [0, 33], [0, 34], [1, 5], [1, 15], [1, 18], [1, 21], [2, 9], [2, 11], [2, 20], [2, 22], [2, 28], [2, 29], [4, 17], [4, 20], [4, 29], [5, 9], [5, 17], [5, 21], [5, 32], [5, 36], [6, 18], [6, 34], [7, 10], [7, 15], [7, 24], [7, 35], [8, 9], [10, 21], [11, 16], [11, 22], [11, 27], [11, 28], [12, 15], [12, 18], [13, 14], [13, 18], [13, 23], [14, 23], [14, 26], [14, 27], [14, 31], [15, 20], [15, 32], [16, 19], [16, 30], [16, 37], [17, 22], [17, 35], [17, 39], [18, 39], [19, 21], [19, 23], [20, 31], [20, 35], [21, 31], [23, 24], [23, 31], [23, 36], [23, 37], [24, 27], [26, 28], [28, 29], [28, 33], [30, 38], [31, 32], [35, 36], [35, 38], [36, 39], [37, 39]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s2/tests/run.py b/tasks/construct-rg-graph-color-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l6-s2/tests/test.sh b/tasks/construct-rg-graph-color-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l6-s5/environment/Dockerfile b/tasks/construct-rg-graph-color-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l6-s5/environment/instance.json b/tasks/construct-rg-graph-color-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6284be497a53282fa3be34299819a1457ddc11f5 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 6], [0, 12], [0, 18], [1, 10], [1, 19], [1, 20], [1, 27], [1, 39], [2, 14], [2, 23], [2, 30], [2, 35], [3, 5], [3, 8], [3, 30], [4, 5], [4, 18], [4, 24], [4, 30], [4, 38], [5, 24], [6, 7], [6, 11], [6, 16], [6, 26], [7, 19], [7, 20], [8, 24], [9, 23], [9, 35], [9, 39], [10, 20], [11, 38], [12, 22], [12, 36], [12, 39], [13, 27], [13, 31], [13, 37], [14, 17], [14, 21], [14, 22], [14, 35], [14, 38], [15, 27], [15, 35], [16, 17], [16, 25], [18, 20], [18, 23], [18, 26], [19, 24], [19, 32], [19, 36], [20, 25], [20, 27], [20, 36], [21, 37], [22, 27], [22, 37], [22, 39], [23, 29], [23, 30], [23, 36], [24, 27], [24, 36], [26, 33], [26, 34], [26, 39], [28, 37], [29, 33], [30, 31], [30, 32], [30, 35], [31, 34], [35, 36], [35, 37], [36, 39]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s5/solution/solve.sh b/tasks/construct-rg-graph-color-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..92193b968bb735e999137ee61d8dee4ab5406e98 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 1, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 1, 3, 2, 2, 3, 1, 1, 3, 3, 2, 1, 2, 1, 1, 2, 3, 1, 2, 2, 3, 1, 2, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l6-s5/tests/check.py b/tasks/construct-rg-graph-color-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l6-s5/tests/instance.json b/tasks/construct-rg-graph-color-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6284be497a53282fa3be34299819a1457ddc11f5 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 40, "num_colors": 3, "edges": [[0, 6], [0, 12], [0, 18], [1, 10], [1, 19], [1, 20], [1, 27], [1, 39], [2, 14], [2, 23], [2, 30], [2, 35], [3, 5], [3, 8], [3, 30], [4, 5], [4, 18], [4, 24], [4, 30], [4, 38], [5, 24], [6, 7], [6, 11], [6, 16], [6, 26], [7, 19], [7, 20], [8, 24], [9, 23], [9, 35], [9, 39], [10, 20], [11, 38], [12, 22], [12, 36], [12, 39], [13, 27], [13, 31], [13, 37], [14, 17], [14, 21], [14, 22], [14, 35], [14, 38], [15, 27], [15, 35], [16, 17], [16, 25], [18, 20], [18, 23], [18, 26], [19, 24], [19, 32], [19, 36], [20, 25], [20, 27], [20, 36], [21, 37], [22, 27], [22, 37], [22, 39], [23, 29], [23, 30], [23, 36], [24, 27], [24, 36], [26, 33], [26, 34], [26, 39], [28, 37], [29, 33], [30, 31], [30, 32], [30, 35], [31, 34], [35, 36], [35, 37], [36, 39]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l6-s5/tests/run.py b/tasks/construct-rg-graph-color-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l6-s5/tests/test.sh b/tasks/construct-rg-graph-color-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l4-s9/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l4-s9/environment/instance.json b/tasks/construct-rg-intermediate-integration-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..548705986dedce3346462956263496019c3b5b36 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-2*log(x**3)", "problem_type": "log_inverse_trig", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l4-s9/tests/check.py b/tasks/construct-rg-intermediate-integration-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s9/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l4-s9/tests/instance.json b/tasks/construct-rg-intermediate-integration-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..548705986dedce3346462956263496019c3b5b36 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-2*log(x**3)", "problem_type": "log_inverse_trig", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l4-s9/tests/run.py b/tasks/construct-rg-intermediate-integration-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l4-s9/tests/test.sh b/tasks/construct-rg-intermediate-integration-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l2-s2/environment/Dockerfile b/tasks/construct-rg-simple-integration-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l2-s2/environment/instance.json b/tasks/construct-rg-simple-integration-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1a2056251f75b043cd8336a5213e03b95633640f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "48*x**5 - 20*x - 7/2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l2-s2/solution/solve.sh b/tasks/construct-rg-simple-integration-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..314457f2228e1c3916288a4b1c5f0ded0746747b --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "8*x**6 - 10*x**2 - 7*x/2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l2-s2/tests/check.py b/tasks/construct-rg-simple-integration-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s2/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-l2-s2/tests/instance.json b/tasks/construct-rg-simple-integration-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1a2056251f75b043cd8336a5213e03b95633640f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "48*x**5 - 20*x - 7/2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l2-s2/tests/run.py b/tasks/construct-rg-simple-integration-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l2-s2/tests/test.sh b/tasks/construct-rg-simple-integration-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l2-s5/environment/Dockerfile b/tasks/construct-rg-simple-integration-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l2-s5/environment/instance.json b/tasks/construct-rg-simple-integration-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3465d7973f04e735471f73ad3e03a33d85c2a454 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "5*x**4/2 - 9*x**2/7 + x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l2-s5/solution/solve.sh b/tasks/construct-rg-simple-integration-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..81f00d2f1d0638f9b393602ce8e5c51068a68195 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "x**5/2 - 3*x**3/7 + x**2/2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l2-s5/tests/check.py b/tasks/construct-rg-simple-integration-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-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-l2-s5/tests/instance.json b/tasks/construct-rg-simple-integration-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3465d7973f04e735471f73ad3e03a33d85c2a454 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "5*x**4/2 - 9*x**2/7 + x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l2-s5/tests/run.py b/tasks/construct-rg-simple-integration-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l2-s5/tests/test.sh b/tasks/construct-rg-simple-integration-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l6-s3/environment/Dockerfile b/tasks/construct-rg-simple-integration-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l6-s3/environment/instance.json b/tasks/construct-rg-simple-integration-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a784d31a85cbe7baff4b9c5adf63e0760c03d9b3 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-25*x**9/4 - 3*x**2 - 14*x + 7/(2*x**2) + 2/x**3 + 9/(2*x**6) + 63/x**8", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l6-s3/solution/solve.sh b/tasks/construct-rg-simple-integration-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e66923ebc389ed877d04ce5fa7cd1362ed496df2 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-5*x**10/8 - x**3 - 7*x**2 - 7/(2*x) - 1/x**2 - 9/(10*x**5) - 9/x**7 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l6-s3/tests/check.py b/tasks/construct-rg-simple-integration-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s3/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l6-s3/tests/instance.json b/tasks/construct-rg-simple-integration-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a784d31a85cbe7baff4b9c5adf63e0760c03d9b3 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-25*x**9/4 - 3*x**2 - 14*x + 7/(2*x**2) + 2/x**3 + 9/(2*x**6) + 63/x**8", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l6-s3/tests/run.py b/tasks/construct-rg-simple-integration-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l6-s3/tests/test.sh b/tasks/construct-rg-simple-integration-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l6-s4/environment/Dockerfile b/tasks/construct-rg-simple-integration-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l6-s4/environment/instance.json b/tasks/construct-rg-simple-integration-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e93cf65950b606601d78da7f594a2eb5cd1c658 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-333*X**8/40 - 14*X**6 - 9/X**2 - 21/(2*X**4) - 12/X**5 + 36/X**10", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l6-s4/solution/solve.sh b/tasks/construct-rg-simple-integration-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c2dcab6b73219eeff443727a83e4f486533b850 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-37*X**9/40 - 2*X**7 + 9/X + 7/(2*X**3) + 3/X**4 - 4/X**9 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l6-s4/tests/check.py b/tasks/construct-rg-simple-integration-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s4/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l6-s4/tests/instance.json b/tasks/construct-rg-simple-integration-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0e93cf65950b606601d78da7f594a2eb5cd1c658 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-333*X**8/40 - 14*X**6 - 9/X**2 - 21/(2*X**4) - 12/X**5 + 36/X**10", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l6-s4/tests/run.py b/tasks/construct-rg-simple-integration-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l6-s4/tests/test.sh b/tasks/construct-rg-simple-integration-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-antiderivative-l3-s2/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l3-s2/environment/instance.json b/tasks/construct-rlve-antiderivative-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..12595f3043f6c7e8d48295d7d05910f748862cbf --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "4*x + 1/sqrt(x)", "max_ops": 44, "max_len": 760, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l3-s2/solution/solve.sh b/tasks/construct-rlve-antiderivative-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ebcdbf28e6688fbbb736d232152df3d0595e7389 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "2*sqrt(x) + 2*x**2"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l3-s2/tests/check.py b/tasks/construct-rlve-antiderivative-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s2/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-l3-s2/tests/instance.json b/tasks/construct-rlve-antiderivative-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..12595f3043f6c7e8d48295d7d05910f748862cbf --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "4*x + 1/sqrt(x)", "max_ops": 44, "max_len": 760, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l3-s2/tests/run.py b/tasks/construct-rlve-antiderivative-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l3-s2/tests/test.sh b/tasks/construct-rlve-antiderivative-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l3-s5/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l3-s5/environment/instance.json b/tasks/construct-rlve-antiderivative-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9dc9ec9f9ccc10f0f0c353575360a0f342976cc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "(x**2/cos(x))**(1/4)*(x**2*sin(x)/(4*cos(x)**2) + x/(2*cos(x)))*cos(x)/x**2", "max_ops": 40, "max_len": 800, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l3-s5/solution/solve.sh b/tasks/construct-rlve-antiderivative-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4946bc20ed258966de47bab0c8e528505d1ce17b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "(x**2/cos(x))**(1/4)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l3-s5/tests/check.py b/tasks/construct-rlve-antiderivative-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s5/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l3-s5/tests/instance.json b/tasks/construct-rlve-antiderivative-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9dc9ec9f9ccc10f0f0c353575360a0f342976cc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "(x**2/cos(x))**(1/4)*(x**2*sin(x)/(4*cos(x)**2) + x/(2*cos(x)))*cos(x)/x**2", "max_ops": 40, "max_len": 800, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l3-s5/tests/run.py b/tasks/construct-rlve-antiderivative-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l3-s5/tests/test.sh b/tasks/construct-rlve-antiderivative-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l3-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l2-s1/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s1/environment/instance.json b/tasks/construct-rlve-bezout-identity-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f51ad5044a904b7040ad290980e1890b50148b1e --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": [72, 96, -108, 96], "target": 12, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s1/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..693da166cd6b0a38aab7007cd308116ad2b4d322 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [4, -4, -1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l2-s1/tests/check.py b/tasks/construct-rlve-bezout-identity-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s1/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-l2-s1/tests/instance.json b/tasks/construct-rlve-bezout-identity-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f51ad5044a904b7040ad290980e1890b50148b1e --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": [72, 96, -108, 96], "target": 12, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s1/tests/run.py b/tasks/construct-rlve-bezout-identity-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s1/tests/test.sh b/tasks/construct-rlve-bezout-identity-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s6/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s6/environment/instance.json b/tasks/construct-rlve-bezout-identity-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b9c0062b8c2f73f5932e3da2bc4a761171a98ab --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [-128, -66, -10, -4], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s6/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7d9e125d709c27d97a091f40e512109337a58a02 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [16, -31, 0, -1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l2-s6/tests/check.py b/tasks/construct-rlve-bezout-identity-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-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-l2-s6/tests/instance.json b/tasks/construct-rlve-bezout-identity-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b9c0062b8c2f73f5932e3da2bc4a761171a98ab --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [-128, -66, -10, -4], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s6/tests/run.py b/tasks/construct-rlve-bezout-identity-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s6/tests/test.sh b/tasks/construct-rlve-bezout-identity-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s8/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s8/environment/instance.json b/tasks/construct-rlve-bezout-identity-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1fcac667c33046c98bf1a2e7e7034fb6b2993eb5 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": [124, -4, 42, -24], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s8/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d493eaed1963102d2744fdf43c5741af751beb43 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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' +{"X": [0, 10, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l2-s8/tests/check.py b/tasks/construct-rlve-bezout-identity-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s8/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-l2-s8/tests/instance.json b/tasks/construct-rlve-bezout-identity-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1fcac667c33046c98bf1a2e7e7034fb6b2993eb5 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": [124, -4, 42, -24], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l2-s8/tests/run.py b/tasks/construct-rlve-bezout-identity-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l2-s8/tests/test.sh b/tasks/construct-rlve-bezout-identity-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l6-s0/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l6-s0/environment/instance.json b/tasks/construct-rlve-bezout-identity-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35729d04a476b707d00d6c91c36efce8a7274ed2 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": [18004, -28890, -13270, -18442, -15464, 31360, 4466, -4056, 29088, 2734, 15212, 17142], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s0/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d2fc227d5022385089a6e522fa88fbc27604e288 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [4838, 3015, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l6-s0/tests/check.py b/tasks/construct-rlve-bezout-identity-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l6-s0/tests/instance.json b/tasks/construct-rlve-bezout-identity-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35729d04a476b707d00d6c91c36efce8a7274ed2 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": [18004, -28890, -13270, -18442, -15464, 31360, 4466, -4056, 29088, 2734, 15212, 17142], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s0/tests/run.py b/tasks/construct-rlve-bezout-identity-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l6-s0/tests/test.sh b/tasks/construct-rlve-bezout-identity-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l6-s7/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l6-s7/environment/instance.json b/tasks/construct-rlve-bezout-identity-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35441aa226f273e65b4d014a2df13b70b815bb93 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": [-16307, 21091, 138, -13179, -23598, -18676, 2829, 29969, 5957, 15065, -25921, -4899], "target": 23, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s7/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b6d6befe5669a50e80ffbc711e2440c09bb26b63 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [-410, -317, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l6-s7/tests/check.py b/tasks/construct-rlve-bezout-identity-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s7/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-l6-s7/tests/instance.json b/tasks/construct-rlve-bezout-identity-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35441aa226f273e65b4d014a2df13b70b815bb93 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": [-16307, 21091, 138, -13179, -23598, -18676, 2829, 29969, 5957, 15065, -25921, -4899], "target": 23, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s7/tests/run.py b/tasks/construct-rlve-bezout-identity-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l6-s7/tests/test.sh b/tasks/construct-rlve-bezout-identity-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l6-s9/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l6-s9/environment/instance.json b/tasks/construct-rlve-bezout-identity-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c26f952cec765b7c0647ce0cbf4b1fda0c684411 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [3396, -23268, 6122, 2866, -16970, -1924, -31354, 31672, -8478, 14886, 2974, -30864], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s9/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5e6e5b973687848240681940cee6862061042918 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [447270, 65280, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l6-s9/tests/check.py b/tasks/construct-rlve-bezout-identity-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s9/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l6-s9/tests/instance.json b/tasks/construct-rlve-bezout-identity-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c26f952cec765b7c0647ce0cbf4b1fda0c684411 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [3396, -23268, 6122, 2866, -16970, -1924, -31354, 31672, -8478, 14886, 2974, -30864], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l6-s9/tests/run.py b/tasks/construct-rlve-bezout-identity-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l6-s9/tests/test.sh b/tasks/construct-rlve-bezout-identity-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-construct-hack-interval-l4-s3/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l4-s3/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42b82fd6c185d695201c52749876a062ae430256 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"mod": 7686302393, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s3/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..51fe27144cc3726264a2afa9d50634c122bbf8a9 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 5617814358, "R": 6617814357} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42b82fd6c185d695201c52749876a062ae430256 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"mod": 7686302393, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l4-s3/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l4-s4/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l4-s4/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..895e8c6342c36ec3b7097714922b415c7ef351e4 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"mod": 8522692339, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s4/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f5d26dd8fe880a82af7831293545b378ba13e601 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 2113461695, "R": 3113461694} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..895e8c6342c36ec3b7097714922b415c7ef351e4 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"mod": 8522692339, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l4-s4/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-crt-l1-s3/environment/Dockerfile b/tasks/construct-rlve-crt-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l1-s3/environment/instance.json b/tasks/construct-rlve-crt-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52c6b45b4febdf093ed0333b5db26d13a2ffffdf --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [15, 14], "residues": [4, 5], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s3/solution/solve.sh b/tasks/construct-rlve-crt-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2346383f8bef3a5e63c542bc4c1fddb7181d67fd --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 19} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l1-s3/tests/check.py b/tasks/construct-rlve-crt-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s3/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-l1-s3/tests/instance.json b/tasks/construct-rlve-crt-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52c6b45b4febdf093ed0333b5db26d13a2ffffdf --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [15, 14], "residues": [4, 5], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s3/tests/run.py b/tasks/construct-rlve-crt-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l1-s3/tests/test.sh b/tasks/construct-rlve-crt-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l1-s4/environment/Dockerfile b/tasks/construct-rlve-crt-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l1-s4/environment/instance.json b/tasks/construct-rlve-crt-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d10d987276e11b7c18cb407cc4ec2c9b4c759c34 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [4, 10], "residues": [1, 7], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s4/solution/solve.sh b/tasks/construct-rlve-crt-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2de3a92cc59ac9423eb380e4b67f3fee4a1c9d7a --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 17} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l1-s4/tests/check.py b/tasks/construct-rlve-crt-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s4/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l1-s4/tests/instance.json b/tasks/construct-rlve-crt-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d10d987276e11b7c18cb407cc4ec2c9b4c759c34 --- /dev/null +++ b/tasks/construct-rlve-crt-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [4, 10], "residues": [1, 7], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l1-s4/tests/run.py b/tasks/construct-rlve-crt-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l1-s4/tests/test.sh b/tasks/construct-rlve-crt-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l5-s2/environment/Dockerfile b/tasks/construct-rlve-crt-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l5-s2/environment/instance.json b/tasks/construct-rlve-crt-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4fc30f3cdf707ec2fd6000e35ccecb7c6e815b53 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [3279395310, 6832203215, 4519823366, 2615421463, 933731197, 1438987691], "residues": [53617477, 3059600192, 852156675, 2045539018, 554491437, 1257877261], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l5-s2/solution/solve.sh b/tasks/construct-rlve-crt-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..007531212dd0d5fc4fb7d50455a7ace1b0b71667 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 9891803407} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l5-s2/tests/check.py b/tasks/construct-rlve-crt-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l5-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-l5-s2/tests/instance.json b/tasks/construct-rlve-crt-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4fc30f3cdf707ec2fd6000e35ccecb7c6e815b53 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [3279395310, 6832203215, 4519823366, 2615421463, 933731197, 1438987691], "residues": [53617477, 3059600192, 852156675, 2045539018, 554491437, 1257877261], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l5-s2/tests/run.py b/tasks/construct-rlve-crt-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l5-s2/tests/test.sh b/tasks/construct-rlve-crt-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-distinct-subset-sum-permutation-l4-s2/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l4-s2/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb73cffe9969fe943556d4016b17db43b0bb7053 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [27, 24, 2, 14, 4, 7, 5, 1, 6, 26, 16, 13, 0, 25], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b5c675358cfe97c7789184456678def023ff2202 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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' +{"B": [0, 25, 4, 16, 5, 13, 6, 2, 7, 27, 24, 14, 1, 26]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb73cffe9969fe943556d4016b17db43b0bb7053 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [27, 24, 2, 14, 4, 7, 5, 1, 6, 26, 16, 13, 0, 25], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l4-s2/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-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-distinct-subset-sum-permutation-l4-s5/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l4-s5/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d8a3adb30c54bf0b943e23c88a2b5e8b48aa874 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": [4, 17, 12, 13, 5, 25, 18, 7, 9, 15, 14, 27, 21, 1], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..81c07d615d75918c3c91f8a1540c02f691e19386 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [5, 18, 13, 14, 7, 27, 21, 9, 12, 17, 15, 1, 25, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-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-l4-s5/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d8a3adb30c54bf0b943e23c88a2b5e8b48aa874 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": [4, 17, 12, 13, 5, 25, 18, 7, 9, 15, 14, 27, 21, 1], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l4-s5/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-even-degree-partition-l1-s3/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l1-s3/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dd0c45640c11eb84bc4f1c07cf5eb65adffe0244 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 4], [1, 2], [1, 3], [2, 4], [3, 4]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l1-s3/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cd8b2affce0dcdcfb946c73700debe04c103fd9b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l1-s3/tests/check.py b/tasks/construct-rlve-even-degree-partition-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s3/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l1-s3/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dd0c45640c11eb84bc4f1c07cf5eb65adffe0244 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 4], [1, 2], [1, 3], [2, 4], [3, 4]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l1-s3/tests/run.py b/tasks/construct-rlve-even-degree-partition-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l1-s3/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l1-s4/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l1-s4/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38cac585fac3fd34e5e4f6c4828d771eb6320273 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [1, 4], [2, 3], [2, 4], [3, 4]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l1-s4/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2ae2ffd201fe81063d975c996c28af1f55ac01d6 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l1-s4/tests/check.py b/tasks/construct-rlve-even-degree-partition-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l1-s4/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38cac585fac3fd34e5e4f6c4828d771eb6320273 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [1, 4], [2, 3], [2, 4], [3, 4]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l1-s4/tests/run.py b/tasks/construct-rlve-even-degree-partition-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l1-s4/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l5-s2/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l5-s2/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7d8fe05e44495a7f7e8257f308f6dab6d8e1a354 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 28, "edges": [[0, 1], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 14], [0, 17], [0, 20], [0, 23], [0, 25], [0, 27], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 18], [1, 21], [1, 27], [2, 3], [2, 5], [2, 6], [2, 11], [2, 12], [2, 14], [2, 17], [2, 19], [2, 24], [2, 25], [3, 5], [3, 14], [3, 16], [3, 17], [3, 25], [3, 26], [3, 27], [4, 16], [4, 17], [4, 24], [5, 11], [5, 13], [5, 14], [5, 15], [5, 17], [5, 21], [5, 25], [5, 26], [5, 27], [6, 10], [6, 18], [6, 19], [6, 23], [6, 24], [6, 25], [6, 27], [7, 8], [7, 9], [7, 10], [7, 17], [7, 18], [7, 20], [7, 21], [7, 25], [7, 26], [8, 11], [8, 17], [8, 18], [8, 20], [8, 21], [8, 22], [8, 25], [8, 26], [9, 12], [9, 13], [9, 17], [9, 19], [9, 25], [9, 27], [10, 15], [10, 17], [10, 18], [10, 25], [10, 26], [11, 19], [11, 20], [11, 21], [11, 25], [12, 14], [12, 19], [12, 23], [13, 14], [13, 16], [13, 17], [13, 24], [13, 25], [14, 15], [14, 16], [14, 17], [14, 18], [14, 25], [15, 16], [15, 17], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [16, 22], [16, 24], [16, 25], [16, 26], [16, 27], [17, 18], [17, 19], [17, 25], [17, 26], [17, 27], [18, 22], [18, 25], [18, 27], [19, 20], [19, 21], [19, 22], [19, 24], [20, 21], [20, 22], [20, 23], [20, 24], [20, 26], [21, 22], [21, 23], [21, 25], [22, 24], [22, 27], [23, 24], [23, 25], [24, 27], [25, 27]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l5-s2/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1df082635a958e669157d33a3cc0c188663c772e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l5-s2/tests/check.py b/tasks/construct-rlve-even-degree-partition-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s2/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-l5-s2/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7d8fe05e44495a7f7e8257f308f6dab6d8e1a354 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 28, "edges": [[0, 1], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 14], [0, 17], [0, 20], [0, 23], [0, 25], [0, 27], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 18], [1, 21], [1, 27], [2, 3], [2, 5], [2, 6], [2, 11], [2, 12], [2, 14], [2, 17], [2, 19], [2, 24], [2, 25], [3, 5], [3, 14], [3, 16], [3, 17], [3, 25], [3, 26], [3, 27], [4, 16], [4, 17], [4, 24], [5, 11], [5, 13], [5, 14], [5, 15], [5, 17], [5, 21], [5, 25], [5, 26], [5, 27], [6, 10], [6, 18], [6, 19], [6, 23], [6, 24], [6, 25], [6, 27], [7, 8], [7, 9], [7, 10], [7, 17], [7, 18], [7, 20], [7, 21], [7, 25], [7, 26], [8, 11], [8, 17], [8, 18], [8, 20], [8, 21], [8, 22], [8, 25], [8, 26], [9, 12], [9, 13], [9, 17], [9, 19], [9, 25], [9, 27], [10, 15], [10, 17], [10, 18], [10, 25], [10, 26], [11, 19], [11, 20], [11, 21], [11, 25], [12, 14], [12, 19], [12, 23], [13, 14], [13, 16], [13, 17], [13, 24], [13, 25], [14, 15], [14, 16], [14, 17], [14, 18], [14, 25], [15, 16], [15, 17], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [16, 22], [16, 24], [16, 25], [16, 26], [16, 27], [17, 18], [17, 19], [17, 25], [17, 26], [17, 27], [18, 22], [18, 25], [18, 27], [19, 20], [19, 21], [19, 22], [19, 24], [20, 21], [20, 22], [20, 23], [20, 24], [20, 26], [21, 22], [21, 23], [21, 25], [22, 24], [22, 27], [23, 24], [23, 25], [24, 27], [25, 27]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l5-s2/tests/run.py b/tasks/construct-rlve-even-degree-partition-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l5-s2/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l5-s5/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l5-s5/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bcc9c49e19e48dcd36c0ec22cf8d9d856650599b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 28, "edges": [[0, 1], [0, 4], [0, 17], [0, 24], [1, 2], [1, 6], [1, 7], [1, 12], [1, 17], [1, 19], [1, 24], [1, 25], [2, 4], [2, 8], [2, 9], [2, 15], [2, 17], [3, 8], [3, 10], [3, 15], [3, 16], [3, 18], [3, 22], [3, 25], [3, 26], [3, 27], [4, 5], [4, 6], [4, 9], [4, 11], [4, 12], [4, 15], [4, 17], [4, 20], [4, 24], [5, 7], [5, 8], [5, 16], [5, 19], [5, 20], [5, 24], [6, 27], [7, 11], [7, 14], [7, 17], [7, 24], [8, 12], [8, 14], [8, 17], [8, 25], [9, 16], [9, 18], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [10, 14], [10, 15], [10, 18], [10, 23], [10, 27], [11, 21], [11, 22], [11, 25], [11, 27], [12, 17], [12, 19], [12, 24], [13, 15], [13, 16], [13, 23], [13, 27], [14, 15], [14, 21], [14, 23], [15, 16], [15, 18], [15, 23], [15, 27], [16, 18], [16, 23], [16, 26], [16, 27], [17, 19], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [20, 22], [21, 22], [21, 23], [21, 27], [22, 26], [22, 27], [23, 25], [23, 27], [24, 25], [25, 27], [26, 27]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l5-s5/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d2304ad7d6a27b40f75d2851651d9f7ecc28adef --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 2, 2, 1, 2, 2, 2, 2, 2, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 2, 2, 1, 1, 1, 2, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l5-s5/tests/check.py b/tasks/construct-rlve-even-degree-partition-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s5/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-l5-s5/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bcc9c49e19e48dcd36c0ec22cf8d9d856650599b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 28, "edges": [[0, 1], [0, 4], [0, 17], [0, 24], [1, 2], [1, 6], [1, 7], [1, 12], [1, 17], [1, 19], [1, 24], [1, 25], [2, 4], [2, 8], [2, 9], [2, 15], [2, 17], [3, 8], [3, 10], [3, 15], [3, 16], [3, 18], [3, 22], [3, 25], [3, 26], [3, 27], [4, 5], [4, 6], [4, 9], [4, 11], [4, 12], [4, 15], [4, 17], [4, 20], [4, 24], [5, 7], [5, 8], [5, 16], [5, 19], [5, 20], [5, 24], [6, 27], [7, 11], [7, 14], [7, 17], [7, 24], [8, 12], [8, 14], [8, 17], [8, 25], [9, 16], [9, 18], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [10, 14], [10, 15], [10, 18], [10, 23], [10, 27], [11, 21], [11, 22], [11, 25], [11, 27], [12, 17], [12, 19], [12, 24], [13, 15], [13, 16], [13, 23], [13, 27], [14, 15], [14, 21], [14, 23], [15, 16], [15, 18], [15, 23], [15, 27], [16, 18], [16, 23], [16, 26], [16, 27], [17, 19], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [20, 22], [21, 22], [21, 23], [21, 27], [22, 26], [22, 27], [23, 25], [23, 27], [24, 25], [25, 27], [26, 27]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l5-s5/tests/run.py b/tasks/construct-rlve-even-degree-partition-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l5-s5/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-graph-isomorphism-l3-s1/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s1/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..564782b413d7e35880aac49b9348dd6d144dd864 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[1, 5], [2, 9], [0, 4], [6, 10], [2, 10], [2, 6], [6, 7], [1, 9], [7, 11], [2, 4], [0, 6], [1, 7], [5, 11], [0, 10], [3, 11], [0, 11], [3, 8], [0, 7], [1, 11], [9, 10], [3, 4], [7, 8], [1, 4], [0, 9], [1, 8], [2, 3], [7, 9], [8, 9], [6, 8], [5, 10], [0, 1], [9, 11], [0, 2], [0, 5], [4, 6], [1, 10], [8, 11], [0, 8], [2, 11], [3, 5], [10, 11], [5, 8]], "edges2": [[3, 11], [0, 1], [9, 10], [6, 8], [0, 4], [4, 10], [3, 4], [5, 9], [2, 11], [5, 7], [1, 5], [10, 11], [7, 9], [3, 5], [1, 6], [4, 6], [0, 5], [4, 5], [2, 7], [4, 8], [1, 10], [1, 7], [6, 10], [0, 3], [0, 6], [0, 2], [1, 2], [1, 9], [4, 11], [3, 8], [3, 6], [2, 3], [5, 6], [3, 9], [5, 8], [8, 9], [5, 11], [0, 11], [0, 8], [4, 7], [0, 10], [5, 10]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s1/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a169ad565ede52e877f7b8060ac9897fe46835ff --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [5, 4, 1, 2, 7, 11, 9, 8, 3, 6, 10, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..564782b413d7e35880aac49b9348dd6d144dd864 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[1, 5], [2, 9], [0, 4], [6, 10], [2, 10], [2, 6], [6, 7], [1, 9], [7, 11], [2, 4], [0, 6], [1, 7], [5, 11], [0, 10], [3, 11], [0, 11], [3, 8], [0, 7], [1, 11], [9, 10], [3, 4], [7, 8], [1, 4], [0, 9], [1, 8], [2, 3], [7, 9], [8, 9], [6, 8], [5, 10], [0, 1], [9, 11], [0, 2], [0, 5], [4, 6], [1, 10], [8, 11], [0, 8], [2, 11], [3, 5], [10, 11], [5, 8]], "edges2": [[3, 11], [0, 1], [9, 10], [6, 8], [0, 4], [4, 10], [3, 4], [5, 9], [2, 11], [5, 7], [1, 5], [10, 11], [7, 9], [3, 5], [1, 6], [4, 6], [0, 5], [4, 5], [2, 7], [4, 8], [1, 10], [1, 7], [6, 10], [0, 3], [0, 6], [0, 2], [1, 2], [1, 9], [4, 11], [3, 8], [3, 6], [2, 3], [5, 6], [3, 9], [5, 8], [8, 9], [5, 11], [0, 11], [0, 8], [4, 7], [0, 10], [5, 10]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s1/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s6/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s6/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4fd29964aecd8c5426e6e3b19bd4c2acc8ca93a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[8, 10], [6, 10], [8, 11], [0, 10], [1, 10], [1, 9], [6, 8], [8, 9], [0, 9]], "edges2": [[2, 9], [1, 9], [3, 9], [3, 7], [1, 3], [3, 11], [10, 11], [9, 10], [7, 10]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s6/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..325522eafee3f048c4402ff075cc9e09bc6d86b3 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [11, 7, 0, 5, 4, 8, 1, 6, 9, 10, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-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-l3-s6/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4fd29964aecd8c5426e6e3b19bd4c2acc8ca93a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[8, 10], [6, 10], [8, 11], [0, 10], [1, 10], [1, 9], [6, 8], [8, 9], [0, 9]], "edges2": [[2, 9], [1, 9], [3, 9], [3, 7], [1, 3], [3, 11], [10, 11], [9, 10], [7, 10]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s6/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s8/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s8/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..597f043181e447b65d3c084d9832982f0a7a5fbd --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[9, 10], [4, 6], [2, 4], [6, 11], [1, 5], [5, 8], [3, 5], [9, 11], [2, 11], [5, 11], [5, 9], [1, 3], [1, 9], [2, 10], [1, 4], [2, 7], [3, 6], [0, 6], [2, 3], [0, 8], [0, 7], [0, 4], [4, 9], [10, 11], [7, 10], [0, 3], [8, 9], [2, 5], [4, 7]], "edges2": [[7, 11], [3, 10], [1, 6], [3, 5], [1, 10], [0, 2], [7, 8], [2, 10], [10, 11], [3, 9], [5, 8], [5, 11], [4, 8], [4, 9], [1, 3], [0, 11], [0, 6], [2, 4], [8, 9], [6, 11], [8, 11], [4, 6], [6, 8], [2, 3], [7, 9], [4, 10], [7, 10], [0, 4], [1, 9]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s8/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff780893985d5ea37065b25c608754656fdf934d --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [3, 7, 4, 9, 10, 8, 1, 2, 5, 11, 0, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..597f043181e447b65d3c084d9832982f0a7a5fbd --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "edges1": [[9, 10], [4, 6], [2, 4], [6, 11], [1, 5], [5, 8], [3, 5], [9, 11], [2, 11], [5, 11], [5, 9], [1, 3], [1, 9], [2, 10], [1, 4], [2, 7], [3, 6], [0, 6], [2, 3], [0, 8], [0, 7], [0, 4], [4, 9], [10, 11], [7, 10], [0, 3], [8, 9], [2, 5], [4, 7]], "edges2": [[7, 11], [3, 10], [1, 6], [3, 5], [1, 10], [0, 2], [7, 8], [2, 10], [10, 11], [3, 9], [5, 8], [5, 11], [4, 8], [4, 9], [1, 3], [0, 11], [0, 6], [2, 4], [8, 9], [6, 11], [8, 11], [4, 6], [6, 8], [2, 3], [7, 9], [4, 10], [7, 10], [0, 4], [1, 9]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l3-s8/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-grid-parity-construction-l3-s1/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s1/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a0be4a563c410c31e54cf1d6cb8f9a85756a61c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["0001", "1101", "0000", "0000", "1000", "0111"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s1/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..41b3d03097ac553885a5add6765b7281ebadc1de --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["0001", "0010", "1011", "1010", "0000", "0010"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a0be4a563c410c31e54cf1d6cb8f9a85756a61c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["0001", "1101", "0000", "0000", "1000", "0111"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s1/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s8/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s8/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b6041f4112d39baf710931e4c27f2eba7b45a120 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["11", "00", "00", "10", "11", "01"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s8/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eb43cf80dd0d68088842c1696e27aa95a3239191 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["11", "11", "11", "11", "01", "11"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b6041f4112d39baf710931e4c27f2eba7b45a120 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["11", "00", "00", "10", "11", "01"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s8/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-imp-party-l1-s9/environment/Dockerfile b/tasks/construct-rlve-imp-party-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l1-s9/environment/instance.json b/tasks/construct-rlve-imp-party-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..595891a821a91e32c3c8d7c32058b393fe94fdd5 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "edges": [[0, 1], [0, 5], [0, 6], [0, 7], [0, 8], [1, 2], [1, 5], [1, 6], [1, 7], [1, 8], [2, 5], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l1-s9/solution/solve.sh b/tasks/construct-rlve-imp-party-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..da2a43c1fe05b22807800c696916113bf111109c --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [5, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l1-s9/tests/check.py b/tasks/construct-rlve-imp-party-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s9/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l1-s9/tests/instance.json b/tasks/construct-rlve-imp-party-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..595891a821a91e32c3c8d7c32058b393fe94fdd5 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "edges": [[0, 1], [0, 5], [0, 6], [0, 7], [0, 8], [1, 2], [1, 5], [1, 6], [1, 7], [1, 8], [2, 5], [3, 5], [3, 6], [3, 7], [4, 5], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8], [6, 7], [6, 8], [7, 8]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l1-s9/tests/run.py b/tasks/construct-rlve-imp-party-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l1-s9/tests/test.sh b/tasks/construct-rlve-imp-party-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l5-s1/environment/Dockerfile b/tasks/construct-rlve-imp-party-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l5-s1/environment/instance.json b/tasks/construct-rlve-imp-party-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eba63ec41936188a592e7b24177fd44b677dade2 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 25], [0, 26], [0, 30], [0, 33], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 41], [0, 43], [0, 45], [0, 48], [0, 50], [0, 51], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 30], [1, 33], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 43], [1, 45], [1, 48], [1, 50], [1, 51], [3, 24], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 26], [4, 30], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 43], [4, 45], [4, 48], [4, 50], [4, 51], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 24], [5, 25], [5, 26], [5, 29], [5, 30], [5, 33], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 40], [5, 41], [5, 43], [5, 45], [5, 48], [5, 50], [5, 51], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 24], [6, 25], [6, 26], [6, 30], [6, 33], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 43], [6, 45], [6, 48], [6, 50], [6, 51], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 25], [7, 26], [7, 30], [7, 33], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 43], [7, 45], [7, 46], [7, 48], [7, 50], [7, 51], [8, 9], [8, 10], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 24], [8, 25], [8, 26], [8, 30], [8, 33], [8, 35], [8, 36], [8, 37], [8, 38], [8, 39], [8, 40], [8, 41], [8, 43], [8, 45], [8, 48], [8, 50], [8, 51], [9, 10], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 24], [9, 25], [9, 26], [9, 30], [9, 33], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 43], [9, 45], [9, 46], [9, 48], [9, 50], [9, 51], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 25], [10, 26], [10, 30], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 43], [10, 45], [10, 48], [10, 50], [10, 51], [10, 53], [12, 13], [12, 14], [12, 15], [12, 16], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 24], [12, 25], [12, 26], [12, 30], [12, 33], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [12, 40], [12, 41], [12, 43], [12, 45], [12, 48], [12, 50], [12, 51], [13, 14], [13, 15], [13, 16], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 26], [13, 30], [13, 33], [13, 35], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 41], [13, 43], [13, 45], [13, 48], [13, 50], [13, 51], [14, 15], [14, 16], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 30], [14, 33], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [14, 40], [14, 41], [14, 43], [14, 45], [14, 48], [14, 50], [14, 51], [15, 16], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 24], [15, 25], [15, 26], [15, 30], [15, 33], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 43], [15, 45], [15, 48], [15, 50], [15, 51], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 30], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [16, 45], [16, 48], [16, 50], [16, 51], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 30], [18, 33], [18, 35], [18, 36], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 43], [18, 45], [18, 48], [18, 50], [18, 51], [19, 20], [19, 21], [19, 22], [19, 24], [19, 25], [19, 26], [19, 30], [19, 33], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 43], [19, 45], [19, 48], [19, 50], [19, 51], [20, 21], [20, 22], [20, 24], [20, 25], [20, 26], [20, 30], [20, 33], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 43], [20, 45], [20, 48], [20, 50], [20, 51], [21, 22], [21, 24], [21, 25], [21, 26], [21, 30], [21, 33], [21, 34], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 43], [21, 45], [21, 48], [21, 50], [21, 51], [22, 24], [22, 25], [22, 26], [22, 30], [22, 33], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [22, 40], [22, 41], [22, 43], [22, 45], [22, 48], [22, 50], [22, 51], [23, 30], [24, 25], [24, 26], [24, 30], [24, 33], [24, 35], [24, 36], [24, 37], [24, 38], [24, 39], [24, 40], [24, 41], [24, 43], [24, 45], [24, 48], [24, 50], [24, 51], [25, 26], [25, 30], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 43], [25, 45], [25, 48], [25, 50], [25, 51], [26, 30], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 41], [26, 43], [26, 45], [26, 48], [26, 50], [26, 51], [30, 33], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [30, 40], [30, 41], [30, 43], [30, 45], [30, 48], [30, 50], [30, 51], [30, 52], [33, 35], [33, 36], [33, 37], [33, 38], [33, 39], [33, 40], [33, 41], [33, 43], [33, 45], [33, 48], [33, 50], [33, 51], [35, 36], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 43], [35, 45], [35, 48], [35, 50], [35, 51], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 43], [36, 45], [36, 48], [36, 50], [36, 51], [37, 38], [37, 39], [37, 40], [37, 41], [37, 43], [37, 45], [37, 48], [37, 50], [37, 51], [38, 39], [38, 40], [38, 41], [38, 43], [38, 45], [38, 48], [38, 50], [38, 51], [39, 40], [39, 41], [39, 43], [39, 45], [39, 48], [39, 50], [39, 51], [40, 41], [40, 43], [40, 45], [40, 48], [40, 50], [40, 51], [41, 43], [41, 45], [41, 48], [41, 49], [41, 50], [41, 51], [43, 45], [43, 48], [43, 50], [43, 51], [45, 48], [45, 50], [45, 51], [48, 50], [48, 51], [50, 51]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l5-s1/solution/solve.sh b/tasks/construct-rlve-imp-party-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc9e37a78e3550b62630dc98e5b89aa1dd7b383a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [4, 5, 6, 7, 8, 16, 20, 24, 30, 33, 37, 38, 40, 41, 43, 48, 50, 51]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l5-s1/tests/check.py b/tasks/construct-rlve-imp-party-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s1/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l5-s1/tests/instance.json b/tasks/construct-rlve-imp-party-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eba63ec41936188a592e7b24177fd44b677dade2 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 25], [0, 26], [0, 30], [0, 33], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 41], [0, 43], [0, 45], [0, 48], [0, 50], [0, 51], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 30], [1, 33], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 43], [1, 45], [1, 48], [1, 50], [1, 51], [3, 24], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 26], [4, 30], [4, 33], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 43], [4, 45], [4, 48], [4, 50], [4, 51], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 24], [5, 25], [5, 26], [5, 29], [5, 30], [5, 33], [5, 35], [5, 36], [5, 37], [5, 38], [5, 39], [5, 40], [5, 41], [5, 43], [5, 45], [5, 48], [5, 50], [5, 51], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 24], [6, 25], [6, 26], [6, 30], [6, 33], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 43], [6, 45], [6, 48], [6, 50], [6, 51], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 24], [7, 25], [7, 26], [7, 30], [7, 33], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 43], [7, 45], [7, 46], [7, 48], [7, 50], [7, 51], [8, 9], [8, 10], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 24], [8, 25], [8, 26], [8, 30], [8, 33], [8, 35], [8, 36], [8, 37], [8, 38], [8, 39], [8, 40], [8, 41], [8, 43], [8, 45], [8, 48], [8, 50], [8, 51], [9, 10], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 24], [9, 25], [9, 26], [9, 30], [9, 33], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 43], [9, 45], [9, 46], [9, 48], [9, 50], [9, 51], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 25], [10, 26], [10, 30], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 43], [10, 45], [10, 48], [10, 50], [10, 51], [10, 53], [12, 13], [12, 14], [12, 15], [12, 16], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 24], [12, 25], [12, 26], [12, 30], [12, 33], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [12, 40], [12, 41], [12, 43], [12, 45], [12, 48], [12, 50], [12, 51], [13, 14], [13, 15], [13, 16], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 26], [13, 30], [13, 33], [13, 35], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 41], [13, 43], [13, 45], [13, 48], [13, 50], [13, 51], [14, 15], [14, 16], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 30], [14, 33], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [14, 40], [14, 41], [14, 43], [14, 45], [14, 48], [14, 50], [14, 51], [15, 16], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 24], [15, 25], [15, 26], [15, 30], [15, 33], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 43], [15, 45], [15, 48], [15, 50], [15, 51], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 30], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [16, 45], [16, 48], [16, 50], [16, 51], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 30], [18, 33], [18, 35], [18, 36], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 43], [18, 45], [18, 48], [18, 50], [18, 51], [19, 20], [19, 21], [19, 22], [19, 24], [19, 25], [19, 26], [19, 30], [19, 33], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 43], [19, 45], [19, 48], [19, 50], [19, 51], [20, 21], [20, 22], [20, 24], [20, 25], [20, 26], [20, 30], [20, 33], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 43], [20, 45], [20, 48], [20, 50], [20, 51], [21, 22], [21, 24], [21, 25], [21, 26], [21, 30], [21, 33], [21, 34], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 43], [21, 45], [21, 48], [21, 50], [21, 51], [22, 24], [22, 25], [22, 26], [22, 30], [22, 33], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [22, 40], [22, 41], [22, 43], [22, 45], [22, 48], [22, 50], [22, 51], [23, 30], [24, 25], [24, 26], [24, 30], [24, 33], [24, 35], [24, 36], [24, 37], [24, 38], [24, 39], [24, 40], [24, 41], [24, 43], [24, 45], [24, 48], [24, 50], [24, 51], [25, 26], [25, 30], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 43], [25, 45], [25, 48], [25, 50], [25, 51], [26, 30], [26, 33], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 41], [26, 43], [26, 45], [26, 48], [26, 50], [26, 51], [30, 33], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [30, 40], [30, 41], [30, 43], [30, 45], [30, 48], [30, 50], [30, 51], [30, 52], [33, 35], [33, 36], [33, 37], [33, 38], [33, 39], [33, 40], [33, 41], [33, 43], [33, 45], [33, 48], [33, 50], [33, 51], [35, 36], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 43], [35, 45], [35, 48], [35, 50], [35, 51], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 43], [36, 45], [36, 48], [36, 50], [36, 51], [37, 38], [37, 39], [37, 40], [37, 41], [37, 43], [37, 45], [37, 48], [37, 50], [37, 51], [38, 39], [38, 40], [38, 41], [38, 43], [38, 45], [38, 48], [38, 50], [38, 51], [39, 40], [39, 41], [39, 43], [39, 45], [39, 48], [39, 50], [39, 51], [40, 41], [40, 43], [40, 45], [40, 48], [40, 50], [40, 51], [41, 43], [41, 45], [41, 48], [41, 49], [41, 50], [41, 51], [43, 45], [43, 48], [43, 50], [43, 51], [45, 48], [45, 50], [45, 51], [48, 50], [48, 51], [50, 51]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l5-s1/tests/run.py b/tasks/construct-rlve-imp-party-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l5-s1/tests/test.sh b/tasks/construct-rlve-imp-party-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l5-s6/tests/run.py b/tasks/construct-rlve-imp-party-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-integer-linear-system-l2-s1/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l2-s1/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91487c44a2bc52caed308c6e7405e7d9e75d25bc --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0, 1, 0], [0, 0, 0, 1, 1], [1, 1, 1, 1, 0], [0, 1, 0, 1, 1], [0, 0, 0, 0, 1], [0, 1, 1, 0, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 0], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 0]], "rhs": [12, 6, 16, 9, 1, 8, 10, 5, 9, 13, 13], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s1/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a3a9edf7f3be13499361324345b714501ffb827d --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [4, 3, 4, 5, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l2-s1/tests/check.py b/tasks/construct-rlve-integer-linear-system-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s1/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l2-s1/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91487c44a2bc52caed308c6e7405e7d9e75d25bc --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0, 1, 0], [0, 0, 0, 1, 1], [1, 1, 1, 1, 0], [0, 1, 0, 1, 1], [0, 0, 0, 0, 1], [0, 1, 1, 0, 1], [0, 0, 1, 1, 1], [0, 0, 0, 1, 0], [1, 0, 1, 0, 1], [1, 1, 0, 1, 1], [1, 0, 1, 1, 0]], "rhs": [12, 6, 16, 9, 1, 8, 10, 5, 9, 13, 13], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s1/tests/run.py b/tasks/construct-rlve-integer-linear-system-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l2-s1/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l2-s6/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l2-s6/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea5e630f0d4022896b80c54f206ab5acdcc50af1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 0, 0, 1], [1, 1, 0, 1, 1], [1, 1, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 1], [0, 0, 1, 0, 1], [0, 1, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], [1, 1, 0, 1, 1], [0, 1, 1, 1, 1], [0, 1, 0, 1, 0]], "rhs": [2, 12, 5, 7, 5, 3, 10, 6, 8, 4, 2, 7, 10, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s6/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f6e66ddcf650459fab390403ff5163c980ac0e1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 2, 5, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l2-s6/tests/check.py b/tasks/construct-rlve-integer-linear-system-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s6/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l2-s6/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea5e630f0d4022896b80c54f206ab5acdcc50af1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 0, 0, 0, 0], [1, 1, 1, 1, 1], [1, 1, 0, 0, 1], [1, 1, 0, 1, 1], [1, 1, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 1, 1, 1], [0, 0, 1, 0, 1], [0, 1, 1, 0, 1], [0, 1, 0, 1, 0], [0, 0, 0, 1, 0], [1, 1, 0, 1, 1], [0, 1, 1, 1, 1], [0, 1, 0, 1, 0]], "rhs": [2, 12, 5, 7, 5, 3, 10, 6, 8, 4, 2, 7, 10, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l2-s6/tests/run.py b/tasks/construct-rlve-integer-linear-system-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l2-s6/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l6-s9/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l6-s9/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..51265bd02ca653c13b3085c6df0b559f2952a844 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 0, 2, 0, 0, 5, 3, 0, 0, 0, 1, 0, 0, 0, 4, 1, 0, 4, 2, 0, 5, 0, 1, 0, 0, 3], [0, 0, 0, 0, 5, 3, 0, 1, 3, 4, 0, 0, 2, 1, 4, 3, 0, 0, 3, 0, 0, 5, 0, 1, 0, 0], [0, 0, 4, 0, 2, 1, 0, 2, 0, 2, 0, 0, 2, 2, 0, 3, 2, 1, 0, 0, 0, 2, 0, 0, 4, 3], [0, 0, 2, 5, 0, 4, 0, 0, 5, 0, 1, 2, 0, 4, 0, 4, 4, 3, 0, 0, 2, 1, 1, 0, 0, 2], [2, 3, 2, 1, 0, 2, 0, 3, 0, 1, 0, 5, 0, 0, 5, 0, 0, 2, 3, 4, 0, 5, 3, 0, 1, 0], [4, 1, 0, 0, 4, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 5, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0], [0, 3, 3, 1, 3, 1, 0, 5, 1, 1, 0, 1, 3, 0, 4, 3, 0, 0, 0, 0, 0, 2, 5, 0, 0, 2], [4, 0, 5, 0, 3, 0, 0, 0, 2, 5, 2, 0, 0, 4, 0, 2, 0, 0, 3, 2, 0, 3, 0, 4, 4, 3], [0, 4, 3, 0, 4, 0, 0, 0, 3, 5, 1, 3, 5, 4, 0, 4, 4, 0, 1, 4, 2, 0, 4, 3, 4, 0], [4, 4, 0, 3, 0, 0, 0, 0, 4, 0, 1, 0, 0, 4, 0, 0, 0, 2, 0, 4, 4, 1, 0, 0, 0, 5], [4, 2, 4, 4, 0, 1, 0, 0, 0, 0, 1, 0, 0, 4, 2, 4, 0, 0, 4, 0, 0, 3, 1, 1, 5, 5], [0, 3, 0, 0, 2, 0, 1, 4, 4, 5, 0, 2, 0, 0, 2, 0, 4, 0, 0, 0, 0, 0, 0, 3, 2, 1], [0, 5, 4, 4, 2, 2, 0, 0, 2, 1, 3, 4, 5, 0, 5, 0, 4, 5, 1, 0, 4, 3, 0, 0, 0, 0], [1, 4, 0, 4, 0, 0, 0, 0, 5, 0, 0, 0, 5, 4, 1, 2, 0, 3, 0, 3, 0, 4, 3, 3, 0, 0], [3, 0, 1, 5, 0, 0, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 3, 0, 0], [0, 0, 0, 0, 4, 3, 0, 3, 3, 3, 0, 0, 0, 0, 5, 2, 0, 1, 0, 4, 0, 4, 1, 0, 0, 2], [0, 0, 1, 0, 0, 5, 1, 0, 3, 2, 0, 3, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 0, 5, 0, 2, 2, 0, 0, 1, 4, 2, 3, 2, 4, 3, 0, 0, 2, 2, 0, 5, 1, 0, 3, 5, 3], [3, 5, 4, 0, 4, 0, 0, 0, 1, 0, 0, 4, 0, 5, 3, 0, 2, 0, 0, 0, 5, 1, 0, 5, 0, 3], [2, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 2, 0, 4, 0, 0, 0, 2, 4, 3, 5, 0, 0, 0, 3, 0], [0, 3, 0, 0, 0, 5, 0, 5, 0, 1, 3, 0, 2, 0, 0, 4, 0, 0, 0, 4, 5, 3, 0, 0, 1, 4], [1, 0, 0, 4, 3, 3, 5, 4, 3, 0, 0, 0, 4, 5, 3, 0, 0, 3, 0, 4, 5, 0, 1, 0, 0, 3], [2, 0, 3, 5, 3, 3, 3, 1, 5, 3, 0, 5, 0, 1, 1, 5, 0, 0, 4, 0, 0, 0, 4, 0, 5, 1], [5, 0, 4, 0, 0, 5, 3, 0, 0, 0, 0, 0, 4, 0, 0, 0, 5, 1, 0, 0, 0, 1, 0, 0, 0, 0], [1, 1, 5, 0, 0, 0, 0, 1, 0, 4, 3, 0, 0, 0, 0, 0, 0, 5, 0, 2, 0, 5, 4, 0, 2, 3], [4, 0, 0, 4, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 4, 0, 0, 0, 3], [1, 0, 0, 0, 0, 0, 0, 5, 3, 4, 1, 0, 0, 5, 3, 0, 5, 0, 0, 3, 4, 1, 0, 3, 0, 5], [0, 0, 3, 0, 0, 2, 0, 0, 0, 5, 0, 1, 0, 1, 0, 0, 5, 5, 4, 3, 0, 0, 3, 0, 0, 0], [0, 3, 0, 0, 0, 3, 5, 0, 0, 2, 0, 0, 5, 0, 0, 2, 2, 0, 0, 4, 2, 3, 1, 0, 0, 0], [0, 0, 2, 4, 3, 3, 4, 1, 5, 0, 0, 4, 0, 0, 1, 0, 3, 4, 0, 2, 3, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 5, 0, 5, 1, 2, 0, 4, 0, 0, 0, 0, 2, 5, 4, 5, 3, 3, 2, 3, 0, 5], [5, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 3, 0, 2, 1, 0, 0, 5, 2, 1, 2, 0, 2, 4], [0, 0, 0, 0, 1, 0, 0, 3, 1, 3, 0, 0, 0, 3, 0, 5, 0, 1, 2, 1, 0, 1, 0, 0, 0, 5], [2, 3, 0, 3, 1, 4, 0, 0, 0, 0, 2, 3, 0, 0, 5, 0, 0, 5, 1, 4, 0, 1, 1, 0, 2, 0], [0, 0, 0, 1, 2, 0, 0, 5, 0, 0, 1, 0, 0, 5, 5, 1, 1, 0, 0, 0, 0, 0, 1, 5, 0, 0], [0, 5, 0, 0, 2, 1, 1, 0, 0, 4, 4, 2, 5, 0, 0, 1, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2], [3, 0, 5, 0, 0, 0, 0, 2, 4, 3, 1, 5, 1, 0, 2, 2, 4, 0, 0, 0, 0, 5, 0, 0, 4, 0], [0, 0, 1, 2, 4, 5, 0, 5, 5, 0, 0, 3, 0, 0, 5, 4, 0, 0, 1, 2, 0, 0, 5, 0, 1, 0], [0, 0, 0, 4, 0, 0, 4, 1, 0, 0, 0, 0, 1, 5, 1, 0, 2, 0, 4, 0, 4, 5, 0, 0, 1, 1], [0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 3, 5, 0, 0, 2, 0, 2, 4, 0], [0, 0, 0, 3, 3, 4, 2, 0, 0, 2, 0, 0, 5, 0, 0, 0, 0, 0, 4, 1, 0, 1, 0, 5, 0, 3], [0, 3, 5, 3, 3, 0, 0, 0, 1, 2, 0, 0, 3, 0, 2, 0, 0, 4, 0, 5, 0, 0, 5, 0, 1, 0], [4, 0, 1, 0, 0, 1, 4, 3, 0, 0, 4, 3, 0, 0, 0, 0, 5, 1, 1, 5, 2, 0, 5, 5, 0, 2], [0, 0, 2, 5, 0, 2, 0, 0, 1, 0, 0, 4, 2, 0, 5, 0, 3, 0, 0, 5, 5, 0, 2, 5, 0, 4], [3, 3, 0, 3, 0, 0, 0, 5, 0, 0, 0, 0, 5, 5, 0, 0, 3, 0, 2, 1, 0, 0, 0, 0, 0, 0], [5, 0, 0, 3, 3, 3, 1, 0, 2, 4, 1, 0, 2, 5, 5, 0, 0, 5, 0, 4, 0, 0, 2, 3, 2, 2], [0, 3, 1, 5, 0, 2, 0, 1, 0, 3, 0, 5, 1, 1, 5, 0, 2, 1, 4, 4, 2, 0, 0, 1, 2, 1], [3, 4, 3, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 2, 2, 5, 1, 0, 3, 0, 1, 5, 0, 0, 1], [0, 0, 0, 0, 2, 0, 5, 5, 5, 0, 0, 0, 5, 0, 0, 4, 3, 4, 0, 0, 0, 5, 2, 5, 4, 0], [4, 5, 0, 4, 3, 1, 2, 0, 1, 0, 0, 0, 2, 0, 5, 0, 0, 0, 3, 5, 1, 0, 0, 4, 2, 0], [0, 0, 3, 3, 0, 1, 3, 4, 0, 5, 5, 0, 0, 0, 1, 5, 0, 2, 3, 0, 0, 2, 0, 0, 0, 0], [5, 1, 5, 0, 4, 0, 3, 5, 3, 0, 0, 4, 1, 1, 5, 5, 0, 3, 3, 3, 1, 0, 5, 2, 5, 1], [0, 5, 0, 0, 0, 4, 0, 2, 0, 0, 1, 5, 0, 3, 4, 3, 3, 2, 0, 0, 0, 3, 1, 0, 0, 5], [0, 1, 5, 4, 1, 2, 3, 0, 2, 0, 2, 1, 0, 0, 1, 0, 0, 5, 0, 1, 5, 0, 0, 0, 0, 0], [1, 4, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 4, 4, 3, 0, 0, 0, 5, 0, 0, 2, 2, 0, 4], [0, 3, 5, 4, 0, 0, 1, 0, 1, 0, 2, 0, 1, 3, 0, 0, 5, 0, 0, 0, 5, 3, 0, 5, 0, 0], [0, 0, 4, 0, 0, 4, 4, 0, 5, 0, 1, 0, 0, 2, 0, 0, 0, 1, 4, 0, 0, 2, 5, 3, 3, 0], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 0, 5, 0, 1, 5, 0, 0, 0, 1, 5, 0], [4, 0, 0, 0, 2, 2, 5, 5, 1, 0, 0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 4, 5, 0, 0, 0, 0], [1, 1, 4, 0, 0, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1, 0, 3, 3, 0, 2, 0, 5, 5, 3], [0, 0, 0, 0, 5, 5, 0, 1, 5, 0, 0, 4, 0, 0, 0, 4, 3, 0, 4, 0, 0, 0, 0, 4, 0, 4], [0, 3, 1, 0, 5, 2, 2, 4, 0, 0, 3, 1, 0, 0, 4, 1, 0, 0, 3, 0, 0, 2, 0, 3, 0, 5], [0, 0, 2, 2, 2, 1, 1, 0, 2, 0, 2, 1, 1, 3, 1, 2, 0, 0, 1, 0, 4, 4, 1, 0, 3, 5], [0, 1, 2, 3, 0, 3, 3, 0, 3, 0, 0, 4, 1, 5, 5, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 4], [0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 3, 0, 2, 0, 0, 2, 0, 5, 4, 0, 0, 0, 0, 0, 0, 4], [0, 0, 0, 1, 0, 0, 4, 4, 4, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 2, 0, 0], [0, 4, 4, 0, 5, 2, 0, 0, 2, 4, 0, 0, 0, 3, 3, 0, 0, 1, 1, 5, 2, 0, 2, 0, 1, 0]], "rhs": [485, 522, 489, 566, 720, 322, 601, 692, 802, 382, 697, 393, 812, 542, 380, 510, 348, 747, 477, 380, 629, 621, 893, 419, 715, 395, 439, 590, 464, 545, 826, 375, 376, 611, 277, 523, 639, 659, 434, 370, 512, 641, 638, 588, 356, 700, 678, 512, 664, 514, 718, 962, 573, 546, 422, 486, 612, 307, 531, 521, 517, 546, 538, 493, 364, 231, 561], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l6-s9/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1fd8da02660878aba9dd8e4e5b259f114a9d6971 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [9, 10, 26, 21, 11, 24, 10, 17, 2, 23, 20, 19, 13, 3, 6, 17, 5, 22, 21, 14, 8, 21, 22, 8, 18, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l6-s9/tests/check.py b/tasks/construct-rlve-integer-linear-system-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s9/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l6-s9/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..51265bd02ca653c13b3085c6df0b559f2952a844 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 0, 2, 0, 0, 5, 3, 0, 0, 0, 1, 0, 0, 0, 4, 1, 0, 4, 2, 0, 5, 0, 1, 0, 0, 3], [0, 0, 0, 0, 5, 3, 0, 1, 3, 4, 0, 0, 2, 1, 4, 3, 0, 0, 3, 0, 0, 5, 0, 1, 0, 0], [0, 0, 4, 0, 2, 1, 0, 2, 0, 2, 0, 0, 2, 2, 0, 3, 2, 1, 0, 0, 0, 2, 0, 0, 4, 3], [0, 0, 2, 5, 0, 4, 0, 0, 5, 0, 1, 2, 0, 4, 0, 4, 4, 3, 0, 0, 2, 1, 1, 0, 0, 2], [2, 3, 2, 1, 0, 2, 0, 3, 0, 1, 0, 5, 0, 0, 5, 0, 0, 2, 3, 4, 0, 5, 3, 0, 1, 0], [4, 1, 0, 0, 4, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 5, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0], [0, 3, 3, 1, 3, 1, 0, 5, 1, 1, 0, 1, 3, 0, 4, 3, 0, 0, 0, 0, 0, 2, 5, 0, 0, 2], [4, 0, 5, 0, 3, 0, 0, 0, 2, 5, 2, 0, 0, 4, 0, 2, 0, 0, 3, 2, 0, 3, 0, 4, 4, 3], [0, 4, 3, 0, 4, 0, 0, 0, 3, 5, 1, 3, 5, 4, 0, 4, 4, 0, 1, 4, 2, 0, 4, 3, 4, 0], [4, 4, 0, 3, 0, 0, 0, 0, 4, 0, 1, 0, 0, 4, 0, 0, 0, 2, 0, 4, 4, 1, 0, 0, 0, 5], [4, 2, 4, 4, 0, 1, 0, 0, 0, 0, 1, 0, 0, 4, 2, 4, 0, 0, 4, 0, 0, 3, 1, 1, 5, 5], [0, 3, 0, 0, 2, 0, 1, 4, 4, 5, 0, 2, 0, 0, 2, 0, 4, 0, 0, 0, 0, 0, 0, 3, 2, 1], [0, 5, 4, 4, 2, 2, 0, 0, 2, 1, 3, 4, 5, 0, 5, 0, 4, 5, 1, 0, 4, 3, 0, 0, 0, 0], [1, 4, 0, 4, 0, 0, 0, 0, 5, 0, 0, 0, 5, 4, 1, 2, 0, 3, 0, 3, 0, 4, 3, 3, 0, 0], [3, 0, 1, 5, 0, 0, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 3, 0, 0], [0, 0, 0, 0, 4, 3, 0, 3, 3, 3, 0, 0, 0, 0, 5, 2, 0, 1, 0, 4, 0, 4, 1, 0, 0, 2], [0, 0, 1, 0, 0, 5, 1, 0, 3, 2, 0, 3, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [1, 0, 5, 0, 2, 2, 0, 0, 1, 4, 2, 3, 2, 4, 3, 0, 0, 2, 2, 0, 5, 1, 0, 3, 5, 3], [3, 5, 4, 0, 4, 0, 0, 0, 1, 0, 0, 4, 0, 5, 3, 0, 2, 0, 0, 0, 5, 1, 0, 5, 0, 3], [2, 0, 0, 0, 2, 1, 0, 0, 1, 0, 0, 2, 0, 4, 0, 0, 0, 2, 4, 3, 5, 0, 0, 0, 3, 0], [0, 3, 0, 0, 0, 5, 0, 5, 0, 1, 3, 0, 2, 0, 0, 4, 0, 0, 0, 4, 5, 3, 0, 0, 1, 4], [1, 0, 0, 4, 3, 3, 5, 4, 3, 0, 0, 0, 4, 5, 3, 0, 0, 3, 0, 4, 5, 0, 1, 0, 0, 3], [2, 0, 3, 5, 3, 3, 3, 1, 5, 3, 0, 5, 0, 1, 1, 5, 0, 0, 4, 0, 0, 0, 4, 0, 5, 1], [5, 0, 4, 0, 0, 5, 3, 0, 0, 0, 0, 0, 4, 0, 0, 0, 5, 1, 0, 0, 0, 1, 0, 0, 0, 0], [1, 1, 5, 0, 0, 0, 0, 1, 0, 4, 3, 0, 0, 0, 0, 0, 0, 5, 0, 2, 0, 5, 4, 0, 2, 3], [4, 0, 0, 4, 0, 2, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 2, 0, 4, 0, 0, 0, 3], [1, 0, 0, 0, 0, 0, 0, 5, 3, 4, 1, 0, 0, 5, 3, 0, 5, 0, 0, 3, 4, 1, 0, 3, 0, 5], [0, 0, 3, 0, 0, 2, 0, 0, 0, 5, 0, 1, 0, 1, 0, 0, 5, 5, 4, 3, 0, 0, 3, 0, 0, 0], [0, 3, 0, 0, 0, 3, 5, 0, 0, 2, 0, 0, 5, 0, 0, 2, 2, 0, 0, 4, 2, 3, 1, 0, 0, 0], [0, 0, 2, 4, 3, 3, 4, 1, 5, 0, 0, 4, 0, 0, 1, 0, 3, 4, 0, 2, 3, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 5, 0, 5, 1, 2, 0, 4, 0, 0, 0, 0, 2, 5, 4, 5, 3, 3, 2, 3, 0, 5], [5, 0, 0, 0, 1, 1, 2, 0, 0, 0, 0, 0, 0, 3, 0, 2, 1, 0, 0, 5, 2, 1, 2, 0, 2, 4], [0, 0, 0, 0, 1, 0, 0, 3, 1, 3, 0, 0, 0, 3, 0, 5, 0, 1, 2, 1, 0, 1, 0, 0, 0, 5], [2, 3, 0, 3, 1, 4, 0, 0, 0, 0, 2, 3, 0, 0, 5, 0, 0, 5, 1, 4, 0, 1, 1, 0, 2, 0], [0, 0, 0, 1, 2, 0, 0, 5, 0, 0, 1, 0, 0, 5, 5, 1, 1, 0, 0, 0, 0, 0, 1, 5, 0, 0], [0, 5, 0, 0, 2, 1, 1, 0, 0, 4, 4, 2, 5, 0, 0, 1, 0, 0, 5, 0, 0, 0, 0, 0, 0, 2], [3, 0, 5, 0, 0, 0, 0, 2, 4, 3, 1, 5, 1, 0, 2, 2, 4, 0, 0, 0, 0, 5, 0, 0, 4, 0], [0, 0, 1, 2, 4, 5, 0, 5, 5, 0, 0, 3, 0, 0, 5, 4, 0, 0, 1, 2, 0, 0, 5, 0, 1, 0], [0, 0, 0, 4, 0, 0, 4, 1, 0, 0, 0, 0, 1, 5, 1, 0, 2, 0, 4, 0, 4, 5, 0, 0, 1, 1], [0, 2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0, 0, 3, 5, 0, 0, 2, 0, 2, 4, 0], [0, 0, 0, 3, 3, 4, 2, 0, 0, 2, 0, 0, 5, 0, 0, 0, 0, 0, 4, 1, 0, 1, 0, 5, 0, 3], [0, 3, 5, 3, 3, 0, 0, 0, 1, 2, 0, 0, 3, 0, 2, 0, 0, 4, 0, 5, 0, 0, 5, 0, 1, 0], [4, 0, 1, 0, 0, 1, 4, 3, 0, 0, 4, 3, 0, 0, 0, 0, 5, 1, 1, 5, 2, 0, 5, 5, 0, 2], [0, 0, 2, 5, 0, 2, 0, 0, 1, 0, 0, 4, 2, 0, 5, 0, 3, 0, 0, 5, 5, 0, 2, 5, 0, 4], [3, 3, 0, 3, 0, 0, 0, 5, 0, 0, 0, 0, 5, 5, 0, 0, 3, 0, 2, 1, 0, 0, 0, 0, 0, 0], [5, 0, 0, 3, 3, 3, 1, 0, 2, 4, 1, 0, 2, 5, 5, 0, 0, 5, 0, 4, 0, 0, 2, 3, 2, 2], [0, 3, 1, 5, 0, 2, 0, 1, 0, 3, 0, 5, 1, 1, 5, 0, 2, 1, 4, 4, 2, 0, 0, 1, 2, 1], [3, 4, 3, 0, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 2, 2, 5, 1, 0, 3, 0, 1, 5, 0, 0, 1], [0, 0, 0, 0, 2, 0, 5, 5, 5, 0, 0, 0, 5, 0, 0, 4, 3, 4, 0, 0, 0, 5, 2, 5, 4, 0], [4, 5, 0, 4, 3, 1, 2, 0, 1, 0, 0, 0, 2, 0, 5, 0, 0, 0, 3, 5, 1, 0, 0, 4, 2, 0], [0, 0, 3, 3, 0, 1, 3, 4, 0, 5, 5, 0, 0, 0, 1, 5, 0, 2, 3, 0, 0, 2, 0, 0, 0, 0], [5, 1, 5, 0, 4, 0, 3, 5, 3, 0, 0, 4, 1, 1, 5, 5, 0, 3, 3, 3, 1, 0, 5, 2, 5, 1], [0, 5, 0, 0, 0, 4, 0, 2, 0, 0, 1, 5, 0, 3, 4, 3, 3, 2, 0, 0, 0, 3, 1, 0, 0, 5], [0, 1, 5, 4, 1, 2, 3, 0, 2, 0, 2, 1, 0, 0, 1, 0, 0, 5, 0, 1, 5, 0, 0, 0, 0, 0], [1, 4, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0, 4, 4, 3, 0, 0, 0, 5, 0, 0, 2, 2, 0, 4], [0, 3, 5, 4, 0, 0, 1, 0, 1, 0, 2, 0, 1, 3, 0, 0, 5, 0, 0, 0, 5, 3, 0, 5, 0, 0], [0, 0, 4, 0, 0, 4, 4, 0, 5, 0, 1, 0, 0, 2, 0, 0, 0, 1, 4, 0, 0, 2, 5, 3, 3, 0], [3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 0, 5, 0, 1, 5, 0, 0, 0, 1, 5, 0], [4, 0, 0, 0, 2, 2, 5, 5, 1, 0, 0, 0, 0, 0, 0, 5, 0, 3, 0, 0, 4, 5, 0, 0, 0, 0], [1, 1, 4, 0, 0, 0, 1, 0, 0, 0, 0, 4, 0, 0, 0, 0, 1, 0, 3, 3, 0, 2, 0, 5, 5, 3], [0, 0, 0, 0, 5, 5, 0, 1, 5, 0, 0, 4, 0, 0, 0, 4, 3, 0, 4, 0, 0, 0, 0, 4, 0, 4], [0, 3, 1, 0, 5, 2, 2, 4, 0, 0, 3, 1, 0, 0, 4, 1, 0, 0, 3, 0, 0, 2, 0, 3, 0, 5], [0, 0, 2, 2, 2, 1, 1, 0, 2, 0, 2, 1, 1, 3, 1, 2, 0, 0, 1, 0, 4, 4, 1, 0, 3, 5], [0, 1, 2, 3, 0, 3, 3, 0, 3, 0, 0, 4, 1, 5, 5, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 4], [0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 3, 0, 2, 0, 0, 2, 0, 5, 4, 0, 0, 0, 0, 0, 0, 4], [0, 0, 0, 1, 0, 0, 4, 4, 4, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 2, 0, 0], [0, 4, 4, 0, 5, 2, 0, 0, 2, 4, 0, 0, 0, 3, 3, 0, 0, 1, 1, 5, 2, 0, 2, 0, 1, 0]], "rhs": [485, 522, 489, 566, 720, 322, 601, 692, 802, 382, 697, 393, 812, 542, 380, 510, 348, 747, 477, 380, 629, 621, 893, 419, 715, 395, 439, 590, 464, 545, 826, 375, 376, 611, 277, 523, 639, 659, 434, 370, 512, 641, 638, 588, 356, 700, 678, 512, 664, 514, 718, 962, 573, 546, 422, 486, 612, 307, 531, 521, 517, 546, 538, 493, 364, 231, 561], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l6-s9/tests/run.py b/tasks/construct-rlve-integer-linear-system-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l6-s9/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-largest-convex-polygon-l1-s1/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s1/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b6bd381fd38dda2bcb53202d6da5103a1af425cd --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[3, 1], [4, 6], [5, 1], [3, 0], [2, 5], [1, 3]], "k": 5, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s1/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..28d9e05ec79eccf4f4ac0d540414da4f0ad1fd13 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [5, 4, 1, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b6bd381fd38dda2bcb53202d6da5103a1af425cd --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[3, 1], [4, 6], [5, 1], [3, 0], [2, 5], [1, 3]], "k": 5, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..51b5cef3bad73159fadf3cb148eb6eafa6e2aaf8 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[6, 2], [3, 4], [5, 3], [4, 6], [0, 5], [6, 6]], "k": 4, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..601dee1c6c70f39b17522e2a1d5ba185e4baf5f0 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 3, 5, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..51b5cef3bad73159fadf3cb148eb6eafa6e2aaf8 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[6, 2], [3, 4], [5, 3], [4, 6], [0, 5], [6, 6]], "k": 4, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ee0bc89a7fdec7c37fb6845bec030f1ef34a713 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[6, 5], [3, 0], [2, 3], [0, 6], [5, 3], [2, 5]], "k": 5, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7cb1d1f2a244eba594970b99c3e4f5e4fe494b45 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 5, 0, 4, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0ee0bc89a7fdec7c37fb6845bec030f1ef34a713 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[6, 5], [3, 0], [2, 3], [0, 6], [5, 3], [2, 5]], "k": 5, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s0/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s0/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0271f4e3d95f53f3a8f977e430bbbbaf40c1dd59 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"points": [[4, 0], [14, 7], [3, 10], [22, 17], [21, 25], [4, 24], [19, 18], [9, 20], [16, 7], [1, 12], [16, 10], [17, 2], [14, 21], [5, 15], [2, 1], [10, 14], [1, 11], [0, 22], [21, 2], [20, 21], [23, 17], [5, 14], [9, 12], [24, 6], [10, 22]], "k": 11, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s0/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4ead44da3d9c0615299ca286941413e0106b1bdb --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [16, 9, 13, 12, 4, 19, 6, 10, 1, 0, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0271f4e3d95f53f3a8f977e430bbbbaf40c1dd59 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"points": [[4, 0], [14, 7], [3, 10], [22, 17], [21, 25], [4, 24], [19, 18], [9, 20], [16, 7], [1, 12], [16, 10], [17, 2], [14, 21], [5, 15], [2, 1], [10, 14], [1, 11], [0, 22], [21, 2], [20, 21], [23, 17], [5, 14], [9, 12], [24, 6], [10, 22]], "k": 11, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s7/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s7/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..19313410518e364433529783b2848d8623f09026 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[12, 4], [17, 0], [0, 2], [19, 18], [1, 3], [1, 12], [18, 4], [7, 1], [21, 3], [6, 17], [9, 1], [9, 10], [25, 9], [8, 23], [10, 20], [24, 13], [6, 13], [20, 6], [22, 6], [3, 17], [3, 20], [8, 16], [25, 8], [0, 15], [13, 18]], "k": 12, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s7/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..479cb5ea5cb9d9308bd1f7eb6e933451c8dd0936 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 16, 21, 24, 3, 15, 12, 22, 18, 6, 10, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-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-l5-s7/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..19313410518e364433529783b2848d8623f09026 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[12, 4], [17, 0], [0, 2], [19, 18], [1, 3], [1, 12], [18, 4], [7, 1], [21, 3], [6, 17], [9, 1], [9, 10], [25, 9], [8, 23], [10, 20], [24, 13], [6, 13], [20, 6], [22, 6], [3, 17], [3, 20], [8, 16], [25, 8], [0, 15], [13, 18]], "k": 12, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s9/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s9/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..813bc75a7b5a952373dbbf57352e22ac3e18543c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[18, 23], [14, 4], [6, 24], [21, 25], [14, 13], [2, 11], [0, 23], [25, 16], [6, 2], [7, 22], [21, 21], [17, 5], [9, 19], [0, 22], [11, 25], [7, 12], [18, 18], [20, 3], [4, 1], [23, 8], [4, 16], [8, 4], [1, 13], [15, 3], [13, 24]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s9/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cf98108bb51f2c7654f9eff760e11c35ceaf53c2 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [13, 6, 2, 24, 0, 10, 7, 19, 17, 23, 1, 15, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/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-l5-s9/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..813bc75a7b5a952373dbbf57352e22ac3e18543c --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[18, 23], [14, 4], [6, 24], [21, 25], [14, 13], [2, 11], [0, 23], [25, 16], [6, 2], [7, 22], [21, 21], [17, 5], [9, 19], [0, 22], [11, 25], [7, 12], [18, 18], [20, 3], [4, 1], [23, 8], [4, 16], [8, 4], [1, 13], [15, 3], [13, 24]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l3-s1/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l3-s1/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce0b8c7929fa65d55ac5765975209f67416b160d --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[11, 12], [1, 3], [2, 3], [1, 11], [1, -1], [16, -15], [-10, 13], [14, -9], [8, -14], [3, 0], [-3, -1], [-3, 3], [15, 7], [-3, -15], [-6, -15], [13, 5]], "area": 16, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l3-s1/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d82f282dc81572e2f21e90b942b313c1d69460bb --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 4, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l3-s1/tests/check.py b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-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-l3-s1/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce0b8c7929fa65d55ac5765975209f67416b160d --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[11, 12], [1, 3], [2, 3], [1, 11], [1, -1], [16, -15], [-10, 13], [14, -9], [8, -14], [3, 0], [-3, -1], [-3, 3], [15, 7], [-3, -15], [-6, -15], [13, 5]], "area": 16, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l3-s1/tests/run.py b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l3-s1/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..07ea7318e4724b8711c4d6cf628fd49374f86efb --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-16, -5], [-10, 4], [15, 10], [-6, 2], [7, 11], [14, -12], [0, 2], [-2, 2], [13, -6], [-4, 16], [-16, 15], [13, 9], [-6, -4], [9, 2], [0, -4], [-16, -13]], "area": 36, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0188fb09534f13c0f4933ad4a7e5c0ffda690e87 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [3, 6, 14, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/tests/check.py b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..07ea7318e4724b8711c4d6cf628fd49374f86efb --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-16, -5], [-10, 4], [15, 10], [-6, 2], [7, 11], [14, -12], [0, 2], [-2, 2], [13, -6], [-4, 16], [-16, 15], [13, 9], [-6, -4], [9, 2], [0, -4], [-16, -13]], "area": 36, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/tests/run.py b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l3-s6/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2936bdfdcd99e5f9d256bf57e78fdb5d3b286b48 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 6], [-13, -1], [-3, 5], [2, -7], [-2, 8], [4, -3], [-13, -10], [-10, 7], [10, -6], [16, 13], [-9, -1], [3, 11], [-14, -5], [5, 6], [15, -4], [-1, 0]], "area": 65, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bad7b699aacb21f571cd1a41c671e9af898c6e3c --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [4, 7, 10, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/tests/check.py b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2936bdfdcd99e5f9d256bf57e78fdb5d3b286b48 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 6], [-13, -1], [-3, 5], [2, -7], [-2, 8], [4, -3], [-13, -10], [-10, 7], [10, -6], [16, 13], [-9, -1], [3, 11], [-14, -5], [5, 6], [15, -4], [-1, 0]], "area": 65, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/tests/run.py b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l3-s8/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-matrix-permutation-equivalence-l4-s3/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l4-s3/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce7878556c7f60a6bfc1ffa420487e34f85a918b --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": ["100101000001", "101111111001", "101110001001", "110110101010", "111010111001", "100100010000", "010001111110", "001100011111", "000011001101", "100100100101"], "B": ["011011100110", "000100100010", "111010010011", "001101011111", "101101101111", "001110111001", "001101101100", "100101100000", "010101100001", "111001001000"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..de7e4c0c34788589e6caaa710aa8d3fbab67f363 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [7, 5, 6, 4, 1, 3, 2, 0, 9, 8], "b": [5, 9, 8, 0, 10, 11, 3, 1, 4, 2, 7, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce7878556c7f60a6bfc1ffa420487e34f85a918b --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": ["100101000001", "101111111001", "101110001001", "110110101010", "111010111001", "100100010000", "010001111110", "001100011111", "000011001101", "100100100101"], "B": ["011011100110", "000100100010", "111010010011", "001101011111", "101101101111", "001110111001", "001101101100", "100101100000", "010101100001", "111001001000"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l4-s3/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l4-s4/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l4-s4/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd5b560e15264c72c35389a85ae965785be06f59 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": ["1101111", "1111111", "1110111", "1110111", "1111111", "1111111", "1111111"], "B": ["1011111", "1111110", "1011111", "1111111", "1111111", "1111111", "1111111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ebad3efac061f2734a4edc22f12a1d2bf371237 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [2, 0, 3, 1, 6, 4, 5], "b": [5, 3, 4, 1, 6, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd5b560e15264c72c35389a85ae965785be06f59 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": ["1101111", "1111111", "1110111", "1110111", "1111111", "1111111", "1111111"], "B": ["1011111", "1111110", "1011111", "1111111", "1111111", "1111111", "1111111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l4-s4/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-max-achromatic-coloring-l1-s0/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s0/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..539b06342d6907831d09effc3c32444d4386f757 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 2], [0, 3], [0, 4], [1, 2], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s0/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9724d48b7abcf18981860acd0757df0cbf16483a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 0, 1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..539b06342d6907831d09effc3c32444d4386f757 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 2], [0, 3], [0, 4], [1, 2], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [4, 5]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s0/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s7/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s7/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..11356a79469d2e4b2c44240a293c8ee53b78d853 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 3], [1, 3], [1, 4], [1, 5], [2, 5], [3, 5], [4, 5]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s7/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..41038d6e4789a1a5901f6c511bb604b3e2b71401 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 1, 0, 2, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..11356a79469d2e4b2c44240a293c8ee53b78d853 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 3], [1, 3], [1, 4], [1, 5], [2, 5], [3, 5], [4, 5]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s7/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s9/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s9/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d55f51fb454ea7207ac904939026e204d7caac5 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [1, 2], [1, 5], [3, 5], [4, 5]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s9/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..167203314e16a61cd80e98c3ad21c96d79753324 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 1, 2, 2, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d55f51fb454ea7207ac904939026e204d7caac5 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [1, 2], [1, 5], [3, 5], [4, 5]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l1-s9/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l5-s1/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l5-s1/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c1ac88b14e19b886785bcfd75898769bd1ff0366 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 7, "edges": [[0, 4], [0, 5], [0, 12], [1, 2], [1, 7], [1, 10], [1, 12], [2, 6], [2, 7], [2, 9], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 8], [4, 9], [4, 11], [4, 12], [5, 7], [5, 9], [5, 11], [6, 7], [6, 8], [6, 9], [7, 10], [9, 10], [10, 12], [11, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s1/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2cf3ab208f1ae361afb73ad608300cb45122f8f7 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 0, 3, 1, 4, 3, 5, 6, 5, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/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-l5-s1/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c1ac88b14e19b886785bcfd75898769bd1ff0366 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 7, "edges": [[0, 4], [0, 5], [0, 12], [1, 2], [1, 7], [1, 10], [1, 12], [2, 6], [2, 7], [2, 9], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [4, 8], [4, 9], [4, 11], [4, 12], [5, 7], [5, 9], [5, 11], [6, 7], [6, 8], [6, 9], [7, 10], [9, 10], [10, 12], [11, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l5-s1/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l5-s6/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l5-s6/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a074a0796bebea44b0b17f812c434999c3635c1 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 7, "edges": [[0, 4], [0, 6], [0, 7], [0, 10], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [2, 4], [2, 7], [2, 9], [2, 10], [2, 11], [3, 5], [3, 7], [3, 9], [3, 10], [4, 6], [4, 9], [5, 8], [5, 11], [6, 10], [6, 11], [7, 11], [7, 12], [8, 9], [8, 11], [8, 12], [9, 10], [10, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s6/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7d7807eafcb102d6de6b305524eee11f1988b1e --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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, 2, 3, 1, 0, 4, 5, 2, 5, 6, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/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-l5-s6/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a074a0796bebea44b0b17f812c434999c3635c1 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 7, "edges": [[0, 4], [0, 6], [0, 7], [0, 10], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [2, 4], [2, 7], [2, 9], [2, 10], [2, 11], [3, 5], [3, 7], [3, 9], [3, 10], [4, 6], [4, 9], [5, 8], [5, 11], [6, 10], [6, 11], [7, 11], [7, 12], [8, 9], [8, 11], [8, 12], [9, 10], [10, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-max-achromatic-coloring-l5-s6/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-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-maximum-clique-l4-s4/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1dcd19662fb858f53d4f007df7b4c910cba2d2fd --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 2], [0, 3], [0, 4], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [0, 14], [0, 15], [0, 21], [0, 22], [0, 23], [0, 26], [0, 27], [0, 29], [0, 30], [0, 31], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 11], [1, 12], [1, 13], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 31], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 25], [2, 26], [2, 28], [2, 29], [2, 31], [3, 5], [3, 6], [3, 7], [3, 9], [3, 10], [3, 13], [3, 15], [3, 16], [3, 18], [3, 19], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [3, 29], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 13], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 28], [4, 31], [5, 6], [5, 8], [5, 9], [5, 10], [5, 12], [5, 15], [5, 16], [5, 17], [5, 19], [5, 20], [5, 21], [5, 22], [5, 24], [5, 27], [5, 28], [5, 29], [5, 30], [6, 8], [6, 9], [6, 10], [6, 12], [6, 14], [6, 21], [6, 22], [6, 23], [6, 25], [6, 27], [6, 28], [6, 30], [6, 31], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 26], [7, 29], [7, 30], [8, 10], [8, 11], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [9, 11], [9, 12], [9, 14], [9, 15], [9, 16], [9, 18], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [9, 30], [9, 31], [10, 11], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [11, 12], [11, 14], [11, 15], [11, 16], [11, 18], [11, 19], [11, 21], [11, 23], [11, 25], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [12, 14], [12, 16], [12, 17], [12, 18], [12, 21], [12, 23], [12, 27], [12, 30], [13, 14], [13, 15], [13, 18], [13, 21], [13, 23], [13, 24], [13, 25], [13, 28], [13, 31], [14, 15], [14, 16], [14, 17], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [15, 16], [15, 18], [15, 19], [15, 21], [15, 22], [15, 23], [15, 24], [15, 26], [15, 27], [15, 28], [15, 30], [15, 31], [16, 18], [16, 20], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 31], [17, 18], [17, 19], [17, 20], [17, 21], [17, 26], [17, 27], [17, 31], [18, 20], [18, 21], [18, 22], [18, 24], [18, 27], [18, 29], [18, 31], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 27], [19, 29], [19, 30], [19, 31], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [21, 22], [21, 23], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 24], [22, 25], [22, 26], [22, 28], [22, 30], [23, 26], [23, 27], [23, 29], [23, 31], [24, 25], [24, 26], [24, 30], [24, 31], [25, 28], [25, 29], [26, 27], [26, 28], [26, 30], [26, 31], [27, 28], [27, 29], [27, 30], [27, 31], [28, 29], [28, 30], [28, 31], [29, 30], [30, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s1/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s1/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d757096e139c85012355c96ab14648e2364c3c5a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 5, "edges": [[0, 1], [0, 6], [0, 7], [0, 9], [0, 10], [0, 11], [0, 13], [0, 15], [0, 16], [1, 3], [1, 7], [1, 9], [1, 10], [1, 12], [1, 16], [1, 17], [2, 5], [2, 9], [2, 12], [2, 13], [2, 15], [2, 17], [3, 4], [3, 5], [3, 6], [3, 9], [3, 10], [3, 13], [3, 14], [3, 16], [4, 5], [4, 7], [4, 10], [4, 16], [5, 7], [5, 8], [5, 9], [5, 13], [5, 14], [5, 15], [5, 16], [6, 9], [6, 10], [6, 15], [6, 16], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 14], [7, 15], [7, 17], [8, 10], [8, 17], [9, 10], [9, 11], [9, 12], [9, 14], [9, 15], [10, 15], [11, 16], [11, 17], [12, 15], [12, 17], [14, 16], [15, 16], [16, 17]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s1/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a5ceec0aee6708259e68b0d6c4712c68d05e754 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 0, 0, 1, 2, 3, 3, 0, 4, 2, 1, 3, 1, 1, 1, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d757096e139c85012355c96ab14648e2364c3c5a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 5, "edges": [[0, 1], [0, 6], [0, 7], [0, 9], [0, 10], [0, 11], [0, 13], [0, 15], [0, 16], [1, 3], [1, 7], [1, 9], [1, 10], [1, 12], [1, 16], [1, 17], [2, 5], [2, 9], [2, 12], [2, 13], [2, 15], [2, 17], [3, 4], [3, 5], [3, 6], [3, 9], [3, 10], [3, 13], [3, 14], [3, 16], [4, 5], [4, 7], [4, 10], [4, 16], [5, 7], [5, 8], [5, 9], [5, 13], [5, 14], [5, 15], [5, 16], [6, 9], [6, 10], [6, 15], [6, 16], [7, 8], [7, 9], [7, 10], [7, 11], [7, 13], [7, 14], [7, 15], [7, 17], [8, 10], [8, 17], [9, 10], [9, 11], [9, 12], [9, 14], [9, 15], [10, 15], [11, 16], [11, 17], [12, 15], [12, 17], [14, 16], [15, 16], [16, 17]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s1/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s6/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s6/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89916d8368bd2509876415fc45097c3c536ea6df --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 7, "edges": [[0, 2], [0, 3], [0, 4], [0, 7], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [1, 2], [1, 3], [1, 5], [1, 6], [1, 8], [1, 9], [1, 10], [1, 12], [1, 14], [1, 15], [1, 16], [1, 17], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 15], [4, 16], [4, 17], [5, 6], [5, 9], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [6, 7], [6, 8], [6, 12], [6, 13], [6, 15], [7, 9], [7, 12], [7, 13], [7, 15], [7, 16], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [9, 11], [9, 14], [9, 16], [9, 17], [10, 11], [10, 16], [10, 17], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [12, 14], [12, 15], [12, 17], [13, 15], [13, 16], [14, 15], [14, 16], [14, 17], [15, 16], [15, 17], [16, 17]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s6/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..179440c7326d24893ec524571d20c47abd241aca --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 0, 1, 2, 3, 4, 1, 4, 5, 1, 5, 4, 6, 3, 3, 5, 6, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-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-l4-s6/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89916d8368bd2509876415fc45097c3c536ea6df --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 7, "edges": [[0, 2], [0, 3], [0, 4], [0, 7], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [1, 2], [1, 3], [1, 5], [1, 6], [1, 8], [1, 9], [1, 10], [1, 12], [1, 14], [1, 15], [1, 16], [1, 17], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 15], [4, 16], [4, 17], [5, 6], [5, 9], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [6, 7], [6, 8], [6, 12], [6, 13], [6, 15], [7, 9], [7, 12], [7, 13], [7, 15], [7, 16], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [9, 11], [9, 14], [9, 16], [9, 17], [10, 11], [10, 16], [10, 17], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [12, 14], [12, 15], [12, 17], [13, 15], [13, 16], [14, 15], [14, 16], [14, 17], [15, 16], [15, 17], [16, 17]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s6/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s8/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s8/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a77064e5795cc7e55ae3a22269f702b385035b1f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 5, "edges": [[0, 1], [0, 8], [0, 11], [0, 16], [0, 17], [1, 5], [1, 8], [1, 11], [1, 13], [1, 14], [1, 15], [1, 16], [2, 3], [2, 8], [2, 9], [2, 12], [2, 13], [2, 15], [2, 17], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 17], [4, 6], [4, 7], [4, 10], [4, 11], [4, 13], [4, 14], [4, 16], [4, 17], [5, 6], [5, 7], [5, 8], [5, 9], [5, 15], [5, 17], [6, 8], [6, 10], [6, 12], [7, 10], [7, 11], [7, 17], [8, 9], [8, 10], [8, 12], [8, 13], [8, 17], [9, 12], [9, 14], [9, 16], [9, 17], [10, 11], [10, 12], [10, 13], [10, 16], [11, 14], [11, 15], [11, 16], [11, 17], [12, 13], [12, 16], [13, 17], [14, 17], [15, 16]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s8/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..20483b681505b4040a1899ac6bdee81dcc449772 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 0, 1, 1, 0, 2, 3, 3, 2, 0, 2, 4, 2, 0, 4, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-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-l4-s8/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a77064e5795cc7e55ae3a22269f702b385035b1f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 5, "edges": [[0, 1], [0, 8], [0, 11], [0, 16], [0, 17], [1, 5], [1, 8], [1, 11], [1, 13], [1, 14], [1, 15], [1, 16], [2, 3], [2, 8], [2, 9], [2, 12], [2, 13], [2, 15], [2, 17], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 17], [4, 6], [4, 7], [4, 10], [4, 11], [4, 13], [4, 14], [4, 16], [4, 17], [5, 6], [5, 7], [5, 8], [5, 9], [5, 15], [5, 17], [6, 8], [6, 10], [6, 12], [7, 10], [7, 11], [7, 17], [8, 9], [8, 10], [8, 12], [8, 13], [8, 17], [9, 12], [9, 14], [9, 16], [9, 17], [10, 11], [10, 12], [10, 13], [10, 16], [11, 14], [11, 15], [11, 16], [11, 17], [12, 13], [12, 16], [13, 17], [14, 17], [15, 16]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l4-s8/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-harmonious-coloring-l4-s2/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l4-s2/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eaf099d47f8771acb0313205b78767515d52c26c --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 5, "edges": [[0, 6], [0, 10], [1, 3], [1, 8], [1, 11], [4, 8], [5, 7], [5, 11], [7, 10]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s2/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..32db8ba3973a608142046ea59a20f7fc4a37b295 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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, 0, 0, 2, 2, 3, 3, 0, 4, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-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-l4-s2/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eaf099d47f8771acb0313205b78767515d52c26c --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 5, "edges": [[0, 6], [0, 10], [1, 3], [1, 8], [1, 11], [4, 8], [5, 7], [5, 11], [7, 10]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l4-s2/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l4-s5/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l4-s5/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..631b2e1f142437e43ecd65bb7f3cc36f2fe80cdc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 5, "edges": [[0, 4], [0, 11], [2, 9], [3, 9], [4, 11], [5, 7], [6, 9], [7, 11], [8, 11]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s5/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..af1a1df689f76301840c3340cdde32bda12857dc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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, 0, 1, 1, 0, 2, 2, 3, 3, 0, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..631b2e1f142437e43ecd65bb7f3cc36f2fe80cdc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "k": 5, "edges": [[0, 4], [0, 11], [2, 9], [3, 9], [4, 11], [5, 7], [6, 9], [7, 11], [8, 11]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-min-harmonious-coloring-l4-s5/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-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-pairwise-sums-recovery-l2-s3/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41809b5dc2c8df44fd4b95102b799435d10f108b --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "sums": [15, 12, 13, 8, 9, 12, 11, 10, 7, 11], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a7bb46f3f90c5524d48bee13e2c2011c13d9c803 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [3, 4, 5, 7, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/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-l2-s3/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41809b5dc2c8df44fd4b95102b799435d10f108b --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "sums": [15, 12, 13, 8, 9, 12, 11, 10, 7, 11], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e5550b68a5f0c15bc4547763aed86a3531093b39 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "sums": [7, 10, 13, 17, 8, 15, 12, 5, 9, 12], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53634c1d6248e4000d57178733ec23b0d6c59197 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [2, 3, 5, 7, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-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-l2-s4/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e5550b68a5f0c15bc4547763aed86a3531093b39 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "sums": [7, 10, 13, 17, 8, 15, 12, 5, 9, 12], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2772249ddfe0723f117387b3058fe02f72878819 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "sums": [18, 77, 60, 94, 64, 61, 58, 39, 61, 39, 69, 27, 60, 46, 58, 18, 39, 45, 63, 26, 47, 57, 87, 59, 43, 25, 64, 62, 34, 55, 30, 14, 33, 29, 32, 31, 39, 65, 61, 44, 6, 21, 73, 71, 13, 60, 81, 32, 39, 54, 48, 23, 46, 48, 47, 85, 12, 45, 14, 61, 43, 53, 75, 54, 13, 36, 24, 79, 34, 68, 36, 62, 80, 59, 50, 29, 86, 5, 51, 23, 46, 74, 44, 47, 50, 22, 56, 28, 60, 17, 3, 57, 52, 36, 31, 34, 96, 78, 56, 38, 39, 87, 11, 25, 62, 21, 83, 82, 53, 91, 49, 49, 33, 40, 78, 36, 59, 17, 27, 50, 7, 80, 75, 33, 82, 36, 23, 57, 23, 51, 80, 76, 16, 73, 16, 67, 37, 56, 53, 20, 70, 81, 50, 72, 57, 15, 62, 72, 19, 19, 77, 71, 75, 43, 53, 65, 42, 73, 17, 50, 75, 43, 69, 59, 57, 47, 63, 21, 9, 48, 35, 57, 32, 68, 33, 59, 68, 64, 48, 60, 40, 74, 42, 83, 49, 71, 38, 15, 63, 44, 37, 26, 69, 4, 51, 58, 35, 41, 54, 46, 51, 36, 46, 10, 51, 26, 89, 46, 50, 30, 37, 31, 50, 55, 95, 35, 54, 55, 42, 70, 59, 29, 25, 57, 27, 97, 31, 49, 22, 38, 19, 52, 67, 13, 41, 15, 18, 72, 79, 41, 47, 35, 47, 37, 25, 26, 84, 52, 25, 35, 60, 15, 64, 71, 40, 66, 30, 58, 27, 56, 92, 44, 65, 28, 14, 24, 37, 59, 39, 24, 30, 56, 90, 26, 74, 62, 46, 45, 16, 12, 49, 52, 44, 49, 50, 10, 12, 41, 45, 16, 66, 42, 44, 28, 41, 20, 93, 62, 43, 80, 52, 29, 28, 53, 41, 65, 35, 28, 55, 11, 41, 20, 34, 34, 49, 38, 51, 48, 77, 5, 62, 40, 38, 17, 56], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..51eaf71d3fba148a814b7d10c74753e99f962cc7 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 2, 3, 4, 8, 9, 11, 12, 13, 14, 15, 17, 22, 24, 26, 27, 30, 32, 33, 35, 38, 42, 45, 47, 48, 49]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2772249ddfe0723f117387b3058fe02f72878819 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "sums": [18, 77, 60, 94, 64, 61, 58, 39, 61, 39, 69, 27, 60, 46, 58, 18, 39, 45, 63, 26, 47, 57, 87, 59, 43, 25, 64, 62, 34, 55, 30, 14, 33, 29, 32, 31, 39, 65, 61, 44, 6, 21, 73, 71, 13, 60, 81, 32, 39, 54, 48, 23, 46, 48, 47, 85, 12, 45, 14, 61, 43, 53, 75, 54, 13, 36, 24, 79, 34, 68, 36, 62, 80, 59, 50, 29, 86, 5, 51, 23, 46, 74, 44, 47, 50, 22, 56, 28, 60, 17, 3, 57, 52, 36, 31, 34, 96, 78, 56, 38, 39, 87, 11, 25, 62, 21, 83, 82, 53, 91, 49, 49, 33, 40, 78, 36, 59, 17, 27, 50, 7, 80, 75, 33, 82, 36, 23, 57, 23, 51, 80, 76, 16, 73, 16, 67, 37, 56, 53, 20, 70, 81, 50, 72, 57, 15, 62, 72, 19, 19, 77, 71, 75, 43, 53, 65, 42, 73, 17, 50, 75, 43, 69, 59, 57, 47, 63, 21, 9, 48, 35, 57, 32, 68, 33, 59, 68, 64, 48, 60, 40, 74, 42, 83, 49, 71, 38, 15, 63, 44, 37, 26, 69, 4, 51, 58, 35, 41, 54, 46, 51, 36, 46, 10, 51, 26, 89, 46, 50, 30, 37, 31, 50, 55, 95, 35, 54, 55, 42, 70, 59, 29, 25, 57, 27, 97, 31, 49, 22, 38, 19, 52, 67, 13, 41, 15, 18, 72, 79, 41, 47, 35, 47, 37, 25, 26, 84, 52, 25, 35, 60, 15, 64, 71, 40, 66, 30, 58, 27, 56, 92, 44, 65, 28, 14, 24, 37, 59, 39, 24, 30, 56, 90, 26, 74, 62, 46, 45, 16, 12, 49, 52, 44, 49, 50, 10, 12, 41, 45, 16, 66, 42, 44, 28, 41, 20, 93, 62, 43, 80, 52, 29, 28, 53, 41, 65, 35, 28, 55, 11, 41, 20, 34, 34, 49, 38, 51, 48, 77, 5, 62, 40, 38, 17, 56], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddf34964934ee8e08d7bc5e592054e469af462d0 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "sums": [8, 52, 30, 51, 30, 39, 43, 46, 59, 83, 38, 86, 66, 56, 47, 74, 63, 41, 77, 36, 39, 43, 36, 53, 27, 40, 48, 46, 59, 46, 68, 59, 36, 53, 52, 38, 49, 75, 55, 56, 58, 47, 61, 29, 46, 50, 43, 65, 60, 41, 62, 54, 56, 60, 37, 31, 18, 35, 34, 41, 36, 49, 43, 69, 49, 68, 87, 28, 64, 81, 46, 76, 67, 51, 71, 61, 76, 13, 40, 45, 21, 31, 74, 42, 90, 72, 4, 63, 25, 46, 37, 28, 26, 38, 57, 70, 54, 57, 31, 50, 60, 74, 39, 50, 31, 65, 38, 58, 44, 45, 52, 53, 51, 94, 41, 41, 11, 66, 58, 66, 44, 24, 84, 23, 14, 54, 40, 58, 28, 25, 45, 29, 55, 75, 54, 60, 68, 42, 47, 63, 40, 43, 76, 17, 76, 33, 41, 35, 61, 75, 56, 38, 59, 65, 31, 62, 71, 24, 69, 78, 49, 64, 54, 55, 47, 68, 23, 42, 41, 35, 36, 79, 46, 71, 48, 21, 61, 16, 44, 26, 27, 73, 75, 97, 61, 52, 34, 26, 55, 45, 65, 50, 49, 35, 31, 56, 57, 38, 57, 60, 50, 16, 34, 42, 71, 44, 51, 19, 25, 29, 54, 24, 69, 44, 33, 58, 48, 43, 64, 61, 32, 20, 14, 19, 34, 21, 79, 64, 22, 50, 49, 11, 51, 60, 29, 6, 27, 79, 73, 65, 33, 56, 32, 81, 37, 25, 63, 63, 17, 36, 57, 53, 45, 56, 89, 18, 86, 67, 49, 67, 45, 38, 15, 45, 72, 39, 69, 64, 62, 39, 53, 15, 37, 66, 52, 16, 62, 47, 72, 35, 59, 40, 48, 46, 56, 7, 53, 91, 9, 47, 79, 37, 33, 30, 82, 34, 24, 29, 36, 70, 66, 85, 72, 54, 53, 83, 39, 49, 34, 26, 33, 48, 27, 12, 82, 35, 26, 67, 16, 57, 78, 51, 44, 71, 20], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3b9b5e2c121c8bd2cd8d053e69b9b6997278946a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [1, 3, 5, 6, 10, 11, 13, 14, 15, 20, 21, 23, 24, 25, 26, 28, 30, 32, 33, 35, 36, 39, 40, 43, 46, 51]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/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-l6-s5/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddf34964934ee8e08d7bc5e592054e469af462d0 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "sums": [8, 52, 30, 51, 30, 39, 43, 46, 59, 83, 38, 86, 66, 56, 47, 74, 63, 41, 77, 36, 39, 43, 36, 53, 27, 40, 48, 46, 59, 46, 68, 59, 36, 53, 52, 38, 49, 75, 55, 56, 58, 47, 61, 29, 46, 50, 43, 65, 60, 41, 62, 54, 56, 60, 37, 31, 18, 35, 34, 41, 36, 49, 43, 69, 49, 68, 87, 28, 64, 81, 46, 76, 67, 51, 71, 61, 76, 13, 40, 45, 21, 31, 74, 42, 90, 72, 4, 63, 25, 46, 37, 28, 26, 38, 57, 70, 54, 57, 31, 50, 60, 74, 39, 50, 31, 65, 38, 58, 44, 45, 52, 53, 51, 94, 41, 41, 11, 66, 58, 66, 44, 24, 84, 23, 14, 54, 40, 58, 28, 25, 45, 29, 55, 75, 54, 60, 68, 42, 47, 63, 40, 43, 76, 17, 76, 33, 41, 35, 61, 75, 56, 38, 59, 65, 31, 62, 71, 24, 69, 78, 49, 64, 54, 55, 47, 68, 23, 42, 41, 35, 36, 79, 46, 71, 48, 21, 61, 16, 44, 26, 27, 73, 75, 97, 61, 52, 34, 26, 55, 45, 65, 50, 49, 35, 31, 56, 57, 38, 57, 60, 50, 16, 34, 42, 71, 44, 51, 19, 25, 29, 54, 24, 69, 44, 33, 58, 48, 43, 64, 61, 32, 20, 14, 19, 34, 21, 79, 64, 22, 50, 49, 11, 51, 60, 29, 6, 27, 79, 73, 65, 33, 56, 32, 81, 37, 25, 63, 63, 17, 36, 57, 53, 45, 56, 89, 18, 86, 67, 49, 67, 45, 38, 15, 45, 72, 39, 69, 64, 62, 39, 53, 15, 37, 66, 52, 16, 62, 47, 72, 35, 59, 40, 48, 46, 56, 7, 53, 91, 9, 47, 79, 37, 33, 30, 82, 34, 24, 29, 36, 70, 66, 85, 72, 54, 53, 83, 39, 49, 34, 26, 33, 48, 27, 12, 82, 35, 26, 67, 16, 57, 78, 51, 44, 71, 20], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s1/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s1/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dab88c42ec4fd20cd2ef331bed55de6836030c07 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": 84820, "B": 88690, "C": 15258, "D": 22353, "target": 22172, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s1/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7b645d85885382261abd060ad3a5605bf2a79ae3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 88688, "Y": 22172} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dab88c42ec4fd20cd2ef331bed55de6836030c07 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": 84820, "B": 88690, "C": 15258, "D": 22353, "target": 22172, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s1/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s6/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s6/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72a5421c627f468cda460690b15b88e5f835b7fd --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": 26804, "B": 63517, "C": 74163, "D": 80659, "target": 40329, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s6/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cd755425982be4c39d921177c2416f6054305391 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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": 40329, "Y": 80658} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-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-l3-s6/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..72a5421c627f468cda460690b15b88e5f835b7fd --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": 26804, "B": 63517, "C": 74163, "D": 80659, "target": 40329, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s6/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s8/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s8/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f2d784e3f9ea6a4aefe816159c017bf441235ce3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": 2862, "B": 20567, "C": 29606, "D": 64020, "target": 20567, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s8/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8cbeab293edf84059decbc4199835d82f6f62b70 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 20567, "Y": 61701} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-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-l3-s8/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f2d784e3f9ea6a4aefe816159c017bf441235ce3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": 2862, "B": 20567, "C": 29606, "D": 64020, "target": 20567, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l3-s8/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-l2-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s2/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c8f3ee20b094f79cb5e700c0b195cb694fa0da07 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [36, 68, 49, 16, 2], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f1950410fa3b584939153d3ef59e69446e7b3733 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -2.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-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-l2-s2/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c8f3ee20b094f79cb5e700c0b195cb694fa0da07 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [36, 68, 49, 16, 2], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s5/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..502b74d3be6358a65a56bc57affd53cf51133166 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, -2, 1, 0, 1], "fmin": "0.289273423937777937935889154385276791977392087", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6f66cc4eb57262ab9aeea25923f3d8454a3baa4e --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.5897545123014584} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/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-l2-s5/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..502b74d3be6358a65a56bc57affd53cf51133166 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, -2, 1, 0, 1], "fmin": "0.289273423937777937935889154385276791977392087", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..276c149ef7507f5787ad2c651a3118c324fb21d8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [2069, 10246, 23227, 31192, 27901, 17724, 8570, 3504, 1352, 480, 134, 24, 2, 0, 2], "fmin": "74.2472391815217440684469375737734650173534310", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3671fa4ffca041520bea9f7505faffb4b7cc03fe --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -0.812132799110263} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..276c149ef7507f5787ad2c651a3118c324fb21d8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [2069, 10246, 23227, 31192, 27901, 17724, 8570, 3504, 1352, 480, 134, 24, 2, 0, 2], "fmin": "74.2472391815217440684469375737734650173534310", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ba04c9bbed002694529eef45b8f949704062afe --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 2, -3, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1668283e1ed43b3d19ab7dac3e8b19e8bd4c67ae --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4ba04c9bbed002694529eef45b8f949704062afe --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 2, -3, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b26c3695db032e7b0cd99320bb3baafe046e6144 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-27, -9, 3, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..876a2af9549c338d793b3904c6619f43826cde7f --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-3, -3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b26c3695db032e7b0cd99320bb3baafe046e6144 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-27, -9, 3, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s8/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da8fc2129b6b3efdf2407de1d1d0501b35d1aa24 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [3, 7, 5, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c171033ddb27dd05009d746534e91515c4c5af55 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-3, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/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-l1-s8/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da8fc2129b6b3efdf2407de1d1d0501b35d1aa24 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [3, 7, 5, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s0/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c54c864e03e57abef87d8ebae9635488b6c85076 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-1565650944000, -1009613721600, 1285219128960, 521911678464, -320491747448, -94618547484, 26729556402, 7765018167, -604310943, -248952012, -3717344, 2615154, 114990, -10704, -618, 15, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0a0f181b9d6b53a70ebb4468b2d345c514be70b1 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-15, -13, -11, -11, -9, -5, -4, -2, -1, 2, 2, 3, 5, 12, 16, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/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-l5-s0/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c54c864e03e57abef87d8ebae9635488b6c85076 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-1565650944000, -1009613721600, 1285219128960, 521911678464, -320491747448, -94618547484, 26729556402, 7765018167, -604310943, -248952012, -3717344, 2615154, 114990, -10704, -618, 15, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s7/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..234ffc743b5ed1bd54f67b5a6ab7ffbbdabdedf4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-3662382366720, 4873861988352, -1126426411008, -1012991840256, 497829860864, 18500979712, -46987583456, 6840202672, 972794944, -350882696, 26985762, 1373423, -314179, 12122, 512, -49, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8b1368e8c3bd86fa3632eefe58bda8681734ef97 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-16, -12, -4, -3, -3, 2, 2, 2, 6, 7, 7, 8, 10, 11, 16, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/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-l5-s7/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..234ffc743b5ed1bd54f67b5a6ab7ffbbdabdedf4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-3662382366720, 4873861988352, -1126426411008, -1012991840256, 497829860864, 18500979712, -46987583456, 6840202672, 972794944, -350882696, 26985762, 1373423, -314179, 12122, 512, -49, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s9/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de3fce71551215eb899e63021a6d780100c213f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-768592281600000, 752654592000000, -152350626816000, -61959249388800, 30607940473920, -3395661872112, -415182717876, 122036613848, -5357232657, -964839954, 109445834, 43686, -527184, 21946, 522, -54, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..06615568556f615ab9ba0bd463b2a3d23250bf73 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-16, -13, -12, -8, -3, 2, 4, 5, 8, 9, 10, 11, 12, 15, 15, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-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-l5-s9/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de3fce71551215eb899e63021a6d780100c213f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-768592281600000, 752654592000000, -152350626816000, -61959249388800, 30607940473920, -3395661872112, -415182717876, 122036613848, -5357232657, -964839954, 109445834, 43686, -527184, 21946, 522, -54, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..27b5e41e9690a187bb182c0bc4159b598432b8fa --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"X": [2, -1, 1, -4, 3], "Y": [42, 6, 2, 492, 198], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36b49a115a674cded12b626e6dab30ead7d4116b --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [0, -3, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..27b5e41e9690a187bb182c0bc4159b598432b8fa --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"X": [2, -1, 1, -4, 3], "Y": [42, 6, 2, 492, 198], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l2-s7/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..25a1e2da20a34327672f23a5edeb777907b8c936 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"X": [4, 2, -2, -4, 3], "Y": [1661, 137, 65, 1037, 575], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bd6c5267f40b3733a5b9ab3040231c44f8a7617d --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [5, -2, 4, 5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..25a1e2da20a34327672f23a5edeb777907b8c936 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"X": [4, 2, -2, -4, 3], "Y": [1661, 137, 65, 1037, 575], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l2-s7/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l2-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s9/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d4a078ffe3a5ec7d0bfdc0d7547452a11dc0810 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"X": [4, 0, -3, -4, -1], "Y": [1327, 3, 375, 1207, 7], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36c723a81149d030446177d9a16636ebf97fafc7 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [3, -1, -1, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/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-l2-s9/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d4a078ffe3a5ec7d0bfdc0d7547452a11dc0810 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"X": [4, 0, -3, -4, -1], "Y": [1327, 3, 375, 1207, 7], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l6-s1/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..33daa6e578b57976fa27f3ea6b47991cf3904e07 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"X": [0, -13, 3, -5, -18, 12, -2, 13, 17, 18, 9, -7, -1, 7, 16, 11, -10, 14, -17], "Y": [3, 485513006071948042958, 1215189630, 18483476208358, 166339859780774143440813, 98071143210280824183, 1570525, 416823369214381662640, 53055714045136763278028, 148920159160575235375545, 538504296172885812, 7489305830982020, 2, 5676334414488538, 17751833939710160270323, 20332287485320779158, 4415368630452681413, 1590730566594875451917, 59644952208302055193810], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f625cb7c16998568d7b07ae22699efabee821b3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [3, -1, 4, -1, -2, 3, 3, 5, -5, -1, 3, 4, -1, 3, 4, 5, 2, -4, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..33daa6e578b57976fa27f3ea6b47991cf3904e07 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"X": [0, -13, 3, -5, -18, 12, -2, 13, 17, 18, 9, -7, -1, 7, 16, 11, -10, 14, -17], "Y": [3, 485513006071948042958, 1215189630, 18483476208358, 166339859780774143440813, 98071143210280824183, 1570525, 416823369214381662640, 53055714045136763278028, 148920159160575235375545, 538504296172885812, 7489305830982020, 2, 5676334414488538, 17751833939710160270323, 20332287485320779158, 4415368630452681413, 1590730566594875451917, 59644952208302055193810], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l6-s1/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s6/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7516908058fd3d1e229ade99d6af96d3b8bb4ef9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"X": [12, -12, -18, -8, 5, 6, 4, -13, -15, 8, -5, 17, 1, 3, -6, -3, 16, -14, 14], "Y": [128850990831703782512, 137757317747849775848, 201232907979463747385762, 94904064881322212, 17676827354546, 476398010158922, 312733797656, 580303949907394010762, 7593586581418457031746, 85821016504391828, 20801729674346, 68707030106966828544962, 2, 1711555658, 545174899192646, 2272401362, 23038953169452567216812, 2197736901841749467342, 2075452449684711137666], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..25c32fc20956d2cef7e9fcd36d810fb3411c8ee8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [-4, -5, 3, -4, -2, 4, 0, 0, 3, 0, 2, 1, 4, -5, 2, -1, 1, -2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/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-l6-s6/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7516908058fd3d1e229ade99d6af96d3b8bb4ef9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"X": [12, -12, -18, -8, 5, 6, 4, -13, -15, 8, -5, 17, 1, 3, -6, -3, 16, -14, 14], "Y": [128850990831703782512, 137757317747849775848, 201232907979463747385762, 94904064881322212, 17676827354546, 476398010158922, 312733797656, 580303949907394010762, 7593586581418457031746, 85821016504391828, 20801729674346, 68707030106966828544962, 2, 1711555658, 545174899192646, 2272401362, 23038953169452567216812, 2197736901841749467342, 2075452449684711137666], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l6-s8/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bab68ae7345c70eb29895ae8e954ef74eae7e408 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"X": [1, 10, -16, 16, -4, 12, 3, 17, -5, -15, -8, -11, 14, -6, -9, 0, -18, 4, -17], "Y": [13, 3393016632331515346, 12964592541221740762188, 15332711185621724541868, 129757757328, 88605965538995490368, 1679952599, 45458158411536500623773, 8145241173871, 4031684803366693572221, 44647699867347748, 14599405106326960993, 1400892102561487729518, 232710532272098, 381098689811724443, -4, 109153853684984495793038, 273875199208, 38823022433522958765619], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d4d6e2731f0fe07e9ff07cc1adfcf3edee30a7a5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-4, -5, 4, -5, 2, 5, 1, 3, 3, 2, 3, -4, -3, 2, 0, 3, -1, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bab68ae7345c70eb29895ae8e954ef74eae7e408 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"X": [1, 10, -16, 16, -4, 12, 3, 17, -5, -15, -8, -11, 14, -6, -9, 0, -18, 4, -17], "Y": [13, 3393016632331515346, 12964592541221740762188, 15332711185621724541868, 129757757328, 88605965538995490368, 1679952599, 45458158411536500623773, 8145241173871, 4031684803366693572221, 44647699867347748, 14599405106326960993, 1400892102561487729518, 232710532272098, 381098689811724443, -4, 109153853684984495793038, 273875199208, 38823022433522958765619], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l6-s8/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-prefix-product-permutation-l2-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l2-s2/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..84d45b38e4d105354ec9e2d2d0562c57a6dfda13 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 97, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s2/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..95ef3f3364fca9537feb71e152fcf4e870ff1281 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 50, 66, 74, 40, 82, 15, 86, 55, 69, 54, 90, 16, 8, 14, 92, 41, 28, 47, 35, 38, 76, 39, 94, 67, 57, 19, 53, 88, 56, 73, 95, 51, 21, 62, 63, 22, 24, 6, 18, 72, 68, 89, 87, 70, 20, 65, 96, 3, 34, 79, 29, 12, 10, 31, 27, 81, 93, 75, 77, 36, 37, 78, 48, 4, 26, 43, 11, 46, 80, 42, 32, 5, 60, 23, 61, 64, 52, 71, 58, 7, 85, 91, 83, 9, 45, 30, 44, 13, 84, 17, 59, 25, 33, 49, 97]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-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-l2-s2/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..84d45b38e4d105354ec9e2d2d0562c57a6dfda13 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 97, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l2-s2/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l2-s5/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-prefix-product-permutation-l2-s5/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b28b746e2651e0f2e0671c88b5d2a8e36db7f5f4 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 73, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s5/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..687cffb3c20446a6df0aad7bdf6f78787c3e55e2 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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' +{"perm": [1, 2, 38, 50, 56, 45, 62, 22, 65, 66, 23, 21, 68, 46, 48, 40, 33, 44, 70, 51, 12, 8, 11, 55, 71, 39, 60, 47, 61, 69, 57, 34, 17, 32, 59, 49, 72, 3, 26, 16, 43, 58, 41, 18, 6, 14, 28, 15, 36, 4, 20, 64, 67, 63, 24, 5, 31, 42, 35, 27, 29, 7, 54, 52, 9, 10, 53, 13, 30, 19, 25, 37, 73]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 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-l2-s5/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b28b746e2651e0f2e0671c88b5d2a8e36db7f5f4 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 73, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-prefix-product-permutation-l2-s5/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-prefix-product-permutation-l6-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l6-s3/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d014c8cc1f4027ecaa4996df061f7fe708346758 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 12011, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s3/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..961cad6e9b1b932e64dbdfdee117f3690d886c97 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 6007, 4005, 3004, 9610, 2003, 1717, 7508, 9343, 10811, 1093, 1002, 925, 859, 3204, 9760, 10599, 4672, 3794, 5406, 573, 547, 4701, 6507, 4325, 463, 3115, 430, 9527, 7608, 4263, 10886, 365, 5300, 9953, 8342, 2598, 7903, 309, 8709, 6153, 287, 839, 274, 9076, 2351, 2301, 3254, 1962, 2163, 11541, 232, 1814, 1558, 7426, 6221, 5269, 4764, 5294, 9810, 10043, 2132, 8199, 11449, 2588, 183, 4662, 8656, 9575, 4977, 10997, 10177, 9544, 7305, 5446, 3952, 157, 155, 3954, 4355, 1039, 3077, 6513, 144, 6925, 420, 7180, 6143, 9043, 10544, 133, 1176, 9429, 1151, 5564, 7633, 4954, 6987, 4126, 1082, 4520, 5771, 9913, 6122, 7322, 6913, 11563, 6785, 9147, 9719, 8874, 3111, 9461, 2635, 941, 8388, 8111, 8653, 1515, 10911, 3376, 5022, 10059, 7072, 3268, 4100, 3784, 5725, 4284, 7300, 1468, 92, 10838, 8337, 3026, 10334, 5875, 4788, 3371, 2489, 8775, 5499, 85, 5089, 11515, 10778, 8662, 3653, 1452, 8729, 9228, 7982, 11855, 79, 8060, 78, 11859, 7983, 4609, 2178, 5820, 520, 1180, 1539, 2476, 3257, 6474, 6078, 996, 3463, 1757, 6216, 487, 9596, 9198, 3072, 5769, 4522, 11341, 11278, 9424, 67, 7352, 6594, 7727, 4715, 6424, 576, 10741, 8788, 10377, 3817, 1868, 8483, 4867, 3494, 2013, 8069, 846, 6547, 9562, 8266, 11657, 2886, 8438, 4957, 7196, 9067, 10173, 9667, 3758, 3457, 7670, 5782, 4973, 3393, 10905, 4574, 3182, 4860, 3588, 10443, 1940, 1556, 1816, 4731, 10213, 1318, 1050, 471, 53, 10200, 8352, 4056, 461, 4327, 9326, 758, 2363, 5456, 3390, 7694, 347, 8517, 10002, 5030, 9532, 9542, 10179, 7640, 4547, 8056, 3704, 7898, 2309, 2863, 10423, 8148, 372, 9656, 2394, 6740, 5938, 6052, 5168, 11425, 3015, 4169, 3707, 7519, 8422, 11173, 45, 2938, 1486, 8400, 1562, 1686, 11151, 1245, 5173, 4388, 6919, 2750, 5859, 43, 11175, 2545, 2744, 5758, 1652, 11395, 6027, 10337, 5864, 1827, 1376, 6732, 6830, 4365, 8700, 10620, 5511, 9997, 9216, 5928, 4109, 40, 3305, 10036, 1121, 6045, 4107, 5930, 6445, 3992, 5836, 2305, 867, 7095, 3855, 8916, 9409, 6266, 7725, 6596, 11057, 770, 7193, 7244, 3920, 1629, 10966, 9243, 10542, 9045, 1391, 6504, 7158, 1732, 5848, 879, 1997, 9114, 4318, 244, 3497, 10804, 4888, 10605, 6708, 7542, 6670, 2885, 11809, 8267, 8513, 5671, 9302, 11645, 9683, 10718, 1126, 34, 6714, 9682, 11652, 9303, 11361, 3864, 260, 2358, 5926, 9218, 1090, 6294, 9973, 5371, 7290, 10400, 1262, 5189, 7747, 1909, 9641, 6940, 9436, 4242, 4756, 2434, 984, 7753, 490, 1007, 5596, 4035, 8563, 6429, 7617, 3274, 5692, 10787, 10492, 10139, 5013, 5829, 1329, 7449, 11131, 10225, 1959, 2479, 2473, 9604, 8510, 4534, 5128, 5087, 87, 4834, 5764, 7885, 10933, 1729, 3788, 9841, 8299, 8897, 29, 2487, 3373, 1697, 639, 5453, 3839, 8293, 2777, 7597, 685, 8436, 2888, 7800, 1682, 5222, 9016, 6976, 8492, 6784, 11905, 6914, 3836, 2366, 11084, 5107, 7234, 6665, 8753, 6531, 7956, 236, 7687, 27, 8899, 11106, 6691, 10182, 2110, 8034, 10962, 231, 11961, 2164, 2261, 10669, 5918, 6385, 1537, 1182, 7674, 8734, 9440, 7701, 9948, 9853, 5796, 174, 2418, 4259, 394, 11007, 7144, 8521, 4094, 10772, 826, 10777, 11867, 5090, 1373, 9826, 10166, 2274, 789, 10034, 3307, 7858, 8340, 9955, 10313, 1155, 4796, 1432, 4590, 5212, 9190, 10080, 1302, 6192, 163, 10834, 2145, 7203, 11346, 9376, 11074, 8975, 7317, 9032, 1772, 8590, 9931, 5713, 3246, 1508, 9520, 2085, 3781, 1854, 3455, 3760, 2976, 10217, 3142, 5587, 11439, 23, 7313, 7475, 6455, 6749, 3031, 10206, 9145, 6787, 6580, 6849, 7613, 5576, 5609, 623, 2142, 2587, 11948, 8200, 1893, 3460, 3581, 7381, 3294, 2930, 6606, 22, 11467, 5588, 189, 1273, 1021, 7378, 4627, 8885, 4363, 6832, 9993, 5698, 1623, 3014, 11746, 5169, 10972, 8938, 8679, 914, 7637, 6694, 2706, 9372, 8290, 9421, 10849, 2183, 6676, 10356, 3188, 11316, 676, 2756, 1584, 4999, 7890, 10614, 11265, 8970, 11385, 2055, 6817, 6026, 11720, 1653, 11003, 11024, 6403, 561, 9872, 3023, 7861, 2054, 11399, 8971, 5806, 3223, 1638, 8002, 5257, 8924, 5562, 1153, 10315, 434, 6561, 3548, 7365, 1928, 10088, 10464, 5662, 4705, 11288, 9139, 2666, 3863, 11643, 9304, 4581, 5529, 7501, 6391, 5065, 3597, 9916, 9628, 9886, 7966, 9204, 815, 9375, 11489, 7204, 4622, 4651, 11277, 11833, 4523, 10263, 696, 606, 9258, 9404, 9585, 7572, 6872, 3405, 8930, 4415, 440, 3578, 999, 8358, 10563, 5684, 8165, 5233, 6128, 4022, 1749, 675, 11408, 3189, 8450, 10792, 5303, 4473, 9360, 1402, 9777, 4158, 9341, 7510, 1443, 4863, 5905, 7113, 4134, 9064, 4257, 2420, 2836, 4792, 10657, 10709, 5823, 1417, 4842, 9138, 11365, 4706, 6569, 3487, 6023, 4120, 9363, 4996, 10847, 9423, 11832, 11342, 4652, 9160, 5681, 5332, 7938, 3178, 6136, 7227, 7185, 9900, 8969, 11401, 10615, 10232, 6551, 9613, 9153, 5520, 4987, 9053, 2686, 239, 9651, 5239, 11206, 3568, 6637, 8171, 2595, 4774, 3874, 2256, 955, 329, 4821, 3475, 9476, 4072, 10724, 4015, 8127, 8132, 8384, 9175, 7223, 8644, 6498, 8806, 3877, 7177, 6251, 9738, 504, 1980, 8804, 6500, 2018, 6317, 4282, 5727, 3215, 2789, 3809, 5082, 7643, 9013, 8852, 7420, 5394, 3567, 11252, 5240, 5070, 9978, 2507, 1171, 2915, 2808, 665, 2639, 3725, 7631, 5566, 8023, 5113, 5809, 980, 6510, 1240, 496, 1237, 3080, 10808, 1899, 10261, 4525, 8273, 3649, 8570, 6100, 2544, 11725, 44, 11740, 8423, 1572, 8888, 1725, 3943, 200, 5467, 2199, 865, 2307, 7900, 2725, 4921, 10097, 4150, 9961, 4449, 11087, 15, 8810, 1244, 11733, 1687, 9813, 849, 9707, 320, 4919, 2727, 4728, 1920, 6827, 4147, 4555, 1389, 9047, 3799, 6164, 343, 10017, 10224, 11603, 7450, 9822, 9906, 5959, 6847, 6582, 8617, 5689, 10514, 4463, 9494, 3915, 10252, 2269, 9398, 6281, 5953, 2633, 9463, 8586, 7924, 10908, 7189, 6690, 11548, 8900, 2554, 9845, 9623, 5077, 3333, 593, 4377, 11080, 3266, 7074, 9984, 7320, 6124, 5374, 3844, 11010, 14, 11155, 4450, 5106, 11559, 2367, 3346, 3265, 11097, 4378, 7061, 6090, 10023, 8974, 11487, 9377, 116, 3626, 5981, 3924, 7088, 2149, 1131, 8689, 5335, 1659, 8965, 1946, 3193, 9756, 769, 11685, 6597, 8297, 9843, 2556, 10373, 4013, 10726, 9293, 3851, 7581, 10980, 8087, 4927, 3137, 8904, 8499, 6093, 5630, 7215, 10583, 2130, 10045, 6203, 823, 5504, 7690, 9578, 392, 4261, 7610, 8053, 6402, 11392, 11004, 6419, 5855, 5389, 5311, 5934, 170, 8551, 8434, 687, 3656, 10919, 13, 11089, 3845, 7143, 11522, 395, 6418, 11023, 11393, 1654, 4468, 9935, 6048, 10176, 11941, 4978, 10394, 5157, 10739, 578, 4636, 8404, 1950, 6722, 8895, 8301, 1229, 8612, 4670, 10601, 8086, 11046, 7582, 6657, 1440, 9102, 7657, 82, 8937, 11423, 5170, 1073, 3640, 3602, 9242, 11679, 1630, 10694, 230, 11543, 8035, 4488, 10244, 3659, 7959, 10522, 3035, 6892, 2224, 10301, 4982, 4966, 10690, 2857, 3937, 7629, 3727, 6760, 7484, 10766, 6842, 1043, 8374, 1891, 8202, 6933, 7105, 1728, 11589, 7886, 101, 7494, 7232, 5109, 4584, 7577, 6896, 2794, 376, 5720, 1201, 12, 11012, 3657, 10246, 3738, 8366, 3228, 1695, 3375, 11892, 1516, 7188, 11109, 7925, 4573, 11795, 3394, 6326, 9296, 10239, 3425, 4091, 3807, 2791, 8794, 8313, 2805, 1976, 312, 5969, 7077, 9659, 1294, 364, 11980, 4264, 10106, 9863, 947, 3325, 7736, 1994, 1791, 9250, 3691, 10438, 7653, 8047, 7471, 5317, 9309, 4425, 6017, 2613, 5734, 6284, 8800, 2583, 95, 6450, 637, 1699, 511, 7218, 9695, 7164, 2314, 2426, 4443, 3146, 2182, 11413, 9422, 11280, 4997, 1586, 8855, 9505, 812, 9099, 7513, 8336, 11879, 93, 2585, 2144, 11492, 164, 10475, 479, 4340, 1859, 6463, 1866, 3819, 8349, 9353, 2284, 7359, 2855, 10692, 1632, 10151, 7680, 4711, 10547, 5425, 6292, 1092, 12002, 9344, 1898, 11184, 3081, 7600, 4887, 11664, 3498, 6344, 5218, 7384, 3130, 6798, 9679, 2500, 10048, 9951, 5302, 11313, 8451, 5633, 7789, 10491, 11610, 5693, 3711, 1028, 3402, 3409, 8236, 9019, 8661, 11866, 11516, 827, 8934, 5502, 825, 11518, 4095, 3202, 861, 281, 6841, 10942, 7485, 1512, 4665, 3931, 1710, 7033, 1621, 5700, 10519, 4486, 8037, 8909, 10228, 1612, 382, 6825, 1922, 10007, 5546, 2629, 3063, 10468, 3645, 8787, 11823, 577, 10993, 5158, 5267, 6223, 4337, 3281, 7664, 7780, 2767, 3683, 8155, 6970, 9292, 11050, 4014, 11238, 4073, 8837, 2299, 2353, 1125, 11650, 9684, 4570, 1529, 7339, 8221, 1932, 518, 5822, 11293, 10658, 5284, 2291, 10220, 2765, 7782, 3751, 4930, 3196, 7740, 2533, 8395, 1799, 229, 10964, 1631, 10820, 2856, 10949, 4967, 9989, 8241, 10608, 6183, 408, 4565, 4688, 10135, 5745, 4290, 9608, 3006, 8317, 4915, 2326, 6307, 5639, 6835, 5917, 11538, 2262, 10351, 5132, 3969, 6354, 5637, 6309, 8847, 10635, 5283, 10708, 11294, 4793, 2320, 9792, 7699, 9442, 6814, 1703, 1737, 10471, 2412, 2208, 6459, 6226, 6239, 7795, 6922, 500, 2188, 10185, 298, 5282, 10660, 8848, 5436, 4083, 9742, 2617, 2563, 9070, 9922, 8017, 7457, 875, 2967, 338, 5510, 11710, 8701, 1595, 2231, 10231, 11264, 11402, 7891, 2652, 704, 2237, 6182, 10686, 8242, 6707, 11662, 4889, 5397, 8085, 10982, 4671, 11995, 9761, 6189, 722, 7172, 2432, 4758, 2953, 3382, 3557, 4905, 8073, 5977, 10538, 2383, 2129, 11037, 7216, 513, 7424, 1560, 8402, 4638, 5329, 10566, 5355, 1036, 2912, 4502, 709, 7151, 8427, 5354, 10575, 5330, 5683, 11324, 8359, 150, 3285, 8598, 1744, 9940, 3012, 1625, 8066, 2800, 4682, 8814, 8504, 3170, 5424, 10815, 4712, 132, 11922, 9044, 11677, 9244, 8332, 2382, 10586, 5978, 2841, 9117, 8672, 5369, 9975, 2580, 7595, 2779, 9074, 276, 3614, 4492, 3593, 3034, 10956, 7960, 4485, 10757, 5701, 3769, 5308, 4462, 11122, 5690, 3276, 4002, 4807, 7393, 4577, 4143, 8766, 535, 2494, 8271, 4527, 1249, 7349, 3359, 120, 1103, 4826, 2115, 2620, 10138, 11609, 10788, 7790, 3889, 3319, 1844, 4086, 7442, 1298, 4675, 8393, 2535, 7943, 5603, 7134, 5627, 478, 10832, 165, 9538, 2411, 10648, 1738, 3644, 10744, 3064, 8042, 5661, 11368, 10089, 2008, 8442, 4064, 7766, 10072, 225, 10198, 55, 4588, 1434, 3612, 278, 10328, 8723, 9255, 10431, 10409, 4508, 1939, 11790, 3589, 842, 3126, 7652, 10875, 3692, 6258, 5401, 6996, 3173, 10408, 10447, 9256, 608, 7015, 1168, 3159, 4595, 8147, 11755, 2864, 2296, 1608, 3311, 1395, 9783, 1905, 2152, 8547, 9090, 3822, 10294, 4507, 10446, 10432, 3174, 9716, 1593, 8703, 9780, 1784, 1261, 11632, 7291, 8626, 6687, 8541, 5156, 10995, 4979, 1254, 6314, 586, 9000, 1458, 3948, 7410, 8092, 333, 1048, 1320, 1194, 1863, 9879, 3816, 11821, 8789, 632, 4012, 11052, 2557, 6442, 2905, 3934, 6496, 8646, 9261, 6156, 6626, 3825, 6254, 292, 619, 1011, 7546, 3187, 11410, 6677, 950, 3049, 5131, 10667, 2263, 8993, 4137, 2194, 1825, 5866, 10291, 6629, 9056, 6542, 7278, 5486, 5863, 11718, 6028, 5874, 11876, 3027, 4212, 444, 6792, 8722, 10450, 279, 863, 2201, 1972, 7987, 6106, 4902, 2734, 8784, 1100, 8639, 433, 11375, 1154, 11503, 9956, 5198, 1363, 10277, 2461, 8377, 5049, 9106, 8081, 1252, 4981, 10952, 2225, 10210, 5544, 10009, 8, 4506, 10411, 3823, 6628, 10344, 5867, 3124, 844, 8071, 4907, 1079, 425, 8226, 4854, 341, 6166, 4305, 2460, 10309, 1364, 1543, 8370, 3634, 6966, 9487, 3414, 1455, 2074, 8185, 2278, 7990, 695, 11339, 4524, 11182, 1900, 7531, 9088, 8549, 172, 5798, 5009, 2268, 11118, 3916, 5802, 2658, 9731, 3737, 10917, 3658, 10959, 4489, 2980, 530, 3424, 10901, 9297, 7167, 4309, 2218, 2845, 6550, 11263, 10616, 2232, 1611, 10753, 8910, 1958, 11602, 11132, 10018, 1135, 2764, 10705, 2292, 3141, 11470, 2977, 3617, 1317, 11785, 4732, 5543, 10299, 2226, 9968, 9144, 11460, 3032, 3595, 5067, 9351, 8351, 11780, 54, 10456, 226, 7283, 10095, 4923, 9866, 4812, 8536, 2539, 9818, 1667, 6148, 297, 10638, 2189, 2109, 11546, 6692, 7639, 11763, 9543, 11940, 10998, 6049, 9666, 11803, 9068, 2565, 8693, 1526, 7928, 2273, 11511, 9827, 6013, 5607, 5578, 7911, 8231, 539, 8559, 2455, 5780, 7672, 1184, 5551, 7679, 10818, 1633, 2135, 5549, 1186, 8195, 194, 3531, 7295, 9051, 4989, 5012, 11608, 10493, 2621, 5744, 10681, 4689, 5102, 6064, 7804, 7819, 5678, 2991, 9202, 7968, 1936, 9550, 3638, 1075, 3812, 566, 8554, 4345, 3861, 2668, 1204, 830, 1753, 4483, 7962, 6979, 2229, 1597, 9862, 10884, 4265, 385, 2373, 5843, 3439, 3299, 4553, 4149, 11159, 4922, 10195, 7284, 871, 5187, 1264, 2007, 10463, 11369, 1929, 4647, 643, 1926, 7367, 3791, 1301, 11496, 9191, 4044, 1888, 2464, 7504, 1569, 224, 10458, 7767, 4250, 8031, 3047, 952, 8821, 4893, 3608, 1024, 5292, 4766, 7071, 11889, 5023, 5002, 3102, 1787, 412, 9535, 8758, 50, 9851, 9950, 10795, 2501, 6202, 11035, 2131, 11951, 9811, 1689, 4027, 9096, 9207, 1120, 11702, 3306, 11508, 790, 3210, 4421, 2928, 3296, 2695, 8920, 2656, 5804, 8973, 11076, 6091, 8501, 4276, 1134, 10223, 11133, 344, 2900, 7834, 8479, 5460, 2402, 7, 10297, 5545, 10748, 1923, 1551, 3572, 5029, 11767, 8518, 198, 3945, 9215, 11708, 5512, 793, 5697, 11429, 6833, 5641, 8240, 10688, 4968, 8210, 9030, 7319, 11094, 7075, 5971, 7139, 8495, 2506, 11203, 5071, 2579, 10532, 5370, 11635, 6295, 2761, 8324, 9143, 10208, 2227, 6981, 2483, 9367, 5476, 4448, 11157, 4151, 627, 615, 5197, 10312, 11504, 8341, 11977, 5301, 10794, 10049, 9852, 11529, 7702, 9797, 5899, 3329, 2892, 6726, 3011, 10557, 1745, 3829, 4105, 6047, 11000, 4469, 5345, 5712, 11481, 8591, 2492, 537, 8233, 7826, 4749, 7807, 8016, 10627, 9071, 5840, 7840, 6821, 9627, 11353, 3598, 6121, 11909, 5772, 4220, 4018, 9499, 8250, 5958, 11128, 9823, 1830, 468, 3980, 8968, 11267, 7186, 1518, 9394, 9452, 7371, 7118, 8407, 5151, 2504, 8497, 8906, 8489, 7965, 11351, 9629, 1429, 977, 1969, 63, 3815, 10379, 1864, 6465, 9386, 7021, 9748, 3022, 11389, 562, 9427, 1178, 522, 4811, 10193, 4924, 946, 10883, 10107, 1598, 3467, 5351, 3553, 7882, 6870, 7574, 5795, 11528, 9949, 10050, 51, 473, 9753, 4933, 9622, 11103, 2555, 11054, 8298, 11586, 3789, 7369, 9454, 5573, 7403, 161, 6194, 4080, 8866, 1163, 601, 5338, 6012, 10165, 11512, 1374, 1829, 9905, 11129, 7451, 7875, 1666, 10189, 2540, 7620, 6545, 848, 11149, 1688, 10042, 11952, 5295, 6764, 7785, 9600, 1367, 5555, 5161, 3963, 3054, 2287, 6362, 5898, 9946, 7703, 1778, 9169, 7698, 10654, 2321, 5120, 1060, 1713, 1804, 2046, 5033, 1904, 10417, 1396, 1783, 10403, 8704, 4157, 11308, 1403, 5832, 6994, 5403, 6162, 3801, 2985, 7953, 3539, 4784, 4830, 7415, 6653, 4658, 6188, 10598, 11996, 3205, 8138, 768, 11059, 3194, 4932, 9848, 474, 1345, 1663, 3021, 9874, 7022, 7003, 1760, 896, 2616, 10631, 4084, 1846, 503, 11225, 6252, 3827, 1747, 4024, 5909, 3736, 10248, 2659, 1190, 4655, 8958, 2213, 5652, 3009, 6728, 1307, 1794, 8873, 11902, 9148, 1592, 10406, 3175, 1292, 9661, 48, 8760, 9231, 6176, 319, 11147, 850, 4114, 256, 9151, 9615, 2714, 4848, 1159, 9588, 6585, 7163, 10856, 7219, 1358, 2222, 6894, 7579, 3853, 7097, 1339, 5707, 4569, 10717, 11651, 11646, 6715, 2499, 10797, 6799, 2825, 4428, 3059, 4753, 4068, 6412, 6399, 4550, 2882, 3757, 11802, 10174, 6050, 5940, 2936, 47, 9713, 1293, 10889, 7078, 2393, 11752, 373, 6088, 7063, 5238, 11254, 240, 6558, 8176, 453, 930, 8668, 3232, 7743, 6939, 11627, 1910, 6171, 4175, 8391, 4677, 3528, 7148, 6110, 3680, 1474, 1428, 9885, 11352, 9917, 6822, 4268, 5076, 11102, 9846, 4934, 2356, 262, 5274, 6340, 2713, 9702, 9152, 11261, 6552, 2002, 12007, 3005, 10678, 4291, 6955, 8509, 11598, 2474, 1541, 1366, 9806, 7786, 2444, 9197, 11838, 488, 7755, 716, 9178, 5751, 8615, 6584, 9698, 1160, 7571, 11334, 9405, 5648, 4840, 1419, 7256, 391, 11030, 7691, 4976, 11943, 8657, 8944, 5657, 6378, 4226, 2415, 2817, 4884, 3895, 7776, 5246, 8265, 11811, 6548, 2847, 3453, 1856, 6234, 6520, 2675, 7707, 1735, 1705, 3637, 10124, 1937, 4510, 5624, 4331, 7304, 11939, 10178, 11764, 9533, 414, 2410, 10473, 166, 8757, 10053, 413, 9541, 11765, 5031, 2048, 2647, 7607, 11983, 431, 8641, 141, 3239, 3421, 2084, 11477, 1509, 3743, 7482, 6762, 5297, 2333, 1217, 1966, 5812, 6861, 2122, 3517, 2034, 811, 10843, 8856, 7536, 5260, 3909, 8249, 9909, 4019, 4963, 4455, 3914, 11120, 4464, 6812, 9444, 6197, 8532, 3413, 10271, 6967, 3100, 5004, 8583, 8779, 4272, 1315, 3619, 1532, 4071, 11240, 3476, 1823, 2196, 4394, 8741, 5912, 837, 289, 9270, 5497, 8777, 8585, 11112, 2634, 11899, 3112, 909, 2169, 960, 1641, 5572, 9838, 7370, 9896, 9395, 1384, 2944, 1842, 3321, 4078, 6196, 9491, 6813, 10652, 7700, 11531, 8735, 8013, 4241, 11625, 6941, 2037, 1482, 4419, 3212, 1150, 11919, 1177, 9870, 563, 66, 11831, 11279, 10848, 11414, 8291, 3841, 765, 7240, 3670, 38, 4111, 9290, 6972, 5644, 6265, 11689, 8917, 2832, 5647, 9584, 11335, 9259, 8648, 5995, 1146, 6280, 11116, 2270, 1383, 9451, 9897, 1519, 1876, 6270, 8471, 7497, 7604, 7020, 9876, 6466, 1267, 8951, 4198, 6059, 900, 2551, 115, 11073, 11488, 11347, 816, 8289, 11416, 2707, 7434, 7872, 5475, 9964, 2484, 4407, 4995, 11282, 4121, 1401, 11310, 4474, 3092, 1987, 6210, 1764, 2283, 10824, 8350, 10202, 5068, 5242, 2873, 650, 8151, 1897, 10810, 12003, 7509, 11306, 4159, 5492, 2458, 4307, 7169, 2877, 3154, 9313, 2820, 7971, 3418, 5382, 2959, 757, 11775, 4328, 7137, 5973, 5176, 6098, 8572, 8716, 1985, 3094, 9183, 4882, 2819, 9333, 3155, 4479, 4424, 10870, 5318, 596, 2642, 4580, 11360, 11644, 11653, 5672, 2397, 2312, 7166, 10238, 10902, 6327, 3850, 11049, 10727, 6971, 9413, 4112, 852, 7093, 869, 7286, 5236, 7065, 7212, 8454, 7110, 1693, 3230, 8670, 9119, 5289, 3120, 4202, 3898, 5496, 9467, 290, 6256, 3694, 7100, 4216, 5093, 285, 6155, 10366, 8647, 9403, 11336, 607, 10430, 10448, 8724, 5717, 2042, 3690, 10877, 1792, 1309, 4232, 1282, 8331, 10541, 11678, 10967, 3603, 4009, 6758, 3729, 3719, 438, 4417, 1484, 2940, 6175, 9710, 8761, 7981, 11861, 8730, 4351, 8797, 798, 8205, 1116, 3220, 5116, 1089, 11638, 5927, 11707, 9998, 3946, 1460, 7332, 3067, 6358, 3699, 1119, 10038, 9097, 814, 11349, 7967, 10127, 2992, 3354, 3071, 11837, 9597, 2445, 7130, 2699, 2681, 4043, 10079, 11497, 5213, 2336, 7586, 5998, 6408, 4881, 9316, 3095, 2606, 6367, 5750, 9592, 717, 7222, 11233, 8385, 6034, 1477, 2897, 7697, 9794, 1779, 5464, 2453, 8561, 4037, 8770, 2989, 5680, 11275, 4653, 1192, 1322, 1065, 8077, 5519, 11260, 9614, 9703, 257, 1591, 9718, 11903, 6786, 11459, 10207, 9969, 8325, 6770, 2665, 11364, 11289, 4843, 2678, 8860, 6524, 8712, 7462, 2344, 8257, 5342, 355, 205, 3576, 442, 4214, 7102, 8683, 2070, 5288, 9276, 8671, 10535, 2842, 4317, 11668, 1998, 4180, 6700, 6081, 5570, 1643, 8080, 10305, 5050, 6878, 7656, 10976, 1441, 7512, 10841, 813, 9206, 10039, 4028, 7406, 5881, 8347, 3821, 10413, 8548, 10258, 7532, 7591, 1983, 8718, 571, 5408, 3349, 8362, 3445, 6072, 2350, 11967, 275, 10528, 2780, 5839, 9921, 10628, 2564, 10172, 11804, 7197, 4256, 11299, 4135, 8995, 7254, 1421, 8632, 4559, 6541, 10342, 6630, 2685, 11257, 4988, 10142, 7296, 5591, 3798, 11137, 1390, 11676, 10543, 11923, 6144, 8891, 7813, 5956, 8252, 542, 1797, 8397, 7523, 1771, 11484, 7318, 9986, 8211, 2243, 4061, 5379, 3242, 2851, 6334, 1885, 2812, 8660, 10780, 8237, 6975, 11567, 5223, 8851, 11211, 7644, 5148, 8007, 5, 2404, 1336, 3697, 6360, 2289, 5286, 2072, 1457, 10389, 587, 268, 7845, 7253, 9062, 4136, 10349, 2264, 2140, 625, 4153, 3675, 136, 1680, 7802, 6066, 5263, 552, 1808, 8419, 1490, 1058, 5122, 7316, 11486, 11075, 10024, 5805, 11384, 11400, 11266, 9901, 3981, 1945, 11062, 1660, 6883, 6928, 7469, 8049, 2212, 9727, 4656, 6655, 7584, 2338, 7261, 4197, 9383, 1268, 1546, 3972, 4680, 2802, 5656, 9573, 8658, 2814, 177, 6245, 8678, 11422, 10973, 83, 5501, 10775, 828, 1206, 4414, 11330, 3406, 6875, 4747, 7828, 5561, 11378, 5258, 7538, 2655, 10027, 2696, 2831, 9408, 11690, 3856, 5045, 2528, 7010, 1957, 10227, 10754, 8038, 8488, 9889, 8498, 11042, 3138, 113, 2553, 11105, 11549, 28, 11584, 8300, 10987, 6723, 2739, 7812, 9041, 6145, 1724, 11170, 1573, 4362, 11432, 4628, 1214, 5216, 6346, 5205, 8577, 8260, 7085, 970, 3110, 11901, 9720, 1795, 544, 6427, 8565, 7569, 1162, 9832, 4081, 5438, 6489, 7852, 6523, 9135, 2679, 2701, 7535, 9504, 10844, 1587, 7419, 11210, 9014, 5224, 5435, 10634, 10661, 6310, 8246, 3508, 1464, 6590, 5016, 1580, 1606, 2298, 10722, 4074, 742, 5878, 4618, 7438, 220, 7154, 5665, 6810, 4466, 1656, 604, 698, 3564, 4892, 10066, 953, 2258, 7082, 1313, 4274, 8503, 10551, 4683, 7917, 1243, 11153, 16, 2254, 3876, 11229, 6499, 11222, 1981, 7593, 2582, 10864, 6285, 797, 9225, 4352, 8312, 10896, 2792, 6898, 6206, 631, 10376, 11822, 10742, 3646, 1099, 10319, 2735, 3344, 2369, 4271, 9482, 8584, 9465, 5498, 11871, 2490, 8593, 6633, 2988, 9163, 4038, 6299, 534, 10506, 4144, 6735, 6415, 7980, 9230, 9711, 49, 10052, 9536, 167, 5540, 6530, 11555, 6666, 6303, 6603, 8666, 932, 917, 4940, 126, 7914, 3734, 5911, 9471, 4395, 401, 6322, 1501, 8012, 9439, 11532, 7675, 1279, 4350, 9227, 11862, 1453, 3416, 7973, 5716, 9254, 10449, 10329, 6793, 4631, 570, 9084, 1984, 9319, 8573, 1913, 7461, 9133, 6525, 6152, 11972, 310, 1978, 506, 4156, 9779, 10404, 1594, 10619, 11711, 4366, 3339, 6646, 6481, 8123, 1525, 10170, 2566, 7936, 5334, 11065, 1132, 4278, 4497, 6113, 2069, 9122, 7103, 6935, 913, 11421, 8939, 6246, 5146, 7646, 3315, 5368, 10534, 9118, 9277, 3231, 9645, 931, 8749, 6604, 2932, 3652, 11865, 10779, 9020, 2813, 8943, 9574, 11944, 4663, 1514, 11894, 8112, 6237, 6228, 5994, 9402, 9260, 10367, 6497, 11231, 7224, 140, 9525, 432, 10317, 1101, 122, 6992, 5834, 3994, 4558, 9059, 1422, 8457, 7116, 7373, 6686, 10398, 7292, 6556, 242, 4320, 7039, 217, 1109, 5688, 11124, 6583, 9590, 5752, 4669, 10984, 1230, 8605, 5140, 682, 3084, 5139, 8610, 1231, 3778, 4189, 3480, 2525, 1743, 10559, 3286, 4041, 2683, 6632, 8773, 2491, 9930, 11482, 1773, 1113, 7923, 11111, 9464, 8778, 9483, 5005, 4804, 6010, 5340, 8259, 8879, 5206, 6169, 1912, 8715, 9320, 6099, 11178, 3650, 2934, 5942, 7568, 8869, 6428, 11615, 4036, 9165, 2454, 10158, 540, 8254, 213, 4344, 10119, 567, 8433, 11016, 171, 10257, 9089, 10414, 2153, 6663, 7236, 4741, 5155, 10396, 6688, 7191, 772, 2538, 10191, 4813, 7823, 3412, 9489, 6198, 4744, 5053, 7713, 5443, 728, 5991, 7043, 3805, 4093, 11520, 7145, 197, 10001, 11768, 348, 1210, 5670, 11655, 8268, 4533, 11597, 9605, 6956, 8102, 3766, 3169, 10550, 8815, 4275, 10021, 6092, 11041, 8905, 9890, 2505, 9980, 7140, 6783, 11565, 6977, 7964, 9888, 8907, 8039, 7335, 2378, 4866, 11818, 1869, 4719, 5459, 10013, 7835, 3905, 5480, 4059, 2245, 7230, 7496, 9390, 6271, 4164, 7718, 8180, 5451, 641, 4649, 4624, 3584, 6661, 2155, 4132, 7115, 8630, 1423, 7109, 9281, 7213, 5632, 10791, 11314, 3190, 7122, 6618, 806, 762, 5377, 4063, 10461, 2009, 6985, 4956, 11807, 2887, 11572, 686, 11015, 8552, 568, 4633, 7388, 3551, 5353, 10568, 7152, 222, 1571, 11172, 11741, 7520, 1489, 8980, 1809, 6947, 659, 2098, 5893, 3632, 8372, 1045, 2772, 8005, 5150, 9893, 7119, 1949, 10990, 4637, 10578, 1561, 11736, 1487, 7522, 9035, 1798, 10697, 2534, 10482, 4676, 9637, 4176, 8110, 11896, 942, 6033, 9174, 11234, 8133, 6119, 3600, 3642, 1740, 5048, 10307, 2462, 1890, 10939, 1044, 8412, 3633, 10274, 1544, 1270, 3227, 10915, 3739, 834, 3444, 9080, 3350, 149, 10562, 11325, 1000, 1095, 1768, 1055, 4055, 11779, 10201, 9352, 10825, 3820, 9092, 5882, 7053, 4772, 2597, 11976, 9954, 11505, 7859, 3025, 11878, 10839, 7514, 5902, 2381, 10540, 9245, 1283, 3859, 4347, 4235, 6769, 9142, 9970, 2762, 1137, 1576, 5756, 2746, 4914, 10676, 3007, 5654, 2804, 10895, 8795, 4353, 3956, 254, 4116, 7843, 270, 4495, 4280, 6319, 1228, 10986, 8896, 11585, 9842, 11055, 6598, 8283, 2776, 11576, 3840, 9420, 11415, 9373, 817, 4383, 1068, 5254, 2775, 8295, 6599, 7328, 4098, 3270, 6103, 2281, 1766, 1097, 3648, 11180, 4526, 10503, 2495, 4532, 8512, 11656, 11810, 9563, 5247, 4230, 1311, 7084, 8878, 8578, 5341, 9130, 2345, 212, 8557, 541, 9038, 5957, 9908, 9500, 3910, 3507, 8845, 6311, 1496, 6706, 10607, 10687, 9990, 5642, 6974, 9018, 10781, 3410, 7825, 9927, 538, 10160, 7912, 128, 6289, 4853, 10283, 426, 2173, 4645, 1931, 10713, 7340, 20, 6608, 5853, 6421, 2965, 877, 5850, 2242, 9029, 9987, 4969, 3490, 7921, 1115, 9223, 799, 6932, 10937, 1892, 11448, 11949, 2133, 1635, 193, 10146, 1187, 3665, 2922, 1601, 1720, 5386, 1650, 5760, 2277, 10267, 2075, 7909, 5580, 5450, 8467, 7719, 5098, 452, 9648, 6559, 436, 3721, 2594, 11249, 6638, 923, 1004, 4871, 5232, 11322, 5685, 2719, 965, 4433, 2324, 4917, 322, 3098, 6969, 10729, 3684, 7667, 1896, 9346, 651, 371, 11754, 10424, 4596, 5362, 8028, 5620, 6950, 4739, 7238, 767, 9758, 3206, 785, 4837, 6118, 8383, 11235, 8128, 3884, 3883, 8131, 11236, 4016, 4222, 1524, 8695, 6482, 4514, 4411, 7128, 2447, 4238, 7810, 2741, 6518, 6236, 8652, 11895, 8389, 4177, 3536, 6534, 5945, 6752, 2512, 3765, 8507, 6957, 7557, 2518, 894, 1762, 6212, 7069, 4768, 332, 10385, 7411, 6031, 944, 4926, 11045, 10981, 10602, 5398, 7347, 1251, 10304, 9107, 1644, 5518, 9155, 1066, 4385, 5976, 10588, 4906, 10287, 845, 11814, 2014, 2799, 10554, 1626, 4604, 7398, 6566, 77, 11857, 80, 7659, 3703, 11760, 4548, 6401, 11026, 7611, 6851, 2211, 8960, 7470, 10873, 7654, 6880, 1348, 5660, 10466, 3065, 7334, 8487, 8908, 10755, 4487, 10961, 11544, 2111, 3046, 10069, 4251, 5619, 8144, 5363, 6573, 5526, 5112, 11193, 5567, 317, 6178, 3379, 7456, 10626, 9923, 7808, 4240, 9438, 8736, 1502, 7207, 6005, 4, 9010, 5149, 8409, 2773, 5256, 11380, 1639, 962, 1288, 776, 3887, 7792, 2103, 2515, 7051, 5884, 694, 10265, 2279, 6105, 10323, 1973, 2918, 4608, 11854, 11860, 9229, 8762, 6416, 397, 3451, 2849, 3244, 5715, 8726, 3417, 9331, 2821, 1935, 10126, 9203, 11350, 9887, 8490, 6978, 10111, 4484, 10521, 10957, 3660, 235, 11553, 6532, 3538, 9769, 2986, 6635, 3570, 1553, 4248, 7769, 7259, 2340, 5602, 10480, 2536, 774, 1290, 3177, 11272, 5333, 8691, 2567, 5818, 2180, 3148, 6576, 1381, 2272, 10168, 1527, 4572, 10907, 11110, 8587, 1114, 8207, 3491, 494, 1242, 8812, 4684, 3733, 8744, 127, 8230, 10161, 5579, 8183, 2076, 5967, 314, 6084, 308, 11974, 2599, 2724, 11162, 2308, 11758, 3705, 4171, 5194, 5989, 730, 2651, 10613, 11403, 5000, 5025, 100, 10932, 11590, 5765, 6869, 9857, 3554, 4899, 713, 2950, 3019, 1665, 9820, 7452, 5474, 9369, 7435, 1506, 3248, 5279, 5185, 873, 7459, 1915, 855, 2053, 11387, 3024, 8339, 11506, 3308, 2235, 706, 2673, 6522, 8862, 6490, 5741, 3544, 4296, 5535, 7252, 8997, 269, 8307, 4117, 6820, 9919, 5841, 2375, 3623, 3904, 8478, 10014, 2901, 5314, 5126, 4536, 5560, 8926, 4748, 9926, 8234, 3411, 8534, 4814, 7759, 5677, 10130, 7805, 4751, 3061, 2631, 5955, 9040, 8892, 2740, 8116, 4239, 8015, 9924, 4750, 7818, 10131, 6065, 8985, 1681, 11570, 2889, 4912, 2748, 6921, 10642, 6240, 2102, 7996, 3888, 10490, 10789, 5634, 2443, 9599, 9807, 6765, 3750, 10703, 2766, 10732, 7665, 3686, 5245, 9565, 3896, 4204, 3999, 2576, 389, 7258, 7947, 4249, 10071, 10459, 4065, 4245, 1943, 3983, 6395, 5676, 7821, 4815, 2948, 715, 9594, 489, 11620, 985, 4404, 32, 1128, 1908, 11629, 5190, 2388, 6938, 9643, 3233, 2532, 10699, 3197, 3511, 1993, 10880, 3326, 7517, 3709, 5695, 795, 6287, 130, 4714, 11827, 6595, 11687, 6267, 1334, 2406, 5059, 5097, 8179, 8468, 4165, 6479, 6648, 5442, 8528, 5054, 4458, 6805, 5846, 1734, 9554, 2676, 4845, 1777, 9796, 9947, 11530, 9441, 10653, 9793, 9170, 2898, 346, 11770, 3391, 4975, 9577, 11031, 5505, 26, 11551, 237, 2688, 4877, 6388, 2467, 4710, 10817, 10152, 5552, 5789, 1278, 8733, 11533, 1183, 10155, 5781, 11799, 3458, 1895, 8153, 3685, 7779, 10733, 3282, 2787, 3217, 3702, 8058, 81, 10975, 9103, 6879, 8046, 10874, 10439, 3127, 582, 5182, 301, 3314, 8675, 5147, 9012, 11212, 5083, 4546, 11762, 10180, 6693, 11419, 915, 934, 4953, 11916, 5565, 11195, 3726, 10946, 3938, 6038, 6839, 283, 5095, 5061, 7276, 6544, 9816, 2541, 3273, 11613, 6430, 7401, 5575, 11455, 6850, 8052, 11027, 4262, 11982, 9528, 2648, 7019, 9388, 7498, 3893, 4886, 10806, 3082, 684, 11574, 2778, 10530, 2581, 8802, 1982, 9086, 7533, 2703, 1144, 5997, 9187, 2337, 8955, 6656, 10979, 11047, 3852, 9690, 6895, 10926, 4585, 5794, 9855, 6871, 11333, 9586, 1161, 8868, 8566, 5943, 6536, 2051, 857, 927, 6908, 5738, 7029, 7049, 2517, 8100, 6958, 4302, 5209, 6622, 6704, 1498, 892, 2520, 5202, 3186, 10358, 1012, 2079, 6669, 11660, 6709, 702, 2654, 8922, 5259, 9503, 8857, 2702, 7590, 9087, 10259, 1901, 4052, 1493, 1257, 3977, 1053, 1770, 9034, 8398, 1488, 8421, 11742, 3708, 7734, 3327, 5901, 8335, 10840, 9100, 1442, 11305, 9342, 12004, 1718, 1603, 1568, 10075, 2465, 6390, 11357, 5530, 3892, 7603, 9389, 8472, 7231, 10930, 102, 6243, 179, 673, 1751, 832, 3741, 1511, 10765, 10943, 6761, 9517, 3744, 3502, 417, 6886, 4183, 6454, 11464, 7314, 5124, 5316, 10872, 8048, 8961, 6929, 4372, 252, 3958, 5613, 2343, 9132, 8713, 1914, 7865, 874, 10625, 8018, 3380, 2955, 5473, 7874, 9821, 11130, 11604, 1330, 7326, 6601, 6305, 2328, 1297, 10485, 4087, 1107, 219, 8832, 4619, 1505, 7871, 9370, 2708, 654, 6485, 6903, 1086, 4437, 6220, 11957, 1559, 10580, 514, 6802, 5393, 11209, 8853, 1588, 3867, 6652, 9765, 4831, 5872, 6030, 8091, 10386, 3949, 4616, 5880, 9094, 4029, 160, 9836, 5574, 7615, 6431, 6565, 8063, 4605, 6134, 3180, 4576, 10509, 4808, 669, 7363, 3550, 8430, 4634, 580, 3129, 10800, 5219, 3293, 11444, 3582, 4626, 11434, 1022, 3610, 1436, 6685, 8628, 7117, 9895, 9453, 9839, 3790, 10083, 1927, 11371, 3549, 7390, 670, 737, 2854, 10822, 2285, 3056, 5359, 2250, 5826, 6593, 11829, 68, 3358, 10500, 1250, 8083, 5399, 6260, 3400, 1030, 1413, 19, 8220, 10714, 1530, 3621, 2377, 8486, 8040, 3066, 9212, 1461, 3200, 4097, 8281, 6600, 7447, 1331, 1879, 6912, 11907, 6123, 11093, 9985, 9031, 11485, 8976, 5123, 7474, 11465, 24, 5507, 4857, 6350, 647, 726, 5445, 11938, 9545, 4332, 1197, 1467, 11882, 4285, 187, 5590, 9050, 10143, 3532, 6555, 8625, 10399, 11633, 5372, 6126, 5235, 9285, 870, 10094, 10196, 227, 1801, 6471, 5485, 10340, 6543, 7622, 5062, 3872, 4776, 3470, 6859, 5814, 3483, 6961, 5137, 3086, 4186, 2088, 4207, 4196, 8953, 2339, 7946, 7770, 390, 9580, 1420, 9061, 8996, 7846, 5536, 6743, 59, 6720, 1952, 4943, 3919, 11682, 7194, 4959, 3669, 9417, 766, 8140, 4740, 8544, 6664, 11557, 5108, 10929, 7495, 8473, 2246, 7184, 11269, 6137, 139, 8643, 11232, 9176, 718, 1357, 9694, 10857, 512, 10582, 11038, 5631, 8453, 9282, 7066, 7007, 3432, 6004, 8010, 1503, 4621, 11345, 11490, 2146, 1821, 3478, 4191, 4255, 9066, 11805, 4958, 7243, 11683, 771, 8539, 6689, 11108, 10909, 1517, 9899, 11268, 7228, 2247, 4599, 6142, 11925, 421, 6250, 11227, 3878, 5896, 6364, 2431, 10595, 723, 2876, 9336, 4308, 10237, 9298, 2313, 10855, 9696, 6586, 5723, 3786, 1731, 11673, 6505, 4703, 5664, 8830, 221, 8426, 10569, 710, 6109, 9634, 3529, 196, 8520, 11521, 11008, 3846, 6782, 8494, 9981, 5972, 9324, 4329, 5626, 10478, 5604, 2829, 2698, 9195, 2446, 8119, 4412, 1208, 350, 1409, 6617, 8448, 3191, 1948, 8406, 9894, 7372, 8629, 8458, 4133, 11301, 5906, 1692, 9280, 8455, 1424, 3941, 1727, 10935, 6934, 8682, 9123, 4215, 9266, 3695, 1338, 9688, 3854, 11692, 868, 9287, 853, 1917, 1819, 2148, 11068, 3925, 969, 8877, 8261, 1312, 8818, 2259, 2166, 2392, 9658, 10890, 5970, 9983, 11095, 3267, 11888, 10060, 4767, 8095, 6213, 7006, 7211, 9283, 5237, 9653, 6089, 11078, 4379, 98, 5027, 3574, 207, 4818, 4771, 8345, 5883, 7993, 2516, 7559, 7030, 1063, 1324, 2025, 3804, 8524, 5992, 6230, 216, 8621, 4321, 2437, 71, 1017, 1620, 10760, 1711, 1062, 7048, 7560, 5739, 6492, 755, 2961, 1872, 7002, 9747, 9875, 9387, 7605, 2649, 732, 1167, 10428, 609, 4124, 6989, 1956, 8912, 2529, 3431, 7210, 7067, 6214, 1759, 9746, 7023, 1873, 406, 6185, 5422, 3172, 10434, 5402, 9774, 5833, 8636, 123, 1955, 7012, 4125, 11914, 4955, 8440, 2010, 247, 2482, 9966, 2228, 10110, 7963, 8491, 11566, 9017, 8238, 5643, 9412, 9291, 10728, 8156, 3099, 9486, 10272, 3635, 1707, 2908, 5136, 7268, 3484, 4301, 7556, 8101, 8508, 9606, 4292, 6917, 4390, 4738, 8142, 5621, 658, 8417, 1810, 2663, 6772, 809, 2036, 9435, 11626, 9642, 7744, 2389, 912, 8681, 7104, 10936, 8203, 800, 4371, 7468, 8962, 6884, 419, 11927, 145, 499, 10641, 7796, 2749, 11729, 4389, 6953, 4293, 3835, 11562, 11906, 7323, 1880, 5950, 5737, 7562, 928, 455, 4780, 1085, 7430, 6486, 3989, 821, 6205, 8792, 2793, 10925, 7578, 9691, 2223, 10954, 3036, 4698, 4540, 6698, 4182, 7478, 418, 6927, 8963, 1661, 1347, 8045, 7655, 9104, 5051, 4746, 8928, 3407, 3404, 11332, 7573, 9856, 7883, 5766, 3337, 4368, 3002, 4007, 3605, 2121, 9510, 5813, 7271, 3471, 1618, 1019, 1275, 6747, 6457, 2210, 8051, 7612, 11456, 6581, 11126, 5960, 266, 589, 1042, 10941, 10767, 282, 7626, 6039, 2691, 5916, 10671, 5640, 9992, 11430, 4364, 11713, 6733, 4146, 11141, 1921, 10750, 383, 4267, 9626, 9918, 7841, 4118, 6025, 11397, 2056, 1702, 10651, 9443, 9492, 4465, 8828, 5666, 3133, 3437, 5845, 7710, 4459, 5392, 7422, 515, 2824, 9678, 10798, 3131, 5668, 1212, 4630, 8721, 10330, 445, 2998, 3163, 6579, 11458, 9146, 11904, 11564, 8493, 7141, 3847, 692, 5886, 4726, 2729, 4949, 2361, 760, 808, 6944, 2664, 9141, 8326, 4236, 2449, 3749, 7784, 9808, 5296, 9516, 7483, 10944, 3728, 9239, 4010, 634, 3090, 4476, 2511, 8105, 5946, 3030, 11462, 6456, 6854, 1276, 5791, 58, 7250, 5537, 5937, 11750, 2395, 5674, 6397, 6414, 8764, 4145, 6829, 11714, 1377, 1354, 1306, 9723, 3010, 9942, 2893, 2738, 8894, 10988, 1951, 7248, 60, 2204, 5250, 2498, 9681, 11647, 35, 2061, 1220, 701, 7541, 11661, 10606, 8243, 1497, 7552, 6623, 994, 6080, 9111, 4181, 6888, 4541, 1142, 2705, 11418, 7638, 10181, 11547, 11107, 7190, 8540, 10397, 8627, 7374, 1437, 1448, 6331, 740, 4076, 3323, 949, 10355, 11411, 2184, 6002, 3434, 3755, 2884, 11659, 7543, 2080, 6302, 8752, 11556, 7235, 8545, 2154, 8461, 3585, 1446, 1439, 10978, 7583, 8956, 4657, 9764, 7416, 3868, 3986, 5441, 7715, 6480, 8697, 3340, 1480, 2039, 379, 4724, 5888, 922, 8170, 11250, 3569, 7951, 2987, 8772, 8594, 2684, 9055, 10343, 10292, 3824, 10364, 6157, 993, 6703, 7553, 5210, 4592, 805, 8447, 7123, 1410, 3929, 4667, 5754, 1578, 5018, 2240, 5852, 8218, 21, 11441, 2931, 8665, 8750, 6304, 7446, 7327, 8282, 8296, 11056, 11686, 7726, 11828, 7353, 5827, 5015, 8842, 1465, 1199, 5722, 7162, 9697, 9589, 8616, 11125, 6848, 11457, 6788, 3164, 1380, 7931, 3149, 5525, 8026, 5364, 4299, 3486, 11286, 4707, 76, 8062, 7399, 6432, 3832, 3547, 11373, 435, 8175, 9649, 241, 8624, 7293, 3533, 2001, 9612, 11262, 10233, 2846, 9561, 11812, 847, 9815, 7621, 7277, 10341, 9057, 4560, 4140, 2645, 2050, 7566, 5944, 8107, 3537, 7955, 11554, 8754, 5541, 4734, 1674, 6151, 8711, 9134, 8861, 7853, 2674, 9556, 6235, 8114, 2742, 2547, 3237, 143, 11929, 3078, 1239, 11189, 981, 4324, 11988, 4702, 7157, 11674, 1392, 304, 2017, 11221, 8805, 11230, 8645, 10368, 3935, 2859, 754, 7027, 5740, 7851, 8863, 5439, 3988, 6902, 7431, 655, 4513, 8122, 8696, 6647, 7716, 4166, 4762, 5271, 6077, 11845, 3258, 5484, 7280, 1802, 1715, 2005, 1266, 9385, 9877, 1865, 10828, 1860, 4335, 6225, 10645, 2209, 6853, 6748, 11463, 7476, 4184, 3088, 636, 10861, 96, 4381, 819, 3991, 11697, 5931, 2904, 10371, 2558, 2176, 4611, 4399, 559, 6405, 1851, 4103, 3831, 6564, 7400, 7616, 11614, 8564, 8870, 545, 575, 11825, 4716, 2964, 8216, 5854, 11022, 11005, 396, 7979, 8763, 6736, 6398, 9672, 4069, 1534, 4880, 9185, 5999, 1850, 6436, 560, 11391, 11025, 8054, 4549, 9671, 6413, 6737, 5675, 7761, 3984, 3870, 5064, 11356, 7502, 2466, 7683, 4878, 1536, 11536, 5919, 974, 4799, 3561, 1223, 4225, 9571, 5658, 1350, 5705, 1341, 5179, 2022, 3774, 5040, 2602, 5749, 9180, 2607, 2430, 7174, 5897, 9799, 2288, 9005, 3698, 9210, 3068, 2441, 5636, 10664, 3970, 1548, 646, 7309, 4858, 3184, 5204, 8881, 5217, 10802, 3499, 359, 2712, 9617, 5275, 5617, 4253, 4193, 1884, 9023, 2852, 739, 6682, 1449, 690, 3849, 9295, 10903, 3395, 890, 1500, 8738, 402, 1227, 8303, 4281, 11219, 2019, 585, 10391, 1255, 1495, 8245, 8846, 10662, 5638, 10673, 2327, 7445, 6602, 8751, 6667, 2081, 533, 8768, 4039, 3288, 2760, 9972, 11636, 1091, 10813, 5426, 4852, 8228, 129, 7730, 796, 8799, 10865, 5735, 5952, 11115, 9399, 1147, 5730, 6062, 5104, 4452, 4985, 5522, 4163, 8470, 9391, 1877, 1333, 7724, 11688, 9410, 5645, 2834, 2422, 3399, 7345, 5400, 10436, 3693, 9268, 291, 10362, 3826, 9737, 11226, 7178, 422, 4129, 5145, 8677, 8940, 178, 7492, 103, 2101, 7794, 10643, 6227, 8651, 8113, 6519, 9557, 1857, 4342, 215, 7041, 5993, 8650, 6238, 10644, 6460, 4336, 10736, 5268, 11956, 7427, 4438, 2159, 486, 11840, 1758, 7005, 7068, 8096, 1763, 9356, 1988, 3041, 630, 8791, 6899, 822, 11034, 10046, 2502, 5153, 4743, 8531, 9490, 9445, 4079, 9834, 162, 11494, 1303, 721, 10597, 9762, 4659, 5421, 6999, 407, 10685, 10609, 2238, 5020, 3378, 8020, 318, 9709, 9232, 2941, 2093, 4174, 9639, 1911, 8575, 5207, 4304, 10280, 342, 11135, 3800, 9772, 5404, 3796, 5593, 992, 6625, 10365, 9262, 286, 11971, 8710, 6526, 1675, 296, 10187, 1668, 1723, 8890, 9042, 11924, 7181, 4600, 5984, 1678, 138, 7226, 11270, 3179, 7396, 4606, 2920, 3667, 4961, 4021, 11320, 5234, 7288, 5373, 11092, 7321, 11908, 9914, 3599, 8382, 8134, 4838, 5650, 2215, 2068, 8685, 4498, 3679, 9633, 7149, 711, 4901, 10322, 7988, 2280, 8278, 3271, 2543, 11177, 8571, 9321, 5177, 1343, 476, 5629, 11040, 8500, 10022, 11077, 7062, 9654, 374, 2796, 307, 7905, 315, 5569, 9110, 6701, 995, 11844, 6475, 5272, 264, 5962, 2349, 9078, 3446, 4446, 5478, 3907, 5262, 8984, 7803, 10132, 5103, 6277, 5731, 899, 9381, 4199, 2974, 3762, 2106, 886, 5167, 11748, 5939, 9665, 10175, 10999, 9936, 4106, 11700, 1122, 4937, 2031, 4875, 2690, 6838, 7627, 3939, 1426, 1476, 9173, 8386, 943, 8090, 7412, 5873, 10336, 11719, 11396, 6818, 4119, 11284, 3488, 4971, 5784, 3364, 2612, 10868, 4426, 2827, 5606, 10164, 9828, 5339, 8580, 4805, 4004, 12010, 3, 8009, 7208, 3433, 6674, 2185, 1849, 6407, 9186, 7587, 1145, 9401, 8649, 6229, 7042, 8525, 729, 7894, 5195, 617, 294, 1677, 6140, 4601, 3923, 11070, 3627, 2840, 10537, 10587, 8074, 4386, 5175, 9323, 7138, 9982, 7076, 10891, 313, 7907, 2077, 1014, 1838, 2348, 6074, 265, 6846, 11127, 9907, 8251, 9039, 7814, 2632, 11114, 6282, 5736, 6910, 1881, 4210, 3029, 6751, 8106, 6535, 7567, 8567, 2935, 9664, 6051, 11749, 6741, 5538, 169, 11018, 5312, 2903, 6444, 11698, 4108, 11706, 9217, 11639, 2359, 4951, 936, 1991, 3513, 973, 6384, 11537, 10670, 6836, 2692, 3442, 836, 9470, 8742, 3735, 9733, 4025, 1691, 7112, 11302, 4864, 2380, 8334, 7515, 3328, 9945, 9798, 6363, 7175, 3879, 3631, 8414, 2099, 105, 4692, 921, 6640, 4725, 6779, 693, 7992, 7052, 8346, 9093, 7407, 4617, 8834, 743, 4787, 11875, 10335, 6029, 7413, 4832, 89, 2971, 3123, 10290, 10345, 1826, 11717, 10338, 5487, 3303, 42, 11727, 2751, 1648, 5388, 11021, 6420, 8217, 6609, 2241, 8213, 878, 11671, 1733, 7709, 6806, 3438, 10102, 2374, 7839, 9920, 9072, 2781, 2304, 11695, 3993, 8635, 6993, 9775, 1404, 1328, 11606, 5014, 6592, 7354, 2251, 1416, 11292, 10710, 519, 11851, 2179, 7934, 2568, 2523, 3482, 7270, 6860, 9511, 1967, 979, 11191, 5114, 3222, 11383, 8972, 10025, 2657, 10250, 3917, 4945, 5008, 10255, 173, 11527, 9854, 7575, 4586, 57, 6745, 1277, 7677, 5553, 1369, 5775, 3363, 6020, 4972, 11798, 7671, 10156, 2456, 5494, 3900, 3362, 5786, 1370, 4219, 9912, 11910, 4521, 11835, 3073, 3336, 6868, 7884, 11591, 4835, 787, 2276, 8187, 1651, 11722, 2745, 8320, 1577, 6613, 4668, 8614, 9591, 9179, 6368, 2603, 325, 4289, 10680, 10136, 2622, 3543, 7850, 6491, 7028, 7561, 6909, 5951, 6283, 10866, 2614, 898, 6061, 6278, 1148, 3214, 11217, 4283, 11884, 3785, 7161, 6587, 1200, 10922, 377, 2041, 9253, 8725, 7974, 3245, 11480, 9932, 5346, 3262, 5411, 4568, 9686, 1340, 6375, 1351, 3167, 3768, 10518, 10758, 1622, 11428, 9994, 794, 7732, 3710, 10786, 11611, 3275, 10513, 11123, 8618, 1110, 2718, 8164, 11323, 10564, 5331, 11274, 9161, 2990, 10129, 7820, 7760, 6396, 6738, 2396, 9301, 11654, 8514, 1211, 6796, 3132, 6809, 8829, 7155, 4704, 11367, 10465, 8043, 1349, 6377, 9572, 8945, 2803, 8315, 3008, 9725, 2214, 6116, 4839, 9583, 9406, 2833, 6264, 9411, 6973, 8239, 9991, 6834, 10672, 6308, 10663, 6355, 2442, 7788, 10790, 8452, 7214, 11039, 6094, 477, 10477, 7135, 4330, 9547, 4511, 657, 6949, 8143, 8029, 4252, 6338, 5276, 5600, 2342, 7464, 3959, 988, 622, 11453, 5577, 10163, 6014, 2828, 7133, 10479, 7944, 2341, 5615, 5277, 3250, 4034, 11617, 1008, 991, 6159, 3797, 9049, 7297, 188, 11438, 11468, 3143, 3449, 399, 4397, 4613, 5449, 8182, 7910, 10162, 5608, 11454, 7614, 7402, 9837, 9455, 1642, 9109, 6082, 316, 8022, 11194, 7632, 11917, 1152, 11377, 8925, 7829, 4537, 550, 5265, 5160, 9804, 1368, 5788, 7678, 10153, 1185, 10148, 2136, 2628, 10747, 10008, 10298, 10211, 4733, 6529, 8755, 168, 5936, 6742, 7251, 7847, 4297, 5366, 3317, 3891, 7500, 11358, 4582, 5111, 8025, 6574, 3150, 4162, 6273, 4986, 11259, 9154, 8078, 1645, 3368, 783, 3208, 792, 9996, 11709, 10621, 339, 4856, 7311, 25, 7689, 11032, 824, 10774, 8935, 84, 11870, 8776, 9466, 9271, 3899, 5778, 2457, 9339, 4160, 3152, 2879, 3302, 5862, 10339, 7279, 6472, 3259, 459, 4058, 8476, 3906, 6069, 4447, 9963, 9368, 7873, 7453, 2956, 1672, 4736, 4392, 2198, 11166, 201, 2452, 9167, 1780, 751, 2401, 10012, 8480, 4720, 3389, 11772, 2364, 3838, 11578, 640, 8466, 8181, 5581, 4614, 3951, 11937, 7306, 727, 8527, 7714, 6649, 3987, 6488, 8864, 4082, 10633, 8849, 5225, 556, 5165, 888, 3397, 2424, 2316, 4851, 6291, 10814, 10548, 3171, 6998, 6186, 4660, 185, 4287, 327, 957, 3717, 3731, 4686, 4567, 5709, 3263, 3348, 9082, 572, 11992, 3795, 6161, 9773, 6995, 10435, 6259, 7346, 8084, 10603, 4890, 3566, 11208, 7421, 6803, 4460, 5310, 11020, 5856, 1649, 8189, 1721, 1670, 2958, 9329, 3419, 3241, 9026, 4062, 8444, 763, 3843, 11091, 6125, 7289, 11634, 9974, 10533, 8673, 3316, 5533, 4298, 6572, 8027, 8145, 4597, 2249, 7356, 3057, 4430, 1035, 10574, 10567, 8428, 3552, 9859, 3468, 4778, 457, 3261, 5711, 9933, 4470, 354, 9129, 8258, 8579, 6011, 9829, 602, 1658, 11064, 8690, 7937, 11273, 5682, 10565, 10576, 4639, 3386, 1616, 3473, 4823, 906, 466, 1832, 4375, 595, 9308, 10871, 7472, 5125, 7832, 2902, 5933, 11019, 5390, 4461, 10516, 3770, 1407, 352, 4472, 11312, 10793, 9952, 11978, 366, 2332, 9515, 6763, 9809, 11953, 4765, 10062, 1025, 3119, 9275, 9120, 2071, 9003, 2290, 10707, 10659, 10636, 299, 5184, 7868, 3249, 5599, 5616, 6339, 9618, 263, 6076, 6476, 4763, 11955, 6222, 10737, 5159, 5557, 551, 8983, 6067, 3908, 9502, 7537, 8923, 11379, 8003, 2774, 8285, 1069, 4530, 2497, 6717, 2205, 4229, 8264, 9564, 7777, 3687, 2872, 9349, 5069, 11205, 11253, 9652, 7064, 9284, 7287, 6127, 11321, 8166, 4872, 3520, 449, 109, 2867, 555, 5434, 8850, 9015, 11568, 1683, 3292, 7383, 10801, 6345, 8882, 1215, 2335, 9189, 11498, 4591, 6621, 7554, 4303, 6168, 8576, 8880, 6347, 3185, 7548, 2521, 2570, 1362, 10311, 9957, 616, 5988, 7895, 4172, 2095, 2387, 7746, 11630, 1263, 10092, 872, 7867, 5280, 300, 7649, 583, 2021, 6373, 1342, 6097, 9322, 5974, 4387, 11731, 1246, 1072, 10971, 11424, 11747, 6053, 887, 5432, 557, 4401, 3962, 9803, 5556, 5266, 10738, 10994, 10395, 8542, 4742, 6200, 2503, 9892, 8408, 8006, 9011, 7645, 8676, 6247, 4130, 2157, 4440, 681, 8609, 8606, 3085, 7267, 6962, 2909, 4358, 3968, 10666, 10352, 3050, 5086, 11595, 4535, 7831, 5315, 7473, 7315, 8977, 1059, 9790, 2322, 4435, 1088, 9220, 3221, 5808, 11192, 8024, 5527, 4583, 10928, 7233, 11558, 11085, 4451, 6276, 6063, 10133, 4690, 107, 451, 8178, 7720, 5060, 7624, 284, 9264, 4217, 1372, 11514, 11868, 86, 11594, 5129, 3051, 4545, 7642, 11213, 3810, 1077, 4909, 3332, 11101, 9624, 4269, 2371, 387, 2578, 9977, 11204, 5241, 9350, 10203, 3596, 11355, 6392, 3871, 7275, 7623, 5096, 7721, 2407, 3505, 3912, 4457, 7712, 8529, 4745, 6877, 9105, 10306, 8378, 1741, 2527, 8914, 3857, 1285, 2722, 2601, 6370, 3775, 2996, 447, 3522, 4050, 1903, 9785, 2047, 9531, 11766, 10003, 3573, 7058, 99, 7888, 5001, 10058, 11890, 3377, 6180, 2239, 6611, 1579, 8841, 6591, 5828, 11607, 10140, 4990, 2267, 10254, 5799, 4946, 4803, 8582, 9484, 3101, 10057, 5024, 7889, 11404, 1585, 10846, 11281, 9364, 4408, 2626, 2138, 2266, 5011, 10141, 9052, 11258, 5521, 6274, 4453, 4965, 10951, 10302, 1253, 10393, 10996, 11942, 9576, 7692, 3392, 11797, 5783, 6021, 3489, 8209, 9988, 10689, 10950, 4983, 4454, 9497, 4020, 6130, 3668, 7242, 7195, 11806, 8439, 6986, 11915, 7634, 935, 5924, 2360, 6776, 2730, 4802, 5007, 5800, 3918, 7246, 1953, 125, 8746, 918, 2030, 6043, 1123, 2355, 9621, 9847, 9754, 3195, 10701, 3752, 3136, 11044, 8088, 945, 9865, 10194, 10096, 11160, 2726, 11145, 321, 8159, 2325, 10675, 8318, 2747, 7798, 2890, 3331, 5079, 1078, 10286, 8072, 10589, 3558, 2733, 10321, 6107, 712, 7880, 3555, 3384, 4641, 2119, 3607, 10065, 8822, 3565, 5396, 10604, 11663, 10805, 7601, 3894, 9567, 2818, 9315, 9184, 6409, 1535, 6387, 7684, 2689, 6041, 2032, 3519, 5231, 8167, 1005, 492, 3493, 11817, 8484, 2379, 5904, 11303, 1444, 3587, 11792, 3183, 6349, 7310, 5508, 340, 10282, 8227, 6290, 5427, 2317, 1158, 9700, 2715, 1776, 7705, 2677, 9137, 11290, 1418, 9582, 5649, 6117, 8135, 786, 5763, 11592, 88, 5871, 7414, 9766, 4785, 745, 2114, 10496, 1104, 905, 5324, 3474, 11242, 330, 4770, 7055, 208, 2947, 7758, 7822, 8535, 10192, 9867, 523, 668, 7392, 10510, 4003, 6009, 8581, 5006, 4947, 2731, 3560, 6382, 975, 1431, 11501, 1156, 2319, 10656, 11295, 2837, 781, 3370, 11874, 5876, 744, 4829, 9767, 3540, 4518, 1084, 6905, 456, 5349, 3469, 7273, 3873, 11247, 2596, 8344, 7054, 4819, 331, 8094, 7070, 10061, 5293, 11954, 5270, 6477, 4167, 3017, 2952, 10593, 2433, 11623, 4243, 4067, 9674, 3060, 7817, 7806, 9925, 7827, 8927, 6876, 5052, 8530, 6199, 5154, 8543, 7237, 8141, 6951, 4391, 5470, 1673, 6528, 5542, 10212, 11786, 1817, 1919, 11143, 2728, 6778, 5887, 6641, 380, 1614, 3388, 5458, 8481, 1870, 2963, 6423, 11826, 7728, 131, 10546, 10816, 7681, 2468, 75, 6568, 11287, 11366, 5663, 7156, 6506, 11989, 548, 4539, 6890, 3037, 528, 2982, 2028, 920, 5890, 106, 5101, 10134, 10682, 4566, 5413, 3732, 7916, 8813, 10552, 2801, 8947, 3973, 3527, 9636, 8392, 10483, 1299, 3793, 11994, 10600, 10983, 8613, 5753, 6614, 3930, 10763, 1513, 8655, 11945, 184, 5420, 6187, 9763, 6654, 8957, 9728, 1191, 9159, 11276, 11343, 4623, 8464, 642, 10086, 1930, 8223, 2174, 2560, 2118, 4896, 3385, 5328, 10577, 8403, 10991, 579, 7387, 8431, 569, 8720, 6794, 1213, 8884, 11433, 7379, 3583, 8463, 4650, 11344, 7205, 1504, 7437, 8833, 5879, 7408, 3950, 5448, 5582, 4398, 6439, 2177, 11853, 7984, 2919, 6133, 7397, 8064, 1627, 3922, 5983, 6141, 7182, 2248, 5361, 8146, 10425, 3160, 804, 6620, 5211, 11499, 1433, 10454, 56, 5793, 7576, 10927, 5110, 5528, 11359, 9305, 2643, 4142, 10508, 7394, 3181, 11794, 10906, 7926, 1528, 10716, 9685, 5708, 5412, 4687, 10683, 409, 883, 2192, 4139, 6540, 9058, 8633, 3995, 1388, 11139, 4148, 10099, 3300, 2881, 9670, 6400, 8055, 11761, 7641, 5084, 3052, 3965, 1141, 6697, 6889, 4699, 549, 5559, 7830, 5127, 11596, 8511, 8269, 2496, 5252, 1070, 1248, 10502, 8272, 11181, 10262, 11340, 11834, 5770, 11911, 1083, 4782, 3541, 2624, 4410, 8121, 6483, 656, 5623, 9548, 1938, 10445, 10410, 10295, 9, 2671, 708, 10571, 2913, 1173, 3678, 6112, 8686, 4279, 8305, 271, 3592, 10525, 3615, 2979, 10243, 10960, 8036, 10756, 10520, 7961, 10112, 1754, 2926, 4423, 9311, 3156, 2510, 6754, 3091, 9359, 11311, 5304, 353, 5344, 9934, 11001, 1655, 8827, 6811, 9493, 11121, 10515, 5309, 5391, 6804, 7711, 5055, 3913, 9496, 4964, 4984, 6275, 5105, 11086, 11156, 9962, 5477, 6070, 3447, 3145, 10852, 2427, 680, 5142, 2158, 6219, 7428, 1087, 5118, 2323, 8161, 966, 1034, 5357, 3058, 9676, 2826, 6016, 10869, 9310, 4480, 2927, 10031, 3211, 9432, 1483, 9235, 439, 11329, 8931, 1207, 7127, 8120, 4515, 2625, 4994, 9365, 2485, 31, 7751, 986, 3961, 5163, 558, 6438, 4612, 5583, 400, 8740, 9472, 2197, 5469, 4737, 6952, 6918, 11730, 5174, 5975, 8075, 1067, 8287, 818, 6448, 97, 7060, 11079, 11098, 594, 5320, 1833, 251, 7467, 6930, 801, 3001, 6866, 3338, 8699, 11712, 6831, 11431, 8886, 1574, 1139, 3967, 5134, 2910, 1038, 11932, 3955, 8311, 8796, 9226, 8731, 1280, 4234, 8328, 3860, 10118, 8555, 214, 6232, 1858, 10830, 480, 3280, 10735, 6224, 6461, 1861, 1196, 7303, 9546, 5625, 7136, 9325, 11776, 462, 11987, 6508, 982, 2436, 7038, 8622, 243, 11667, 9115, 2843, 2220, 1360, 2572, 483, 2066, 2217, 10236, 7168, 9337, 2459, 10279, 6167, 5208, 7555, 6959, 3485, 6571, 5365, 5534, 7848, 3545, 3834, 6916, 6954, 9607, 10679, 5746, 326, 5418, 186, 7299, 11883, 5726, 11218, 6318, 8304, 4496, 8687, 1133, 10020, 8502, 8816, 1314, 9481, 8780, 2370, 5075, 9625, 6823, 384, 10105, 10885, 11981, 7609, 11028, 393, 11524, 2419, 11298, 9065, 7198, 4192, 6337, 5618, 8030, 10070, 7768, 7948, 1554, 1942, 7764, 4066, 4755, 11624, 9437, 8014, 7809, 8117, 2448, 6768, 8327, 4348, 1281, 9247, 1310, 8263, 5248, 2206, 2414, 9570, 6379, 1224, 1523, 8125, 4017, 9911, 5773, 1371, 5092, 9265, 7101, 9124, 443, 10332, 3028, 5948, 1882, 4195, 7263, 2089, 3998, 7774, 3897, 9273, 3121, 2973, 6058, 9382, 8952, 7262, 4208, 1883, 6336, 4254, 7199, 3479, 8602, 3779, 2087, 7265, 3087, 6453, 7477, 6887, 6699, 9112, 1999, 3535, 8109, 8390, 9638, 6172, 2094, 5193, 7896, 3706, 11744, 3016, 4761, 6478, 7717, 8469, 6272, 5523, 3151, 5491, 9340, 11307, 9778, 8705, 507, 3674, 8989, 626, 9960, 11158, 10098, 4554, 11140, 6828, 6734, 8765, 10507, 4578, 2644, 6539, 4561, 2193, 10348, 8994, 9063, 11300, 7114, 8459, 2156, 5144, 6248, 423, 1081, 11913, 6988, 7013, 610, 1400, 9362, 11283, 6024, 6819, 7842, 8308, 255, 9705, 851, 9289, 9414, 39, 11705, 5929, 11699, 6046, 9937, 3830, 6434, 1852, 3783, 11886, 3269, 8280, 7329, 3201, 10771, 11519, 8522, 3806, 10899, 3426, 903, 1106, 7441, 10486, 1845, 9741, 10632, 5437, 8865, 9833, 6195, 9446, 3322, 6680, 741, 8836, 10723, 11239, 9477, 1533, 6411, 9673, 4754, 4244, 7765, 10460, 8443, 5378, 9027, 2244, 8475, 5481, 460, 11778, 8353, 1056, 1492, 7529, 1902, 5035, 3523, 2126, 663, 2810, 1887, 10078, 9192, 2682, 8596, 3287, 6298, 8769, 9164, 8562, 11616, 5597, 3251, 2784, 153, 159, 7405, 9095, 10040, 1690, 5908, 9734, 1748, 11319, 6129, 4962, 9498, 9910, 4221, 8126, 11237, 10725, 11051, 10374, 633, 6757, 9240, 3604, 6864, 3003, 12009, 6008, 4806, 10511, 3277, 2575, 7773, 4205, 2090, 1387, 4557, 8634, 5835, 11696, 6446, 820, 6901, 6487, 5440, 6650, 3869, 6394, 7762, 1944, 8967, 9902, 469, 1052, 7526, 1258, 3105, 3526, 4679, 8948, 1547, 6353, 10665, 5133, 4359, 1140, 4543, 3053, 9802, 5162, 4402, 987, 5612, 7465, 253, 8310, 4354, 11933, 156, 11936, 5447, 4615, 7409, 10387, 1459, 9214, 9999, 199, 11168, 1726, 7107, 1425, 6037, 7628, 10947, 2858, 6495, 10369, 2906, 1709, 10762, 4666, 6615, 1411, 1032, 968, 7087, 11069, 5982, 4602, 1628, 11681, 7245, 4944, 5801, 10251, 11119, 9495, 4456, 5056, 3506, 8248, 9501, 5261, 6068, 5479, 8477, 7836, 3624, 118, 3361, 5777, 5495, 9272, 4203, 7775, 9566, 4885, 7602, 7499, 5531, 3318, 10489, 7791, 7997, 777, 3882, 8130, 8129, 3885, 778, 3630, 5895, 7176, 11228, 8807, 2255, 11246, 4775, 7274, 5063, 6393, 3985, 6651, 7417, 1589, 259, 11642, 11362, 2667, 10117, 4346, 8329, 1284, 5044, 8915, 11691, 7096, 9689, 7580, 11048, 9294, 6328, 691, 6781, 7142, 11009, 11090, 5375, 764, 9419, 8292, 11577, 5454, 2365, 11561, 6915, 4294, 3546, 6563, 6433, 4104, 9938, 1746, 9736, 6253, 10363, 6627, 10293, 10412, 9091, 8348, 10826, 1867, 11820, 10378, 9880, 64, 565, 10121, 1076, 5081, 11214, 2790, 10898, 4092, 8523, 7044, 2026, 2984, 9771, 6163, 11136, 9048, 5592, 6160, 5405, 11993, 4673, 1300, 10082, 7368, 9840, 11587, 1730, 7160, 5724, 11885, 4101, 1853, 11475, 2086, 4188, 8603, 1232, 2995, 5039, 6371, 2023, 1326, 1406, 5307, 10517, 5702, 3168, 8506, 8103, 2513, 2105, 6056, 2975, 11472, 3456, 11801, 9668, 2883, 6672, 3435, 3135, 4929, 10702, 7783, 6766, 2450, 203, 357, 3501, 7481, 9518, 1510, 7487, 833, 8365, 10916, 10247, 9732, 5910, 8743, 7915, 4685, 5414, 3718, 9238, 6759, 10945, 7630, 11196, 2640, 598, 2593, 8173, 437, 9237, 3730, 5415, 958, 2171, 428, 3117, 1027, 10785, 5694, 7733, 7518, 11743, 4170, 7897, 11759, 8057, 7660, 3218, 1118, 9209, 6359, 9006, 1337, 7099, 9267, 6257, 10437, 10876, 9251, 2043, 2871, 5244, 7778, 7666, 8154, 10730, 2768, 1473, 9632, 6111, 4499, 1174, 135, 8988, 4154, 508, 2059, 37, 9416, 7241, 4960, 6131, 2921, 8193, 1188, 2661, 1812, 234, 7958, 10958, 10245, 10918, 11013, 688, 1451, 11864, 8663, 2933, 8569, 11179, 8274, 1098, 8786, 10743, 10469, 1739, 8380, 3601, 10969, 1074, 10123, 9551, 1706, 6965, 10273, 8371, 8413, 5894, 3880, 779, 2839, 5980, 11071, 117, 3903, 7837, 2376, 7337, 1531, 9479, 1316, 10215, 2978, 4491, 10526, 277, 10452, 1435, 7376, 1023, 10064, 4894, 2120, 6863, 4008, 9241, 10968, 3641, 8381, 6120, 9915, 11354, 5066, 10204, 3033, 10524, 4493, 272, 841, 10442, 11791, 4861, 1445, 6660, 8462, 4625, 7380, 11445, 3461, 998, 11327, 441, 9126, 206, 7057, 5028, 10004, 1552, 7950, 6636, 11251, 11207, 5395, 4891, 8823, 699, 1222, 6381, 4800, 2732, 4904, 10590, 3383, 4898, 7881, 9858, 5352, 8429, 7389, 7364, 11372, 6562, 3833, 4295, 7849, 5742, 2623, 4517, 4783, 9768, 7954, 6533, 8108, 4178, 2000, 6554, 7294, 10144, 195, 7147, 9635, 4678, 3974, 3106, 2125, 4049, 5036, 448, 5230, 4873, 2033, 9508, 2123, 3108, 972, 5921, 1992, 7738, 3198, 1463, 8844, 8247, 3911, 5057, 2408, 416, 7480, 3745, 358, 6343, 10803, 11665, 245, 2012, 11816, 4868, 493, 7920, 8208, 4970, 6022, 11285, 6570, 4300, 6960, 7269, 5815, 2524, 8601, 4190, 7200, 1822, 9475, 11241, 4822, 5325, 1617, 6858, 7272, 4777, 5350, 9860, 1599, 2924, 1756, 11842, 997, 3580, 11446, 1894, 7669, 11800, 3759, 11473, 1855, 9559, 2848, 7977, 398, 5585, 3144, 4445, 6071, 9079, 8363, 835, 5914, 2693, 3298, 10101, 5844, 6807, 3134, 3754, 6673, 6003, 7209, 7008, 2530, 3235, 2549, 902, 4090, 10900, 10240, 531, 2083, 9522, 3240, 5381, 9330, 7972, 8727, 1454, 10270, 9488, 8533, 7824, 8235, 10782, 3403, 6874, 8929, 11331, 6873, 3408, 10783, 1029, 7344, 6261, 2423, 5430, 889, 6325, 10904, 11796, 4974, 7693, 11771, 5457, 4721, 1615, 5327, 4640, 4897, 3556, 10591, 2954, 7455, 8019, 6179, 5021, 11891, 10912, 1696, 11581, 2488, 11873, 4789, 782, 5516, 1646, 2753, 2611, 6019, 5785, 5776, 3901, 119, 10499, 7350, 69, 2439, 3070, 9200, 2993, 1234, 148, 8361, 9081, 5409, 3264, 11082, 2368, 8782, 2736, 2895, 1479, 6645, 8698, 4367, 6867, 5767, 3074, 592, 11100, 5078, 4910, 2891, 9944, 5900, 7516, 7735, 10881, 948, 6679, 4077, 9447, 1843, 10488, 3890, 5532, 5367, 8674, 7647, 302, 1394, 10419, 1609, 2234, 7857, 11507, 10035, 11703, 41, 5861, 5488, 2880, 4552, 10100, 3440, 2694, 10029, 2929, 11443, 7382, 5220, 1684, 1564, 2759, 6297, 4040, 8597, 10560, 151, 2786, 7663, 10734, 4338, 481, 2574, 4001, 10512, 5691, 11612, 7618, 2542, 6102, 8279, 4099, 11887, 7073, 11096, 11081, 3347, 5410, 5710, 5347, 458, 5483, 6473, 11846, 2477, 1961, 11964, 2302, 2783, 4033, 5598, 5278, 7869, 1507, 11479, 5714, 7975, 2850, 9025, 5380, 3420, 9523, 142, 6515, 2548, 3429, 2531, 7742, 9644, 8669, 9278, 1694, 10914, 8367, 1271, 191, 1637, 11382, 5807, 5115, 9221, 1117, 3701, 7661, 2788, 11216, 5728, 1149, 9431, 4420, 10032, 791, 5514, 784, 8137, 9759, 11997, 860, 10770, 4096, 7330, 1462, 3510, 7739, 10700, 4931, 9755, 11060, 1947, 7121, 8449, 11315, 11409, 10357, 7547, 5203, 6348, 4859, 11793, 4575, 7395, 6135, 11271, 7939, 1291, 9715, 10407, 10433, 6997, 5423, 10549, 8505, 3767, 5703, 1352, 1379, 6578, 6789, 2999, 803, 4594, 10426, 1169, 2509, 4478, 9312, 9334, 2878, 5490, 4161, 5524, 6575, 7932, 2181, 10851, 4444, 3448, 5586, 11469, 10218, 2293, 112, 8903, 11043, 4928, 3753, 3436, 6808, 5667, 6797, 10799, 7385, 581, 7651, 10440, 843, 10289, 5868, 2972, 4201, 9274, 5290, 1026, 3713, 429, 11985, 464, 908, 9460, 11900, 8875, 971, 3515, 2124, 3525, 3975, 1259, 1786, 10056, 5003, 9485, 6968, 8157, 323, 2605, 9182, 9317, 1986, 9358, 4475, 6755, 635, 6452, 4185, 7266, 5138, 8607, 683, 7599, 10807, 11185, 1238, 6512, 11930, 1040, 591, 3335, 5768, 11836, 9199, 3355, 2440, 6357, 9211, 7333, 8041, 10467, 10745, 2630, 7816, 4752, 9675, 4429, 5358, 7357, 2286, 9801, 3964, 4544, 5085, 5130, 10353, 951, 10068, 8032, 2112, 747, 613, 629, 6208, 1989, 938, 527, 4697, 6891, 10955, 10523, 3594, 10205, 11461, 6750, 5947, 4211, 10333, 11877, 8338, 7860, 11388, 9873, 9749, 1664, 7877, 2951, 4760, 4168, 11745, 11426, 1624, 10556, 9941, 6727, 9724, 5653, 8316, 10677, 9609, 12008, 4006, 6865, 4369, 802, 3162, 6790, 446, 5038, 3776, 1233, 3353, 9201, 10128, 5679, 9162, 8771, 6634, 7952, 9770, 3802, 2027, 4695, 529, 10242, 4490, 3616, 10216, 11471, 3761, 6057, 4200, 3122, 5869, 90, 1470, 337, 10623, 876, 8215, 6422, 4717, 1871, 7025, 756, 9328, 5383, 1671, 5472, 7454, 3381, 10592, 4759, 3018, 7878, 714, 7757, 4816, 209, 1841, 9449, 1385, 2092, 6174, 9233, 1485, 11738, 46, 9663, 5941, 8568, 3651, 8664, 6605, 11442, 3295, 10030, 4422, 4481, 1755, 3465, 1600, 8192, 3666, 6132, 4607, 7985, 1974, 2807, 11200, 1172, 4501, 10572, 1037, 4357, 5135, 6963, 1708, 3933, 10370, 6443, 5932, 5313, 7833, 10015, 345, 7696, 9171, 1478, 3342, 2737, 6725, 9943, 3330, 4911, 7799, 11571, 8437, 11808, 11658, 6671, 3756, 9669, 4551, 3301, 5489, 3153, 9335, 7170, 724, 649, 9348, 5243, 3688, 2044, 1806, 554, 5227, 110, 2295, 10422, 11756, 2310, 2399, 753, 6494, 3936, 10948, 10691, 10821, 7360, 738, 6333, 9024, 3243, 7976, 3452, 9560, 6549, 10234, 2219, 4316, 9116, 10536, 5979, 3628, 780, 4791, 11296, 2421, 6263, 5646, 9407, 8918, 2697, 7132, 5605, 6015, 4427, 9677, 6800, 516, 1934, 7970, 9332, 9314, 4883, 9568, 2416, 176, 8942, 8659, 9021, 1886, 4046, 664, 11199, 2916, 1975, 10894, 8314, 5655, 8946, 4681, 10553, 8067, 2015, 306, 6086, 375, 10924, 6897, 8793, 10897, 3808, 11215, 3216, 7662, 3283, 152, 4032, 3252, 2303, 5838, 9073, 10529, 7596, 11575, 8294, 8284, 5255, 8004, 8410, 1046, 335, 1472, 3682, 10731, 7781, 10704, 10221, 1136, 8323, 9971, 6296, 3289, 1565, 1583, 11406, 677, 2610, 3366, 1647, 5858, 11728, 6920, 7797, 4913, 8319, 5757, 11723, 2546, 6517, 8115, 7811, 8893, 6724, 2894, 3343, 8783, 10320, 4903, 3559, 4801, 4948, 6777, 4727, 11144, 4920, 11161, 7901, 2600, 5042, 1286, 964, 8163, 5686, 1111, 1775, 4847, 9701, 9616, 6341, 360, 369, 653, 7433, 9371, 11417, 6695, 1143, 7589, 7534, 8858, 2680, 9194, 7131, 2830, 8919, 10028, 3297, 3441, 5915, 6837, 6040, 4876, 7685, 238, 11256, 9054, 6631, 8595, 4042, 9193, 2700, 8859, 9136, 4844, 7706, 9555, 6521, 7854, 707, 4504, 10, 1203, 10116, 3862, 11363, 9140, 6771, 6945, 1811, 3663, 1189, 9730, 10249, 5803, 10026, 8921, 7539, 703, 10612, 7892, 731, 7018, 7606, 9529, 2049, 6538, 4141, 4579, 9306, 597, 3724, 11197, 666, 525, 940, 11898, 9462, 11113, 5954, 7815, 3062, 10746, 5547, 2137, 4993, 4409, 4516, 3542, 5743, 10137, 10494, 2116, 2562, 10630, 9743, 897, 5733, 10867, 6018, 3365, 2754, 678, 2429, 6366, 9181, 3096, 324, 5748, 6369, 5041, 2723, 7902, 11975, 8343, 4773, 11248, 8172, 3722, 599, 1165, 734, 182, 11947, 11450, 2143, 10836, 94, 10863, 8801, 7594, 10531, 9976, 5072, 388, 7772, 4000, 3278, 482, 4313, 1361, 5200, 2522, 5817, 7935, 8692, 10171, 9069, 10629, 2618, 2117, 4643, 2175, 6441, 10372, 11053, 9844, 11104, 8901, 114, 9379, 901, 3428, 3236, 6516, 2743, 11724, 11176, 6101, 3272, 7619, 9817, 10190, 8537, 773, 7942, 10481, 8394, 10698, 7741, 3234, 3430, 7009, 8913, 5046, 1742, 8600, 3481, 5816, 2569, 5201, 7549, 893, 8099, 7558, 7050, 7994, 2104, 3764, 8104, 6753, 4477, 3157, 1170, 11202, 9979, 8496, 9891, 5152, 6201, 10047, 10796, 9680, 6716, 5251, 4531, 8270, 10504, 536, 9929, 8592, 8774, 11872, 3372, 11582, 30, 4406, 9366, 9965, 6982, 248, 2472, 11600, 1960, 3256, 11847, 1540, 9603, 11599, 2480, 249, 1835, 74, 4709, 7682, 6389, 7503, 10076, 1889, 8376, 10308, 10278, 4306, 9338, 5493, 5779, 10157, 8560, 9166, 5465, 202, 3748, 6767, 4237, 8118, 7129, 9196, 9598, 7787, 5635, 6356, 3069, 3356, 70, 7037, 4322, 983, 11622, 4757, 10594, 7173, 6365, 2608, 679, 4442, 10853, 2315, 5429, 3398, 6262, 2835, 11297, 4258, 11525, 175, 2816, 9569, 4227, 2207, 10647, 10472, 9539, 415, 3504, 5058, 7722, 1335, 9008, 6, 10011, 5461, 752, 2861, 2311, 9300, 5673, 6739, 11751, 9657, 7079, 2167, 911, 6937, 7745, 5191, 2096, 661, 2128, 10585, 10539, 8333, 5903, 4865, 8485, 7336, 3622, 7838, 5842, 10103, 386, 5074, 4270, 8781, 3345, 11083, 11560, 3837, 5455, 11773, 759, 6775, 4950, 5925, 11640, 261, 9620, 4935, 1124, 10720, 2300, 11966, 9077, 6073, 5963, 1839, 211, 8256, 9131, 7463, 5614, 5601, 7945, 7260, 8954, 7585, 9188, 5214, 1216, 9514, 5298, 367, 362, 1296, 7444, 6306, 10674, 4916, 8160, 4434, 5119, 9791, 10655, 4794, 1157, 4850, 5428, 2425, 10854, 7165, 9299, 2398, 2862, 11757, 7899, 11163, 866, 11694, 5837, 2782, 3253, 11965, 2352, 10721, 8838, 1607, 10421, 2865, 111, 3140, 10219, 10706, 5285, 9004, 6361, 9800, 3055, 7358, 10823, 9354, 1765, 8277, 6104, 7989, 10266, 8186, 5761, 788, 11510, 10167, 7929, 1382, 9397, 11117, 10253, 5010, 4991, 2139, 8992, 10350, 10668, 11539, 2165, 7081, 8819, 954, 11245, 3875, 8808, 17, 1415, 5825, 7355, 5360, 4598, 7183, 7229, 8474, 4060, 9028, 8212, 5851, 6610, 5019, 6181, 10610, 705, 7856, 3309, 1610, 10230, 10617, 1596, 10109, 6980, 9967, 10209, 10300, 10953, 6893, 9692, 1359, 4315, 2844, 10235, 4310, 2067, 6115, 5651, 9726, 8959, 8050, 6852, 6458, 10646, 2413, 4228, 5249, 6718, 61, 1971, 10325, 864, 11165, 5468, 4393, 9473, 1824, 10347, 4138, 4562, 884, 2108, 10184, 10639, 501, 1848, 6001, 6675, 11412, 10850, 3147, 7933, 5819, 11852, 4610, 6440, 2559, 4644, 8224, 427, 3715, 959, 9458, 910, 2391, 7080, 2260, 11540, 11962, 1963, 2064, 485, 6218, 4439, 5143, 4131, 8460, 6662, 8546, 10415, 1906, 1130, 11067, 7089, 1820, 7202, 11491, 10835, 2586, 11451, 624, 8991, 2265, 4992, 2627, 5548, 10149, 1634, 8198, 11950, 10044, 11036, 10584, 2384, 662, 4048, 3524, 3107, 3516, 9509, 6862, 3606, 4895, 4642, 2561, 2619, 10495, 4827, 746, 3045, 8033, 11545, 10183, 2190, 885, 6055, 3763, 2514, 7995, 7793, 6241, 104, 5892, 8415, 660, 2386, 5192, 4173, 6173, 2942, 1386, 3997, 4206, 7264, 4187, 3780, 11476, 9521, 3422, 532, 6301, 6668, 7544, 1013, 5966, 7908, 8184, 10268, 1456, 9002, 5287, 9121, 8684, 6114, 2216, 4311, 484, 2161, 1964, 1219, 6712, 36, 3672, 509, 1701, 6816, 11398, 11386, 7862, 856, 7565, 6537, 2646, 9530, 5032, 9786, 1805, 2870, 3689, 9252, 5718, 378, 6643, 1481, 9434, 6942, 810, 9507, 3518, 4874, 6042, 4938, 919, 4694, 2983, 3803, 7045, 1325, 3773, 6372, 5180, 584, 6316, 11220, 6501, 305, 2798, 8068, 11815, 3495, 246, 6984, 8441, 10462, 10090, 1265, 6468, 1716, 12006, 9611, 6553, 3534, 4179, 9113, 11669, 880, 1790, 10879, 7737, 3512, 5922, 937, 3040, 6209, 9357, 3093, 9318, 8717, 9085, 7592, 8803, 11223, 505, 8707, 311, 10893, 2806, 2917, 7986, 10324, 2202, 62, 9882, 978, 5811, 9512, 1218, 2063, 2162, 11963, 3255, 2478, 11601, 10226, 8911, 7011, 6990, 124, 4942, 7247, 6721, 10989, 8405, 7120, 3192, 11061, 8966, 3982, 7763, 4246, 1555, 11789, 10444, 4509, 9549, 10125, 7969, 2822, 517, 10712, 8222, 4646, 10087, 11370, 7366, 10084, 644, 1550, 10006, 10749, 6826, 11142, 4729, 1818, 7091, 854, 7864, 7460, 8714, 8574, 6170, 9640, 11628, 7748, 1129, 2151, 10416, 9784, 5034, 4051, 7530, 10260, 11183, 10809, 9345, 8152, 7668, 3459, 11447, 8201, 10938, 8375, 2463, 10077, 4045, 2811, 9022, 6335, 4194, 4209, 5949, 6911, 7324, 1332, 6269, 9392, 1520, 405, 7001, 7024, 2962, 4718, 8482, 11819, 3818, 10827, 6464, 9878, 10380, 1195, 4334, 6462, 10829, 4341, 6233, 9558, 3454, 11474, 3782, 4102, 6435, 6406, 6000, 2186, 502, 9740, 4085, 10487, 3320, 9448, 2945, 210, 2347, 5964, 1015, 73, 2470, 250, 4374, 5321, 467, 9904, 9824, 1375, 11716, 5865, 10346, 2195, 9474, 3477, 7201, 2147, 7090, 1918, 4730, 11787, 1557, 11959, 233, 3662, 2662, 6946, 8418, 8981, 553, 2869, 2045, 9787, 1714, 6470, 7281, 228, 10696, 8396, 9036, 543, 8872, 9721, 1308, 9249, 10878, 1995, 881, 411, 10055, 3103, 1260, 10402, 9781, 1397, 750, 5463, 9168, 9795, 7704, 4846, 2716, 1112, 8589, 11483, 9033, 7524, 1054, 8355, 1096, 8276, 2282, 9355, 6211, 8097, 895, 9745, 7004, 6215, 11841, 3464, 2925, 4482, 10113, 831, 7489, 674, 11318, 4023, 9735, 3828, 9939, 10558, 8599, 2526, 5047, 8379, 3643, 10470, 10649, 1704, 9553, 7708, 5847, 11672, 7159, 3787, 11588, 10934, 7106, 3942, 11169, 8889, 6146, 1669, 5385, 8190, 1602, 7507, 12005, 2004, 6469, 1803, 9788, 1061, 7032, 10761, 3932, 2907, 6964, 3636, 9552, 1736, 10650, 6815, 2057, 510, 10859, 638, 11580, 3374, 10913, 3229, 9279, 7111, 5907, 4026, 10041, 9812, 11150, 11734, 1563, 3291, 5221, 11569, 7801, 8986, 137, 6139, 5985, 295, 6150, 6527, 4735, 5471, 2957, 5384, 1722, 6147, 10188, 9819, 7876, 3020, 9750, 1346, 6882, 8964, 11063, 5336, 603, 8826, 4467, 11002, 11394, 11721, 5759, 8188, 5387, 5857, 2752, 3367, 5517, 8079, 9108, 5571, 9456, 961, 8001, 11381, 3224, 192, 8197, 2134, 10150, 10819, 10693, 10965, 11680, 3921, 4603, 8065, 10555, 3013, 11427, 5699, 10759, 7034, 1018, 6857, 3472, 5326, 3387, 4722, 381, 10752, 10229, 2233, 3310, 10420, 2297, 8839, 1581, 1567, 7506, 1719, 8191, 2923, 3466, 9861, 10108, 2230, 10618, 8702, 10405, 9717, 9149, 258, 3866, 7418, 8854, 10845, 4998, 11405, 2757, 1566, 1605, 8840, 5017, 6612, 5755, 8321, 1138, 4361, 8887, 11171, 8424, 223, 10074, 7505, 1604, 1582, 2758, 3290, 1685, 11735, 8401, 10579, 7425, 11958, 1815, 11788, 1941, 4247, 7949, 3571, 10005, 1924, 645, 6352, 3971, 8949, 1269, 8369, 10275, 1365, 9602, 2475, 11848, 1181, 11535, 6386, 4879, 6410, 4070, 9478, 3620, 7338, 10715, 4571, 7927, 10169, 8694, 8124, 4223, 1225, 404, 1875, 9393, 9898, 7187, 10910, 11893, 8654, 4664, 10764, 7486, 3742, 9519, 11478, 3247, 7870, 7436, 4620, 7206, 8011, 8737, 6323, 891, 7551, 6705, 8244, 6312, 1256, 7528, 4053, 1057, 8979, 8420, 7521, 8399, 11737, 2939, 9234, 4418, 9433, 2038, 6644, 3341, 2896, 9172, 6035, 1427, 9631, 3681, 2769, 336, 2969, 91, 11881, 7301, 1198, 6589, 8843, 3509, 3199, 7331, 9213, 3947, 10388, 9001, 2073, 10269, 3415, 8728, 11863, 3654, 689, 6330, 6683, 1438, 6659, 3586, 4862, 11304, 7511, 9101, 10977, 6658, 1447, 6684, 7375, 3611, 10453, 4589, 11500, 4797, 976, 9884, 9630, 1475, 6036, 3940, 7108, 8456, 8631, 9060, 7255, 9581, 4841, 11291, 5824, 2252, 18, 7342, 1031, 3928, 6616, 7124, 351, 5306, 3771, 1327, 5831, 9776, 11309, 9361, 4122, 611, 749, 1782, 9782, 10418, 3312, 303, 6503, 11675, 9046, 11138, 4556, 3996, 2091, 2943, 9450, 9396, 2271, 7930, 6577, 3165, 1353, 6731, 11715, 1828, 9825, 11513, 5091, 4218, 5774, 5787, 5554, 9805, 9601, 1542, 10276, 10310, 5199, 2571, 4314, 2221, 9693, 7220, 719, 1305, 6730, 1378, 3166, 5704, 6376, 5659, 8044, 6881, 1662, 9751, 475, 6096, 5178, 6374, 5706, 9687, 7098, 3696, 9007, 2405, 7723, 6268, 1878, 7325, 7448, 11605, 5830, 1405, 3772, 2024, 7046, 1064, 9157, 1193, 10382, 1049, 11784, 10214, 3618, 9480, 4273, 8817, 7083, 8262, 4231, 9248, 1793, 9722, 6729, 1355, 720, 6191, 11495, 10081, 3792, 4674, 10484, 7443, 2329, 363, 10888, 9660, 9714, 3176, 7940, 775, 7999, 963, 2721, 5043, 3858, 8330, 9246, 4233, 4349, 8732, 7676, 5790, 6746, 6855, 1020, 11436, 190, 3226, 8368, 1545, 8950, 9384, 6467, 2006, 10091, 5188, 11631, 10401, 1785, 3104, 3976, 7527, 1494, 6313, 10392, 4980, 10303, 8082, 7348, 10501, 4528, 1071, 5172, 11732, 11152, 8811, 7918, 495, 11188, 6511, 3079, 11186, 497, 147, 3352, 2994, 3777, 8604, 8611, 10985, 8302, 6320, 403, 1522, 4224, 6380, 3562, 700, 6711, 2062, 1965, 9513, 2334, 5215, 8883, 4629, 6795, 5669, 8515, 349, 7126, 4413, 8932, 829, 10115, 2669, 11, 10921, 5721, 6588, 1466, 7302, 4333, 1862, 10381, 1321, 9158, 4654, 9729, 2660, 3664, 8194, 10147, 5550, 10154, 7673, 11534, 1538, 11849, 521, 9869, 9428, 11920, 134, 3677, 4500, 2914, 11201, 2508, 3158, 10427, 7016, 733, 2591, 600, 9831, 8867, 7570, 9587, 9699, 4849, 2318, 4795, 11502, 10314, 11376, 5563, 11918, 9430, 3213, 5729, 6279, 9400, 5996, 7588, 2704, 6696, 4542, 3966, 4360, 1575, 8322, 2763, 10222, 10019, 4277, 8688, 11066, 2150, 1907, 7749, 33, 11649, 10719, 2354, 4936, 6044, 11701, 10037, 9208, 3700, 3219, 9222, 8206, 7922, 8588, 1774, 2717, 5687, 8619, 218, 7440, 4088, 904, 4825, 10497, 121, 8638, 10318, 8785, 3647, 8275, 1767, 8356, 1001, 12001, 10812, 6293, 11637, 9219, 5117, 4436, 7429, 6904, 4781, 4519, 11912, 4127, 424, 10285, 4908, 5080, 3811, 10122, 3639, 10970, 5171, 1247, 4529, 5253, 8286, 4384, 8076, 9156, 1323, 7047, 7031, 1712, 9789, 5121, 8978, 1491, 4054, 8354, 1769, 7525, 3978, 470, 11783, 1319, 10383, 334, 2771, 8411, 8373, 10940, 6843, 590, 3076, 11931, 4356, 2911, 10573, 5356, 4431, 967, 3927, 1412, 7343, 3401, 10784, 3712, 3118, 5291, 10063, 3609, 7377, 11435, 1274, 6856, 1619, 7035, 72, 1837, 5965, 2078, 7545, 10359, 620, 990, 5595, 11618, 491, 4870, 8168, 924, 12000, 1094, 8357, 11326, 3579, 3462, 11843, 6079, 6702, 6624, 6158, 5594, 1009, 621, 5611, 3960, 4403, 7752, 11621, 2435, 4323, 6509, 11190, 5810, 1968, 9883, 1430, 4798, 6383, 5920, 3514, 3109, 8876, 7086, 3926, 1033, 4432, 8162, 2720, 1287, 8000, 1640, 9457, 2170, 3716, 5416, 328, 11244, 2257, 8820, 10067, 3048, 10354, 6678, 3324, 10882, 9864, 4925, 8089, 6032, 8387, 11897, 2636, 526, 3039, 1990, 5923, 4952, 7635, 916, 8748, 8667, 9646, 454, 6907, 7563, 858, 11999, 1003, 8169, 6639, 5889, 4693, 2029, 4939, 8747, 933, 7636, 11420, 8680, 6936, 2390, 2168, 9459, 3113, 465, 5323, 4824, 1105, 4089, 3427, 2550, 9380, 6060, 5732, 2615, 9744, 1761, 8098, 2519, 7550, 1499, 6324, 3396, 5431, 5166, 6054, 2107, 2191, 4563, 410, 1789, 1996, 11670, 5849, 8214, 2966, 10624, 7458, 7866, 5186, 10093, 7285, 9286, 7094, 11693, 2306, 11164, 2200, 10326, 280, 10769, 3203, 11998, 926, 7564, 2052, 7863, 1916, 7092, 9288, 4113, 9706, 11148, 9814, 6546, 11813, 8070, 10288, 3125, 10441, 3590, 273, 11969, 288, 9469, 5913, 3443, 8364, 3740, 7488, 1752, 10114, 1205, 8933, 10776, 11517, 10773, 5503, 11033, 6204, 6900, 3990, 6447, 4382, 8288, 9374, 11348, 9205, 9098, 10842, 9506, 2035, 6943, 6773, 761, 8446, 6619, 4593, 3161, 3000, 4370, 6931, 8204, 9224, 8798, 6286, 7731, 5696, 9995, 5513, 3209, 10033, 11509, 2275, 5762, 4836, 8136, 3207, 5515, 3369, 4790, 2838, 3629, 3881, 3886, 7998, 1289, 7941, 2537, 8538, 7192, 11684, 11058, 9757, 8139, 7239, 9418, 3842, 5376, 8445, 807, 6774, 2362, 11774, 9327, 2960, 7026, 6493, 2860, 2400, 5462, 1781, 1398, 612, 3044, 2113, 4828, 4786, 5877, 8835, 4075, 6681, 6332, 2853, 7361, 671, 181, 2590, 1166, 7017, 2650, 7893, 5990, 8526, 5444, 7307, 648, 2875, 7171, 10596, 6190, 1304, 1356, 7221, 9177, 9593, 7756, 2949, 7879, 4900, 6108, 7150, 10570, 4503, 2672, 7855, 2236, 10611, 2653, 7540, 6710, 1221, 3563, 8824, 605, 11338, 10264, 7991, 5885, 6780, 3848, 6329, 1450, 3655, 11014, 8435, 11573, 7598, 3083, 8608, 5141, 4441, 2428, 2609, 2755, 11407, 11317, 1750, 7490, 180, 736, 7362, 7391, 4809, 524, 2638, 11198, 2809, 4047, 2127, 2385, 2097, 8416, 6948, 5622, 4512, 6484, 7432, 2709, 370, 8150, 9347, 2874, 725, 7308, 6351, 1549, 1925, 10085, 4648, 8465, 5452, 11579, 1698, 10860, 6451, 3089, 6756, 4011, 10375, 8790, 6207, 3042, 614, 9959, 4152, 8990, 2141, 11452, 5610, 989, 1010, 10360, 293, 5987, 5196, 9958, 628, 3043, 748, 1399, 4123, 7014, 10429, 9257, 11337, 697, 8825, 1657, 5337, 9830, 1164, 2592, 3723, 2641, 9307, 5319, 4376, 11099, 3334, 3075, 1041, 6844, 267, 8999, 10390, 6315, 2020, 5181, 7650, 3128, 7386, 4635, 10992, 10740, 11824, 6425, 546, 11991, 5407, 9083, 8719, 4632, 8432, 8553, 10120, 3813, 65, 9426, 9871, 11390, 6404, 6437, 4400, 5164, 5433, 5226, 2868, 1807, 8982, 5264, 5558, 4538, 4700, 11990, 574, 6426, 8871, 1796, 9037, 8253, 8558, 10159, 8232, 9928, 2493, 10505, 8767, 6300, 2082, 3423, 10241, 2981, 4696, 3038, 939, 2637, 667, 4810, 9868, 1179, 11850, 5821, 10711, 1933, 2823, 6801, 7423, 10581, 7217, 10858, 1700, 2058, 3673, 4155, 8706, 1979, 11224, 9739, 1847, 2187, 10640, 6923, 146, 1236, 11187, 1241, 7919, 3492, 4869, 1006, 11619, 7754, 9595, 11839, 6217, 2160, 2065, 4312, 2573, 3279, 4339, 10831, 10476, 5628, 6095, 1344, 9752, 9849, 52, 11782, 1051, 3979, 9903, 1831, 5322, 907, 3114, 11986, 4326, 11777, 4057, 5482, 3260, 5348, 4779, 6906, 929, 9647, 8177, 5099, 108, 5229, 3521, 5037, 2997, 6791, 10331, 4213, 9125, 3577, 11328, 4416, 9236, 3720, 8174, 6560, 11374, 10316, 8640, 9526, 11984, 3116, 3714, 2172, 8225, 10284, 1080, 4128, 6249, 7179, 11926, 6926, 6885, 7479, 3503, 2409, 9540, 9534, 10054, 1788, 882, 4564, 10684, 6184, 7000, 1874, 1521, 1226, 6321, 8739, 4396, 5584, 3450, 7978, 6417, 11006, 11523, 4260, 11029, 9579, 7257, 7771, 2577, 5073, 2372, 10104, 4266, 6824, 10751, 1613, 4723, 6642, 2040, 5719, 10923, 2795, 6087, 9655, 11753, 8149, 652, 2710, 361, 2331, 5299, 11979, 10887, 1295, 2330, 368, 2711, 6342, 3500, 3746, 204, 9128, 5343, 4471, 5305, 1408, 7125, 1209, 8516, 11769, 7695, 2899, 10016, 11134, 6165, 10281, 4855, 5509, 10622, 2968, 1471, 2770, 1047, 10384, 8093, 4769, 4820, 11243, 956, 5417, 4288, 5747, 2604, 3097, 8158, 4918, 11146, 9708, 6177, 8021, 5568, 6083, 7906, 5968, 10892, 1977, 8708, 11973, 7904, 6085, 2797, 2016, 6502, 1393, 3313, 7648, 5183, 5281, 10637, 10186, 6149, 1676, 5986, 618, 10361, 6255, 9269, 9468, 838, 11970, 6154, 9263, 5094, 7625, 6840, 10768, 862, 10327, 10451, 3613, 10527, 9075, 11968, 840, 3591, 4494, 8306, 7844, 8998, 588, 6845, 5961, 6075, 5273, 9619, 2357, 11641, 3865, 1590, 9150, 9704, 4115, 8309, 3957, 7466, 4373, 1834, 2471, 2481, 6983, 2011, 3496, 11666, 4319, 8623, 6557, 9650, 11255, 2687, 7686, 11552, 7957, 3661, 1813, 11960, 11542, 10963, 10695, 1800, 7282, 10197, 10457, 10073, 1570, 8425, 7153, 8831, 7439, 1108, 8620, 7040, 6231, 4343, 8556, 8255, 2346, 1840, 2946, 4817, 7056, 3575, 9127, 356, 3747, 2451, 5466, 11167, 3944, 10000, 8519, 7146, 3530, 10145, 8196, 1636, 3225, 1272, 11437, 5589, 7298, 4286, 5419, 4661, 11946, 2589, 735, 672, 7491, 6244, 8941, 2815, 2417, 11526, 5797, 10256, 8550, 11017, 5935, 5539, 8756, 9537, 10474, 10833, 11493, 6193, 9835, 7404, 4030, 154, 11935, 3953, 11934, 158, 4031, 2785, 3284, 10561, 8360, 3351, 1235, 498, 6924, 11928, 6514, 3238, 9524, 8642, 7225, 6138, 1679, 8987, 3676, 1175, 11921, 10545, 4713, 7729, 6288, 8229, 7913, 8745, 4941, 1954, 6991, 8637, 1102, 10498, 3360, 3902, 3625, 11072, 9378, 2552, 8902, 3139, 2294, 2866, 5228, 450, 5100, 4691, 5891, 2100, 6242, 7493, 10931, 7887, 5026, 7059, 4380, 6449, 10862, 2584, 10837, 11880, 1469, 2970, 5870, 4833, 11593, 5088, 11869, 5500, 8936, 10974, 7658, 8059, 11858, 11856, 8061, 6567, 4708, 2469, 1836, 1016, 7036, 2438, 3357, 7351, 11830, 9425, 564, 3814, 9881, 1970, 2203, 6719, 7249, 6744, 5792, 4587, 10455, 10199, 11781, 472, 9850, 10051, 8759, 9712, 9662, 2937, 11739, 11174, 11726, 5860, 3304, 11704, 4110, 9415, 3671, 2060, 6713, 11648, 1127, 7750, 4405, 2486, 11583, 8898, 11550, 7688, 5506, 7312, 11466, 11440, 6607, 8219, 7341, 1414, 2253, 8809, 11154, 11088, 11011, 10920, 1202, 2670, 4505, 10296, 10010, 2403, 9009, 8008, 6006, 12011]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s3/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-l6-s3/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d014c8cc1f4027ecaa4996df061f7fe708346758 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 12011, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l6-s3/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l6-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l6-s4/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c3575eae12645e2bb58660e7639a35ff4af57b1 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 22391, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s4/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..889b536933a04dd3232a40a05e76d7f447a711a6 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 11197, 7465, 5599, 17914, 3733, 12796, 2800, 2489, 20153, 18321, 1867, 8613, 17594, 5972, 12596, 10538, 1245, 2358, 10077, 4266, 9161, 20445, 934, 12540, 4307, 8294, 19993, 14671, 14182, 17336, 17494, 21035, 16465, 2560, 623, 3632, 12375, 17799, 5039, 4370, 13329, 9374, 4581, 9455, 10223, 20010, 11663, 11425, 17466, 10977, 2154, 15210, 15343, 3665, 9997, 15714, 7336, 21633, 18287, 5507, 19864, 16350, 19943, 15158, 10518, 12032, 8233, 21743, 12476, 9462, 312, 3375, 13012, 19108, 6188, 15413, 8900, 20408, 2520, 10229, 13381, 9443, 6665, 15543, 15883, 4891, 2291, 19373, 4728, 4430, 5112, 13243, 21201, 13907, 5832, 21007, 5713, 14476, 19929, 19510, 5489, 3914, 12273, 854, 18801, 8790, 7672, 9245, 1833, 8675, 4999, 18429, 19053, 8568, 14864, 20861, 10817, 4705, 9144, 3702, 2754, 8921, 21128, 6987, 19371, 2293, 9972, 10589, 18775, 20170, 16455, 19530, 17212, 10616, 4117, 19777, 10872, 13049, 17434, 21598, 15927, 4855, 11352, 2935, 1688, 3809, 17702, 16381, 20750, 1039, 14290, 18587, 7707, 3468, 15646, 17543, 21400, 19998, 12456, 9319, 5115, 2611, 6691, 8686, 4722, 10325, 3333, 7553, 7772, 20166, 7942, 907, 2446, 4991, 1146, 22139, 9687, 15387, 13560, 5073, 13411, 9300, 13752, 18640, 6622, 5030, 10601, 20378, 6954, 1525, 14112, 7426, 10504, 12517, 2857, 5684, 18434, 9565, 9965, 11475, 20951, 21289, 2745, 5353, 13153, 14712, 6137, 10393, 11623, 14327, 9401, 18082, 15591, 10832, 15032, 18471, 4623, 16053, 917, 16313, 4338, 4921, 2500, 6370, 9215, 3552, 9527, 881, 15480, 12602, 18628, 7785, 10431, 8481, 5409, 14267, 2353, 4779, 15768, 1023, 13047, 10874, 12573, 6764, 4461, 12239, 21760, 10612, 3494, 9903, 9686, 22215, 1147, 20109, 16182, 698, 5295, 19712, 9388, 1631, 21281, 14304, 8228, 7521, 20961, 13922, 19802, 1749, 16504, 7685, 2059, 8941, 9889, 5212, 16632, 21907, 6525, 4415, 19913, 4782, 21995, 20414, 7964, 12100, 2428, 13420, 16872, 13792, 1468, 7003, 12040, 16202, 1905, 17762, 20047, 4826, 8191, 3296, 21571, 1340, 520, 6504, 18341, 19015, 9294, 19037, 3854, 8769, 12930, 73, 19019, 9730, 8772, 7749, 21896, 2897, 21195, 17619, 17424, 17858, 4660, 4091, 2558, 16467, 1306, 10546, 3346, 18853, 15539, 7848, 13557, 10356, 5163, 20320, 1667, 16080, 3777, 21071, 15082, 5648, 21279, 1633, 15167, 17784, 454, 9422, 12419, 11806, 2496, 14418, 11769, 17825, 11070, 19806, 4844, 1569, 7694, 20708, 17976, 2482, 2537, 16162, 6706, 5154, 15846, 16779, 18072, 10438, 20516, 21366, 14507, 20351, 13711, 17257, 5301, 8019, 21385, 14180, 14673, 765, 763, 14675, 18252, 16518, 14909, 10994, 16448, 5239, 6259, 17009, 1429, 6724, 14038, 17517, 20413, 22110, 4783, 21438, 4983, 20326, 5738, 8224, 10476, 11003, 10645, 18651, 1373, 3231, 2677, 6593, 6577, 6290, 18552, 15324, 3069, 11814, 5197, 10101, 5812, 20956, 7164, 7200, 4701, 16544, 20237, 7185, 7796, 1619, 16612, 20262, 18712, 5017, 9236, 979, 2312, 1077, 8027, 11171, 459, 8734, 8157, 16074, 13365, 17310, 2461, 5461, 12446, 6833, 14381, 14647, 4608, 347, 12972, 5365, 4764, 11221, 441, 13660, 18936, 7578, 17497, 19442, 20510, 16084, 3893, 19707, 5216, 20912, 4241, 13312, 2705, 19173, 7134, 20695, 1177, 21594, 2390, 17437, 19080, 12337, 512, 3107, 6524, 22115, 16633, 14254, 6287, 871, 14578, 15962, 2231, 12718, 6120, 2896, 22076, 7750, 16502, 1751, 12943, 10906, 4952, 5966, 16039, 8381, 11108, 9982, 574, 4488, 10055, 483, 19287, 21650, 11545, 9740, 2648, 1820, 21052, 303, 15890, 13066, 816, 21707, 10641, 9128, 18348, 15509, 15310, 6731, 3761, 14844, 10481, 8949, 18157, 6237, 21097, 20057, 875, 21395, 19448, 16101, 3843, 16619, 1030, 6328, 4471, 3112, 4945, 18028, 13802, 5487, 19512, 6115, 10954, 6214, 3263, 11297, 2208, 722, 9957, 9141, 13587, 20483, 10998, 12643, 21403, 14257, 15178, 14443, 17246, 4589, 12410, 509, 17906, 15149, 19632, 15795, 18092, 2476, 11930, 10946, 3502, 17668, 17216, 4173, 19297, 13962, 953, 17412, 20077, 9359, 10024, 5325, 13609, 5420, 4096, 3189, 12844, 5795, 10786, 5962, 11866, 18753, 11456, 18654, 14448, 13502, 9171, 7097, 9508, 18764, 15843, 9498, 9519, 1785, 13123, 5880, 4385, 19462, 17661, 19832, 37, 18762, 9510, 19311, 16061, 3465, 15582, 16020, 3875, 10611, 22144, 12240, 1449, 13894, 10598, 19826, 8810, 6028, 19908, 3564, 20125, 17482, 13526, 11075, 2046, 17720, 12475, 22323, 8234, 21085, 11849, 1304, 16469, 8513, 12869, 20279, 9427, 1496, 7770, 7555, 15120, 12902, 6779, 8385, 16374, 8427, 2582, 1641, 21356, 20857, 834, 5291, 19236, 2124, 1889, 5822, 10536, 12598, 18737, 16112, 14020, 1968, 10640, 21869, 817, 7758, 7584, 14950, 20088, 15490, 11423, 11665, 15907, 11567, 6210, 258, 17099, 17523, 12444, 5463, 18405, 4906, 5885, 17755, 8913, 2788, 16731, 20055, 21099, 12220, 13618, 14384, 785, 5450, 15043, 16521, 21550, 9001, 20184, 560, 12437, 15269, 1269, 5066, 19277, 7516, 14549, 11089, 13773, 18992, 19119, 17199, 8390, 9719, 20232, 13308, 16415, 3243, 21454, 11544, 21879, 19288, 7254, 3277, 10176, 3538, 6856, 7654, 8629, 10794, 2651, 18229, 4010, 9165, 10693, 13548, 18286, 22333, 7337, 21627, 383, 7719, 382, 21631, 7338, 1665, 20322, 19655, 19455, 7697, 7455, 12920, 16693, 14129, 19420, 14035, 2620, 20265, 3130, 19181, 8505, 8008, 715, 16944, 14558, 5236, 18215, 19696, 8759, 9031, 10207, 15926, 22251, 17435, 2392, 2389, 21915, 1178, 2492, 12105, 21359, 12521, 14065, 10821, 15308, 15511, 16434, 859, 5502, 13916, 5323, 10026, 9326, 523, 687, 14636, 1616, 2981, 1339, 22092, 3297, 14094, 3289, 1738, 14341, 1084, 20472, 13992, 18858, 7303, 1535, 673, 17103, 6544, 2599, 8936, 5051, 14786, 14102, 9000, 21674, 16522, 14778, 14946, 14796, 19722, 2351, 14269, 19468, 6000, 10119, 106, 3593, 4034, 15094, 5958, 810, 16892, 19502, 4474, 21327, 5242, 20552, 18095, 2509, 4598, 15814, 16105, 490, 7816, 12352, 2335, 539, 999, 4014, 14656, 5586, 12865, 230, 6914, 15563, 12401, 4079, 13385, 19233, 4873, 6683, 16322, 19851, 9073, 1231, 5768, 2731, 20991, 17419, 8563, 3417, 9864, 7191, 4847, 7324, 7911, 13500, 14450, 174, 19948, 17682, 17096, 2683, 8456, 13578, 6966, 5611, 6339, 221, 6081, 18026, 4947, 20664, 13810, 14985, 19675, 8749, 8207, 20917, 17851, 21451, 2122, 19238, 12387, 1947, 25, 9854, 5485, 13804, 11543, 21652, 3244, 2121, 21464, 17852, 2138, 1353, 17511, 9587, 5250, 14763, 15762, 10348, 8430, 589, 4982, 21993, 4784, 12391, 20801, 8719, 15621, 20736, 15006, 6169, 13417, 11452, 1486, 1554, 15376, 14458, 8828, 11058, 10424, 8317, 1865, 18323, 20417, 3144, 13156, 436, 20082, 18485, 3516, 19177, 16743, 1116, 10094, 17555, 6285, 14256, 21826, 12644, 19997, 22234, 17544, 15071, 6392, 19447, 21853, 876, 18380, 6472, 16688, 16649, 18396, 13672, 6774, 14179, 22014, 8020, 15779, 4191, 20288, 16750, 3626, 16187, 13215, 11483, 14488, 13440, 3319, 5028, 6624, 242, 9347, 9644, 14506, 22021, 20517, 5773, 545, 16066, 19699, 12520, 21590, 12106, 20856, 21722, 1642, 152, 8104, 19141, 10605, 17729, 2341, 11604, 15514, 10854, 3936, 5321, 13918, 15760, 14765, 20370, 19734, 7755, 20779, 18851, 3348, 3366, 13406, 1881, 6311, 18618, 6257, 5241, 21530, 4475, 18195, 9079, 19690, 3119, 15451, 10549, 20973, 10029, 20080, 438, 14367, 10698, 12784, 20920, 2818, 8051, 828, 1922, 3695, 8310, 3750, 11711, 5388, 14360, 20196, 2236, 16615, 12752, 16646, 2473, 20555, 20210, 2507, 18097, 20521, 2744, 22189, 20952, 16698, 3058, 3480, 16673, 4564, 14303, 22130, 1632, 22050, 5649, 985, 12300, 4391, 11557, 14248, 4979, 2318, 4571, 9412, 6794, 5753, 10242, 14127, 16695, 4503, 6322, 17601, 10702, 12570, 7129, 18624, 18785, 12191, 7222, 15197, 19819, 9970, 2295, 15183, 17401, 177, 255, 2285, 20149, 12356, 7575, 6907, 21012, 10410, 7898, 20434, 20242, 18715, 12434, 13254, 17161, 11129, 16669, 8607, 12947, 6036, 20030, 1747, 19804, 11072, 2087, 10881, 9649, 13134, 18177, 1697, 477, 800, 19902, 2242, 10039, 20060, 4680, 10676, 16208, 20767, 2663, 7603, 6805, 10189, 13906, 22298, 13244, 2516, 1595, 9913, 17618, 22074, 2898, 6948, 16589, 13760, 14177, 6776, 17129, 13640, 9377, 5826, 16924, 2742, 20523, 16124, 18420, 20583, 17947, 11132, 4586, 4987, 3549, 11371, 15950, 21145, 20578, 12414, 7922, 10310, 15945, 16005, 4760, 13319, 893, 16626, 6562, 9662, 14136, 11405, 2193, 8599, 20927, 9561, 8831, 17322, 21112, 11854, 19, 20036, 20577, 21171, 15951, 12550, 9656, 18866, 8031, 2199, 1733, 15416, 18987, 18295, 19206, 3967, 1938, 6784, 5306, 6986, 22268, 8922, 17316, 7123, 725, 17328, 18143, 10254, 16495, 10062, 21109, 12979, 15601, 7979, 14210, 11853, 21150, 17323, 12978, 21118, 10063, 13575, 19937, 8004, 17959, 4170, 5538, 19114, 12219, 21682, 20056, 21856, 6238, 18922, 11162, 1673, 15313, 11033, 10543, 654, 5925, 327, 11848, 21741, 8235, 16713, 4257, 15287, 6435, 11836, 10140, 11818, 4714, 11188, 11944, 6299, 15081, 22053, 3778, 2912, 18756, 1505, 17647, 11863, 3390, 20286, 4193, 2373, 19383, 11860, 4214, 20698, 12487, 19411, 821, 302, 21874, 1821, 10429, 7787, 11613, 9307, 2646, 9742, 20814, 20533, 12258, 20254, 945, 4883, 14107, 6016, 16464, 22359, 17495, 7580, 9369, 16239, 19252, 8412, 18206, 1789, 12180, 17560, 16516, 18254, 10935, 3741, 409, 19163, 15075, 18956, 14988, 4554, 18671, 10409, 21240, 6908, 18941, 17454, 5712, 22295, 5833, 3714, 7954, 13945, 5784, 9289, 14301, 4566, 11325, 5362, 8550, 6316, 8762, 19191, 17418, 21497, 2732, 5108, 9203, 18870, 13649, 14435, 2943, 6294, 8878, 7142, 4457, 4438, 12590, 13040, 8366, 9324, 10028, 21319, 10550, 15837, 17306, 16334, 18005, 6899, 18388, 5383, 393, 15670, 13921, 22126, 7522, 7423, 8261, 7163, 21971, 5813, 4501, 16697, 21288, 22190, 11476, 4113, 6219, 20672, 7635, 10152, 635, 8500, 13729, 5402, 9639, 5749, 14954, 14836, 7275, 19426, 5545, 12524, 6887, 4752, 20692, 7883, 9560, 21154, 8600, 291, 15391, 16920, 4860, 2817, 21312, 12785, 17850, 21466, 8208, 8445, 1622, 4240, 21923, 5217, 16968, 19478, 10940, 966, 20840, 8072, 14823, 6798, 1639, 2584, 16284, 16798, 12965, 660, 14624, 8048, 15023, 4527, 4315, 3432, 16593, 3636, 1326, 4747, 9115, 9941, 13201, 9453, 4583, 13975, 5347, 6409, 17970, 10258, 20339, 11012, 11167, 9037, 3669, 3328, 10814, 15438, 192, 8282, 3860, 16424, 11387, 15436, 10816, 22275, 14865, 15089, 833, 21721, 21357, 12107, 9828, 14681, 9728, 19021, 3849, 15354, 3728, 10711, 17656, 5530, 8347, 20137, 7065, 8071, 20906, 967, 7018, 13450, 12506, 15029, 10133, 2141, 12761, 10300, 9591, 4356, 4253, 6425, 15200, 17548, 358, 14700, 19668, 3949, 18475, 10620, 13814, 10507, 9108, 20532, 21044, 9743, 4380, 12634, 4516, 10072, 5104, 18493, 19159, 9708, 11126, 3707, 8718, 21435, 12392, 19876, 1195, 12481, 10958, 18999, 11785, 17911, 12442, 17525, 6053, 19319, 10680, 17007, 6261, 11092, 7033, 14265, 5411, 14150, 18850, 21337, 7756, 819, 19413, 14596, 430, 5782, 13947, 1479, 18154, 20295, 2662, 21207, 16209, 19557, 15859, 13004, 262, 1113, 344, 7227, 18514, 2110, 12004, 15594, 1491, 19810, 670, 1038, 22242, 16382, 1649, 17206, 18243, 6010, 1645, 5188, 12065, 12234, 7171, 16757, 11738, 15005, 21432, 15622, 18192, 2039, 20625, 6202, 3652, 15054, 768, 2072, 337, 6314, 8552, 17133, 14468, 11230, 1300, 7081, 15664, 8543, 2526, 7705, 18589, 13777, 18247, 11030, 15696, 17975, 22033, 7695, 19457, 147, 18585, 14292, 18669, 4556, 18594, 12486, 21057, 4215, 1176, 21917, 7135, 7882, 20930, 4753, 14196, 8442, 5060, 14565, 11249, 4815, 1797, 12998, 13213, 16189, 18743, 8994, 14175, 13762, 11601, 16954, 19642, 7634, 20947, 6220, 13433, 13997, 10664, 12514, 13817, 13809, 21472, 4948, 9048, 20193, 1255, 6978, 13495, 19798, 19103, 826, 8053, 16276, 11441, 12862, 15104, 11113, 17372, 2362, 1168, 2590, 270, 5890, 500, 9451, 13203, 17385, 18524, 16319, 13989, 7813, 6433, 15289, 11311, 19582, 14653, 19890, 7782, 8044, 6201, 20732, 2040, 8684, 6693, 19168, 9617, 10584, 2437, 3962, 3342, 5583, 19357, 16703, 9926, 4967, 4537, 12873, 616, 9271, 14080, 4186, 1366, 10214, 10496, 15991, 8710, 10416, 4282, 17577, 1709, 9396, 16128, 6498, 3596, 3134, 2424, 1988, 14858, 18410, 3956, 11339, 17946, 21179, 18421, 4452, 11283, 12413, 21170, 21146, 20037, 11597, 19744, 518, 1342, 11965, 15424, 17479, 17985, 9988, 14679, 9830, 2806, 8644, 3170, 13147, 111, 13719, 3041, 12313, 20209, 21295, 2474, 18094, 21528, 5243, 18101, 4642, 7493, 15523, 9838, 2171, 4375, 13237, 4104, 16888, 10459, 3179, 8926, 4274, 10726, 6488, 12257, 21043, 20815, 9109, 6194, 14075, 974, 4071, 13, 13781, 16123, 21182, 2743, 21291, 18098, 7377, 5772, 21365, 22022, 10439, 12818, 8986, 1061, 16083, 21928, 19443, 20122, 10561, 12265, 20268, 677, 16572, 8756, 16069, 4794, 18465, 13821, 7315, 7382, 20291, 19077, 19008, 16370, 5160, 15411, 6190, 295, 4632, 13687, 18259, 10997, 21829, 13588, 14073, 6196, 17359, 10401, 7414, 4360, 2010, 7811, 13991, 21564, 1085, 18699, 16116, 3085, 16739, 6709, 4858, 16922, 5828, 11939, 6251, 11973, 17886, 18884, 11156, 18425, 1261, 15610, 19124, 16725, 13371, 16408, 8909, 4159, 10005, 933, 22369, 9162, 15924, 10209, 12304, 12768, 7029, 17774, 12359, 11414, 20241, 21237, 7899, 9243, 7674, 12954, 5248, 9589, 10302, 8372, 684, 11754, 13613, 16243, 14224, 8778, 6152, 3143, 21417, 18324, 7963, 22109, 21996, 17518, 15712, 9999, 2519, 22313, 8901, 19968, 1804, 7536, 11765, 14392, 18782, 9724, 9809, 10927, 17723, 11634, 15474, 20386, 4067, 14432, 17737, 19540, 4942, 8325, 4066, 20394, 15475, 18032, 1918, 14583, 19987, 7090, 6953, 22203, 10602, 15206, 14599, 7890, 9228, 2096, 19733, 21340, 14766, 19571, 15636, 13009, 13102, 8094, 18971, 6608, 9405, 5742, 3999, 18440, 3731, 17916, 4200, 1660, 1769, 13710, 22019, 14508, 12835, 11317, 647, 4674, 11552, 16018, 15584, 18449, 18309, 11011, 20876, 10259, 14754, 2887, 14707, 273, 13453, 19229, 17514, 9850, 5710, 17456, 5737, 21991, 4984, 17249, 19654, 21624, 1666, 22057, 5164, 12017, 12022, 11272, 7612, 15248, 3889, 9571, 8017, 5303, 8966, 8865, 11320, 1171, 11513, 16998, 10473, 18953, 15014, 16623, 19664, 13164, 2021, 2661, 20769, 18155, 8951, 19076, 20495, 7383, 16749, 21381, 4192, 21063, 3391, 3878, 1636, 10390, 5909, 9426, 21735, 12870, 5919, 12879, 12471, 17899, 19148, 941, 930, 3156, 676, 20505, 12266, 3129, 21613, 2621, 18711, 21961, 16613, 2238, 4074, 9098, 5916, 4540, 944, 21041, 12259, 1560, 9633, 7726, 6688, 5275, 9281, 10487, 18648, 5015, 18714, 21236, 20435, 11415, 53, 7184, 21966, 16545, 3001, 17588, 13307, 21656, 9720, 12605, 7651, 4026, 18917, 11610, 16802, 12157, 12554, 1848, 18019, 15351, 14025, 13071, 9153, 5856, 3210, 13890, 7564, 18376, 2506, 21294, 20556, 12314, 18129, 8308, 3697, 17572, 2906, 19519, 10987, 1237, 13795, 10278, 2235, 21301, 14361, 1254, 20661, 9049, 14752, 10261, 19973, 12568, 10704, 11095, 559, 21672, 9002, 19545, 19364, 12725, 6092, 12936, 12172, 8337, 16009, 13478, 19607, 7152, 16454, 22261, 18776, 12012, 7941, 22221, 7773, 2825, 6430, 493, 9676, 17346, 12114, 2196, 1093, 5779, 2133, 18320, 22382, 2490, 1180, 12355, 21244, 2286, 14802, 15902, 2552, 14593, 10405, 2877, 2259, 16317, 18526, 7064, 20843, 8348, 19515, 2252, 6077, 14357, 3784, 8801, 2999, 16547, 17983, 17481, 21750, 3565, 10560, 20508, 19444, 9393, 9182, 6096, 5552, 14807, 7445, 7599, 12852, 9910, 11437, 16181, 22137, 1148, 2245, 7592, 17624, 8701, 17501, 89, 3021, 128, 12422, 1143, 7211, 10075, 2360, 17374, 13159, 3788, 15483, 3454, 15489, 21702, 14951, 16401, 14016, 15145, 18484, 21413, 437, 21317, 10030, 9358, 21802, 17413, 1122, 17823, 11771, 8581, 7410, 5565, 13505, 8335, 12174, 4304, 16686, 6474, 9067, 14214, 4679, 21211, 10040, 874, 21855, 21098, 21683, 16732, 4663, 1044, 10790, 5441, 13858, 4825, 22096, 17763, 15876, 9089, 2670, 849, 8125, 239, 17615, 11596, 20576, 21147, 20, 12317, 2298, 5020, 1746, 21226, 6037, 13536, 17270, 16534, 6566, 19300, 16721, 10384, 18199, 1332, 3011, 3802, 8618, 3403, 14517, 5095, 12773, 18149, 11662, 22345, 10224, 17818, 13276, 12454, 20000, 798, 479, 4957, 797, 20005, 12455, 22233, 21401, 12645, 7857, 14670, 22364, 8295, 13029, 18076, 18963, 7089, 20381, 14584, 3415, 8565, 11638, 18016, 9158, 4689, 6014, 14109, 18535, 19658, 10284, 12567, 20189, 10262, 5171, 19258, 1803, 20406, 8902, 10292, 287, 8974, 10943, 16762, 5555, 13489, 12103, 2494, 11808, 1775, 18432, 5686, 18270, 19171, 2707, 10573, 17681, 21485, 175, 17403, 16490, 15157, 22328, 16351, 12343, 7973, 10626, 8003, 21106, 13576, 8458, 6660, 5082, 447, 16933, 19509, 22292, 14477, 15979, 16027, 16556, 18264, 19626, 5703, 5746, 1097, 1839, 4300, 580, 10464, 15766, 4781, 22112, 4416, 362, 19857, 3563, 21752, 6029, 17123, 19592, 10, 2241, 21214, 801, 10289, 2435, 10586, 351, 7976, 8466, 17471, 225, 16024, 7781, 20629, 14654, 4016, 2182, 1100, 4297, 867, 17796, 18904, 10443, 9494, 15754, 9148, 1194, 20799, 12393, 1984, 81, 12165, 6538, 14588, 17928, 13849, 1677, 14689, 16349, 22330, 5508, 15657, 13678, 19854, 6233, 3562, 19910, 363, 6232, 19860, 13679, 9072, 21502, 16323, 19548, 8248, 14333, 16227, 4757, 10555, 12255, 6490, 2248, 7801, 16928, 3990, 13532, 18301, 325, 5927, 36, 21771, 17662, 8662, 16993, 17685, 8809, 21755, 10599, 5032, 11994, 6788, 16914, 9969, 21252, 15198, 6427, 8980, 13095, 13281, 12043, 13965, 669, 20753, 1492, 6110, 4843, 22037, 11071, 21224, 1748, 22124, 13923, 14315, 19102, 20657, 13496, 16777, 15848, 837, 13458, 7657, 8997, 5517, 16362, 5272, 2614, 11523, 5369, 2963, 17277, 164, 15703, 17120, 2606, 10871, 22255, 4118, 15667, 8357, 779, 2129, 3683, 7644, 18875, 3218, 15261, 17114, 5098, 16266, 6542, 17105, 4886, 13553, 17060, 16790, 12059, 17168, 4289, 3150, 17140, 7541, 11294, 11027, 9769, 13085, 1347, 12652, 517, 20574, 11598, 753, 4165, 8824, 8424, 5932, 11926, 12891, 7754, 21339, 20371, 2097, 1625, 1187, 14791, 9692, 10747, 17126, 12905, 13303, 2350, 21545, 14797, 6244, 3025, 9706, 19161, 411, 15801, 11347, 9387, 22133, 5296, 911, 13938, 5215, 21925, 3894, 11209, 5807, 9044, 4654, 2855, 12519, 21361, 16067, 8758, 21603, 18216, 10267, 12976, 17325, 3118, 21323, 9080, 473, 3221, 2442, 11821, 7054, 17565, 14204, 5543, 19428, 5118, 11180, 12281, 8748, 21469, 14986, 18958, 4685, 6650, 8120, 3948, 20822, 14701, 15402, 13163, 20299, 16624, 895, 1403, 17286, 10283, 19976, 18536, 19454, 21623, 20323, 17250, 5468, 1210, 1871, 1103, 205, 17041, 9582, 11763, 7538, 7633, 20674, 16955, 18690, 123, 13473, 19011, 9336, 16577, 5205, 15794, 21816, 15150, 14650, 4604, 9471, 5702, 19923, 18265, 14052, 6559, 11148, 5423, 2917, 16659, 13053, 10200, 15173, 4863, 6973, 19153, 14088, 5951, 4645, 4056, 7151, 20173, 13479, 708, 5663, 15873, 13877, 3555, 15471, 19057, 14354, 18058, 15577, 19406, 9596, 9, 19905, 17124, 10749, 11536, 12562, 1829, 13750, 9302, 4602, 14652, 20631, 11312, 6825, 13079, 7218, 17532, 1472, 1082, 14343, 7372, 15635, 20368, 14767, 14619, 2229, 15964, 13415, 6171, 17491, 8177, 17716, 5577, 15379, 4348, 15858, 20765, 16210, 17767, 10660, 8511, 16471, 16678, 7919, 8247, 19849, 16324, 19363, 20182, 9003, 5864, 3450, 4941, 20390, 17738, 2692, 9875, 197, 16710, 19031, 9125, 6961, 17211, 22259, 16456, 14957, 9059, 3712, 5835, 4131, 5948, 3582, 14398, 10986, 20202, 2907, 11987, 2251, 20135, 8349, 6114, 21840, 5488, 22291, 19930, 16934, 7638, 2057, 7687, 3110, 4473, 21532, 16893, 3818, 11479, 16272, 496, 318, 1199, 15446, 7269, 6865, 5126, 13897, 5377, 4820, 2190, 2875, 10407, 18673, 10523, 18614, 1324, 3638, 10939, 20909, 16969, 2773, 5735, 17458, 8086, 3444, 15677, 13572, 5999, 21542, 14270, 3942, 4086, 15976, 17660, 21773, 4386, 15496, 11040, 146, 20706, 7696, 21622, 19656, 18537, 13626, 7957, 1409, 16100, 21852, 21396, 6393, 9392, 20121, 20509, 21929, 17498, 15300, 10116, 4223, 10829, 12007, 4196, 13316, 4231, 10962, 17023, 2609, 5117, 19680, 5544, 20935, 7276, 16666, 17950, 11679, 14034, 21616, 14130, 15232, 5563, 7412, 10403, 14595, 20776, 820, 21055, 12488, 12709, 19338, 9595, 19595, 15578, 6483, 4226, 11526, 7285, 18508, 7729, 15220, 5638, 7512, 13591, 2264, 5847, 2158, 4806, 12912, 13027, 8297, 19106, 13014, 16569, 11859, 21060, 2374, 18592, 4558, 4772, 4971, 17186, 6601, 18889, 4727, 22303, 2292, 22266, 6988, 16148, 2674, 12688, 3205, 12724, 20181, 19546, 16325, 7115, 10170, 14227, 16702, 20614, 5584, 14658, 4519, 8673, 1835, 10081, 12860, 11443, 16603, 19333, 18915, 4028, 11292, 7543, 15337, 4830, 13126, 9594, 19408, 12710, 5694, 1107, 18914, 19347, 16604, 9408, 11138, 17136, 7433, 15335, 7545, 7068, 417, 10580, 10861, 3282, 10679, 20789, 6054, 4836, 16110, 18739, 7341, 9433, 16060, 21767, 9511, 6276, 1925, 5655, 18873, 7646, 13060, 14491, 5356, 16720, 20024, 6567, 13961, 21806, 4174, 16637, 10069, 14661, 3533, 15092, 4036, 7253, 21649, 21880, 484, 15870, 14705, 2889, 17921, 548, 17449, 14070, 7515, 21666, 5067, 2702, 1071, 6943, 6381, 15189, 16346, 18463, 4796, 3863, 13374, 10126, 2127, 781, 3213, 17243, 18796, 1802, 19970, 5172, 11375, 3370, 18546, 8411, 21030, 16240, 1975, 977, 9238, 7683, 16506, 4640, 18103, 2639, 5254, 8649, 15750, 12386, 21462, 2123, 21718, 5292, 4872, 21506, 13386, 9585, 17513, 20332, 13454, 6927, 16232, 14424, 13748, 1831, 9247, 16044, 9580, 17043, 16050, 11736, 16759, 11933, 1854, 13468, 15555, 8849, 10718, 9568, 17392, 3966, 21134, 18296, 598, 9550, 6241, 4562, 16675, 9517, 9500, 14641, 5893, 9330, 8956, 11200, 17417, 20993, 8763, 9704, 3027, 9670, 9660, 6564, 16536, 2178, 8504, 21611, 3131, 5151, 16742, 21410, 3517, 2625, 7133, 21919, 2706, 19952, 18271, 9616, 20621, 6694, 10669, 17077, 15074, 21019, 410, 19717, 9707, 20806, 18494, 8023, 11411, 4262, 14087, 19613, 6974, 5977, 740, 940, 20273, 17900, 10148, 4042, 12527, 15204, 10604, 21352, 8105, 13141, 9779, 8696, 7930, 9605, 17698, 5360, 11327, 16178, 557, 11097, 11368, 9218, 3614, 16724, 20453, 15611, 12251, 10577, 17198, 21660, 18993, 15138, 746, 12218, 21101, 5539, 11531, 3072, 11715, 6187, 22317, 13013, 19387, 8298, 825, 20656, 19799, 14316, 9122, 9602, 14201, 300, 823, 8300, 13790, 16874, 6033, 15731, 17313, 6841, 3586, 5990, 8379, 16041, 17065, 7397, 7503, 12336, 21912, 17438, 19007, 20494, 20292, 8952, 1020, 17366, 10313, 16088, 14297, 3424, 13022, 6156, 18723, 1522, 11580, 5476, 12232, 12067, 169, 14841, 14353, 19599, 15472, 11636, 8567, 22278, 18430, 1777, 16811, 6940, 11846, 329, 3541, 1058, 19028, 8238, 4272, 8928, 12459, 12088, 3853, 22085, 9295, 4750, 6889, 9600, 9124, 19534, 16711, 8237, 19044, 1059, 8988, 4962, 11017, 3138, 3848, 20851, 9729, 22080, 74, 9382, 9293, 22087, 18342, 14745, 9335, 19637, 13474, 16369, 20493, 19078, 17439, 16429, 10529, 1329, 2108, 18516, 11784, 20795, 10959, 15955, 3568, 10890, 15137, 19118, 21661, 13774, 2377, 7877, 18294, 21136, 15417, 16418, 13726, 14832, 7283, 11528, 5625, 7808, 2408, 13829, 899, 12530, 17695, 4546, 6607, 20363, 8095, 3324, 9372, 13331, 15693, 15316, 7088, 19989, 18077, 1502, 5801, 4684, 19673, 14987, 21017, 15076, 15013, 20302, 10474, 8226, 14306, 2921, 6717, 7469, 6999, 11583, 16528, 2851, 17453, 21010, 6909, 2303, 6905, 7577, 21932, 13661, 13670, 18398, 15720, 7111, 10097, 6331, 628, 6812, 14685, 156, 6748, 11161, 21095, 6239, 9552, 16596, 11609, 20227, 4027, 19346, 19334, 1108, 5721, 16307, 17627, 11174, 18748, 13487, 5557, 10442, 19882, 17797, 12377, 10321, 11780, 251, 12491, 16940, 11331, 7025, 14141, 6893, 11446, 583, 4726, 19375, 6602, 14528, 8693, 11155, 20458, 17887, 8160, 13368, 6995, 18555, 3907, 982, 3217, 19769, 7645, 19306, 5656, 13648, 20987, 9204, 7327, 8030, 21141, 9657, 15087, 14867, 15218, 7731, 3101, 7302, 21562, 13993, 12216, 748, 15538, 22063, 3347, 21336, 20780, 14151, 4809, 8490, 16488, 17405, 1219, 11023, 13177, 228, 12867, 8515, 2792, 6923, 9679, 6063, 8352, 12546, 16159, 2535, 2484, 642, 2269, 11834, 6437, 3397, 11504, 10635, 4636, 13482, 18236, 14897, 13289, 5569, 11879, 9666, 16303, 8303, 16444, 2871, 7996, 10181, 15551, 3305, 16404, 15332, 13337, 9041, 8789, 22286, 855, 18360, 15894, 1801, 19260, 17244, 14445, 8064, 12994, 10298, 12763, 12051, 12408, 4591, 12190, 21256, 18625, 9723, 20401, 14393, 13174, 3267, 5670, 12011, 20169, 22262, 10590, 9857, 9211, 16870, 13422, 14574, 5642, 1014, 6207, 15842, 21781, 9509, 21769, 38, 10019, 12839, 5799, 1504, 21068, 2913, 11455, 21789, 11867, 6821, 5983, 13486, 18908, 11175, 8740, 17861, 8993, 20680, 16190, 1663, 7340, 19315, 16111, 21712, 12599, 3791, 15518, 15936, 12781, 12698, 6574, 7049, 56, 12397, 6860, 13355, 1521, 19066, 6157, 13865, 10105, 5012, 10648, 10901, 12433, 21235, 20243, 5016, 21960, 20263, 2622, 14750, 9051, 16097, 13517, 11904, 3747, 18210, 7762, 4205, 16115, 20470, 1086, 14084, 2188, 4822, 6619, 10685, 13248, 122, 19640, 16956, 5230, 11266, 1590, 13676, 15659, 15691, 13333, 2867, 16559, 1388, 14440, 17293, 6129, 18115, 10522, 19484, 10408, 21014, 4555, 20702, 14293, 18569, 7038, 1545, 11683, 3952, 2036, 4478, 7, 9598, 6891, 14143, 8062, 14447, 21787, 11457, 1372, 21985, 10646, 5014, 20245, 10488, 3689, 4184, 14082, 1088, 10683, 6621, 22207, 13753, 5220, 11116, 17605, 6229, 15689, 15661, 531, 7550, 8042, 7784, 22160, 12603, 9722, 18784, 21257, 7130, 5281, 6099, 6133, 6256, 21330, 6312, 339, 1323, 19482, 10524, 15574, 17003, 8035, 2262, 13593, 16145, 9233, 2301, 6911, 9793, 3658, 6876, 14887, 11105, 10146, 17902, 9539, 12485, 20700, 4557, 19381, 2375, 13776, 20714, 7706, 22239, 14291, 20704, 148, 4692, 13512, 12210, 6844, 18346, 9130, 10501, 5499, 2893, 10915, 18282, 17990, 15026, 7037, 18667, 14294, 4327, 8680, 5138, 5201, 16439, 14903, 10124, 13376, 13834, 12201, 4812, 3906, 18879, 6996, 15323, 21978, 6291, 543, 5775, 9350, 8410, 19254, 3371, 1543, 7040, 8370, 10304, 3355, 309, 13625, 19453, 19657, 19977, 14110, 1527, 5970, 17596, 3126, 9020, 5987, 7063, 20139, 16318, 20638, 17386, 16774, 16868, 9213, 6372, 631, 11783, 19001, 2109, 20758, 7228, 8363, 13986, 6686, 7728, 19400, 7286, 4455, 7144, 2080, 12823, 5003, 6308, 467, 2687, 11185, 8532, 15777, 8022, 19158, 20807, 5105, 12112, 17348, 11142, 17580, 3837, 3515, 21412, 20083, 15146, 6180, 8520, 16903, 104, 10121, 15037, 10619, 20820, 3950, 11685, 4622, 22175, 15033, 13705, 17673, 12346, 13820, 20499, 4795, 19269, 16347, 14691, 15382, 12560, 11538, 1048, 17073, 10187, 6807, 3946, 8122, 2927, 18308, 20342, 15585, 3940, 14272, 2724, 1572, 3919, 10709, 3730, 20358, 4000, 3982, 1807, 11055, 9564, 22194, 5685, 19955, 1776, 19052, 22279, 5000, 3186, 1260, 20456, 11157, 8435, 4451, 20582, 21180, 16125, 12098, 7966, 14964, 16897, 5883, 4908, 18392, 3955, 20587, 14859, 16058, 9435, 4905, 21690, 5464, 2555, 8862, 13522, 17013, 15719, 18933, 13671, 21389, 16650, 2034, 3954, 18412, 4909, 8869, 5382, 20966, 6900, 13667, 6226, 4163, 755, 13229, 6471, 21393, 877, 7738, 2505, 20212, 7565, 12155, 16804, 7292, 6828, 9994, 15535, 14741, 2165, 3477, 3048, 11102, 10060, 16497, 15893, 18799, 856, 7300, 3103, 15141, 11704, 15810, 5456, 12244, 3248, 9867, 15508, 21866, 9129, 18579, 6845, 9786, 14744, 19014, 22088, 6505, 6752, 17747, 2784, 15243, 6646, 9486, 9092, 14500, 16542, 4703, 10819, 14067, 2006, 2000, 7962, 20416, 21418, 1866, 22381, 20154, 2134, 13296, 13540, 12026, 9991, 885, 9009, 18051, 12121, 11010, 20341, 18450, 2928, 6418, 10109, 5659, 17732, 324, 19836, 13533, 11243, 16972, 597, 19205, 21135, 18988, 7878, 9225, 5854, 9155, 1851, 5506, 22332, 21634, 13549, 5130, 17989, 18573, 10916, 1444, 16175, 7354, 11776, 137, 2617, 6727, 13852, 9615, 19170, 19953, 5687, 16121, 13783, 14051, 19625, 19924, 16557, 2869, 16446, 10996, 20485, 13688, 9174, 8625, 10934, 21023, 16517, 22008, 14676, 12029, 9767, 11029, 20712, 13778, 4801, 6009, 20746, 17207, 7159, 16832, 8525, 15002, 14896, 18820, 13483, 1945, 12389, 4786, 16166, 4009, 21639, 2652, 13570, 15679, 4649, 4433, 1290, 16856, 5176, 586, 3097, 5757, 10266, 19695, 21604, 5237, 16450, 9477, 7761, 18703, 3748, 8312, 1788, 21028, 8413, 17778, 6613, 1011, 2106, 1331, 20021, 10385, 2958, 9078, 21325, 4476, 2038, 20734, 15623, 10248, 14630, 3692, 6279, 8375, 7250, 10691, 9167, 13292, 4744, 10532, 1335, 1696, 21218, 13135, 7939, 12014, 13598, 16391, 12276, 2955, 11565, 15909, 2990, 10868, 17026, 17631, 9076, 2960, 11432, 6440, 9845, 6236, 21858, 8950, 20294, 20770, 1480, 471, 9082, 11661, 20012, 12774, 11811, 11534, 10751, 10253, 21122, 17329, 18036, 1565, 15969, 10807, 5679, 1311, 7107, 9356, 10032, 10981, 3238, 8307, 20207, 12315, 22, 13233, 17706, 15745, 12909, 14154, 3351, 13466, 1856, 11668, 9764, 10521, 18675, 6130, 14726, 11976, 1795, 4817, 6677, 15059, 14627, 14540, 5224, 2638, 19244, 4641, 20550, 5244, 7376, 20520, 21292, 2508, 21527, 20553, 2475, 21814, 15796, 10218, 2327, 5708, 9852, 27, 14100, 14788, 15590, 22179, 9402, 8273, 17865, 1501, 18962, 19990, 13030, 6654, 10437, 22024, 16780, 16056, 14861, 6303, 8098, 3826, 13714, 13209, 16299, 9459, 10801, 17001, 15576, 19597, 14355, 6079, 223, 17473, 13738, 12120, 18312, 9010, 12952, 7676, 7700, 7013, 2834, 6536, 12167, 4577, 14189, 14124, 9265, 12801, 1564, 18141, 17330, 14978, 1917, 20384, 15476, 12449, 13801, 21843, 4946, 21474, 6082, 17353, 42, 9065, 6476, 15350, 20221, 1849, 9157, 19982, 11639, 12649, 1581, 9760, 6405, 5494, 16512, 619, 2932, 6898, 20968, 16335, 10092, 1118, 10837, 10651, 10776, 7181, 7052, 11823, 13954, 10331, 9896, 4525, 15025, 18572, 18283, 5131, 10340, 9987, 20568, 17480, 20127, 16548, 14062, 5548, 15867, 280, 2481, 22032, 20709, 15697, 11726, 9773, 10257, 20878, 6410, 6363, 7156, 14242, 8660, 17664, 92, 17282, 17743, 4169, 21104, 8005, 14410, 17935, 1414, 9804, 8112, 14772, 11678, 19423, 16667, 11131, 21178, 20584, 11340, 17202, 13957, 3971, 1812, 11111, 15106, 3887, 15250, 1413, 17956, 14411, 15628, 247, 10155, 16034, 13848, 19869, 14589, 17253, 17194, 12294, 16064, 547, 19282, 2890, 862, 1067, 4199, 20356, 3732, 22387, 5600, 12441, 20793, 11786, 4666, 6178, 15148, 21818, 510, 12339, 9538, 18597, 10147, 19147, 20274, 12472, 10930, 7297, 16437, 5203, 16579, 1439, 5697, 1130, 16072, 8159, 18883, 20459, 11974, 14728, 16140, 10422, 11060, 15370, 12226, 9758, 1583, 12322, 7734, 3039, 13721, 7179, 10778, 13088, 12496, 4401, 7369, 1500, 18079, 8274, 5731, 8992, 18745, 8741, 4659, 22071, 17425, 1783, 9521, 16476, 2137, 21450, 21465, 20918, 12786, 4697, 3420, 15787, 8658, 14244, 10564, 13972, 11135, 7404, 1378, 3723, 1692, 3800, 3013, 17622, 7594, 16151, 3192, 5719, 1110, 8091, 1394, 11069, 22039, 11770, 20074, 1123, 12982, 14992, 13275, 20008, 10225, 4351, 8205, 8751, 13018, 45, 12939, 1511, 8419, 11260, 1217, 17407, 5146, 572, 9984, 3606, 10204, 5038, 22353, 12376, 18903, 19883, 868, 6580, 12494, 13090, 2809, 7742, 2764, 12923, 7241, 7745, 453, 22047, 15168, 7476, 11500, 8201, 6612, 18204, 8414, 7573, 12358, 20438, 7030, 10707, 3921, 219, 6341, 10659, 19555, 16211, 13875, 15875, 20046, 22097, 1906, 8707, 16288, 11757, 3571, 8912, 21687, 5886, 3148, 4291, 1844, 14901, 16441, 2783, 18338, 6753, 6713, 4168, 17961, 17283, 13192, 13348, 2691, 19539, 20391, 14433, 13651, 4534, 323, 18303, 5660, 2340, 21350, 10606, 4484, 16216, 6761, 11633, 20397, 10928, 12474, 21745, 2047, 10842, 5576, 19562, 8178, 2332, 1183, 11718, 13758, 16591, 3434, 2721, 15744, 18125, 13234, 2413, 16380, 22244, 3810, 8882, 5359, 19134, 9606, 4545, 18974, 12531, 15192, 425, 5850, 4063, 11575, 120, 13250, 8808, 19828, 16994, 17095, 21484, 19949, 10574, 1317, 11206, 13863, 6159, 7971, 12345, 18468, 13706, 167, 12069, 17215, 21809, 3503, 3019, 91, 17964, 8661, 19831, 21772, 19463, 15977, 14479, 5529, 20846, 10712, 8361, 7230, 16388, 5914, 9100, 4212, 11862, 21066, 1506, 13279, 13097, 3358, 15505, 1462, 1702, 8198, 7259, 6165, 2548, 11839, 6387, 1229, 9075, 18164, 17027, 457, 11173, 18910, 16308, 8700, 20105, 7593, 17834, 3014, 17423, 22073, 21196, 9914, 11595, 20039, 240, 6626, 2479, 282, 399, 956, 10003, 4161, 6228, 18636, 11117, 12695, 10701, 21261, 6323, 1893, 3929, 3125, 18531, 5971, 22378, 8614, 4148, 16385, 6515, 13306, 20234, 3002, 9482, 8241, 3545, 13904, 10191, 3836, 18488, 11143, 1708, 20597, 4283, 15717, 17015, 2905, 20204, 3698, 15775, 8534, 2345, 298, 14203, 19683, 7055, 3052, 9268, 16515, 21025, 12181, 16338, 3076, 6284, 21406, 10095, 7113, 16327, 16282, 2586, 357, 20825, 15201, 902, 15070, 21399, 22235, 15647, 4866, 16342, 6465, 144, 11042, 15683, 1928, 5472, 1471, 19577, 7219, 2778, 15421, 6745, 4852, 6052, 20791, 12443, 21693, 17100, 3159, 888, 15711, 20412, 21997, 14039, 9849, 20331, 19230, 9586, 21447, 1354, 8287, 5287, 2632, 8841, 11799, 10743, 6509, 88, 20103, 8702, 15299, 19441, 21930, 7579, 21034, 22360, 17337, 8176, 19564, 6172, 12957, 3987, 704, 16509, 3980, 4002, 13525, 21749, 20126, 17984, 20569, 15425, 16784, 14526, 6604, 13737, 18054, 224, 19894, 8467, 15274, 9755, 10976, 22342, 11426, 7239, 12925, 7990, 15558, 8014, 8085, 19474, 5736, 20328, 5711, 21009, 18942, 2852, 2004, 14069, 19280, 549, 4366, 920, 1730, 13346, 13194, 11486, 503, 16428, 19006, 19079, 21913, 2391, 21597, 22252, 13050, 13404, 3368, 11377, 12462, 9929, 12466, 1782, 17857, 22072, 17620, 3015, 5208, 8562, 21496, 20992, 19192, 11201, 8144, 1121, 20076, 21803, 954, 401, 2068, 5145, 17806, 1218, 18845, 16489, 19946, 176, 21248, 15184, 8813, 15429, 8155, 8736, 13717, 113, 3965, 19208, 9569, 3891, 16086, 10315, 16773, 18523, 20639, 13204, 7265, 12287, 3674, 11746, 3744, 2149, 3680, 434, 13158, 20094, 2361, 20648, 11114, 5222, 14542, 15943, 10312, 19073, 1021, 15770, 188, 11793, 2569, 10400, 20479, 6197, 13360, 12188, 4593, 41, 18024, 6083, 13695, 14465, 11141, 18490, 12113, 20160, 9677, 6925, 13456, 839, 7608, 7345, 14531, 8175, 17493, 22361, 14183, 13950, 1705, 7829, 14977, 18035, 18142, 21123, 726, 3117, 19692, 12977, 21111, 21151, 8832, 182, 8983, 14312, 7122, 21126, 8923, 6840, 19090, 15732, 2460, 21947, 13366, 8162, 16333, 20970, 15838, 15320, 7472, 7167, 14770, 8114, 7875, 2379, 9621, 5278, 2628, 6128, 18677, 14441, 15180, 12320, 1585, 3901, 10282, 19660, 1404, 13191, 17742, 17962, 93, 9151, 13073, 163, 19783, 2964, 2714, 11214, 15131, 10886, 16533, 20027, 13537, 15527, 2902, 8497, 11797, 8843, 4109, 4405, 12054, 10878, 5397, 5300, 22017, 13712, 3828, 17193, 17926, 14590, 5467, 19653, 20324, 4985, 4588, 21822, 14444, 18795, 19261, 3214, 5652, 15686, 366, 6548, 12897, 6641, 10009, 6022, 1902, 6983, 12036, 335, 2074, 10377, 8797, 11942, 11190, 14251, 12130, 2422, 3136, 11019, 13259, 5536, 4172, 21808, 17669, 12070, 10615, 22258, 19531, 6962, 14240, 7158, 18242, 20747, 1650, 10329, 13956, 17944, 11341, 8389, 21659, 19120, 10578, 419, 12293, 17925, 17254, 3829, 5955, 4499, 5815, 2759, 6600, 19377, 4972, 13832, 13378, 12503, 276, 5762, 8454, 2685, 469, 1482, 5426, 8639, 3755, 11278, 5023, 7852, 4288, 19756, 12060, 12499, 11657, 5436, 3705, 11128, 21232, 13255, 17082, 7834, 788, 4179, 5944, 390, 16135, 1065, 864, 1842, 4293, 15018, 16219, 9438, 1964, 12805, 948, 7631, 7540, 19753, 3151, 13745, 7432, 19329, 11139, 14467, 20723, 8553, 5819, 13639, 21188, 6777, 12904, 19726, 10748, 19591, 19906, 6030, 2605, 19780, 15704, 2145, 13113, 12771, 5097, 19766, 15262, 3771, 16295, 16843, 6528, 5514, 14105, 4885, 19762, 6543, 21558, 674, 3158, 17522, 21694, 259, 2682, 21483, 17683, 16995, 5135, 377, 14375, 2083, 13428, 15608, 1263, 15408, 10359, 14162, 7833, 17159, 13256, 6446, 6390, 15073, 19165, 10670, 7139, 10186, 18456, 1049, 8476, 813, 12368, 594, 8785, 7396, 19084, 16042, 9249, 5374, 16789, 19759, 13554, 6453, 8118, 6652, 13032, 12371, 6145, 10773, 7501, 7399, 9120, 14318, 8417, 1513, 15985, 16049, 19219, 9581, 19647, 206, 9241, 7901, 3091, 5674, 13510, 4694, 3260, 11067, 1396, 13844, 9420, 456, 17630, 18165, 10869, 2608, 19431, 10963, 9777, 13143, 5331, 5605, 8495, 2904, 17574, 15718, 18400, 13523, 4004, 1428, 22001, 6260, 20787, 10681, 1090, 8034, 18611, 15575, 18060, 10802, 10472, 20304, 11514, 5134, 17094, 17684, 19829, 8663, 1452, 12755, 8509, 10662, 13999, 15736, 13911, 237, 8127, 1611, 8244, 12417, 9424, 5911, 13601, 14723, 6102, 8783, 596, 18298, 11244, 2772, 19477, 20910, 5218, 13755, 14524, 16786, 13900, 6141, 11079, 15570, 16412, 10735, 5229, 18689, 19641, 20675, 11602, 2343, 8536, 14521, 11721, 15256, 14513, 13170, 14557, 21607, 716, 7351, 11330, 18897, 12492, 6582, 4040, 10150, 7637, 19508, 19931, 448, 9948, 702, 3989, 19839, 7802, 5142, 2741, 21184, 5827, 20464, 4859, 20923, 15392, 10812, 3330, 10162, 9968, 19821, 6789, 13930, 10741, 11801, 12538, 936, 8590, 552, 2882, 103, 18480, 8521, 16047, 15987, 4383, 5882, 18415, 14965, 11891, 3817, 19501, 21533, 811, 8478, 10458, 20541, 4105, 62, 2530, 6737, 10345, 9506, 7099, 15864, 5285, 8289, 13395, 2603, 6032, 19093, 13791, 22104, 13421, 18771, 9212, 18521, 16775, 13498, 7913, 4736, 1548, 14047, 11490, 9962, 10721, 9133, 5175, 18222, 1291, 3280, 10863, 16770, 8188, 2712, 2966, 1459, 9870, 8330, 4413, 6527, 17110, 16296, 2276, 7587, 5630, 2432, 8905, 3487, 11952, 9577, 8524, 18240, 7160, 2976, 14982, 2323, 8889, 13224, 9103, 3576, 10515, 10087, 9627, 6740, 9274, 11550, 4676, 2832, 7015, 7937, 13137, 6939, 19050, 1778, 3037, 7736, 879, 9529, 7291, 18373, 12156, 20225, 11611, 7789, 12964, 20899, 16285, 15994, 14927, 5, 4480, 9953, 12058, 19758, 17061, 5375, 13899, 16964, 14525, 17477, 15426, 915, 16055, 18071, 22025, 15847, 19796, 13497, 16867, 18522, 17387, 10316, 8187, 16852, 10864, 3413, 14586, 6540, 16268, 14805, 5554, 19962, 10944, 11932, 19216, 11737, 20739, 7172, 2996, 14882, 12350, 7818, 3625, 21380, 20289, 7384, 14336, 7310, 342, 1115, 21409, 19178, 5152, 6708, 20467, 3086, 3521, 8746, 12283, 4089, 4662, 20054, 21684, 2789, 6521, 7690, 6993, 13370, 20452, 19125, 3615, 10383, 20023, 19301, 5357, 8884, 12682, 16526, 11585, 4256, 21083, 8236, 19030, 19535, 198, 3960, 2439, 4124, 6273, 9925, 20613, 19358, 14228, 9682, 3057, 21287, 20953, 4502, 21264, 14128, 21618, 12921, 2766, 2471, 16648, 21391, 6473, 20065, 4305, 12542, 2064, 4938, 1385, 99, 7918, 19551, 16472, 9516, 19200, 4563, 21284, 3481, 6087, 8606, 21230, 11130, 17949, 19424, 7277, 7479, 14118, 4530, 13402, 13052, 19619, 2918, 4936, 2066, 403, 14170, 5787, 12987, 2033, 18395, 21390, 16689, 2472, 21297, 12753, 1454, 7440, 5994, 15598, 1126, 12152, 10068, 19295, 4175, 12128, 14253, 21906, 22116, 5213, 13940, 7826, 11146, 6561, 21161, 894, 19663, 20300, 15015, 1875, 1029, 21849, 3844, 13044, 12751, 21299, 2237, 20261, 21962, 1620, 8447, 1391, 13105, 8222, 5740, 9407, 19332, 19348, 11444, 6895, 11355, 9548, 600, 11608, 18919, 9553, 3635, 20890, 3433, 17710, 13759, 21192, 6949, 11183, 2689, 13350, 13606, 14999, 12291, 421, 1438, 17893, 5204, 19635, 9337, 13839, 5262, 8755, 20503, 678, 11858, 19385, 13015, 1208, 5470, 1930, 10455, 10434, 8485, 97, 1387, 18680, 2868, 18263, 19925, 16028, 15239, 5941, 12918, 7457, 7839, 14061, 17982, 20128, 3000, 20236, 21967, 4702, 18331, 14501, 13167, 4102, 13239, 2177, 19184, 6565, 20026, 17271, 10887, 11760, 13389, 2850, 18944, 11584, 16716, 12683, 11269, 14777, 21549, 21675, 15044, 14908, 22007, 18253, 21024, 17561, 9269, 618, 18009, 5495, 3979, 17486, 705, 4639, 19246, 7684, 22122, 1750, 21894, 7751, 3197, 13064, 15892, 18362, 10061, 21120, 10255, 9775, 10965, 15156, 19945, 17404, 18846, 8491, 16254, 12002, 2112, 12968, 5415, 8793, 6004, 4742, 13294, 2136, 17854, 9522, 2116, 9515, 16677, 19552, 8512, 21738, 1305, 22067, 2559, 22358, 21036, 6017, 13968, 2655, 10468, 7281, 14834, 14956, 19529, 22260, 20171, 7153, 5840, 9476, 18213, 5238, 22004, 10995, 18261, 2870, 18812, 8304, 2782, 17749, 14902, 18563, 5202, 17895, 7298, 858, 21584, 15512, 11606, 602, 10528, 19005, 17440, 504, 6355, 11386, 20865, 3861, 4798, 16, 9798, 13725, 18985, 15418, 3242, 21654, 13309, 10734, 16959, 15571, 3643, 8908, 20450, 13372, 3865, 15331, 18806, 3306, 14015, 20086, 14952, 5751, 6796, 14825, 12328, 8820, 2924, 852, 12275, 18172, 13599, 5913, 17652, 7231, 6514, 17591, 4149, 1648, 20749, 22243, 17703, 2414, 8285, 1356, 5930, 8426, 21726, 8386, 12383, 5159, 20492, 19009, 13475, 7207, 13582, 640, 2486, 5271, 19789, 5518, 3301, 6663, 9445, 1166, 2364, 8858, 11152, 9782, 12342, 19942, 22329, 19865, 14690, 18462, 19270, 15190, 12533, 6464, 17540, 4867, 1603, 3075, 17558, 12182, 10091, 18004, 20969, 17307, 8163, 12713, 3558, 14042, 16281, 17552, 7114, 19362, 19547, 19850, 21503, 6684, 13988, 20637, 18525, 20140, 2260, 8037, 4337, 22171, 918, 4368, 5041, 8699, 17626, 18911, 5722, 13788, 8302, 18814, 9667, 2214, 9458, 18063, 13210, 2275, 16842, 17111, 3772, 16261, 7669, 5418, 13611, 11756, 17759, 8708, 15993, 16797, 20900, 2585, 17551, 16328, 14043, 2880, 554, 11440, 20653, 8054, 9674, 495, 19498, 11480, 15900, 14804, 16765, 6541, 19764, 5099, 3717, 4279, 7668, 16293, 3773, 16138, 14730, 7680, 209, 12001, 16486, 8492, 5431, 11315, 12837, 10021, 5340, 11621, 10395, 12659, 14223, 20422, 13614, 1974, 19251, 21031, 9370, 3326, 3671, 8529, 4717, 14423, 19226, 6928, 10884, 15133, 4756, 19846, 14334, 7386, 963, 8977, 2828, 4903, 9437, 17147, 15019, 6760, 17726, 4485, 7246, 3911, 13874, 17766, 19556, 20766, 21208, 10677, 3284, 77, 6981, 1904, 22099, 12041, 13283, 1863, 8319, 1913, 5035, 9034, 7331, 14348, 1767, 1662, 18742, 20681, 13214, 21378, 3627, 6552, 10825, 697, 22136, 20110, 11438, 556, 19131, 11328, 7353, 18279, 1445, 1722, 8961, 9737, 11470, 8730, 8725, 4008, 18231, 4787, 3758, 6705, 22029, 2538, 2534, 18832, 12547, 4235, 536, 1297, 3472, 12842, 3191, 17832, 7595, 2673, 19369, 6989, 9232, 18607, 13594, 10453, 1932, 10421, 17883, 14729, 16259, 3774, 1064, 17153, 391, 5385, 1607, 11302, 8622, 6497, 20594, 9397, 12097, 18419, 21181, 20524, 13782, 18268, 5688, 12469, 12881, 3084, 20469, 18700, 4206, 14019, 21711, 18738, 19316, 4837, 988, 8138, 489, 21523, 15815, 414, 3842, 21851, 19449, 1410, 13516, 18707, 9052, 10448, 1320, 7313, 13823, 7531, 4325, 14296, 19071, 10314, 17389, 3892, 21927, 20511, 1062, 3776, 22055, 1668, 13842, 1398, 13632, 13364, 21949, 8158, 17889, 1131, 4793, 20501, 8757, 19698, 21362, 546, 17923, 12295, 3464, 21766, 19312, 9434, 18408, 14860, 18070, 16781, 916, 22173, 4624, 11735, 19218, 17044, 15986, 16901, 8522, 9579, 19221, 9248, 17064, 19085, 8380, 21888, 5967, 11008, 12123, 13847, 17930, 10156, 7778, 15982, 4425, 15238, 16555, 19926, 15980, 7780, 19892, 226, 13179, 3874, 21763, 15583, 20344, 11553, 11495, 10805, 15971, 15449, 3121, 7205, 13477, 20175, 8338, 10553, 4759, 21165, 15946, 5314, 7321, 996, 2947, 13002, 15861, 15806, 15674, 14926, 16796, 16286, 8709, 20601, 10497, 12632, 4382, 16900, 16048, 17045, 1514, 4424, 16031, 7779, 16026, 19927, 14478, 17659, 19464, 4087, 12285, 7267, 15448, 16014, 10806, 18139, 1566, 7194, 2576, 13414, 19567, 2230, 21901, 14579, 1759, 7105, 1313, 10558, 3567, 18997, 10960, 4233, 12549, 21144, 21172, 11372, 9136, 5313, 16004, 21166, 10311, 17368, 14543, 8838, 5335, 14276, 8539, 12780, 18733, 15519, 10510, 7482, 11401, 9209, 9859, 6050, 4854, 22250, 21599, 10208, 20443, 9163, 4012, 1001, 5706, 2329, 13327, 4372, 7044, 11900, 9807, 9726, 14683, 6814, 2989, 18168, 11566, 21698, 11666, 1858, 10137, 2551, 20146, 14803, 16270, 11481, 13217, 13770, 6264, 1800, 18798, 18361, 16498, 13065, 21872, 304, 4053, 15642, 6571, 11649, 4890, 22306, 15544, 10084, 15161, 6007, 4803, 9088, 20045, 17764, 13876, 19603, 5664, 14704, 19285, 485, 279, 17979, 5549, 5284, 16880, 7100, 15805, 15998, 13003, 20764, 19558, 4349, 10227, 2522, 7806, 5627, 6126, 2630, 5289, 836, 19795, 16778, 22026, 5155, 9497, 21780, 18765, 6208, 11569, 15319, 17305, 20971, 10551, 8340, 2770, 11246, 5766, 1233, 12732, 3208, 5858, 2368, 3094, 8433, 11159, 6750, 6507, 10745, 9694, 3663, 15345, 15799, 413, 16104, 21524, 4599, 9900, 5455, 18354, 11705, 15757, 15673, 15997, 15862, 7101, 12741, 11346, 19715, 412, 15817, 15346, 10217, 18091, 21815, 19633, 5206, 3017, 3505, 7866, 4918, 8657, 17846, 3421, 2031, 12989, 14122, 14191, 4614, 4190, 21383, 8021, 18496, 8533, 17570, 3699, 11709, 3752, 187, 17364, 1022, 22152, 4780, 19915, 10465, 9504, 10347, 21443, 14764, 21342, 13919, 15672, 15808, 11706, 9147, 19879, 9495, 5157, 12385, 19240, 8650, 7149, 4058, 12908, 18124, 17707, 2722, 14274, 5337, 9362, 4319, 11957, 13910, 16986, 14000, 13934, 2459, 17312, 19091, 6034, 12949, 85, 6851, 7421, 7524, 7177, 13723, 9800, 7110, 18932, 18399, 17014, 17575, 4284, 7335, 22335, 9998, 20411, 17519, 889, 6072, 8406, 3883, 14666, 2144, 17119, 19781, 165, 13708, 1771, 3226, 11725, 17974, 20710, 11031, 15315, 18966, 13332, 18683, 15660, 18634, 6230, 365, 17240, 5653, 1927, 17536, 11043, 15639, 4648, 18226, 13571, 19471, 3445, 14925, 15996, 15807, 15758, 13920, 20963, 394, 8356, 19775, 4119, 8542, 20718, 7082, 530, 18633, 15690, 18684, 13677, 19862, 5509, 12049, 12765, 5573, 13120, 8315, 10426, 6971, 4865, 17542, 22236, 3469, 11233, 6570, 15887, 4054, 4647, 15681, 11044, 13008, 20367, 19572, 7373, 6176, 4668, 10761, 9819, 246, 17933, 14412, 8185, 10318, 10247, 18191, 20735, 21433, 8720, 1006, 8215, 1204, 5265, 9490, 665, 14009, 12250, 19123, 20454, 1262, 17088, 13429, 10398, 2571, 5480, 8464, 7978, 21116, 12980, 1125, 16641, 5995, 7569, 1490, 20755, 12005, 10831, 22178, 18083, 14789, 1189, 12205, 3939, 18448, 20343, 16019, 21764, 3466, 7709, 6482, 19405, 19596, 18059, 17002, 18612, 10525, 3642, 16411, 16960, 11080, 2813, 9315, 15100, 4022, 12400, 21510, 6915, 9946, 450, 8013, 17461, 7991, 8848, 19212, 13469, 5079, 3304, 18808, 10182, 3813, 4048, 12608, 12858, 10083, 15882, 22307, 6666, 14973, 7847, 22062, 18854, 749, 14740, 18369, 9995, 3667, 9039, 13339, 11947, 15123, 2901, 17268, 13538, 13298, 9837, 20547, 7494, 9106, 10509, 15935, 18734, 3792, 7507, 10853, 21347, 11605, 16433, 21585, 15309, 21865, 18349, 9868, 1461, 17642, 3359, 12794, 3735, 8251, 3500, 10948, 5792, 11039, 19460, 4387, 1426, 4006, 8727, 11422, 21701, 20089, 3455, 14817, 1152, 1382, 3453, 20091, 3789, 12601, 22162, 882, 6831, 12448, 18031, 20385, 20395, 11635, 19056, 19600, 3556, 12715, 5049, 8938, 3166, 6162, 11510, 12746, 14602, 9431, 7343, 7610, 11274, 9700, 14570, 9255, 5581, 3344, 10548, 21321, 3120, 16013, 15972, 7268, 19494, 1200, 5805, 11211, 10114, 15302, 2014, 191, 20869, 10815, 20863, 11388, 11750, 13267, 2861, 5183, 8154, 17398, 8814, 914, 16783, 17478, 20570, 11966, 6744, 17529, 2779, 3241, 16417, 18986, 21137, 1734, 8899, 22315, 6189, 20490, 5161, 10358, 17086, 1264, 126, 3023, 6246, 13162, 19666, 14702, 5666, 9024, 3513, 3839, 7071, 14923, 3447, 10811, 16919, 20924, 292, 10354, 13559, 22213, 9688, 11981, 14497, 12559, 18460, 14692, 4347, 19560, 5578, 14457, 21425, 1555, 8944, 9753, 15276, 12225, 17880, 11061, 3498, 8253, 9278, 9624, 1954, 4620, 11687, 11300, 1609, 8129, 9885, 7366, 3823, 3727, 20849, 3850, 14024, 20220, 18020, 6477, 10494, 10216, 15798, 15818, 3664, 22338, 15211, 4396, 10571, 2709, 4829, 19342, 7544, 19327, 7434, 13336, 18805, 16405, 3866, 2255, 1551, 14323, 14847, 3068, 21977, 18553, 6997, 7471, 17304, 15839, 11570, 7087, 18965, 15694, 11032, 21092, 1674, 6730, 21864, 15510, 21586, 10822, 7076, 3429, 2405, 2013, 15441, 10115, 19440, 17499, 8703, 13221, 610, 12886, 5512, 6530, 6589, 9653, 11310, 20633, 6434, 21081, 4258, 13038, 12592, 6672, 3462, 12297, 4840, 6067, 3032, 12224, 15372, 9754, 17469, 8468, 8080, 5076, 1268, 21669, 12438, 10337, 11517, 9822, 1135, 3770, 17113, 19767, 3219, 475, 1699, 14512, 16948, 11722, 5318, 12208, 13514, 1412, 17937, 3888, 20314, 7613, 7449, 13742, 6645, 18336, 2785, 2221, 5940, 16554, 16029, 4426, 8152, 5185, 4152, 5562, 19418, 14131, 1436, 423, 15194, 14920, 5091, 7624, 7776, 10158, 1653, 5637, 19398, 7730, 18862, 14868, 6669, 8671, 4521, 11616, 4395, 15342, 22339, 2155, 428, 14598, 20376, 10603, 19143, 12528, 901, 17547, 20826, 6426, 19818, 21253, 7223, 14919, 15228, 424, 17693, 12532, 16345, 19271, 6382, 8917, 6026, 8812, 17400, 21249, 2296, 12319, 17291, 14442, 21824, 14258, 9313, 2815, 4862, 19616, 10201, 1139, 7197, 7475, 17783, 22048, 1634, 3880, 14031, 4740, 6006, 15880, 10085, 10517, 22327, 19944, 16491, 10966, 4929, 9469, 4606, 14649, 19631, 21817, 17907, 6179, 18483, 20084, 14017, 4208, 11703, 18356, 3104, 745, 19117, 18994, 10891, 14194, 4755, 16229, 10885, 17273, 11215, 9188, 5010, 10107, 6420, 6946, 2900, 15529, 11948, 12901, 21730, 7556, 1457, 2968, 5728, 14915, 10895, 11924, 5934, 7560, 3411, 10866, 2992, 3886, 17939, 11112, 20650, 12863, 5588, 4021, 15566, 9316, 8931, 11462, 4497, 5957, 21536, 4035, 19291, 3534, 832, 20859, 14866, 18864, 9658, 9672, 8056, 5647, 22052, 21072, 6300, 8571, 1896, 15012, 18955, 21018, 19164, 17078, 6391, 21398, 17545, 903, 14483, 13188, 3525, 14364, 11224, 13358, 6199, 8046, 14626, 18108, 6678, 59, 761, 767, 20729, 3653, 3079, 12961, 6933, 14784, 5053, 7863, 13702, 14907, 16520, 21676, 5451, 11064, 6217, 4115, 10618, 18477, 10122, 14905, 13704, 18470, 22176, 10833, 10132, 20835, 12507, 7036, 18571, 17991, 4526, 20894, 8049, 2820, 6759, 16218, 17148, 4294, 1874, 16622, 20301, 18954, 15077, 1897, 2103, 5645, 8058, 6168, 21431, 20737, 11739, 14895, 18238, 8526, 12290, 16583, 13607, 5327, 3310, 14891, 5343, 13274, 17820, 12983, 11257, 4553, 21016, 18957, 19674, 21470, 13811, 2322, 16829, 2977, 11991, 1916, 18034, 17331, 7830, 14875, 7846, 15541, 6667, 14870, 1434, 14133, 8280, 194, 11890, 16896, 18416, 7967, 8647, 5256, 3065, 7059, 9058, 19528, 16457, 14835, 20938, 5750, 16400, 20087, 21703, 7585, 2278, 14795, 21547, 14779, 7147, 8652, 9285, 7661, 14715, 14695, 773, 9474, 5842, 14555, 13172, 14395, 12214, 13995, 13435, 11195, 4, 16795, 15995, 15675, 3446, 15395, 7072, 5090, 15227, 15195, 7224, 4611, 10894, 15115, 5729, 8276, 11882, 6460, 10993, 22006, 16519, 15045, 13703, 15035, 10123, 18562, 16440, 17750, 1845, 6871, 13288, 18819, 18237, 15003, 11740, 11619, 5342, 14995, 3311, 10058, 11104, 18600, 6877, 11541, 13806, 12349, 16754, 2997, 8803, 8322, 3115, 728, 7845, 14975, 7831, 14164, 266, 1433, 14971, 6668, 15217, 18863, 15088, 20860, 22276, 8569, 6302, 18069, 16057, 18409, 20588, 1989, 10629, 2749, 14761, 5252, 2641, 11100, 3050, 7057, 3067, 15326, 14324, 10480, 21861, 3762, 14352, 19059, 170, 14622, 662, 7274, 20937, 14955, 16458, 7282, 18983, 13727, 8502, 2180, 4018, 10239, 12327, 16397, 6797, 20904, 8073, 13978, 4617, 10036, 1151, 15487, 3456, 462, 4897, 1360, 13025, 12914, 14634, 689, 7444, 20116, 5553, 16764, 16269, 15901, 20147, 2287, 4770, 4560, 6243, 19721, 21546, 14947, 2279, 9542, 9691, 19729, 1188, 15589, 18084, 14101, 21553, 5052, 15049, 6934, 11120, 2078, 7146, 14945, 21548, 16523, 11270, 12024, 13542, 11677, 17952, 8113, 17301, 7168, 14618, 19570, 20369, 21341, 15761, 21444, 5251, 14854, 2750, 1720, 1447, 12242, 5458, 2886, 20337, 10260, 20191, 9050, 18709, 2623, 3519, 3088, 9334, 19013, 18343, 9787, 2164, 18368, 15536, 750, 13765, 8934, 2601, 13397, 8220, 13107, 7452, 7679, 16258, 16139, 17884, 11975, 18113, 6131, 6101, 16976, 13602, 109, 13149, 1962, 9440, 4345, 14694, 14940, 7662, 6136, 22185, 13154, 3146, 5888, 272, 20335, 2888, 19284, 15871, 5665, 15401, 19667, 20823, 359, 1686, 2937, 772, 14939, 14716, 4346, 15381, 18461, 16348, 19866, 1678, 3805, 155, 18926, 6813, 15912, 9727, 20853, 9829, 20566, 9989, 12028, 18251, 22009, 764, 22012, 14181, 22363, 19994, 7858, 12759, 2143, 15706, 3884, 2994, 7174, 3532, 19293, 10070, 4518, 19355, 5585, 21515, 4015, 19889, 20630, 19583, 4603, 19630, 15151, 4607, 21941, 14382, 13620, 316, 498, 5892, 19197, 9501, 2658, 1055, 1615, 21575, 688, 14810, 12915, 4182, 3691, 18189, 10249, 14539, 18107, 15060, 8047, 20896, 661, 14839, 171, 2228, 19569, 14768, 7169, 12236, 6361, 6412, 6368, 2502, 1765, 14350, 3764, 234, 11963, 1344, 10781, 5593, 9430, 15462, 12747, 7889, 20375, 15207, 429, 20775, 19414, 10404, 20144, 2553, 5466, 17252, 17927, 19870, 6539, 16767, 3414, 19986, 20382, 1919, 8403, 1758, 15961, 21902, 872, 10042, 5641, 18769, 13423, 14286, 9254, 15456, 9701, 8452, 5764, 11248, 20687, 5061, 7417, 7519, 8230, 5310, 5235, 21606, 16945, 13171, 14935, 5843, 8333, 13507, 9713, 11088, 21664, 7517, 7419, 6853, 332, 8837, 15942, 17369, 5223, 18106, 14628, 10250, 9747, 2398, 7724, 9635, 7987, 8174, 17339, 7346, 8692, 18887, 6603, 17476, 16785, 16965, 13756, 11720, 16950, 8537, 14278, 5094, 20015, 3404, 4100, 13169, 16947, 15257, 1700, 1464, 12834, 20350, 22020, 21367, 9645, 7793, 2019, 13166, 16541, 18332, 9093, 12558, 15384, 11982, 1155, 1960, 13151, 5355, 19303, 13061, 13439, 21375, 11484, 13196, 12577, 13187, 15068, 904, 8894, 5528, 17658, 15978, 19928, 22293, 5714, 2843, 14147, 9978, 1225, 12084, 11229, 20722, 17134, 11140, 17350, 13696, 3257, 12789, 8194, 11826, 8827, 21424, 15377, 5579, 9257, 4218, 10380, 2226, 173, 21487, 13501, 21786, 18655, 8063, 18794, 17245, 21823, 15179, 17292, 18678, 1389, 8449, 8766, 2942, 20985, 13650, 17736, 20392, 4068, 1978, 285, 10294, 3976, 7430, 13747, 19225, 16233, 4718, 10049, 2453, 11768, 22041, 2497, 13928, 6791, 1278, 8184, 15627, 17934, 17957, 8006, 8507, 12757, 7860, 14220, 9467, 4931, 6836, 13546, 10695, 10985, 19521, 3583, 12213, 14933, 13173, 18781, 20402, 11766, 2455, 1288, 4435, 7984, 13887, 784, 21679, 13619, 14646, 21942, 6834, 4933, 14309, 12821, 2082, 17091, 378, 1009, 6615, 3898, 3236, 10983, 10697, 21315, 439, 11223, 15065, 3526, 1253, 20195, 21302, 5389, 3783, 20132, 6078, 18057, 19598, 19058, 14842, 3763, 14610, 1766, 16193, 7332, 7768, 1498, 7371, 19574, 1083, 21566, 1739, 6118, 12720, 7309, 16747, 7385, 16226, 19847, 8249, 3737, 7947, 3600, 9400, 22181, 11624, 10479, 14846, 15327, 1552, 1488, 7571, 8416, 17048, 9121, 19101, 19800, 13924, 7121, 17318, 8984, 12820, 14378, 4934, 2920, 18950, 8227, 22129, 21282, 4565, 21000, 9290, 2029, 3423, 19070, 16089, 4326, 18568, 18668, 20703, 18586, 22240, 1040, 3253, 9253, 14572, 13424, 8874, 10491, 12588, 4440, 7622, 5093, 14519, 8538, 15939, 5336, 15742, 2723, 18446, 3941, 19467, 21543, 2352, 22155, 5410, 20783, 7034, 12509, 12199, 13836, 12196, 9312, 15177, 21825, 21404, 6286, 21905, 16634, 12129, 17224, 11191, 4978, 21273, 11558, 12263, 10563, 17844, 8659, 17966, 7157, 17209, 6963, 4996, 13658, 443, 6320, 4505, 3511, 9026, 5085, 6061, 9681, 16701, 19359, 10171, 8777, 20421, 16244, 12660, 9466, 14405, 7861, 5055, 4901, 2830, 4678, 20062, 9068, 11358, 11852, 21114, 7980, 6767, 12076, 5622, 5542, 19682, 17566, 299, 19098, 9603, 7932, 10568, 8441, 20690, 4754, 15135, 10892, 4613, 15782, 14123, 18041, 4578, 13643, 926, 1477, 13949, 17335, 22362, 14672, 22013, 21386, 6775, 21190, 13761, 20678, 8995, 7659, 9287, 5786, 16654, 404, 11918, 3442, 8088, 265, 14873, 7832, 17084, 10360, 69, 651, 1309, 5681, 3364, 3350, 18122, 12910, 4808, 18849, 20781, 5412, 9977, 14473, 2844, 2545, 8061, 18657, 6892, 18894, 7026, 13116, 9813, 11404, 21158, 9663, 8279, 14969, 1435, 15231, 19419, 21617, 16694, 21265, 10243, 9264, 18040, 14190, 15783, 12990, 4313, 4529, 16663, 7480, 10512, 12729, 8259, 7425, 22200, 1526, 18534, 19978, 6015, 21038, 4884, 17107, 5515, 8999, 21552, 14787, 18085, 28, 2401, 9365, 3005, 3288, 21569, 3298, 8604, 6089, 3580, 5950, 19612, 19154, 4263, 2187, 18697, 1087, 18644, 4185, 20606, 9272, 6742, 11968, 973, 20529, 6195, 20481, 13589, 7514, 19279, 17450, 2005, 18328, 10820, 21588, 12522, 5547, 17981, 16549, 7840, 8887, 2325, 10220, 2217, 6385, 11841, 6558, 19624, 18266, 13784, 9448, 11489, 16862, 1549, 2257, 2879, 16280, 16329, 3559, 9848, 17516, 21998, 6725, 2619, 21615, 19421, 11680, 4739, 15164, 3881, 8408, 9352, 1417, 13070, 20219, 15352, 3851, 12090, 1967, 21710, 16113, 4207, 15144, 20085, 16402, 3307, 6353, 506, 11286, 12249, 15613, 666, 6020, 10011, 11051, 5193, 735, 12675, 13933, 15735, 16987, 10663, 20669, 13434, 14931, 12215, 18857, 21563, 20473, 7812, 20636, 16320, 6685, 18511, 8364, 13042, 3846, 3140, 1364, 4188, 4616, 14821, 8074, 5346, 20881, 4584, 11134, 17842, 10565, 13568, 2654, 16462, 6018, 668, 19812, 12044, 952, 21805, 19298, 6568, 11235, 3970, 17943, 17203, 10330, 17995, 11824, 8196, 1704, 17334, 14184, 1478, 20772, 5783, 21003, 7955, 13628, 12691, 7825, 16630, 5214, 19709, 912, 8816, 2458, 15734, 14001, 12676, 10740, 16912, 6790, 14416, 2498, 4923, 7120, 14314, 19801, 22125, 20962, 15671, 15759, 21343, 5322, 21581, 5503, 11936, 11961, 236, 16985, 15737, 11958, 5831, 22297, 21202, 10190, 17583, 3546, 5906, 6140, 16963, 16787, 5376, 19490, 5127, 10597, 21757, 1450, 8665, 7563, 20214, 3211, 783, 14386, 7985, 9637, 5404, 11732, 2840, 5923, 656, 9525, 3554, 19602, 15874, 17765, 16212, 3912, 5491, 6347, 12815, 5560, 4154, 7392, 10104, 18721, 6158, 17677, 11207, 3896, 6617, 4824, 20049, 5442, 7873, 8116, 6455, 9614, 18273, 6728, 1676, 19868, 17929, 16035, 12124, 9419, 17030, 1397, 16078, 1669, 5261, 16575, 9338, 12195, 14261, 12200, 18559, 13377, 17184, 4973, 898, 18977, 2409, 10756, 3339, 116, 7530, 16092, 7314, 20498, 18466, 12347, 13808, 20666, 12515, 10506, 20818, 10621, 2321, 14984, 21471, 20665, 13818, 12348, 14884, 11542, 21456, 5486, 21842, 18029, 12450, 9194, 10764, 10484, 10277, 20199, 1238, 1467, 22103, 16873, 19094, 8301, 16305, 5723, 1164, 9447, 14050, 18267, 16122, 20525, 14, 4800, 18246, 20713, 18590, 2376, 18991, 21662, 11090, 6263, 15897, 13218, 4137, 11460, 8933, 14738, 751, 11600, 20677, 14176, 21191, 16590, 17711, 11719, 14523, 16966, 5219, 18639, 22208, 9301, 19586, 1830, 19224, 14425, 7431, 17138, 3152, 6644, 15245, 7450, 13109, 12119, 18053, 17474, 6605, 4548, 8150, 4428, 4730, 2563, 5401, 20942, 8501, 14831, 18984, 16419, 9799, 15723, 7178, 17873, 3040, 20559, 112, 17395, 8737, 13208, 18065, 3827, 17256, 22018, 20352, 1770, 15701, 166, 17672, 18469, 15034, 14906, 15046, 7864, 3507, 11239, 12613, 3256, 14464, 17351, 6084, 4768, 2289, 4893, 7095, 9173, 18258, 20486, 4633, 6106, 6401, 1793, 11978, 9545, 9071, 19853, 19861, 15658, 18685, 1591, 959, 6773, 21388, 18397, 18934, 13662, 6225, 18386, 6901, 10972, 10922, 6224, 13669, 18935, 21933, 442, 14237, 4997, 8677, 9186, 11217, 3647, 4533, 17735, 14434, 20986, 18871, 5657, 10111, 2717, 925, 14187, 4579, 9376, 21187, 17130, 5820, 1891, 6325, 2696, 791, 13363, 16076, 1399, 3203, 12690, 13943, 7956, 19452, 18538, 310, 9464, 12662, 315, 14645, 14383, 21680, 12221, 8168, 1973, 16242, 20423, 11755, 16290, 5419, 21798, 5326, 14998, 16584, 13351, 3591, 108, 14722, 16977, 5912, 16390, 18173, 12015, 5166, 10452, 16144, 18608, 2263, 19395, 7513, 14072, 20482, 21830, 9142, 4707, 2566, 639, 16366, 7208, 4994, 6965, 21480, 8457, 19936, 21107, 10064, 5998, 19470, 15678, 18227, 2653, 13970, 10566, 7934, 970, 11336, 12831, 1241, 5072, 22212, 15388, 10355, 22060, 7849, 6452, 17059, 19760, 4887, 10595, 5129, 18285, 21635, 10694, 14401, 6837, 3182, 11676, 14774, 12025, 18317, 13297, 15526, 17269, 20028, 6038, 11242, 18300, 19837, 3991, 8872, 13426, 2085, 11074, 21748, 17483, 4003, 17012, 18401, 8863, 8968, 8109, 11903, 18706, 16098, 1411, 15252, 12209, 18582, 4693, 17035, 5675, 9712, 14552, 8334, 20069, 5566, 9170, 21785, 14449, 21488, 7912, 16866, 16776, 19797, 20658, 6979, 79, 1986, 2426, 12102, 19960, 5556, 18907, 18749, 5984, 1944, 18235, 18821, 4637, 707, 19606, 20174, 16010, 7206, 16368, 19010, 19638, 124, 1266, 5078, 15554, 19213, 1855, 18120, 3352, 9935, 13076, 7295, 10932, 8627, 7656, 19793, 838, 17343, 6926, 19228, 20333, 274, 12505, 20837, 7019, 12641, 11000, 11627, 11911, 534, 4237, 2100, 3318, 21374, 14489, 13062, 3199, 11194, 14930, 13996, 20670, 6221, 12657, 10397, 15607, 17089, 2084, 13529, 8873, 14285, 14573, 18770, 16871, 22105, 2429, 11451, 21429, 6170, 19566, 15965, 2577, 9299, 22210, 5074, 8082, 9574, 1880, 21333, 3367, 17432, 13051, 16661, 4531, 3649, 1714, 8219, 14735, 2602, 16877, 8290, 842, 720, 2210, 2849, 16530, 11761, 9584, 19232, 21507, 4080, 4343, 9442, 22310, 10230, 12502, 17183, 13833, 18560, 10125, 19266, 3864, 16407, 20451, 16726, 6994, 18881, 8161, 17309, 21948, 16075, 13633, 792, 12187, 17357, 6198, 15063, 11225, 1520, 18725, 6861, 9055, 3590, 13605, 16585, 2690, 17740, 13193, 17444, 1731, 2201, 7642, 3685, 6297, 11946, 15531, 9040, 18804, 15333, 7435, 2866, 18682, 15692, 18967, 9373, 22350, 4371, 15918, 2330, 8180, 11036, 12847, 8713, 2541, 892, 21163, 4761, 4230, 19434, 4197, 1069, 2704, 21921, 4242, 10733, 16414, 21655, 20233, 17589, 6516, 2349, 19724, 12906, 4060, 7894, 9836, 15525, 13539, 18318, 2135, 16478, 4743, 18182, 9168, 5568, 18818, 14898, 6872, 11885, 1577, 1862, 16200, 12042, 19814, 13096, 17645, 1507, 12453, 20007, 17819, 14993, 5344, 8076, 3293, 12792, 3361, 2860, 15433, 11751, 526, 4046, 3815, 11893, 11671, 5535, 17219, 11020, 6445, 17081, 17160, 21233, 12435, 562, 8807, 17687, 121, 18692, 10686, 6638, 2515, 21200, 22299, 5113, 9321, 2176, 16538, 4103, 20543, 4376, 2412, 17705, 18126, 23, 1949, 6470, 18382, 756, 11701, 4210, 9102, 16826, 8890, 609, 15297, 8704, 4136, 13769, 15898, 11482, 21377, 16188, 20682, 12999, 2274, 16298, 18064, 13715, 8738, 11177, 7264, 17384, 20640, 9452, 20884, 9942, 8594, 11630, 12576, 14486, 11485, 17443, 13347, 17741, 17284, 1405, 3524, 15067, 14484, 12578, 10991, 6462, 12535, 3621, 5524, 3873, 16022, 227, 18842, 11024, 3266, 18780, 14394, 14934, 14556, 16946, 14514, 4101, 16540, 14502, 2020, 20298, 19665, 15403, 6247, 3787, 20093, 17375, 435, 21415, 3145, 14711, 22186, 5354, 14493, 1961, 14720, 110, 20561, 3171, 6350, 5330, 17020, 9778, 19139, 8106, 7822, 6938, 16813, 7938, 18176, 21219, 9650, 11049, 10013, 12149, 8268, 4354, 9593, 19340, 4831, 5879, 21776, 1786, 8314, 15652, 5574, 10844, 9812, 14139, 7027, 12770, 17117, 2146, 11907, 12118, 13740, 7451, 14733, 8221, 16608, 1392, 8093, 20365, 13010, 3377, 307, 3357, 17644, 13280, 19815, 8981, 184, 8642, 2808, 17792, 12495, 17870, 10779, 1346, 19748, 9770, 9882, 10196, 8134, 7217, 19579, 6826, 7294, 13463, 9936, 162, 17279, 9152, 20218, 14026, 1418, 12366, 815, 21871, 15891, 16499, 3198, 13438, 14490, 19304, 7647, 3381, 2757, 5817, 8555, 10199, 19618, 16660, 13403, 17433, 22253, 10873, 22150, 1024, 12750, 16617, 3845, 13984, 8365, 20977, 12591, 15285, 4259, 12362, 2315, 592, 12370, 17055, 6653, 18075, 19991, 8296, 19389, 12913, 14812, 1361, 6155, 19068, 3425, 9063, 44, 17813, 8752, 1207, 16568, 19386, 19107, 22318, 3376, 13101, 20366, 15637, 11045, 2680, 261, 20763, 15860, 15999, 2948, 2273, 13212, 20683, 1798, 6266, 10297, 18792, 8065, 213, 4312, 14121, 15784, 2032, 16652, 5788, 3062, 11256, 14991, 17821, 1124, 15600, 21117, 21110, 17324, 19693, 10268, 8548, 5364, 21938, 348, 9975, 5414, 16483, 2113, 659, 20898, 16799, 7790, 6932, 15051, 3080, 6334, 3986, 17489, 6173, 5247, 20430, 7675, 18049, 9011, 84, 15729, 6035, 21228, 8608, 8344, 10905, 21892, 1752, 9191, 1510, 17811, 46, 12171, 20178, 6093, 4331, 11593, 9916, 72, 22082, 8770, 9732, 8172, 7989, 17463, 7240, 17788, 2765, 16692, 21619, 7456, 16552, 5942, 4181, 14633, 14811, 13026, 19390, 4807, 14153, 18123, 15746, 4059, 13302, 19725, 17127, 6778, 21729, 15121, 11949, 2513, 6640, 17237, 6549, 614, 12875, 3195, 7753, 19736, 11927, 6629, 12047, 5511, 15295, 611, 3630, 625, 3083, 16118, 12470, 20276, 5920, 5717, 3194, 12894, 615, 20609, 4538, 5918, 20278, 21736, 8514, 18840, 229, 21513, 5587, 15103, 20651, 11442, 19350, 10082, 15546, 12609, 10053, 4490, 3797, 9909, 20113, 7600, 12703, 10414, 8712, 13323, 11037, 5794, 21794, 3190, 16153, 3473, 5798, 18759, 10020, 16250, 11316, 20349, 14509, 1465, 1240, 13563, 11337, 3958, 200, 12429, 11674, 3184, 5002, 18503, 2081, 14377, 14310, 8985, 20514, 10440, 5559, 13870, 6348, 3173, 5351, 2747, 10631, 9006, 3162, 4881, 947, 17144, 1965, 12092, 1563, 18038, 9266, 3054, 2986, 2799, 22385, 3734, 15503, 3360, 13270, 3294, 8193, 14462, 3258, 4696, 17849, 20919, 21313, 10699, 12697, 18732, 15937, 8540, 4121, 3224, 1773, 11810, 18148, 20013, 5096, 17116, 13114, 7028, 20440, 12305, 5572, 15654, 12050, 18790, 10299, 20832, 2142, 14668, 7859, 14407, 8508, 16990, 1453, 16645, 21298, 16616, 13045, 1025, 7888, 14601, 15463, 11511, 1173, 9260, 11345, 15803, 7102, 11084, 9842, 1251, 3528, 7307, 12722, 3207, 15830, 1234, 8258, 14115, 10513, 3578, 6091, 20180, 19365, 3206, 12734, 7308, 14338, 6119, 21899, 2232, 5048, 15469, 3557, 16331, 8164, 5693, 19337, 19409, 12489, 253, 179, 7007, 10413, 12850, 7601, 2665, 11647, 6573, 18731, 12782, 10700, 17603, 11118, 6936, 7824, 13942, 13629, 3204, 19367, 2675, 3233, 1588, 11268, 16525, 16717, 8885, 7842, 11306, 12160, 10739, 13932, 14002, 736, 2162, 9789, 3767, 3610, 1993, 12585, 6480, 7711, 1541, 3373, 314, 13622, 9465, 14222, 16245, 10396, 13431, 6222, 10924, 10847, 516, 19746, 1348, 1580, 18014, 11640, 12142, 7856, 19996, 21402, 21827, 10999, 13448, 7020, 7118, 4925, 11418, 10166, 4515, 20811, 4381, 15989, 10498, 10724, 4276, 11873, 10363, 4144, 11365, 2644, 9309, 12512, 10666, 4421, 12137, 5900, 11429, 5372, 9251, 3255, 13698, 11240, 6040, 10052, 12857, 15547, 4049, 7650, 20230, 9721, 18627, 22161, 15481, 3790, 18736, 21713, 10537, 22376, 5973, 8669, 6671, 15284, 13039, 20978, 4439, 14282, 10492, 6479, 12668, 1994, 11467, 11548, 9276, 8255, 10990, 13186, 14485, 13197, 11631, 6763, 22148, 10875, 7128, 21259, 10703, 20188, 19974, 10285, 1539, 7713, 1828, 19588, 11537, 18459, 15383, 14498, 9094, 6869, 1847, 20223, 12158, 11308, 9655, 21143, 15952, 4234, 16158, 18833, 8353, 4878, 2063, 16684, 4306, 22367, 935, 16909, 11802, 3620, 13183, 6463, 16344, 15191, 17694, 18975, 900, 15203, 19144, 4043, 6886, 20933, 5546, 14064, 21589, 21360, 19700, 2856, 22197, 10505, 13816, 20667, 10665, 12622, 9310, 12198, 14263, 7035, 15028, 20836, 13451, 275, 17182, 13379, 10231, 11656, 17166, 12061, 4400, 17869, 13089, 17793, 6581, 16939, 18898, 252, 12708, 19410, 21056, 20699, 18595, 9540, 2281, 10957, 20797, 1196, 4776, 10799, 9461, 22322, 21744, 17721, 10929, 17898, 20275, 12880, 16119, 5689, 1781, 17427, 9930, 4965, 9928, 17429, 11378, 12087, 19040, 8929, 9318, 22232, 19999, 20006, 13277, 1508, 9193, 13800, 18030, 15477, 6832, 21944, 5462, 21692, 17524, 20792, 17912, 5601, 10336, 15268, 21670, 561, 13253, 21234, 18716, 10902, 5533, 11673, 12827, 201, 10919, 12230, 5478, 2573, 1142, 20099, 129, 11805, 22044, 9423, 16980, 8245, 7921, 21169, 20579, 11284, 508, 21820, 4590, 18788, 12052, 4407, 1826, 7715, 10366, 4078, 21509, 15564, 4023, 6859, 18727, 57, 6680, 1983, 19875, 20800, 21436, 4785, 18233, 1946, 21461, 19239, 15751, 5158, 16372, 8387, 11343, 9262, 10245, 10320, 18902, 17798, 22354, 3633, 9555, 6144, 17054, 13033, 593, 17069, 814, 13068, 1419, 1075, 2314, 13036, 4260, 11413, 20437, 17775, 7574, 21243, 20150, 1181, 2334, 21520, 7817, 16753, 14883, 13807, 13819, 18467, 17674, 7972, 19941, 16352, 9783, 9537, 17904, 511, 21911, 19081, 7504, 11290, 4030, 5897, 1274, 1285, 8819, 16396, 14826, 10240, 5755, 3099, 7733, 17876, 1584, 17290, 15181, 2297, 20034, 21, 18128, 20208, 20557, 3042, 9534, 6848, 6512, 7233, 11877, 5571, 12767, 20441, 10210, 6057, 4390, 21276, 986, 4839, 15281, 3463, 16063, 17924, 17195, 420, 16582, 15000, 8527, 3673, 17382, 7266, 15974, 4088, 16735, 8747, 19677, 11181, 6951, 7092, 2954, 18171, 16392, 853, 22288, 3915, 7357, 7489, 3832, 9018, 3128, 20267, 20506, 10562, 14246, 11559, 7363, 1559, 20253, 21042, 20534, 6489, 19843, 10556, 1315, 10576, 19122, 15612, 14010, 11287, 3795, 4492, 3247, 18352, 5457, 14757, 1448, 21759, 22145, 4462, 6360, 14616, 7170, 20741, 12066, 19062, 5477, 12426, 10920, 10974, 9757, 17879, 15371, 15277, 3033, 8167, 13617, 21681, 21100, 19115, 747, 18856, 13994, 14932, 14396, 3584, 6843, 18581, 13513, 15253, 5319, 3938, 15587, 1190, 8488, 4811, 18558, 13835, 14262, 12510, 9311, 14260, 13837, 9339, 2776, 7221, 21255, 18786, 4592, 17356, 13361, 793, 6468, 1951, 10090, 16337, 17559, 21026, 1790, 11898, 7046, 6596, 4303, 20067, 8336, 20177, 12937, 47, 2384, 4576, 18043, 6537, 19872, 82, 9013, 9892, 10738, 12678, 11307, 12553, 20224, 16803, 18374, 7566, 10067, 16639, 1127, 8267, 13130, 10014, 12074, 6769, 4203, 7764, 7855, 12647, 11641, 4249, 1272, 5899, 12619, 4422, 1516, 2055, 7640, 2203, 2421, 17223, 14252, 16635, 4176, 2699, 9418, 13846, 16036, 11009, 18311, 18052, 13739, 13110, 11908, 8597, 2195, 20159, 17347, 18491, 5106, 2734, 2418, 9827, 20855, 21358, 21591, 2493, 19959, 13490, 2427, 22107, 7965, 18418, 16126, 9398, 3602, 9631, 1562, 12803, 1966, 14022, 3852, 19039, 12460, 11379, 11228, 14470, 1226, 6449, 5026, 3321, 6306, 5005, 5621, 14207, 6768, 12147, 10015, 3492, 10614, 17214, 17670, 168, 19061, 12233, 20742, 5189, 8438, 4399, 12498, 17167, 19757, 16791, 9954, 7126, 10877, 17261, 4406, 12407, 18789, 12764, 15655, 5510, 12888, 6630, 951, 13964, 19813, 13282, 16201, 22100, 7004, 8835, 334, 17231, 6984, 5308, 8232, 22325, 10519, 9766, 18250, 14677, 9990, 18316, 13541, 14775, 11271, 20317, 12018, 10374, 10373, 12021, 20318, 5165, 13597, 18174, 7940, 20168, 18777, 5671, 2371, 4195, 19436, 10830, 15593, 20756, 2111, 16485, 16255, 210, 10771, 6147, 9735, 8963, 6787, 19823, 5033, 1915, 14980, 2978, 7799, 2250, 19517, 2908, 3721, 1380, 1154, 14496, 15385, 9689, 9544, 13682, 1794, 18112, 14727, 17885, 20460, 6252, 4511, 11334, 972, 14077, 6743, 15423, 20571, 1343, 14607, 235, 13913, 11937, 5830, 13909, 15738, 4320, 370, 1878, 9576, 16835, 3488, 2512, 12900, 15122, 15530, 13340, 6298, 21074, 11189, 17226, 8798, 6250, 20462, 5829, 11960, 13914, 5504, 1853, 19215, 16760, 10945, 21812, 2477, 6628, 12890, 19737, 5933, 15113, 10896, 11590, 5394, 2090, 3441, 14168, 405, 11391, 10768, 8068, 7548, 533, 13445, 11628, 8596, 12117, 13111, 2147, 3746, 18705, 13518, 8110, 9806, 15915, 7045, 12178, 1791, 6403, 9762, 11670, 13262, 3816, 16895, 14966, 195, 9877, 8578, 1576, 13286, 6873, 6459, 14912, 8277, 9665, 18816, 5570, 12307, 7234, 67, 10362, 12628, 4277, 3719, 2910, 3780, 6820, 18752, 21790, 5963, 3389, 21065, 17648, 4213, 21059, 19384, 16570, 679, 9796, 18, 21149, 21113, 14211, 11359, 1303, 21740, 21086, 328, 19048, 6941, 1073, 1421, 6557, 14054, 6386, 17635, 2549, 10139, 21079, 6436, 18827, 2270, 1886, 10129, 8148, 4550, 8422, 8826, 14460, 8195, 13953, 17996, 7053, 19685, 2443, 4713, 21077, 10141, 3272, 5196, 21975, 3070, 11533, 18147, 12775, 1774, 19957, 2495, 22043, 12420, 130, 3619, 12537, 16910, 10742, 17505, 8842, 17265, 8498, 637, 2568, 17362, 189, 2016, 7188, 3251, 1042, 4665, 17910, 20794, 19000, 18517, 632, 250, 18900, 10322, 5180, 136, 18277, 7355, 3917, 1574, 8580, 20073, 17824, 22040, 14419, 2454, 14391, 20403, 7537, 19645, 9583, 13388, 16531, 10888, 3570, 17758, 16289, 13612, 20424, 685, 525, 13266, 15434, 11389, 407, 3743, 17380, 3675, 11493, 11555, 4393, 11618, 14894, 15004, 20738, 16758, 19217, 16051, 4625, 2839, 13883, 5405, 8395, 1725, 9880, 9772, 17973, 15698, 3227, 5317, 15255, 16949, 14522, 13757, 17712, 1184, 6186, 19110, 3073, 1605, 5387, 21304, 3751, 15773, 3700, 9146, 15756, 15809, 18355, 15142, 4209, 13227, 757, 8846, 7993, 11409, 8025, 1079, 9610, 9697, 4791, 1133, 9824, 2206, 11299, 15362, 4621, 18473, 3951, 18664, 1546, 4738, 14033, 19422, 17951, 14773, 13543, 3183, 12826, 12430, 5534, 13261, 11894, 9763, 18118, 1857, 15906, 21699, 11424, 22344, 20011, 18150, 9083, 5980, 5435, 17165, 12500, 10232, 9716, 8462, 5482, 10593, 4889, 15885, 6572, 12700, 2666, 5268, 2803, 10858, 4248, 12141, 12648, 18015, 19983, 8566, 19055, 15473, 20396, 17724, 6762, 12575, 13198, 8595, 11910, 13446, 11001, 10478, 14326, 22182, 10394, 16247, 5341, 14893, 11741, 4394, 15213, 4522, 9306, 21048, 7788, 16801, 20226, 18918, 16597, 601, 16432, 15513, 21348, 2342, 16953, 20676, 13763, 752, 19743, 20575, 20038, 17616, 9915, 12933, 4332, 5393, 11922, 10897, 6378, 6423, 4255, 16715, 16527, 18945, 7000, 5475, 19064, 1523, 6956, 1531, 119, 17689, 4064, 8327, 806, 7086, 15318, 15840, 6209, 21697, 15908, 18169, 2956, 10387, 6801, 216, 7362, 12262, 14247, 21274, 4392, 11743, 11494, 16017, 20345, 4675, 16818, 9275, 12582, 11468, 9739, 21878, 21651, 21455, 13805, 14885, 6878, 1047, 18458, 12561, 19589, 10750, 18146, 11812, 3071, 19112, 5540, 5624, 18981, 7284, 19402, 4227, 5368, 19786, 2615, 139, 9345, 244, 9821, 15266, 10338, 5133, 16997, 20305, 1172, 12745, 15464, 6163, 7261, 5121, 5861, 10634, 18824, 3398, 7257, 8200, 17781, 7477, 7279, 10470, 10804, 16016, 11554, 11744, 3676, 9961, 16861, 14048, 9449, 502, 17442, 13195, 14487, 21376, 13216, 15899, 16271, 19499, 3819, 4112, 20950, 22191, 9966, 10164, 11420, 8729, 16170, 9738, 11547, 12583, 1995, 4671, 9920, 4496, 15097, 8932, 13767, 4138, 1371, 18653, 21788, 18754, 2914, 1485, 21428, 13418, 2430, 5632, 10462, 582, 18892, 6894, 16602, 19349, 12861, 20652, 16277, 555, 16180, 20111, 9911, 1597, 3395, 6439, 18161, 2961, 5371, 12617, 5901, 7238, 17465, 22343, 11664, 21700, 15491, 8728, 11472, 10165, 12637, 4926, 52, 20240, 20436, 12360, 4261, 19156, 8024, 11697, 7994, 2873, 2192, 21157, 14137, 9814, 9208, 15932, 7483, 388, 5946, 4133, 1909, 565, 9751, 8946, 10767, 11916, 406, 11749, 15435, 20864, 16425, 6356, 10271, 4083, 2053, 1518, 11227, 12086, 12461, 17430, 3369, 19256, 5173, 9135, 15949, 21173, 3550, 9217, 19128, 11098, 2643, 12625, 4145, 1682, 6698, 7079, 1302, 11851, 14212, 9069, 9547, 16600, 6896, 2934, 22248, 4856, 6711, 6755, 9386, 19714, 15802, 12742, 9261, 12381, 8388, 17201, 17945, 20585, 3957, 12830, 13564, 971, 11970, 4512, 7024, 18896, 16941, 7352, 16177, 19132, 5361, 20998, 4567, 355, 2588, 1170, 20307, 8866, 646, 20348, 12836, 16251, 5432, 6824, 19581, 20632, 15290, 9654, 12552, 12159, 12679, 7843, 730, 8621, 16131, 1608, 15361, 11688, 2207, 21835, 3264, 11026, 19751, 7542, 19344, 4029, 12334, 7505, 3794, 12248, 14011, 507, 12412, 20580, 4453, 7288, 1744, 5022, 17172, 3756, 4789, 9699, 15458, 7611, 20316, 12023, 14776, 16524, 12684, 1589, 18687, 5231, 1162, 5725, 4445, 1216, 17808, 8420, 4552, 14990, 12984, 3063, 5258, 7927, 5044, 3904, 4814, 20686, 14566, 5765, 15833, 2771, 16971, 18299, 13534, 6039, 12612, 13699, 3508, 1936, 3969, 13959, 6569, 15644, 3470, 1299, 20721, 14469, 12085, 11380, 1519, 13357, 15064, 14365, 440, 21935, 4765, 3484, 3646, 13654, 9187, 15130, 17274, 2715, 10113, 15443, 5806, 19705, 3895, 13862, 17678, 1318, 10450, 5168, 8143, 17416, 19193, 8957, 7464, 22390, 3, 14929, 13436, 3200, 4977, 14250, 17225, 11943, 21075, 4715, 8531, 18498, 2688, 16587, 6950, 12280, 19678, 5119, 7263, 13206, 8739, 18747, 18909, 17628, 458, 21953, 8028, 7329, 9036, 20874, 11013, 10308, 7924, 1672, 21094, 18923, 6749, 15824, 8434, 18424, 20457, 18885, 8694, 9781, 16354, 8859, 4094, 5422, 19622, 6560, 16628, 7827, 1707, 17579, 18489, 17349, 14466, 17135, 19330, 9409, 7403, 17841, 13973, 4585, 21177, 17948, 16668, 21231, 17162, 3706, 20804, 9709, 5869, 7617, 10370, 2077, 14782, 6935, 12694, 17604, 18637, 5221, 17371, 20649, 15105, 17940, 1813, 9981, 21886, 8382, 10145, 18599, 14888, 10059, 18364, 3049, 14851, 2642, 11367, 19129, 558, 20186, 10705, 7032, 20785, 6262, 13772, 21663, 14550, 9714, 10234, 9841, 12739, 7103, 1761, 2812, 15569, 16961, 6142, 9557, 2045, 21747, 13527, 2086, 21223, 19805, 22038, 17826, 1395, 17032, 3261, 6216, 15041, 5452, 3497, 15369, 17881, 10423, 21422, 8829, 9563, 18436, 1808, 4448, 5192, 14005, 10012, 13132, 9651, 6591, 2679, 13007, 15638, 15682, 17537, 145, 19459, 15497, 5793, 12846, 13324, 8181, 10542, 21091, 15314, 15695, 20711, 18248, 9768, 19750, 11295, 3265, 13176, 18843, 1220, 6444, 13258, 17220, 3137, 19024, 4963, 9932, 10307, 11166, 20875, 20340, 18310, 12122, 16037, 5968, 1529, 6958, 10644, 21987, 10477, 11626, 13447, 12642, 21828, 20484, 18260, 16447, 22005, 14910, 6461, 13185, 12579, 8256, 1236, 20201, 19520, 14399, 10696, 14369, 3237, 18132, 10033, 1957, 2153, 22341, 17467, 9756, 12228, 10921, 13665, 6902, 693, 10729, 50, 4928, 15155, 16492, 9776, 17022, 19432, 4232, 15954, 18998, 20796, 12482, 2282, 6213, 21838, 6116, 1741, 9532, 3044, 5791, 15499, 3501, 21811, 11931, 16761, 19963, 8975, 965, 20908, 19479, 3639, 605, 3740, 21022, 18255, 8626, 13461, 7296, 17897, 12473, 17722, 20398, 9810, 10846, 12655, 6223, 13664, 10973, 12229, 12427, 202, 1443, 18281, 18574, 2894, 6122, 6494, 9177, 1017, 7906, 9198, 4951, 21891, 12944, 8345, 5532, 12432, 18717, 10649, 10839, 6377, 11589, 11923, 15114, 14916, 4612, 14193, 15136, 18995, 3569, 11759, 16532, 17272, 15132, 16230, 6929, 9648, 21221, 2088, 5396, 17260, 12055, 7127, 12572, 22149, 13048, 22254, 19778, 2607, 17025, 18166, 2991, 15109, 3412, 16769, 16853, 3281, 19322, 10581, 4247, 11643, 2804, 9832, 3935, 21346, 15515, 7508, 8588, 938, 742, 515, 12654, 10925, 9811, 13118, 5575, 17718, 2048, 6376, 10899, 10650, 18001, 1119, 8146, 10131, 15031, 22177, 15592, 12006, 19437, 4224, 6485, 696, 16184, 6553, 7075, 15307, 21587, 14066, 18329, 4704, 22274, 20862, 15437, 20870, 3329, 16918, 15393, 3448, 5866, 5678, 18138, 15970, 16015, 11496, 10471, 17000, 18061, 9460, 12478, 4777, 2355, 1818, 2650, 21641, 8630, 1717, 5440, 20051, 1045, 6880, 5961, 21792, 5796, 3475, 2167, 5592, 14605, 1345, 13087, 17871, 7180, 17999, 10652, 7500, 17052, 6146, 11999, 211, 8067, 11915, 11392, 8947, 10483, 13798, 9195, 9818, 15631, 4669, 1997, 6920, 3338, 13827, 2410, 4378, 9745, 10252, 18145, 11535, 19590, 17125, 19727, 9693, 15821, 6508, 17504, 11800, 16911, 13931, 12677, 12161, 9893, 5228, 16958, 16413, 13310, 4243, 2382, 49, 10969, 694, 6487, 20536, 4275, 12630, 10499, 9132, 16859, 9963, 9567, 19210, 8850, 7620, 4442, 2971, 8360, 17655, 20847, 3729, 18442, 3920, 17772, 7031, 11094, 20187, 12569, 21260, 17602, 12696, 12783, 21314, 14368, 10984, 14400, 13547, 21636, 9166, 18184, 7251, 4038, 6584, 6637, 13247, 18693, 6620, 18642, 1089, 17006, 20788, 19320, 3283, 16207, 21209, 4681, 8636, 7871, 5444, 7138, 17076, 19166, 6695, 4420, 12621, 12513, 20668, 13998, 16988, 8510, 19554, 17768, 6342, 3176, 5635, 1655, 7389, 7499, 10775, 18000, 10838, 10900, 18718, 5013, 18650, 21986, 11004, 6959, 9127, 21868, 21708, 1969, 8781, 6104, 4635, 18823, 11505, 5862, 9005, 12810, 2748, 14856, 1990, 8002, 19939, 7974, 353, 4569, 2320, 13813, 20819, 18476, 15038, 4116, 22257, 17213, 12071, 3493, 22143, 21761, 3876, 3393, 1599, 4483, 17728, 21351, 19142, 15205, 20377, 22204, 5031, 19825, 21756, 13895, 5128, 13551, 4888, 11651, 5483, 9856, 18774, 22263, 9973, 350, 19898, 2436, 20619, 9618, 4246, 10860, 19323, 418, 17197, 19121, 12252, 1316, 17680, 19950, 2708, 15340, 4397, 8440, 14198, 7933, 13567, 13971, 17843, 14245, 12264, 20507, 20123, 3566, 15957, 1314, 12254, 19844, 4758, 16007, 8339, 15836, 20972, 21320, 15452, 3345, 22065, 1307, 653, 21090, 11034, 8182, 1280, 1244, 22375, 12597, 21714, 5823, 3009, 1334, 18180, 4745, 1328, 19004, 16430, 603, 3641, 15573, 18613, 19483, 18674, 18116, 9765, 12031, 22326, 15159, 10086, 16823, 3577, 12728, 14116, 7481, 15934, 15520, 9107, 20817, 13815, 12516, 22198, 7427, 5498, 18577, 9131, 10723, 12631, 15990, 20602, 10215, 15348, 6478, 12587, 14283, 8875, 3688, 18647, 20246, 9282, 10276, 13797, 10765, 8948, 21860, 14845, 14325, 11625, 11002, 21988, 8225, 18952, 20303, 16999, 10803, 11497, 7280, 16460, 2656, 9503, 15765, 19916, 581, 11448, 5633, 3178, 20540, 16889, 8479, 10433, 16564, 1931, 16143, 13595, 5167, 11204, 1319, 16095, 9053, 6863, 7271, 9493, 19881, 18905, 5558, 12817, 20515, 22023, 18073, 6655, 8484, 16563, 10456, 8480, 22158, 7786, 21050, 1822, 6970, 15650, 8316, 21421, 11059, 17882, 16141, 1933, 4508, 7666, 4281, 20599, 8711, 12849, 12704, 7008, 7897, 21239, 21013, 18672, 19485, 2876, 20143, 14594, 19415, 7413, 20478, 17360, 2570, 15606, 13430, 12658, 16246, 11622, 22183, 6138, 5908, 20282, 1637, 6800, 11563, 2957, 18198, 20022, 16722, 3616, 2225, 14453, 4219, 8796, 17228, 2075, 10372, 12020, 12019, 10375, 2076, 11122, 7618, 8852, 4077, 12403, 7716, 4143, 12627, 11874, 68, 14161, 17085, 15409, 5162, 22059, 13558, 15389, 293, 6192, 9111, 2580, 8429, 21442, 15763, 9505, 16883, 6738, 9629, 3604, 9986, 17987, 5132, 11516, 15267, 12439, 5602, 2636, 5226, 9895, 17994, 13955, 17204, 1651, 10160, 3332, 22225, 4723, 5179, 11779, 18901, 12378, 10246, 15625, 8186, 16772, 17388, 16087, 19072, 17367, 15944, 21167, 7923, 11165, 11014, 9933, 3354, 18541, 8371, 20427, 9590, 20831, 12762, 18791, 12995, 6267, 3975, 14428, 286, 19966, 8903, 2434, 19900, 802, 1035, 1538, 12566, 19975, 19659, 17287, 3902, 5046, 2234, 20198, 13796, 10485, 9283, 8654, 4341, 4082, 11384, 6357, 8547, 12975, 19694, 18217, 5758, 8141, 5170, 19972, 20190, 14753, 20338, 20877, 17971, 9774, 16494, 21121, 18144, 10752, 9746, 14538, 14629, 18190, 15624, 10319, 12379, 9263, 14126, 21266, 5754, 12326, 14827, 4019, 5590, 2169, 9840, 11086, 9715, 11655, 12501, 13380, 22311, 2521, 15856, 4350, 17817, 20009, 22346, 9456, 2216, 14057, 2326, 18090, 15797, 15347, 10495, 20603, 1367, 4834, 6056, 12303, 20442, 15925, 21600, 9032, 5037, 17801, 3607, 1138, 15172, 19617, 13054, 8556, 8133, 13082, 9883, 8131, 8558, 3835, 17582, 13905, 21203, 6806, 18455, 17074, 7140, 8880, 3812, 15550, 18809, 7997, 7461, 8399, 3537, 21646, 3278, 1293, 712, 8776, 14226, 19360, 7116, 7022, 4514, 12636, 11419, 11473, 9967, 16916, 3331, 10327, 1652, 15223, 7777, 16033, 17931, 248, 634, 20945, 7636, 16936, 4041, 19146, 17901, 18598, 11106, 8383, 6781, 3271, 11817, 21078, 11837, 2550, 15904, 1859, 1351, 2140, 20834, 15030, 10834, 8147, 11831, 1887, 2126, 19265, 13375, 18561, 14904, 15036, 18478, 105, 21540, 6001, 4222, 19439, 15301, 15442, 11212, 2716, 13646, 5658, 18305, 6419, 15127, 5011, 18720, 13866, 7393, 5811, 21973, 5198, 4469, 6330, 18930, 7112, 17554, 21407, 1117, 18003, 16336, 12183, 1952, 9626, 16822, 10516, 15160, 15881, 15545, 12859, 19351, 1836, 2185, 4265, 22372, 2359, 20096, 7212, 5103, 20809, 4517, 14660, 19294, 16638, 12153, 7567, 5997, 13574, 21108, 21119, 16496, 18363, 11103, 14889, 3312, 482, 21882, 4489, 12856, 12610, 6041, 2452, 14421, 4719, 3926, 8574, 8586, 7510, 5640, 14576, 873, 20059, 21212, 2243, 1150, 14819, 4618, 1956, 10980, 18133, 9357, 20079, 21318, 20974, 9325, 21579, 5324, 21800, 9360, 5339, 16249, 12838, 18760, 39, 4595, 3491, 12073, 12148, 13131, 11050, 14006, 6021, 17235, 6642, 3154, 932, 20447, 4160, 17608, 957, 1593, 2518, 20410, 15713, 22336, 3666, 15534, 18370, 6829, 884, 18315, 12027, 14678, 20567, 17986, 10341, 3605, 17803, 573, 21885, 11109, 1814, 1224, 14472, 14148, 5413, 12970, 349, 10588, 22264, 2294, 21251, 19820, 16915, 10163, 11474, 22192, 9566, 10720, 16860, 11491, 3677, 1159, 9140, 21832, 723, 7125, 12057, 16792, 4481, 1601, 4869, 701, 16931, 449, 15561, 6916, 4363, 8593, 13200, 20885, 9116, 2387, 2394, 161, 13075, 13464, 3353, 10306, 11015, 4964, 12465, 17428, 12463, 4966, 20612, 16704, 6274, 9513, 2118, 4495, 11464, 4672, 649, 71, 12932, 11594, 17617, 21197, 1596, 11436, 20112, 12853, 3798, 1694, 1337, 2983, 9685, 22141, 3495, 5454, 15812, 4600, 9304, 4524, 17993, 10332, 5227, 10737, 12162, 9014, 5211, 22118, 8942, 1557, 7365, 15358, 8130, 10195, 13083, 9771, 11728, 1726, 8577, 11888, 196, 19537, 2693, 1033, 804, 8329, 16847, 1460, 15507, 18350, 3249, 7190, 21493, 3418, 4699, 7202, 6049, 15930, 9210, 18773, 10591, 5484, 21458, 26, 18087, 5709, 20330, 17515, 14040, 3560, 6235, 18159, 6441, 1250, 12738, 11085, 10235, 2170, 20546, 15524, 13299, 7895, 7010, 3934, 10856, 2805, 20565, 14680, 20854, 12108, 2419, 2205, 11690, 1134, 15265, 11518, 245, 15630, 10762, 9196, 7908, 9207, 11403, 14138, 13117, 10845, 10926, 20399, 9725, 15914, 11901, 8111, 17954, 1415, 9354, 7109, 15722, 13724, 16420, 17, 11856, 680, 3657, 18603, 6912, 232, 3766, 12672, 2163, 14743, 18344, 6846, 9536, 12341, 16353, 11153, 8695, 19138, 13142, 17021, 10964, 16493, 10256, 17972, 11727, 9881, 13084, 19749, 11028, 18249, 12030, 10520, 18117, 11669, 11895, 6404, 18012, 1582, 17878, 12227, 10975, 17468, 15275, 15373, 8945, 11394, 566, 991, 2397, 14537, 10251, 10753, 4379, 20813, 21045, 2647, 21877, 11546, 11469, 16171, 8962, 11997, 6148, 8171, 12928, 8771, 22079, 19020, 20852, 14682, 15913, 9808, 20400, 18783, 18626, 12604, 20231, 21657, 8391, 8461, 11654, 10233, 11087, 14551, 13508, 5676, 5868, 11125, 20805, 19160, 19718, 3026, 19189, 8764, 8451, 14569, 15457, 11275, 4790, 11693, 9611, 3662, 15820, 10746, 19728, 14792, 9543, 11980, 15386, 22214, 22140, 9904, 2984, 3056, 16700, 14229, 6062, 18836, 6924, 17345, 20161, 494, 16274, 8055, 15085, 9659, 19187, 3028, 2213, 16302, 18815, 11880, 8278, 14135, 21159, 6563, 19186, 9671, 15086, 18865, 21142, 12551, 11309, 15291, 6590, 11048, 13133, 21220, 10882, 6930, 7792, 14505, 21368, 9348, 5777, 1095, 5748, 20940, 5403, 13885, 7986, 14534, 7725, 20251, 1561, 12094, 3603, 10343, 6739, 16821, 10088, 1953, 15365, 9279, 5277, 17297, 2380, 4245, 10583, 20620, 19169, 18272, 13853, 6456, 3661, 9696, 11694, 1080, 1474, 4544, 17697, 19135, 7931, 14200, 19099, 9123, 19033, 6890, 18659, 8, 19594, 19407, 19339, 13127, 4355, 20830, 10301, 20428, 5249, 21446, 17512, 19231, 13387, 11762, 19646, 17042, 19220, 16045, 8523, 16834, 11953, 1879, 13408, 8083, 8016, 20312, 3890, 17391, 19209, 10719, 9964, 22193, 18435, 11056, 8830, 21153, 20928, 7884, 2044, 11077, 6143, 12373, 3634, 16595, 18920, 6240, 19203, 599, 16599, 11356, 9070, 13681, 11979, 9690, 14793, 2280, 12484, 18596, 17903, 12340, 9784, 6847, 12311, 3043, 10951, 1742, 7290, 16806, 880, 22164, 3553, 13879, 657, 2115, 16475, 17855, 1784, 21778, 9499, 19199, 16676, 16473, 2117, 9923, 6275, 19310, 21768, 18763, 21782, 7098, 16882, 10346, 15764, 10466, 2657, 14640, 19198, 9518, 21779, 15844, 5156, 15753, 19880, 10444, 7272, 664, 15615, 5266, 2668, 9091, 18334, 6647, 4270, 8240, 17586, 3003, 9367, 7582, 7760, 18212, 16451, 5841, 14937, 774, 5701, 19628, 4605, 15153, 4930, 14404, 14221, 12661, 13623, 311, 22321, 12477, 10800, 18062, 16300, 2215, 10222, 22347, 4582, 20883, 13202, 20641, 501, 11488, 14049, 13785, 1165, 16358, 6664, 22309, 13382, 4344, 14718, 1963, 17146, 16220, 4904, 18407, 16059, 19313, 7342, 15461, 14603, 5594, 1495, 21734, 20280, 5910, 16979, 12418, 22045, 455, 17029, 13845, 12125, 2700, 5069, 1283, 1276, 6793, 21269, 4572, 7402, 11137, 19331, 16605, 5741, 20361, 6609, 8272, 18081, 22180, 14328, 3601, 12096, 16127, 20595, 1710, 9181, 20120, 19445, 6394, 6533, 1630, 22132, 19713, 11348, 6756, 2027, 9292, 19017, 75, 3286, 3007, 5825, 21186, 13641, 4580, 22349, 13330, 18968, 3325, 16238, 21032, 7581, 9480, 3004, 14097, 2402, 4318, 15740, 5338, 10023, 21801, 20078, 10031, 18134, 7108, 9802, 1416, 14028, 8409, 18548, 5776, 9643, 21369, 243, 11520, 140, 4960, 8990, 5733, 2775, 12194, 13838, 16576, 19636, 19012, 14746, 3089, 7903, 8955, 19195, 5894, 6502, 522, 21578, 10027, 20975, 8367, 2175, 13241, 5114, 22231, 12457, 8930, 15099, 15567, 2814, 15176, 14259, 12197, 12511, 12623, 2645, 21047, 11614, 4523, 9898, 4601, 19585, 13751, 22209, 13412, 2578, 9113, 4749, 19036, 22086, 19016, 9383, 2028, 14300, 21001, 5785, 14172, 7660, 14942, 8653, 10275, 10486, 20247, 5276, 9623, 15366, 8254, 12581, 11549, 16819, 6741, 14079, 20607, 617, 16514, 17562, 3053, 12800, 18039, 14125, 10244, 12380, 11344, 12743, 1174, 4217, 14455, 5580, 15455, 14571, 14287, 3254, 12615, 5373, 17063, 16043, 19222, 1832, 22283, 7673, 20432, 7900, 17039, 207, 7682, 19248, 978, 21958, 5018, 2300, 18606, 16146, 6990, 2728, 2095, 20373, 7891, 5853, 18292, 7879, 5447, 7837, 7459, 7999, 3613, 19127, 11369, 3551, 22166, 6371, 18520, 16869, 18772, 9858, 15931, 11402, 9815, 7909, 7326, 18869, 20988, 5109, 4652, 9046, 4950, 10908, 7907, 9817, 10763, 13799, 12451, 1509, 12941, 1753, 5009, 15129, 11216, 13655, 8678, 4329, 6095, 20119, 9394, 1711, 6205, 1016, 10911, 6495, 8624, 18257, 13689, 7096, 21784, 13503, 5567, 13291, 18183, 10692, 21637, 4011, 15923, 20444, 22370, 4267, 4688, 19981, 18017, 1850, 18290, 5855, 20217, 13072, 17280, 94, 1193, 19878, 15755, 11707, 3701, 22272, 4706, 13586, 21831, 9958, 1160, 5233, 5312, 15948, 11373, 5174, 16858, 10722, 10500, 18578, 18347, 21867, 10642, 6960, 19533, 19032, 9601, 19100, 14317, 17049, 7400, 4574, 2386, 9940, 20886, 4748, 9297, 2579, 10351, 6193, 20531, 20816, 10508, 15521, 7495, 3575, 16825, 13225, 4211, 17650, 5915, 20258, 4075, 8854, 6868, 12557, 14499, 18333, 9487, 2669, 20044, 15877, 4804, 2160, 738, 5979, 11660, 18151, 472, 19689, 21324, 18196, 2959, 18163, 17632, 1230, 21501, 19852, 13680, 9546, 11357, 14213, 20063, 6475, 18022, 43, 13020, 3426, 6701, 3711, 19527, 14958, 7060, 3589, 13353, 6862, 10447, 16096, 18708, 14751, 20192, 20662, 4949, 9200, 4653, 19703, 5808, 8788, 18803, 13338, 15532, 3668, 20873, 11168, 7330, 16195, 5036, 10206, 21601, 8760, 6318, 445, 5084, 14232, 3512, 15399, 5667, 1942, 5986, 18529, 3127, 12268, 3833, 8560, 5210, 9891, 12163, 83, 12951, 18050, 18313, 886, 3161, 12809, 10632, 5863, 19544, 20183, 21673, 21551, 14103, 5516, 19791, 7658, 14174, 20679, 18744, 17862, 5732, 9342, 4961, 19026, 1060, 20513, 12819, 14311, 17319, 183, 13094, 19816, 6428, 2827, 16223, 964, 10942, 19964, 288, 5522, 3623, 7820, 8108, 13520, 8864, 20309, 5304, 6786, 11996, 9736, 16172, 1723, 8397, 7463, 11199, 19194, 9331, 7904, 1019, 19075, 20293, 18156, 21859, 10482, 10766, 11393, 9752, 15374, 1556, 9888, 22119, 2060, 3165, 15467, 5050, 21555, 2600, 14737, 13766, 11461, 15098, 9317, 12458, 19041, 4273, 20538, 3180, 6839, 17315, 21127, 22269, 2755, 3383, 6025, 15187, 6383, 2219, 2787, 21686, 17756, 3572, 4158, 20449, 16409, 3644, 3486, 16837, 2433, 10291, 19967, 20407, 22314, 15414, 1735, 2596, 5617, 5527, 14481, 905, 7944, 608, 13223, 16827, 2324, 14059, 7841, 12681, 16718, 5358, 17700, 3811, 10184, 7141, 20982, 6295, 3687, 10490, 14284, 13425, 13530, 3992, 5381, 18390, 4910, 645, 11319, 20308, 8967, 13521, 18402, 2556, 4093, 11151, 16355, 2365, 5124, 6867, 9096, 4076, 10368, 7619, 10717, 19211, 15556, 7992, 11699, 758, 4108, 17264, 11798, 17506, 2633, 5334, 15941, 14544, 333, 12038, 7005, 181, 17321, 21152, 9562, 11057, 21423, 14459, 11827, 8423, 19740, 4166, 6715, 2923, 16395, 12329, 1286, 2457, 13936, 913, 15428, 17399, 15185, 6027, 21754, 19827, 17686, 13251, 563, 1911, 8321, 14880, 2998, 20130, 3785, 6249, 11941, 17227, 10378, 4220, 6003, 16481, 5416, 7671, 22285, 18802, 9042, 5809, 7395, 17067, 595, 16974, 6103, 10638, 1970, 6151, 20420, 14225, 10172, 713, 8010, 7748, 22078, 9731, 12929, 22083, 3855, 2941, 14437, 8450, 9703, 19190, 20994, 6317, 9030, 21602, 19697, 16068, 20502, 16573, 5263, 1206, 13017, 17814, 8206, 21468, 19676, 12282, 16736, 3522, 1407, 7959, 4658, 17860, 18746, 11176, 13207, 13716, 17396, 8156, 21951, 460, 3458, 8724, 16169, 11471, 11421, 15492, 4007, 16168, 8731, 3459, 3996, 1005, 15620, 21434, 20802, 3708, 6735, 2532, 2540, 13322, 12848, 10415, 20600, 15992, 16287, 17760, 1907, 4135, 13220, 15298, 17500, 20104, 17625, 16309, 5042, 7929, 19137, 9780, 11154, 18886, 14529, 7347, 7487, 7359, 3924, 4721, 22227, 6692, 20623, 2041, 375, 5137, 18566, 4328, 9185, 13656, 4998, 22281, 1834, 19353, 4520, 15215, 6670, 12594, 5974, 3409, 7562, 13892, 1451, 16992, 19830, 17663, 17965, 14243, 17845, 15788, 4919, 4340, 10274, 9284, 14943, 7148, 15749, 19241, 5255, 14962, 7968, 3169, 20563, 2807, 13092, 185, 3754, 17174, 5427, 7870, 10674, 4682, 5803, 1202, 8217, 1716, 10793, 21642, 7655, 13460, 10933, 18256, 9175, 6496, 16130, 11303, 731, 3402, 20017, 3803, 1680, 4147, 17593, 22379, 1868, 6271, 4126, 8343, 12946, 21229, 16670, 6088, 14092, 3299, 5520, 290, 20926, 21155, 2194, 12116, 11909, 11629, 13199, 9943, 4364, 551, 16907, 937, 10851, 7509, 10045, 8575, 1728, 922, 7409, 20072, 11772, 1575, 11887, 9878, 1727, 8585, 10046, 3927, 1895, 15079, 6301, 14863, 22277, 19054, 11637, 19984, 3416, 21495, 17420, 5209, 9016, 3834, 10193, 8132, 10198, 13055, 5818, 17132, 20724, 6315, 20996, 5363, 12974, 10269, 6358, 4464, 2525, 20717, 15665, 4120, 12779, 15938, 14277, 14520, 16951, 2344, 17569, 15776, 18497, 11186, 4716, 16235, 3672, 12289, 15001, 18239, 16833, 9578, 16046, 16902, 18481, 6181, 4628, 6519, 2791, 18839, 12868, 21737, 16470, 19553, 10661, 16989, 12756, 14408, 8007, 21610, 19182, 2179, 14830, 13728, 20943, 636, 11796, 17266, 2903, 17017, 5606, 5430, 16253, 16487, 18847, 4810, 12203, 1191, 96, 16562, 10435, 6656, 5408, 22157, 10432, 10457, 16890, 812, 17071, 1050, 6634, 6722, 1431, 268, 2592, 8079, 15273, 17470, 19895, 7977, 15603, 5481, 11653, 9717, 8392, 6659, 19935, 13577, 21481, 2684, 17179, 5763, 14568, 9702, 8765, 14438, 1390, 16610, 1621, 20915, 8209, 5059, 20689, 14197, 10569, 4398, 12063, 5190, 4450, 18423, 11158, 15825, 3095, 588, 21441, 10349, 2581, 21725, 16375, 5931, 19739, 8825, 11828, 4551, 11259, 17809, 1512, 17047, 14319, 7572, 17777, 18205, 21029, 19253, 18547, 9351, 14029, 3882, 15708, 6073, 1757, 14581, 1920, 830, 3536, 10178, 7462, 8959, 1724, 11730, 5406, 6658, 8460, 9718, 21658, 17200, 11342, 12382, 16373, 21727, 6780, 10144, 11107, 21887, 16040, 19086, 5991, 2308, 7249, 18186, 6280, 683, 20426, 10303, 18542, 7041, 2174, 9323, 20976, 13041, 13985, 18512, 7229, 17654, 10713, 2972, 778, 19774, 15668, 395, 4877, 12545, 18834, 6064, 6113, 19514, 20136, 20844, 5531, 10904, 12945, 8609, 4127, 2769, 15835, 10552, 16008, 20176, 12173, 20068, 13506, 14553, 5844, 4412, 16846, 9871, 805, 11573, 4065, 20388, 4943, 3114, 14879, 8804, 1912, 16198, 1864, 21420, 10425, 15651, 13121, 1787, 18208, 3749, 21306, 3696, 20206, 18130, 3239, 2781, 16443, 18813, 16304, 13789, 19095, 824, 19105, 19388, 13028, 19992, 22365, 4308, 7606, 841, 13394, 16878, 5286, 17509, 1355, 16378, 2415, 3859, 20867, 193, 14968, 14134, 9664, 11881, 14913, 5730, 17864, 18080, 9403, 6610, 8203, 4353, 13129, 12150, 1128, 5699, 776, 2974, 7162, 20958, 7424, 14114, 12730, 1235, 10989, 12580, 9277, 15367, 3499, 15501, 3736, 14332, 19848, 19549, 7920, 12416, 16981, 1612, 3544, 17585, 9483, 4271, 19043, 19029, 16712, 21084, 21742, 22324, 12033, 5309, 14561, 7520, 22128, 14305, 18951, 10475, 21989, 5739, 16607, 13106, 14734, 13398, 1715, 8632, 1203, 15618, 1007, 380, 7721, 31, 5058, 8444, 20916, 21467, 8750, 17815, 4352, 8270, 6611, 17780, 11501, 7258, 17639, 1703, 13952, 11825, 14461, 12790, 3295, 22094, 4827, 2711, 16851, 16771, 10317, 15626, 14413, 1279, 10541, 11035, 13325, 2331, 17715, 19563, 17492, 17338, 14532, 7988, 12927, 9733, 6149, 1972, 13616, 12222, 3034, 5692, 12712, 16332, 17308, 13367, 18882, 17888, 16073, 21950, 8735, 17397, 15430, 5184, 15236, 4427, 13734, 4549, 11830, 10130, 10835, 1120, 17415, 11202, 5169, 10264, 5759, 488, 16107, 989, 568, 7216, 13081, 10197, 8557, 10194, 9884, 15359, 1610, 16983, 238, 20041, 850, 2926, 18452, 3947, 19670, 6651, 17057, 6454, 13855, 7874, 17300, 14771, 17953, 9805, 11902, 13519, 8969, 7821, 13140, 19140, 21353, 153, 3807, 1690, 3725, 3825, 18067, 6304, 3323, 18970, 20364, 13103, 1393, 17828, 1111, 264, 14166, 3443, 19473, 17459, 8015, 9573, 13409, 5075, 15272, 8469, 2593, 3292, 13272, 5345, 13977, 14822, 20905, 20841, 7066, 7547, 11914, 10769, 212, 12993, 18793, 14446, 18656, 14144, 2546, 6167, 15008, 5646, 15084, 9673, 16275, 20654, 827, 21310, 2819, 15022, 20895, 14625, 15061, 6200, 20627, 7783, 18630, 7551, 3335, 2795, 4336, 16315, 2261, 18610, 17004, 1091, 2198, 21140, 18867, 7328, 11170, 21954, 1078, 11696, 11410, 19157, 18495, 15778, 21384, 22015, 5302, 20311, 9572, 8084, 17460, 15559, 451, 7747, 8774, 714, 21609, 8506, 14409, 17958, 21105, 19938, 10627, 1991, 3612, 9220, 7460, 10180, 18810, 2872, 11408, 11698, 8847, 15557, 17462, 12926, 8173, 14533, 9636, 13886, 14387, 4436, 4459, 6766, 14209, 21115, 15602, 8465, 19896, 352, 10625, 19940, 12344, 17675, 6160, 3168, 8646, 14963, 18417, 12099, 22108, 20415, 18325, 2001, 4657, 8743, 1408, 19451, 13627, 13944, 21004, 3715, 5101, 7214, 570, 5148, 3599, 14330, 3738, 607, 8892, 906, 22220, 20167, 12013, 18175, 13136, 16814, 7016, 969, 13566, 10567, 14199, 9604, 19136, 8697, 5043, 11253, 5259, 1671, 11164, 10309, 21168, 12415, 8246, 19550, 16679, 100, 2465, 6415, 4735, 16865, 13499, 21489, 7325, 9206, 9816, 9197, 10909, 1018, 8954, 9332, 3090, 17038, 9242, 20433, 21238, 10411, 7009, 9835, 13300, 4061, 5852, 9227, 20374, 14600, 12748, 1026, 373, 2043, 9559, 20929, 20693, 7136, 5446, 9224, 18293, 18989, 2378, 17299, 8115, 13856, 5443, 10673, 8637, 5428, 5608, 4917, 15790, 3506, 13701, 15047, 5054, 14219, 14406, 12758, 14669, 19995, 12646, 12143, 7765, 4287, 17170, 5024, 6451, 13556, 22061, 15540, 14974, 14876, 729, 11305, 12680, 8886, 14060, 16550, 7458, 9222, 5448, 787, 17158, 17083, 14163, 14874, 14976, 17332, 1706, 11145, 16629, 13941, 12692, 6937, 13139, 8107, 8970, 3624, 16752, 12351, 21521, 491, 6432, 20635, 13990, 20474, 2011, 2407, 18979, 5626, 15854, 2523, 4466, 5141, 16927, 19840, 2249, 11989, 2979, 1618, 21964, 7186, 2018, 14504, 9646, 6931, 12963, 16800, 11612, 21049, 10430, 22159, 18629, 8043, 20628, 19891, 16025, 15981, 16032, 10157, 15224, 7625, 2824, 20165, 22222, 7554, 21732, 1497, 14346, 7333, 4286, 7854, 12144, 4204, 18702, 18211, 9478, 7583, 21705, 818, 20778, 21338, 19735, 12892, 3196, 16501, 21895, 22077, 8773, 8011, 452, 17786, 7242, 2763, 17790, 2810, 1763, 2504, 18378, 878, 16808, 3038, 17875, 12323, 3100, 18861, 15219, 19399, 18509, 6687, 20250, 9634, 14535, 2399, 30, 8212, 381, 21629, 384, 4142, 10365, 12404, 1827, 12564, 1540, 12666, 6481, 15580, 3467, 22238, 18588, 20715, 2527, 6045, 3932, 7012, 18047, 7677, 7454, 21621, 19456, 20707, 22034, 1570, 2726, 6992, 16728, 6522, 3109, 19505, 2058, 22121, 16505, 19247, 9239, 208, 16257, 14731, 7453, 7699, 18048, 12953, 20431, 9244, 22284, 8791, 5417, 16292, 16262, 4280, 10418, 4509, 6254, 6135, 14714, 14941, 9286, 14173, 8996, 19792, 13459, 8628, 21643, 6857, 4025, 20229, 12606, 4050, 3380, 13059, 19305, 18874, 19770, 3684, 13343, 2202, 12133, 2056, 19507, 16935, 10151, 20946, 20673, 19643, 7539, 17142, 949, 6632, 1052, 2024, 2823, 7775, 15225, 5092, 14280, 4441, 10716, 8851, 10369, 11123, 5870, 845, 7448, 15247, 20315, 11273, 15459, 7344, 17341, 840, 8292, 4309, 6804, 21205, 2664, 12702, 12851, 20114, 7446, 847, 2672, 16150, 17833, 17623, 20106, 2246, 6492, 6124, 5629, 16840, 2277, 14949, 21704, 7759, 9479, 9368, 21033, 17496, 21931, 18937, 6906, 21242, 12357, 17776, 8415, 14320, 1489, 15596, 5996, 10066, 12154, 18375, 20213, 13891, 8666, 3410, 15111, 5935, 7438, 1456, 15119, 21731, 7771, 22223, 3334, 8041, 18631, 532, 11913, 8069, 7067, 19326, 15336, 19343, 11293, 19752, 17141, 7632, 19644, 11764, 20404, 1805, 3984, 6336, 4324, 16091, 13824, 117, 1533, 7305, 3530, 7176, 15725, 7422, 20960, 22127, 8229, 14562, 7418, 14548, 21665, 19278, 14071, 13590, 19396, 5639, 10044, 8587, 10852, 15516, 3793, 11289, 12335, 19082, 7398, 17051, 10774, 10653, 7390, 4156, 3574, 9105, 15522, 20548, 4643, 5953, 3831, 12270, 7358, 8690, 7348, 5874, 387, 11400, 15933, 10511, 14117, 16664, 7278, 11499, 17782, 15169, 7198, 7166, 17303, 15321, 6998, 18947, 6718, 6398, 5598, 22389, 11198, 8958, 8398, 10179, 7998, 9221, 7838, 16551, 12919, 21620, 7698, 7678, 14732, 13108, 13741, 15246, 7614, 846, 7598, 20115, 14808, 690, 2306, 5993, 16643, 1455, 7558, 5936, 2865, 13335, 15334, 19328, 17137, 13746, 14426, 3977, 5497, 10503, 22199, 14113, 8260, 20959, 7523, 15726, 6852, 14547, 7518, 14563, 5062, 4359, 20477, 10402, 19416, 5564, 20071, 8582, 923, 2719, 3436, 1377, 17840, 11136, 9410, 4573, 9119, 17050, 7502, 19083, 17066, 8786, 5810, 10103, 13867, 4155, 7498, 10654, 1656, 962, 16225, 14335, 16748, 20290, 20496, 7316, 3439, 2092, 5771, 20519, 18099, 5245, 6175, 15634, 19573, 14344, 1499, 17867, 4402, 3822, 15357, 9886, 1558, 12261, 11560, 217, 3923, 8689, 7488, 12271, 3916, 11775, 18278, 16176, 11329, 16942, 717, 5873, 7486, 8691, 14530, 17340, 7609, 15460, 9432, 19314, 18740, 1664, 21626, 21632, 22334, 15715, 4285, 7767, 14347, 16194, 9035, 11169, 8029, 18868, 9205, 7910, 21490, 4848, 995, 16002, 5315, 3229, 1375, 3438, 7381, 20497, 13822, 16093, 1321, 341, 16746, 14337, 12721, 12735, 3529, 7527, 1534, 21561, 18859, 3102, 18358, 857, 16436, 17896, 10931, 13462, 13077, 6827, 18372, 16805, 9530, 1743, 11281, 4454, 18507, 19401, 11527, 18982, 14833, 16459, 10469, 11498, 7478, 16665, 19425, 20936, 14837, 663, 9492, 10445, 6864, 19493, 15447, 15973, 12286, 17383, 13205, 11178, 5120, 11508, 6164, 17638, 8199, 11502, 3399, 3276, 21648, 19289, 4037, 10690, 18185, 8376, 2309, 3910, 16214, 4486, 576, 2762, 7744, 17787, 12924, 17464, 11427, 5902, 2449, 66, 11876, 12308, 6513, 16387, 17653, 8362, 18513, 20759, 345, 4610, 14918, 15196, 21254, 12192, 2777, 17531, 19578, 13080, 8135, 569, 7951, 5102, 10074, 20097, 1144, 4993, 13581, 16367, 13476, 16011, 3122, 6048, 9861, 4700, 21969, 7165, 7474, 15170, 1140, 2575, 15967, 1567, 4846, 21492, 9865, 3250, 11790, 2017, 7795, 21965, 20238, 54, 7051, 17998, 10777, 17872, 13722, 15724, 7525, 3531, 14663, 2995, 16756, 20740, 12235, 14617, 14769, 17302, 7473, 7199, 21970, 20957, 8262, 2975, 16831, 18241, 17208, 14241, 17967, 6364, 5839, 16453, 20172, 19608, 4057, 15748, 8651, 14944, 14780, 2079, 18505, 4456, 20981, 8879, 10185, 17075, 10671, 5445, 7881, 20694, 21918, 19174, 2626, 5280, 18623, 21258, 12571, 10876, 12056, 9955, 724, 21125, 17317, 14313, 13925, 4924, 12639, 7021, 10169, 19361, 16326, 17553, 10096, 18931, 15721, 9801, 9355, 18135, 1312, 15959, 1760, 11083, 12740, 15804, 15863, 16881, 9507, 21783, 9172, 13690, 4894, 2953, 12278, 6952, 20380, 19988, 18964, 15317, 11571, 807, 6883, 529, 15663, 20719, 1301, 11361, 6699, 3428, 15306, 10823, 6554, 5089, 14922, 15396, 3840, 416, 19325, 7546, 8070, 20842, 20138, 18527, 5988, 3588, 9057, 14959, 3066, 14849, 3051, 17564, 19684, 11822, 17997, 7182, 55, 18729, 6575, 6595, 12177, 11899, 15916, 4373, 2173, 8369, 18543, 1544, 18666, 18570, 15027, 12508, 14264, 20784, 11093, 10706, 17773, 20439, 12769, 13115, 14140, 18895, 11332, 4513, 10168, 7117, 12640, 13449, 20838, 968, 7936, 16815, 2833, 18046, 7701, 3933, 9834, 7896, 10412, 12705, 180, 8834, 12039, 22101, 1469, 5474, 11582, 18946, 7470, 15322, 18554, 18880, 13369, 16727, 7691, 2727, 9231, 16147, 19370, 22267, 21129, 5307, 12035, 17232, 1903, 16204, 78, 13494, 20659, 1256, 3407, 5976, 19152, 19614, 4864, 15649, 10427, 1823, 4915, 5610, 21479, 13579, 4995, 14239, 17210, 19532, 9126, 10643, 11005, 1530, 11578, 1524, 22202, 20379, 7091, 12279, 11182, 16588, 21193, 2899, 15125, 6421, 6380, 19273, 1072, 11845, 19049, 16812, 13138, 7823, 12693, 11119, 14783, 15050, 12962, 7791, 9647, 10883, 16231, 19227, 13455, 17344, 9678, 18837, 2793, 3337, 10758, 1998, 2008, 4362, 9945, 15562, 21511, 231, 9792, 18604, 2302, 18940, 21011, 21241, 7576, 18938, 2304, 692, 10971, 13666, 18387, 20967, 18006, 2933, 11354, 16601, 11445, 18893, 14142, 18658, 9599, 19034, 4751, 20932, 12525, 4044, 528, 7084, 808, 5960, 10788, 1046, 11540, 14886, 18601, 3659, 6458, 11884, 13287, 14899, 1846, 12556, 9095, 8855, 5125, 19492, 7270, 10446, 9054, 13354, 18726, 12398, 4024, 7653, 21644, 3539, 331, 14546, 7420, 15727, 86, 6511, 12310, 9535, 9785, 18345, 18580, 12211, 3585, 19089, 17314, 8924, 3181, 13545, 14402, 4932, 14380, 21943, 12447, 15478, 883, 9993, 18371, 7293, 13078, 19580, 11313, 5433, 5982, 18751, 11868, 3781, 5391, 4334, 2797, 2988, 15911, 14684, 18927, 629, 6374, 2050, 3945, 18454, 10188, 21204, 7604, 4310, 215, 11562, 10388, 1638, 20903, 14824, 16398, 5752, 21268, 9413, 1277, 14415, 13929, 16913, 19822, 11995, 8964, 5305, 21131, 1939, 3270, 10143, 8384, 21728, 12903, 17128, 21189, 14178, 21387, 13673, 960, 1658, 4202, 12146, 12075, 14208, 7981, 4460, 22147, 12574, 11632, 17725, 16217, 15020, 2821, 2026, 9385, 11349, 6712, 17746, 18339, 6506, 15823, 11160, 18924, 157, 4851, 17528, 15422, 11967, 14078, 9273, 16820, 9628, 10344, 16884, 2531, 8716, 3709, 6703, 3760, 21863, 15311, 1675, 13851, 18274, 2618, 14037, 21999, 1430, 8473, 6635, 6586, 6397, 7468, 18948, 2922, 8822, 4167, 17745, 6754, 11350, 4857, 20466, 16740, 5153, 22028, 16163, 3759, 6733, 3710, 9061, 3427, 7078, 11362, 1683, 4419, 10668, 19167, 20622, 8685, 22228, 2612, 5274, 20249, 7727, 18510, 13987, 16321, 21504, 4874, 1982, 12395, 58, 15058, 18109, 4818, 5379, 3994, 3461, 15283, 12593, 8670, 15216, 14869, 14972, 15542, 22308, 9444, 16359, 3302, 5081, 19934, 8459, 8393, 5407, 8483, 10436, 18074, 13031, 17056, 8119, 19671, 4686, 4269, 9485, 18335, 15244, 13743, 3153, 10008, 17236, 12898, 2514, 13246, 10687, 6585, 6721, 8474, 1051, 7629, 950, 12046, 12889, 11928, 2478, 17613, 241, 21371, 5029, 22206, 18641, 10684, 18694, 4823, 13860, 3897, 14372, 1010, 18203, 17779, 8202, 8271, 9404, 20362, 18972, 4547, 13736, 17475, 14527, 18888, 19376, 17187, 2760, 578, 4302, 12176, 7047, 6576, 21981, 2678, 11047, 9652, 15292, 6531, 6396, 6720, 6636, 10688, 4039, 16938, 12493, 17794, 869, 6289, 21980, 6594, 7048, 18730, 12699, 11648, 15886, 15643, 11234, 13960, 19299, 20025, 16535, 19185, 9661, 21160, 16627, 11147, 19623, 14053, 11842, 1422, 5088, 7074, 10824, 16185, 3628, 613, 12896, 17238, 367, 5615, 2598, 21557, 17104, 19763, 16267, 16766, 14587, 19871, 12166, 18044, 2835, 1629, 9390, 6395, 6588, 15293, 5513, 17109, 16844, 4414, 22114, 21908, 3108, 7689, 16729, 2790, 8517, 4629, 2348, 13305, 17590, 16386, 7232, 12309, 6849, 87, 17503, 10744, 15822, 6751, 18340, 22089, 521, 9328, 5895, 4032, 3595, 20593, 16129, 8623, 9176, 10912, 6123, 7590, 2247, 19842, 12256, 20535, 10727, 695, 10827, 4225, 19404, 15579, 7710, 12667, 12586, 10493, 15349, 18021, 9066, 20064, 16687, 21392, 18381, 13230, 1950, 12185, 794, 143, 17539, 16343, 12534, 13184, 10992, 14911, 11883, 6874, 3660, 9613, 13854, 8117, 17058, 13555, 7850, 5025, 12082, 1227, 6389, 17080, 13257, 11021, 1221, 1249, 9844, 18160, 11433, 3396, 18826, 11835, 21080, 15288, 20634, 7814, 492, 20163, 2826, 8979, 19817, 15199, 20827, 4254, 11587, 6379, 6945, 15126, 10108, 18306, 2929, 4734, 7915, 2466, 6367, 14614, 6362, 17969, 20879, 5348, 6345, 5493, 18011, 9761, 11896, 1792, 13684, 6107, 5597, 7467, 6719, 6587, 6532, 9391, 19446, 21397, 15072, 17079, 6447, 1228, 17634, 11840, 14055, 2218, 8916, 15188, 19272, 6944, 6422, 11588, 10898, 10840, 2049, 6810, 630, 18519, 9214, 22167, 2501, 14613, 6413, 2467, 5838, 7155, 17968, 6411, 14615, 12237, 4463, 8546, 10270, 11385, 16426, 505, 14013, 3308, 5329, 13145, 3172, 12814, 13871, 5492, 6407, 5349, 3175, 10658, 17769, 220, 21477, 5612, 4323, 7533, 3985, 12959, 3081, 627, 18929, 10098, 4470, 21847, 1031, 2695, 13636, 1892, 17600, 21262, 4504, 14235, 444, 9029, 8761, 20995, 8551, 20725, 338, 18617, 21331, 1882, 466, 18501, 5004, 12079, 3322, 8097, 18068, 14862, 8570, 15080, 21073, 11945, 13341, 3686, 8877, 20983, 2944, 542, 18551, 21979, 6578, 870, 21904, 14255, 21405, 17556, 3077, 3655, 682, 8374, 18187, 3693, 1924, 19309, 9512, 9924, 16705, 4125, 8611, 1869, 1212, 3974, 10296, 12996, 1799, 15896, 13771, 11091, 20786, 17008, 22002, 5240, 21329, 18619, 6134, 7664, 4510, 11972, 20461, 11940, 8799, 3786, 13161, 15404, 3024, 19720, 14798, 4561, 19202, 9551, 18921, 21096, 21857, 18158, 9846, 3561, 19859, 19855, 364, 15688, 18635, 17606, 4162, 18385, 13668, 13663, 10923, 12656, 13432, 20671, 20948, 4114, 15040, 11065, 3262, 21837, 10955, 2283, 257, 21696, 11568, 15841, 18766, 1015, 9179, 1712, 3651, 20731, 20626, 8045, 15062, 13359, 17358, 20480, 14074, 20530, 9110, 10352, 294, 20489, 15412, 22316, 19109, 11716, 1185, 1627, 2837, 4627, 8519, 18482, 15147, 17908, 4667, 15633, 7374, 5246, 12956, 17490, 19565, 13416, 21430, 15007, 8059, 2547, 17637, 7260, 11509, 15465, 3167, 7970, 17676, 13864, 18722, 19067, 13023, 1362, 3142, 20419, 8779, 1971, 8170, 9734, 11998, 10772, 17053, 12372, 9556, 11078, 16962, 13901, 5907, 10392, 22184, 14713, 7663, 6255, 18620, 6100, 14725, 18114, 18676, 17294, 2629, 15852, 5628, 7589, 6493, 10913, 2895, 21898, 12719, 14339, 1740, 10953, 21839, 19513, 8350, 6065, 4842, 19808, 1493, 5596, 6400, 13685, 4634, 10637, 8782, 16975, 14724, 6132, 18621, 5282, 5551, 20118, 9183, 4330, 12935, 20179, 12726, 3579, 14091, 8605, 16671, 3482, 4767, 13694, 17352, 18025, 21475, 222, 18056, 14356, 20133, 2253, 3868, 1756, 8405, 15709, 890, 2543, 2846, 3031, 15279, 4841, 6112, 8351, 18835, 9680, 14230, 5086, 1424, 4389, 12302, 10211, 4835, 19318, 20790, 17526, 4853, 15929, 9860, 7203, 3123, 3931, 7703, 2528, 64, 2451, 10051, 12611, 11241, 13535, 20029, 21227, 12948, 15730, 19092, 16875, 2604, 17122, 19907, 21753, 8811, 15186, 8918, 3384, 1901, 17234, 10010, 14007, 667, 13967, 16463, 21037, 14108, 19979, 4690, 150, 1644, 20745, 18244, 4802, 15879, 15162, 4741, 16480, 8794, 4221, 10118, 21541, 19469, 13573, 10065, 7568, 15597, 16642, 7441, 2307, 8378, 19087, 3587, 7062, 18528, 9021, 1943, 13485, 18750, 6822, 5434, 11659, 9084, 739, 19151, 6975, 3408, 8668, 12595, 22377, 17595, 18532, 1528, 11007, 16038, 21889, 4953, 3388, 11865, 21791, 10787, 6881, 809, 21535, 15095, 4498, 17191, 3830, 7491, 4644, 19611, 14089, 3581, 19523, 4132, 11398, 389, 17155, 4180, 12917, 16553, 15240, 2222, 133, 2864, 7437, 7559, 15112, 11925, 19738, 8425, 16376, 1357, 35, 19834, 326, 21088, 655, 13881, 2841, 5716, 12878, 20277, 12871, 4539, 20257, 9099, 17651, 16389, 13600, 16978, 9425, 20281, 10391, 6139, 13902, 3547, 4989, 2448, 7237, 11428, 12618, 12138, 1273, 12332, 4031, 6501, 9329, 19196, 14642, 499, 20643, 271, 14709, 3147, 17754, 21688, 4907, 18414, 16898, 4384, 21775, 13124, 4832, 1369, 4140, 386, 7485, 7349, 718, 844, 7616, 11124, 9710, 5677, 10809, 3449, 19543, 9004, 10633, 11506, 5122, 2367, 15828, 3209, 20216, 9154, 18291, 9226, 7892, 4062, 17691, 426, 2157, 19393, 2265, 4411, 8332, 14554, 14936, 9475, 16452, 7154, 6365, 2468, 4130, 19525, 3713, 21006, 22296, 13908, 11959, 11938, 20463, 16923, 21185, 9378, 3008, 10535, 21715, 1890, 13638, 17131, 8554, 13056, 2758, 17189, 4500, 20955, 21972, 10102, 7394, 8787, 9043, 19704, 11210, 15444, 1201, 8634, 4683, 18960, 1503, 18758, 12840, 3474, 10785, 21793, 12845, 11038, 15498, 10949, 3045, 3061, 12986, 16653, 14171, 9288, 21002, 13946, 20773, 431, 2132, 20156, 1094, 9642, 9349, 18549, 544, 21364, 20518, 7378, 2093, 2730, 21499, 1232, 15832, 11247, 14567, 8453, 17180, 277, 487, 8140, 10265, 18218, 3098, 12325, 10241, 21267, 6795, 16399, 14953, 20939, 9640, 1096, 19921, 5704, 1003, 3998, 20360, 9406, 16606, 8223, 21990, 20327, 17457, 19475, 2774, 9341, 8991, 17863, 8275, 14914, 15116, 2969, 4444, 11263, 1163, 13787, 16306, 18912, 1109, 17830, 3193, 12877, 5921, 2842, 14475, 22294, 21008, 17455, 20329, 9851, 18088, 2328, 15920, 1002, 5745, 19922, 19627, 9472, 775, 8265, 1129, 17891, 1440, 1106, 19336, 12711, 8165, 3035, 1780, 12468, 16120, 18269, 19954, 18433, 22195, 2858, 3363, 14157, 1310, 18137, 10808, 5867, 9711, 13509, 17036, 3092, 2370, 12010, 18778, 3268, 1941, 9023, 15400, 14703, 15872, 19604, 709, 2339, 17731, 18304, 10110, 13647, 18872, 19307, 1926, 15685, 17241, 3215, 984, 21278, 22051, 15083, 8057, 15009, 2104, 1013, 18768, 14575, 10043, 7511, 19397, 15221, 1654, 10656, 3177, 10461, 11449, 2431, 16839, 7588, 6125, 15853, 7807, 18980, 11529, 5541, 14206, 12077, 5006, 3871, 5526, 8896, 2597, 6546, 368, 4322, 6338, 21478, 6967, 4916, 7868, 5429, 8494, 17018, 5332, 2635, 10335, 12440, 17913, 22388, 7466, 6399, 6108, 1494, 9429, 14604, 10782, 2168, 10237, 4020, 15102, 12864, 21514, 14657, 19356, 20615, 3343, 15454, 9256, 14456, 15378, 19561, 17717, 10843, 13119, 15653, 12766, 12306, 11878, 18817, 13290, 9169, 13504, 20070, 7411, 19417, 15233, 4153, 13869, 12816, 10441, 18906, 13488, 19961, 16763, 14806, 20117, 6097, 5283, 15866, 17980, 14063, 12523, 20934, 19427, 19681, 14205, 5623, 11530, 19113, 21102, 4171, 17218, 13260, 11672, 12431, 10903, 8346, 20845, 17657, 14480, 8895, 5618, 3872, 13181, 3622, 8972, 289, 8602, 3300, 16361, 19790, 8998, 14104, 17108, 6529, 15294, 12887, 12048, 15656, 19863, 22331, 18288, 1852, 11935, 13915, 21582, 860, 2892, 18576, 10502, 7428, 3978, 16511, 18010, 6406, 6346, 13872, 3913, 22290, 19511, 21841, 13803, 21457, 9855, 10592, 11652, 8463, 15604, 2572, 12425, 12231, 19063, 11581, 7001, 1470, 17534, 1929, 16566, 1209, 19652, 17251, 14591, 2554, 18404, 21691, 12445, 21945, 2462, 2885, 14756, 12243, 18353, 15811, 9901, 3496, 11063, 15042, 21677, 786, 7836, 9223, 7880, 7137, 10672, 7872, 13857, 20050, 10791, 1718, 2752, 3704, 17164, 11658, 5981, 6823, 11314, 16252, 8493, 5607, 7869, 8638, 17175, 1483, 2916, 19621, 11149, 4095, 21797, 13610, 16291, 7670, 8792, 16482, 12969, 9976, 14149, 20782, 14266, 22156, 8482, 6657, 8394, 11731, 13884, 9638, 20941, 13730, 2564, 4709, 5299, 17259, 10879, 2089, 11921, 11591, 4333, 6818, 3782, 14359, 21303, 11712, 1606, 16133, 392, 20965, 18389, 8870, 3993, 6675, 4819, 19489, 13898, 16788, 17062, 9250, 12616, 11430, 2962, 19785, 11524, 4228, 4763, 21937, 12973, 8549, 20997, 11326, 19133, 17699, 8883, 16719, 19302, 14492, 13152, 22187, 2746, 12812, 3174, 6344, 6408, 20880, 13976, 8075, 13273, 14994, 14892, 11620, 16248, 10022, 9361, 15741, 14275, 15940, 8839, 2634, 5604, 17019, 13144, 6351, 3309, 14997, 13608, 21799, 10025, 21580, 13917, 21344, 3937, 12207, 15254, 11723, 3228, 7320, 16003, 15947, 9137, 5234, 14560, 8231, 12034, 6985, 21130, 6785, 8965, 20310, 8018, 22016, 17258, 5398, 4710, 910, 19711, 22134, 699, 4871, 19235, 21719, 835, 15850, 2631, 17508, 8288, 16879, 15865, 5550, 6098, 18622, 7131, 2627, 17296, 9622, 9280, 20248, 6689, 2613, 19788, 16363, 2487, 2802, 11645, 2667, 9489, 15616, 1205, 8754, 16574, 13840, 1670, 7926, 11254, 3064, 14961, 8648, 19242, 2640, 14853, 14762, 21445, 9588, 20429, 12955, 6174, 7375, 18100, 20551, 21529, 21328, 6258, 22003, 16449, 18214, 21605, 14559, 5311, 9138, 1161, 11265, 18688, 16957, 10736, 9894, 10333, 2637, 18105, 14541, 17370, 11115, 18638, 13754, 16967, 20911, 21924, 19708, 13939, 16631, 22117, 9890, 9015, 8561, 17421, 3016, 15793, 19634, 16578, 17894, 16438, 18564, 5139, 4468, 10100, 21974, 11815, 3273, 734, 14004, 11052, 4449, 8437, 12064, 20743, 1646, 4151, 15235, 8153, 15431, 2862, 135, 11778, 10323, 4724, 585, 18221, 16857, 9134, 11374, 19257, 19971, 10263, 8142, 11203, 10451, 13596, 12016, 20319, 22058, 10357, 15410, 20491, 16371, 12384, 15752, 9496, 15845, 22027, 6707, 16741, 19179, 3132, 3598, 7949, 571, 17805, 17408, 2069, 2740, 16926, 7803, 4467, 5200, 18565, 8681, 376, 17093, 16996, 11515, 10339, 17988, 18284, 13550, 10596, 13896, 19491, 6866, 8856, 2366, 5860, 11507, 7262, 11179, 19679, 19429, 2610, 22230, 9320, 13242, 22300, 4431, 4651, 9202, 20989, 2733, 12111, 18492, 20808, 10073, 7213, 7952, 3716, 16265, 19765, 17115, 12772, 20014, 14518, 14279, 7623, 15226, 14921, 7073, 6555, 1423, 6060, 14231, 9027, 446, 19933, 6661, 3303, 15553, 13470, 1267, 15271, 8081, 13410, 22211, 13561, 1242, 1282, 9416, 2701, 19276, 21667, 1270, 4251, 4358, 7416, 14564, 20688, 8443, 8210, 32, 4900, 14218, 7862, 15048, 14785, 21554, 8937, 15468, 12716, 2233, 10280, 3903, 11252, 7928, 8698, 16310, 4369, 22352, 17800, 10205, 9033, 16196, 1914, 11993, 19824, 10600, 22205, 6623, 21372, 3320, 12081, 6450, 7851, 17171, 11279, 1745, 20032, 2299, 9235, 21959, 18713, 20244, 18649, 10647, 18719, 10106, 15128, 9189, 1754, 3870, 5620, 12078, 6307, 18502, 12824, 3185, 18428, 22280, 8676, 13657, 14238, 6964, 13580, 7209, 1145, 22217, 2447, 5904, 3548, 21175, 4587, 17248, 20325, 21992, 21439, 590, 2317, 21272, 14249, 11192, 3201, 1401, 897, 13831, 17185, 19378, 4773, 321, 4536, 20611, 9927, 12464, 9931, 11016, 19025, 8989, 9343, 141, 796, 20002, 480, 3314, 3387, 5965, 21890, 10907, 9199, 9047, 20663, 21473, 18027, 21844, 3113, 8324, 20389, 19541, 3451, 1384, 16682, 2065, 16657, 2919, 14308, 14379, 6835, 14403, 9468, 15154, 10967, 51, 11417, 12638, 7119, 13926, 2499, 22169, 4339, 8656, 15789, 7867, 5609, 6968, 1824, 4409, 2267, 644, 8868, 18391, 18413, 5884, 21689, 18406, 9436, 16221, 2829, 14217, 5056, 33, 1359, 14814, 463, 2952, 7094, 13691, 2290, 22305, 15884, 11650, 10594, 13552, 19761, 17106, 14106, 21039, 946, 12807, 3163, 2062, 12544, 8354, 396, 1981, 6682, 21505, 19234, 5293, 700, 9950, 1602, 16341, 17541, 15648, 6972, 19615, 15174, 2816, 20922, 16921, 20465, 6710, 11351, 22249, 15928, 6051, 17527, 6746, 158, 994, 7323, 21491, 7192, 1568, 22036, 19807, 6111, 6066, 15280, 12298, 987, 16109, 19317, 6055, 10212, 1368, 5878, 13125, 19341, 15338, 2710, 8190, 22095, 20048, 13859, 6618, 18695, 2189, 19488, 5378, 6676, 18110, 1796, 20685, 11250, 3905, 18557, 12202, 8489, 18848, 14152, 12911, 19391, 2159, 9087, 15878, 6008, 18245, 13779, 15, 16422, 3862, 19268, 18464, 20500, 16070, 1132, 11692, 9698, 11276, 3757, 16165, 18232, 12390, 21437, 21994, 22111, 19914, 15767, 22153, 2354, 10798, 12479, 1197, 320, 4970, 19379, 4559, 14800, 2288, 13693, 6085, 3483, 11220, 21936, 5366, 4229, 13318, 21164, 16006, 10554, 19845, 16228, 15134, 14195, 20691, 20931, 6888, 19035, 9296, 9114, 20887, 1327, 10531, 18181, 13293, 16479, 6005, 15163, 14032, 11681, 1547, 16864, 7914, 6416, 2930, 621, 2562, 13732, 4429, 22302, 19374, 18890, 584, 5178, 10324, 22226, 8687, 3925, 10048, 14422, 16234, 8530, 11187, 21076, 11819, 2444, 909, 5298, 5399, 2565, 13585, 9143, 22273, 10818, 18330, 16543, 21968, 7201, 9862, 3419, 17848, 12787, 3259, 17034, 13511, 18583, 149, 6013, 19980, 9159, 4268, 6649, 19672, 18959, 5802, 8635, 10675, 21210, 20061, 14215, 2831, 16817, 11551, 20346, 648, 9919, 11465, 1996, 10760, 15632, 6177, 17909, 11787, 1043, 20053, 16733, 4090, 22070, 17859, 8742, 7960, 2002, 2854, 19702, 9045, 9201, 5110, 4432, 18225, 15680, 15640, 4055, 19610, 5952, 7492, 20549, 18102, 19245, 16507, 706, 13481, 18822, 10636, 6105, 13686, 20487, 296, 2347, 6518, 8518, 6182, 2838, 11734, 16052, 22174, 18472, 11686, 15363, 1955, 10035, 14820, 13979, 4189, 15781, 14192, 10893, 14917, 7225, 346, 21940, 14648, 15152, 9470, 19629, 14651, 19584, 9303, 9899, 15813, 21525, 2510, 3490, 10017, 40, 17355, 12189, 18787, 12409, 21821, 17247, 4986, 21176, 11133, 13974, 20882, 9454, 22348, 9375, 13642, 14188, 18042, 12168, 2385, 9118, 7401, 9411, 21270, 2319, 10623, 354, 11324, 20999, 14302, 21283, 16674, 19201, 6242, 14799, 4771, 19380, 18593, 20701, 18670, 21015, 14989, 11258, 8421, 11829, 8149, 13735, 6606, 18973, 17696, 9607, 1475, 928, 943, 20256, 5917, 12872, 20610, 4968, 322, 17734, 13652, 3648, 13401, 16662, 14119, 4314, 20893, 15024, 17992, 9897, 9305, 11615, 15214, 8672, 19354, 14659, 10071, 20810, 12635, 10167, 7023, 11333, 11971, 6253, 7665, 10419, 1934, 3510, 14234, 6321, 21263, 16696, 20954, 5814, 17190, 5956, 15096, 11463, 9921, 2119, 3246, 12246, 3796, 12855, 10054, 21883, 575, 7245, 16215, 17727, 10607, 1600, 9952, 16793, 6, 18661, 2037, 18194, 21326, 21531, 19503, 3111, 21846, 6329, 10099, 5199, 5140, 7804, 2524, 8545, 6359, 12238, 22146, 6765, 7982, 4437, 20980, 7143, 18506, 7287, 11282, 20581, 18422, 8436, 5191, 11053, 1809, 1215, 11262, 5726, 2970, 10715, 7621, 14281, 12589, 20979, 4458, 7983, 14388, 1289, 18224, 4650, 5111, 22301, 4729, 13733, 8151, 15237, 16030, 15983, 1515, 12136, 12620, 10667, 6696, 1684, 361, 19912, 22113, 6526, 16845, 8331, 5845, 2266, 4913, 1825, 12406, 12053, 17262, 4110, 3821, 7368, 17868, 12497, 12062, 8439, 10570, 15341, 15212, 11617, 11742, 11556, 21275, 12301, 6058, 1425, 15495, 19461, 21774, 5881, 16899, 15988, 12633, 20812, 9744, 10754, 2411, 13236, 20544, 2172, 7043, 15917, 13328, 22351, 5040, 16311, 919, 17447, 550, 8592, 9944, 6917, 2009, 20476, 7415, 5063, 4252, 20829, 9592, 13128, 8269, 8204, 17816, 10226, 15857, 19559, 15380, 14693, 14717, 9441, 13383, 4081, 10273, 8655, 4920, 22170, 16314, 8038, 2796, 6817, 5392, 11592, 12934, 6094, 9184, 8679, 18567, 14295, 16090, 7532, 6337, 5613, 369, 11956, 15739, 9363, 2403, 3431, 20892, 4528, 14120, 12991, 214, 6803, 7605, 8293, 22366, 12541, 16685, 20066, 12175, 6597, 579, 19918, 1840, 866, 19885, 1101, 1873, 15017, 17149, 1843, 17752, 3149, 19755, 17169, 7853, 7766, 7334, 15716, 17576, 20598, 10417, 7667, 16263, 3718, 11872, 12629, 10725, 20537, 8927, 19042, 8239, 9484, 6648, 4687, 9160, 22371, 10078, 2186, 14086, 19155, 11412, 12361, 13037, 15286, 21082, 16714, 11586, 6424, 20828, 4357, 5064, 1271, 12140, 11642, 10859, 10582, 9619, 2381, 10732, 13311, 21922, 20913, 1623, 2099, 13443, 535, 16157, 12548, 15953, 10961, 19433, 13317, 4762, 5367, 11525, 19403, 6484, 10828, 19438, 10117, 6002, 8795, 10379, 14454, 9258, 1175, 20697, 21058, 11861, 17649, 9101, 13226, 11702, 15143, 14018, 16114, 18701, 7763, 12145, 6770, 1659, 20355, 17917, 1068, 13315, 19435, 12008, 2372, 21062, 20287, 21382, 15780, 4615, 13980, 1365, 20605, 14081, 18645, 3690, 14632, 12916, 5943, 17156, 789, 2698, 12127, 16636, 19296, 21807, 17217, 5537, 21103, 17960, 17744, 6714, 8823, 19741, 754, 18384, 6227, 17607, 10004, 20448, 8910, 3573, 7497, 7391, 13868, 5561, 15234, 5186, 1647, 16384, 17592, 8615, 1681, 11364, 12626, 10364, 7717, 385, 5876, 1370, 11459, 13768, 13219, 8705, 1908, 11397, 5947, 19524, 5836, 2469, 2768, 8342, 8610, 6272, 16706, 2440, 3223, 12778, 8541, 15666, 19776, 22256, 10617, 15039, 6218, 20949, 11477, 3820, 4404, 17263, 8844, 759, 61, 16887, 20542, 13238, 16539, 13168, 14515, 3405, 1258, 3188, 21796, 5421, 11150, 8860, 2557, 22069, 4661, 16734, 12284, 15975, 19465, 3943, 2052, 11383, 10272, 4342, 13384, 21508, 12402, 10367, 8853, 9097, 20259, 2239, 12, 20527, 975, 1977, 14431, 20393, 20387, 8326, 11574, 17690, 5851, 7893, 13301, 12907, 15747, 7150, 19609, 4646, 15641, 15888, 305, 3379, 7649, 12607, 15548, 3814, 13264, 527, 6885, 12526, 19145, 10149, 16937, 6583, 10689, 7252, 19290, 15093, 21537, 3594, 6500, 5896, 12333, 11291, 19345, 18916, 20228, 7652, 6858, 12399, 15565, 15101, 5589, 10238, 14828, 2181, 19888, 14655, 21516, 1000, 15922, 9164, 21638, 18230, 16167, 8726, 15493, 1427, 17011, 13524, 17484, 3981, 18439, 20359, 5743, 1004, 8722, 3460, 6674, 5380, 8871, 13531, 19838, 16929, 703, 17488, 12958, 6335, 7534, 1806, 18438, 4001, 17485, 16510, 5496, 7429, 14427, 10295, 6268, 1213, 1811, 17942, 13958, 11236, 1937, 21133, 19207, 17393, 114, 3341, 20617, 2438, 16708, 199, 12829, 11338, 20586, 18411, 18393, 2035, 18663, 11684, 18474, 20821, 19669, 8121, 18453, 6808, 2051, 4085, 19466, 14271, 18447, 15586, 12206, 5320, 21345, 10855, 9833, 7011, 7702, 6046, 3124, 17598, 1894, 8573, 10047, 4720, 8688, 7360, 218, 17771, 10708, 18443, 1573, 11774, 7356, 12272, 22289, 5490, 13873, 16213, 7247, 2310, 981, 18878, 18556, 4813, 11251, 5045, 10281, 17288, 1586, 3235, 14371, 6616, 13861, 11208, 19706, 21926, 16085, 17390, 9570, 20313, 15249, 17938, 15107, 2993, 14665, 15707, 8407, 14030, 15165, 1635, 20284, 3392, 10610, 21762, 16021, 13180, 5525, 5619, 5007, 1755, 6075, 2254, 15330, 16406, 13373, 19267, 4797, 16423, 20866, 8283, 2416, 2736, 2940, 8768, 22084, 19038, 12089, 14023, 15353, 20850, 19022, 3139, 13983, 13043, 16618, 21850, 16102, 415, 7070, 15397, 3514, 18487, 17581, 10192, 8559, 9017, 12269, 7490, 5954, 17192, 17255, 13713, 18066, 8099, 3726, 15356, 7367, 4403, 4111, 11478, 19500, 16894, 11892, 13263, 4047, 15549, 10183, 8881, 17701, 22245, 1689, 8102, 154, 14687, 1679, 8617, 20018, 3012, 17836, 1693, 9908, 12854, 4491, 12247, 11288, 7506, 15517, 18735, 12600, 15482, 20092, 13160, 6248, 8800, 20131, 14358, 5390, 6819, 11869, 2911, 21070, 22054, 16081, 1063, 16137, 16260, 16294, 17112, 15263, 1136, 3609, 12671, 9790, 233, 14609, 14351, 14843, 21862, 6732, 6704, 16164, 4788, 11277, 17173, 8640, 186, 15772, 11710, 21305, 8311, 18209, 18704, 11905, 2148, 17379, 11747, 408, 21021, 10936, 606, 7946, 14331, 8250, 15502, 12795, 22386, 17915, 20357, 18441, 10710, 20848, 15355, 3824, 8100, 1691, 17838, 1379, 11985, 2909, 11871, 4278, 16264, 5100, 7953, 21005, 5834, 19526, 9060, 6702, 6734, 8717, 20803, 11127, 17163, 5437, 2753, 22271, 9145, 11708, 15774, 17571, 20205, 8309, 21307, 1923, 6278, 18188, 14631, 4183, 18646, 10489, 8876, 6296, 13342, 7643, 19771, 2130, 433, 17377, 2150, 1158, 9960, 11492, 11745, 17381, 12288, 8528, 16236, 3327, 20872, 9038, 15533, 9996, 22337, 15344, 15819, 9695, 9612, 6457, 6875, 18602, 9794, 681, 6282, 3078, 15053, 20730, 6203, 1713, 13400, 4532, 13653, 11218, 3485, 8907, 16410, 15572, 10526, 604, 10938, 19480, 1325, 20889, 16594, 9554, 12374, 22355, 624, 12884, 612, 6551, 16186, 21379, 16751, 7819, 8971, 5523, 13182, 12536, 11803, 131, 2224, 10382, 16723, 19126, 9219, 8000, 1992, 12670, 3768, 1137, 10203, 17802, 9985, 10342, 9630, 12095, 9399, 14329, 7948, 5149, 3133, 20592, 6499, 4033, 21538, 107, 13604, 13352, 9056, 7061, 5989, 19088, 6842, 12212, 14397, 19522, 5949, 14090, 6090, 12727, 10514, 16824, 9104, 7496, 4157, 8911, 17757, 11758, 10889, 18996, 15956, 10559, 20124, 21751, 19909, 19858, 6234, 9847, 14041, 16330, 12714, 15470, 19601, 13878, 9526, 22165, 9216, 11370, 21174, 4988, 5905, 13903, 17584, 8242, 1613, 1057, 19046, 330, 6855, 21645, 10177, 8400, 831, 15091, 19292, 14662, 7175, 7526, 7306, 12736, 1252, 14363, 15066, 13189, 1406, 8745, 16737, 3087, 14748, 2624, 19176, 21411, 18486, 3838, 15398, 9025, 14233, 4506, 1935, 11238, 13700, 7865, 15791, 3018, 17667, 21810, 10947, 15500, 8252, 15368, 11062, 5453, 9902, 22142, 10613, 12072, 10016, 4596, 2511, 11951, 16836, 8906, 3645, 11219, 4766, 6086, 16672, 21285, 3059, 3047, 18366, 2166, 10784, 5797, 12841, 16154, 1298, 11232, 15645, 22237, 7708, 15581, 21765, 16062, 12296, 15282, 6673, 3995, 8723, 8732, 461, 14816, 15488, 20090, 15484, 1383, 4940, 19542, 5865, 10810, 15394, 14924, 15676, 19472, 8087, 14167, 11919, 2091, 7380, 7317, 1376, 7406, 2720, 17709, 16592, 20891, 4316, 2404, 15305, 7077, 6700, 9062, 13021, 19069, 14298, 2030, 15786, 17847, 4698, 9863, 21494, 8564, 19985, 14585, 16768, 10865, 15110, 7561, 8667, 5975, 6976, 1257, 4099, 14516, 20016, 8619, 732, 3275, 7256, 11503, 18825, 6438, 11434, 1598, 10609, 3877, 20285, 21064, 11864, 5964, 4954, 3315, 1900, 6024, 8919, 2756, 13058, 7648, 4051, 306, 13100, 13011, 22319, 313, 12664, 1542, 18545, 19255, 11376, 17431, 13405, 21334, 3349, 14156, 5682, 2859, 13269, 12793, 15504, 17643, 13098, 308, 18540, 10305, 9934, 13465, 18121, 14155, 3365, 21335, 18852, 22064, 10547, 15453, 5582, 20616, 3963, 115, 13826, 10757, 6921, 2794, 8040, 7552, 22224, 10326, 10161, 16917, 10813, 20871, 3670, 16237, 9371, 18969, 8096, 6305, 12080, 5027, 21373, 13441, 2101, 1899, 3386, 4955, 481, 10057, 14890, 14996, 5328, 6352, 14014, 16403, 18807, 15552, 5080, 6662, 16360, 5519, 8603, 14093, 21570, 22093, 8192, 12791, 13271, 8077, 2594, 1737, 21568, 14095, 3006, 9380, 76, 16206, 10678, 19321, 10862, 16854, 1292, 10175, 21647, 7255, 3400, 733, 5195, 11816, 10142, 6782, 1940, 5669, 18779, 13175, 11025, 11296, 21836, 6215, 11066, 17033, 4695, 12788, 14463, 13697, 12614, 9252, 14288, 1041, 11789, 7189, 9866, 18351, 12245, 4493, 2120, 21453, 21653, 16416, 15419, 2780, 8306, 18131, 10982, 14370, 3899, 1587, 12686, 2676, 21983, 1374, 7319, 5316, 11724, 15699, 1772, 12777, 4122, 2441, 19687, 474, 15260, 19768, 18876, 983, 5651, 17242, 19262, 782, 13889, 20215, 5857, 15829, 12733, 12723, 19366, 12689, 13630, 1400, 4976, 11193, 13437, 13063, 16500, 7752, 12893, 12876, 5718, 17831, 16152, 12843, 21795, 4097, 1259, 18427, 5001, 12825, 11675, 13544, 6838, 8925, 20539, 10460, 5634, 10657, 6343, 5350, 12813, 6349, 13146, 20562, 8645, 7969, 6161, 15466, 8939, 2061, 4880, 12808, 9007, 887, 17521, 17101, 675, 20270, 931, 10007, 6643, 13744, 17139, 19754, 4290, 17753, 5887, 14710, 13155, 21416, 20418, 6153, 1363, 13982, 3847, 19023, 11018, 17221, 2423, 20591, 3597, 5150, 19180, 21612, 20266, 12267, 9019, 18530, 17597, 3930, 6047, 7204, 16012, 15450, 21322, 19691, 17326, 727, 14878, 8323, 4944, 21845, 4472, 19504, 7688, 6523, 21909, 513, 744, 15140, 18357, 7301, 18860, 7732, 12324, 5756, 18219, 587, 8432, 15826, 2369, 5673, 17037, 7902, 9333, 14747, 3520, 16738, 20468, 16117, 12882, 626, 6333, 12960, 15052, 3654, 6283, 17557, 16339, 1604, 11714, 19111, 11532, 11813, 21976, 15325, 14848, 7058, 14960, 5257, 11255, 12985, 5789, 3046, 3479, 21286, 16699, 9683, 2985, 12799, 9267, 17563, 7056, 14850, 11101, 18365, 3478, 3060, 5790, 10950, 9533, 12312, 20558, 13720, 17874, 7735, 16809, 1779, 5691, 8166, 12223, 15278, 6068, 2847, 2212, 9669, 19188, 9705, 19719, 6245, 15405, 127, 20101, 90, 17666, 3504, 15792, 5207, 17422, 17621, 17835, 3801, 20019, 1333, 10534, 5824, 9379, 3287, 14096, 9366, 9481, 17587, 20235, 16546, 20129, 8802, 14881, 16755, 7173, 14664, 3885, 15108, 10867, 18167, 15910, 6815, 2798, 12798, 3055, 9684, 9905, 1338, 21573, 1617, 7798, 11990, 14981, 16830, 7161, 8263, 777, 8359, 10714, 4443, 5727, 15117, 1458, 16849, 2713, 17276, 19784, 5370, 11431, 18162, 9077, 18197, 10386, 11564, 18170, 12277, 7093, 4895, 464, 1884, 2272, 13001, 16000, 997, 541, 6293, 20984, 14436, 8767, 3856, 2737, 771, 14697, 1687, 22247, 11353, 6897, 18007, 620, 4733, 6417, 18307, 18451, 8123, 851, 16394, 8821, 6716, 18949, 14307, 4935, 16658, 19620, 5424, 1484, 11454, 18755, 21069, 3779, 11870, 3720, 11986, 19518, 20203, 17573, 17016, 8496, 17267, 15528, 15124, 6947, 21194, 22075, 21897, 6121, 10914, 18575, 5500, 861, 17920, 19283, 14706, 20336, 14755, 5459, 2463, 102, 16905, 553, 16279, 14044, 2258, 20142, 10406, 19486, 2191, 11407, 7995, 18811, 16445, 18262, 16558, 18681, 13334, 7436, 5937, 134, 5182, 15432, 13268, 3362, 5683, 22196, 12518, 19701, 4655, 2003, 17452, 18943, 16529, 13390, 2211, 3030, 6069, 2544, 14146, 14474, 5715, 5922, 13882, 11733, 4626, 6183, 1628, 6535, 18045, 7014, 16816, 4677, 14216, 4902, 16222, 8978, 6429, 20164, 7774, 7626, 2025, 6758, 15021, 8050, 21311, 20921, 4861, 15175, 9314, 15568, 11081, 1762, 7741, 17791, 13091, 8643, 20564, 9831, 10857, 11644, 5269, 2488, 22384, 12797, 2987, 6816, 4335, 8039, 3336, 6922, 18838, 8516, 6520, 16730, 21685, 8914, 2220, 15242, 18337, 17748, 16442, 8305, 3240, 15420, 17530, 7220, 12193, 9340, 5734, 19476, 16970, 11245, 15834, 8341, 4128, 2470, 16691, 12922, 17789, 7743, 7243, 577, 6599, 17188, 5816, 13057, 3382, 8920, 22270, 3703, 5438, 1719, 14760, 14855, 10630, 12811, 5352, 22188, 21290, 20522, 21183, 16925, 5143, 2070, 770, 2939, 3857, 2417, 12110, 5107, 20990, 21498, 5769, 2094, 9230, 6991, 7692, 1571, 18445, 14273, 15743, 17708, 3435, 7407, 924, 13645, 10112, 11213, 17275, 2965, 16850, 8189, 4828, 15339, 10572, 19951, 19172, 21920, 13313, 1070, 19275, 5068, 9417, 12126, 4177, 790, 13635, 6326, 1032, 9874, 19538, 17739, 13349, 16586, 11184, 18499, 468, 17178, 8455, 21482, 17097, 260, 13006, 11046, 6592, 21982, 3232, 12687, 19368, 16149, 7596, 848, 20043, 9090, 9488, 5267, 11646, 12701, 7602, 21206, 20768, 20296, 2022, 1054, 14639, 9502, 10467, 16461, 13969, 13569, 18228, 21640, 10795, 1819, 21876, 9741, 21046, 9308, 12624, 11366, 11099, 14852, 5253, 19243, 18104, 5225, 10334, 5603, 5333, 8840, 17507, 5288, 15851, 6127, 17295, 5279, 7132, 19175, 3518, 14749, 18710, 20264, 21614, 14036, 6726, 18275, 138, 11522, 19787, 5273, 6690, 22229, 5116, 19430, 17024, 10870, 19779, 17121, 6031, 16876, 13396, 14736, 8935, 21556, 6545, 5616, 8897, 1736, 3291, 8078, 8470, 269, 20645, 1169, 11322, 356, 17550, 16283, 20901, 1640, 21724, 8428, 10350, 9112, 9298, 13413, 15966, 7195, 1141, 12424, 5479, 15605, 10399, 17361, 11794, 638, 13584, 4708, 5400, 13731, 4731, 622, 22357, 16466, 22068, 4092, 8861, 18403, 5465, 14592, 20145, 15903, 10138, 11838, 17636, 6166, 8060, 14145, 2845, 6070, 891, 13321, 8714, 2533, 16161, 22030, 2483, 18831, 16160, 2539, 8715, 6736, 16885, 63, 6044, 7704, 20716, 8544, 4465, 7805, 15855, 10228, 22312, 20409, 10000, 1594, 21199, 13245, 6639, 12899, 11950, 3489, 4597, 21526, 18096, 21293, 20211, 18377, 7739, 1764, 14612, 6369, 22168, 4922, 13927, 14417, 22042, 11807, 19958, 12104, 21592, 1179, 20152, 22383, 2801, 5270, 16364, 641, 18830, 2536, 22031, 17977, 281, 17612, 6627, 11929, 21813, 18093, 20554, 21296, 16647, 16690, 2767, 4129, 5837, 6366, 6414, 7916, 101, 2884, 5460, 21946, 17311, 15733, 13935, 8817, 1287, 14390, 11767, 14420, 10050, 6042, 65, 7236, 5903, 4990, 22218, 908, 4712, 11820, 19686, 3222, 4123, 16707, 3961, 20618, 10585, 19899, 10290, 8904, 16838, 5631, 11450, 13419, 22106, 12101, 13491, 1987, 20590, 3135, 17222, 12131, 2204, 9826, 12109, 2735, 3858, 8284, 16379, 17704, 13235, 4377, 10755, 13828, 18978, 7809, 2012, 15304, 3430, 4317, 9364, 14098, 29, 7723, 14536, 9748, 992, 160, 9938, 2388, 21596, 17436, 21914, 21595, 2393, 9939, 9117, 4575, 12169, 48, 10731, 4244, 9620, 17298, 7876, 18990, 13775, 18591, 19382, 21061, 4194, 12009, 5672, 3093, 15827, 5859, 5123, 8857, 16356, 1167, 20647, 17373, 20095, 10076, 22373, 1246, 1817, 10797, 4778, 22154, 14268, 21544, 19723, 13304, 6517, 4630, 297, 17568, 8535, 16952, 11603, 21349, 17730, 5661, 710, 1295, 538, 21519, 12353, 1182, 17714, 8179, 13326, 15919, 5707, 18089, 10219, 14058, 8888, 16828, 14983, 13812, 10622, 4570, 21271, 4980, 591, 13035, 12363, 1076, 21956, 980, 3909, 7248, 8377, 5992, 7442, 691, 6904, 18939, 6910, 18605, 9234, 5019, 20033, 12318, 15182, 21250, 9971, 22265, 19372, 22304, 4892, 13692, 4769, 14801, 20148, 21245, 256, 6212, 10956, 12483, 9541, 14794, 14948, 7586, 16841, 16297, 13211, 13000, 2949, 1885, 11833, 18828, 643, 4912, 4410, 5846, 19394, 13592, 18609, 8036, 16316, 20141, 2878, 14045, 1550, 15329, 3867, 6076, 20134, 19516, 11988, 7800, 19841, 6491, 7591, 20107, 1149, 10038, 21213, 19903, 11, 4073, 20260, 16614, 21300, 20197, 10279, 5047, 12717, 21900, 15963, 19568, 14620, 172, 14452, 10381, 3617, 132, 5939, 15241, 2786, 8915, 6384, 14056, 10221, 9457, 16301, 9668, 3029, 2848, 13391, 721, 21834, 11298, 11689, 9825, 2420, 12132, 7641, 13344, 1732, 21139, 8032, 1092, 20158, 12115, 8598, 21156, 11406, 2874, 19487, 4821, 18696, 14085, 4264, 10079, 1837, 1099, 19887, 4017, 14829, 8503, 19183, 16537, 13240, 9322, 8368, 7042, 4374, 20545, 9839, 10236, 5591, 10783, 3476, 18367, 14742, 9788, 12673, 737, 9086, 4805, 19392, 5848, 427, 15209, 22340, 10978, 1958, 1157, 3679, 17378, 3745, 11906, 13112, 17118, 15705, 14667, 12760, 20833, 10134, 1352, 21449, 17853, 16477, 13295, 18319, 20155, 5780, 432, 3682, 19772, 780, 19264, 10127, 1888, 21717, 19237, 21463, 21452, 3245, 4494, 9922, 9514, 16474, 9523, 658, 12967, 16484, 12003, 20757, 18515, 19002, 1330, 18201, 1012, 5644, 15010, 1898, 3317, 13442, 4238, 1624, 19732, 20372, 9229, 2729, 5770, 7379, 3440, 11920, 5395, 10880, 21222, 11073, 13528, 13427, 17090, 14376, 12822, 18504, 7145, 14781, 11121, 10371, 10376, 17229, 336, 20727, 769, 2739, 5144, 17409, 402, 16656, 4937, 16683, 12543, 4879, 3164, 8940, 22120, 7686, 19506, 7639, 12134, 1517, 11382, 4084, 3944, 6809, 6375, 10841, 17719, 21746, 11076, 9558, 7885, 374, 8683, 20624, 20733, 18193, 4477, 18662, 3953, 18394, 16651, 12988, 15785, 3422, 14299, 9291, 9384, 6757, 2822, 7627, 1053, 2660, 20297, 13165, 14503, 7794, 7187, 11791, 190, 15440, 15303, 2406, 7810, 20475, 4361, 6918, 1999, 18327, 14068, 17451, 2853, 4656, 7961, 18326, 2007, 6919, 10759, 4670, 11466, 12584, 12669, 3611, 8001, 10628, 14857, 20589, 2425, 13492, 80, 19874, 12394, 6681, 4875, 397, 284, 14430, 4069, 976, 19250, 16241, 13615, 8169, 6150, 8780, 10639, 21709, 14021, 12091, 12804, 17145, 9439, 14719, 13150, 14494, 1156, 2152, 10979, 10034, 4619, 15364, 9625, 10089, 12184, 6469, 13231, 24, 21460, 12388, 18234, 13484, 5985, 9022, 5668, 3269, 6783, 21132, 3968, 11237, 3509, 4507, 10420, 16142, 10454, 16565, 5471, 17535, 15684, 5654, 19308, 6277, 3694, 21308, 829, 8402, 14582, 20383, 18033, 14979, 11992, 5034, 16197, 8320, 8805, 564, 11396, 4134, 8706, 17761, 22098, 16203, 6982, 17233, 6023, 3385, 3316, 2102, 15011, 15078, 8572, 3928, 17599, 6324, 13637, 5821, 21716, 2125, 10128, 11832, 2271, 2950, 465, 6310, 21332, 13407, 9575, 11954, 371, 1028, 16621, 15016, 4295, 1102, 19650, 1211, 6270, 8612, 22380, 18322, 21419, 8318, 16199, 13284, 1578, 1350, 10136, 15905, 11667, 18119, 13467, 19214, 11934, 5505, 18289, 9156, 18018, 20222, 12555, 6870, 14900, 17751, 4292, 17150, 865, 4299, 19919, 1098, 2184, 10080, 19352, 8674, 22282, 9246, 19223, 13749, 19587, 12563, 7714, 12405, 4408, 4914, 6969, 10428, 21051, 21875, 2649, 10796, 2356, 1247, 1223, 9980, 11110, 17941, 3972, 1214, 4447, 11054, 18437, 3983, 7535, 20405, 19969, 19259, 18797, 15895, 6265, 12997, 20684, 4816, 18111, 11977, 13683, 6402, 11897, 12179, 21027, 18207, 8313, 13122, 21777, 9520, 17856, 17426, 12467, 5690, 3036, 16810, 19051, 18431, 19956, 11809, 12776, 3225, 15700, 13709, 20353, 1661, 16192, 14349, 14611, 2503, 7740, 2811, 11082, 7104, 15960, 14580, 8404, 6074, 3869, 5008, 9190, 12942, 21893, 16503, 22123, 19803, 21225, 20031, 5021, 11280, 7289, 9531, 10952, 6117, 14340, 21567, 3290, 2595, 8898, 15415, 21138, 2200, 13345, 17445, 921, 8584, 8576, 9879, 11729, 8396, 8960, 16173, 1446, 14759, 2751, 5439, 10792, 8631, 8218, 13399, 3650, 6204, 9180, 9395, 20596, 17578, 11144, 7828, 17333, 13951, 8197, 17640, 1463, 14511, 15258, 476, 21217, 18178, 1336, 9907, 3799, 17837, 3724, 8101, 3808, 22246, 2936, 14698, 360, 4418, 6697, 11363, 4146, 8616, 3804, 14688, 19867, 13850, 6729, 15312, 21093, 11163, 7925, 5260, 13841, 16079, 22056, 20321, 21625, 7339, 18741, 16191, 1768, 20354, 4201, 6771, 961, 7388, 10655, 5636, 15222, 10159, 10328, 17205, 20748, 16383, 4150, 5187, 20744, 6011, 151, 21355, 21723, 2583, 20902, 6799, 10389, 20283, 3879, 15166, 22049, 21280, 22131, 9389, 6534, 2836, 6184, 1186, 19731, 2098, 4239, 20914, 8446, 16611, 21963, 7797, 2980, 21574, 14637, 1056, 3543, 8243, 16982, 8128, 15360, 11301, 16132, 5386, 11713, 3074, 16340, 4868, 9951, 4482, 10608, 3394, 11435, 9912, 21198, 2517, 10001, 958, 13675, 18686, 11267, 12685, 3234, 3900, 17289, 12321, 17877, 9759, 18013, 12650, 1349, 1861, 13285, 11886, 8579, 11773, 3918, 18444, 2725, 7693, 22035, 4845, 7193, 15968, 18140, 18037, 12802, 12093, 9632, 20252, 12260, 7364, 9887, 8943, 15375, 21426, 1487, 14322, 15328, 2256, 14046, 16863, 4737, 11682, 18665, 7039, 18544, 3372, 12665, 7712, 12565, 10286, 1036, 672, 21560, 7304, 7528, 118, 11577, 6957, 11006, 5969, 18533, 14111, 22201, 6955, 11579, 19065, 18724, 13356, 11226, 11381, 2054, 12135, 4423, 15984, 17046, 8418, 17810, 12940, 9192, 12452, 13278, 17646, 21067, 18757, 5800, 18961, 18078, 17866, 7370, 14345, 7769, 21733, 9428, 5595, 6109, 19809, 20754, 15595, 7570, 14321, 1553, 21427, 11453, 2915, 5425, 17176, 470, 18153, 20771, 13948, 14185, 927, 4543, 9608, 1081, 19576, 17533, 5473, 7002, 22102, 13793, 1239, 12833, 14510, 1701, 17641, 15506, 9869, 16848, 2967, 15118, 7557, 7439, 16644, 12754, 16991, 8664, 13893, 21758, 12241, 14758, 1721, 16174, 18280, 10917, 203, 1105, 5696, 17892, 16580, 422, 15230, 14132, 14970, 14871, 267, 8472, 6723, 22000, 17010, 4005, 15494, 4388, 6059, 5087, 6556, 11843, 1074, 12365, 13069, 14027, 9353, 9803, 17955, 17936, 15251, 13515, 16099, 19450, 7958, 8744, 3523, 13190, 17285, 19661, 896, 4975, 3202, 13631, 16077, 13843, 17031, 11068, 17827, 8092, 13104, 16609, 8448, 14439, 18679, 16560, 98, 16681, 4939, 3452, 15485, 1153, 11984, 3722, 17839, 7405, 3437, 7318, 3230, 21984, 18652, 11458, 4139, 5877, 4833, 10213, 20604, 4187, 13981, 3141, 6154, 13024, 14813, 4898, 34, 5929, 16377, 8286, 17510, 21448, 2139, 10135, 1860, 1579, 12651, 19747, 13086, 10780, 14606, 11964, 20572, 519, 22091, 21572, 2982, 9906, 1695, 18179, 10533, 3010, 20020, 18200, 2107, 19003, 10530, 4746, 20888, 3637, 19481, 18615, 340, 7312, 16094, 10449, 11205, 17679, 10575, 12253, 10557, 15958, 7106, 18136, 5680, 14158, 652, 10545, 22066, 16468, 21739, 11850, 11360, 7080, 20720, 11231, 3471, 16155, 537, 2337, 711, 10174, 3279, 16855, 18223, 4434, 14389, 2456, 8818, 12330, 1275, 9415, 5070, 1243, 10540, 8183, 14414, 6792, 9414, 1284, 12331, 5898, 12139, 4250, 5065, 21668, 15270, 5077, 13471, 125, 15407, 17087, 15609, 20455, 18426, 3187, 4098, 3406, 6977, 20660, 20194, 14362, 3527, 12737, 9843, 6442, 1222, 1816, 2357, 22374, 10539, 1281, 5071, 13562, 12832, 1466, 13794, 20200, 10988, 8257, 12731, 15831, 5767, 21500, 9074, 17633, 6388, 6448, 12083, 14471, 9979, 1815, 1248, 6443, 11022, 18844, 17406, 17807, 11261, 4446, 1810, 3973, 6269, 1870, 19651, 5469, 16567, 13016, 8753, 5264, 15617, 8216, 8633, 5804, 15445, 19495, 319, 4775, 12480, 20798, 19877, 9149, 95, 8487, 12204, 15588, 14790, 19730, 1626, 6185, 11717, 17713, 2333, 12354, 20151, 2491, 21593, 21916, 20696, 4216, 9259, 12744, 11512, 20306, 11321, 2589, 20646, 2363, 16357, 9446, 13786, 5724, 11264, 5232, 9139, 9959, 3678, 2151, 1959, 14495, 11983, 1381, 15486, 14818, 10037, 2244, 20108, 22138, 22216, 4992, 7210, 20098, 12423, 2574, 7196, 15171, 10202, 3608, 3769, 15264, 9823, 11691, 4792, 16071, 17890, 5698, 8266, 12151, 16640, 15599, 12981, 17822, 20075, 17414, 8145, 10836, 18002, 10093, 21408, 16744, 343, 20761, 263, 8090, 17829, 5720, 18913, 19335, 5695, 1441, 204, 19649, 1872, 4296, 19886, 2183, 1838, 19920, 5747, 9641, 5778, 20157, 2197, 8033, 17005, 10682, 18643, 14083, 18698, 20471, 21565, 14342, 19575, 1473, 9609, 11695, 8026, 21955, 2313, 12364, 1420, 11844, 6942, 19274, 2703, 13314, 4198, 17918, 863, 17152, 16136, 3775, 16082, 20512, 8987, 19027, 19045, 3542, 1614, 14638, 2659, 2023, 7628, 6633, 8475, 17072, 18457, 11539, 6879, 10789, 20052, 4664, 11788, 3252, 14289, 22241, 20751, 671, 1537, 10287, 803, 9873, 2694, 6327, 21848, 16620, 1876, 372, 7887, 12749, 13046, 22151, 15769, 17365, 19074, 8953, 7905, 10910, 9178, 6206, 18767, 5643, 2105, 18202, 6614, 14373, 379, 8214, 15619, 8721, 3997, 5744, 5705, 15921, 4013, 21517, 540, 2946, 16001, 7322, 4849, 159, 2396, 9749, 567, 8137, 16108, 4838, 12299, 21277, 5650, 3216, 18877, 3908, 2311, 21957, 9237, 19249, 1976, 4070, 20528, 14076, 11969, 11335, 13565, 7935, 7017, 20839, 20907, 10941, 8976, 16224, 7387, 1657, 6772, 13674, 1592, 10002, 17609, 400, 17411, 21804, 13963, 12045, 6631, 7630, 17143, 12806, 4882, 21040, 20255, 4541, 929, 20272, 19149, 741, 10850, 8589, 16908, 12539, 22368, 20446, 10006, 3155, 20271, 942, 4542, 1476, 14186, 13644, 2718, 7408, 8583, 1729, 17446, 4367, 16312, 22172, 16054, 16782, 15427, 8815, 13937, 19710, 5297, 4711, 2445, 22219, 7943, 8893, 14482, 15069, 17546, 15202, 12529, 18976, 13830, 4974, 1402, 19662, 16625, 21162, 13320, 2542, 6071, 15710, 17520, 3160, 9008, 18314, 9992, 6830, 15479, 22163, 9528, 16807, 7737, 18379, 21394, 21854, 20058, 10041, 14577, 21903, 6288, 6579, 17795, 19884, 4298, 1841, 17151, 1066, 17919, 2891, 5501, 21583, 16435, 7299, 18359, 18800, 22287, 12274, 16393, 2925, 8124, 20042, 2671, 7597, 7447, 7615, 5871, 719, 13393, 8291, 7607, 17342, 13457, 19794, 15849, 5290, 21720, 20858, 15090, 3535, 8401, 1921, 21309, 8052, 20655, 19104, 8299, 19096, 301, 21054, 19412, 20777, 7757, 21706, 21870, 13067, 12367, 17070, 8477, 16891, 21534, 5959, 6882, 7085, 11572, 8328, 9872, 1034, 10288, 19901, 21215, 478, 20004, 20001, 4958, 142, 6467, 12186, 13362, 13634, 2697, 4178, 17157, 7835, 5449, 21678, 14385, 13888, 3212, 19263, 2128, 19773, 8358, 2973, 8264, 5700, 9473, 14938, 14696, 2938, 2738, 2071, 20728, 15055, 762, 22011, 14674, 22010, 766, 15056, 60, 4107, 8845, 11700, 13228, 18383, 4164, 19742, 11599, 13764, 14739, 15537, 18855, 12217, 19116, 15139, 3105, 514, 10849, 939, 19150, 5978, 9085, 2161, 12674, 14003, 5194, 3274, 3401, 8620, 11304, 7844, 14877, 3116, 17327, 21124, 7124, 9956, 21833, 2209, 13392, 843, 5872, 7350, 16943, 21608, 8009, 8775, 10173, 1294, 2338, 5662, 19605, 13480, 4638, 16508, 17487, 3988, 16930, 9949, 4870, 5294, 22135, 16183, 10826, 6486, 10728, 10970, 6903, 2305, 7443, 14809, 14635, 21576, 524, 11753, 20425, 8373, 6281, 3656, 9795, 11857, 16571, 20504, 20269, 3157, 17102, 21559, 1536, 1037, 20752, 19811, 13966, 6019, 14008, 15614, 9491, 7273, 14838, 14623, 20897, 12966, 2114, 9524, 13880, 5924, 21089, 10544, 1308, 14159, 70, 9918, 4673, 20347, 11318, 8867, 4911, 2268, 18829, 2485, 16365, 13583, 2567, 11795, 8499, 20944, 10153, 249, 11782, 18518, 6373, 6811, 18928, 6332, 3082, 12883, 3631, 22356, 2561, 4732, 2931, 18008, 16513, 9270, 20608, 12874, 12895, 6550, 3629, 12885, 15296, 13222, 8891, 7945, 3739, 10937, 3640, 10527, 16431, 11607, 16598, 9549, 19204, 18297, 16973, 8784, 17068, 12369, 13034, 2316, 4981, 21440, 8431, 3096, 18220, 5177, 4725, 18891, 11447, 10463, 19917, 4301, 6598, 2761, 7244, 4487, 21884, 9983, 17804, 5147, 7950, 7215, 8136, 990, 9750, 11395, 1910, 8806, 13252, 12436, 21671, 20185, 11096, 19130, 16179, 11439, 16278, 2881, 16906, 8591, 4365, 17448, 19281, 17922, 16065, 21363, 5774, 18550, 6292, 2945, 998, 21518, 2336, 1296, 16156, 4236, 13444, 11912, 7549, 18632, 15662, 7083, 6884, 4045, 13265, 11752, 686, 21577, 9327, 6503, 22090, 1341, 20573, 19745, 12653, 10848, 743, 3106, 21910, 12338, 17905, 21819, 12411, 11285, 14012, 6354, 16427, 17441, 11487, 9450, 20642, 5891, 14643, 317, 19497, 16273, 9675, 20162, 6431, 7815, 21522, 16106, 8139, 5760, 278, 15869, 19286, 21881, 10056, 3313, 4956, 20003, 799, 21216, 1698, 15259, 3220, 19688, 9081, 18152, 1481, 17177, 2686, 18500, 6309, 1883, 2951, 4896, 14815, 3457, 8733, 21952, 11172, 17629, 17028, 9421, 22046, 17785, 7746, 8012, 15560, 9947, 16932, 19932, 5083, 9028, 6319, 14236, 13659, 21934, 11222, 14366, 21316, 20081, 21414, 13157, 17376, 3681, 2131, 5781, 20774, 14597, 15208, 2156, 5849, 17692, 15193, 15229, 1437, 16581, 12292, 17196, 10579, 19324, 7069, 3841, 16103, 15816, 15800, 19716, 19162, 21020, 3742, 11748, 11390, 11917, 14169, 16655, 2067, 17410, 955, 17610, 283, 1980, 4876, 8355, 15669, 20964, 5384, 16134, 17154, 5945, 11399, 7484, 5875, 4141, 7718, 21630, 21628, 7720, 8213, 1008, 14374, 17092, 5136, 8682, 2042, 7886, 1027, 1877, 11955, 4321, 5614, 6547, 17239, 15687, 6231, 19856, 19911, 4417, 1685, 14699, 20824, 17549, 2587, 11323, 4568, 10624, 7975, 19897, 10587, 9974, 12971, 21939, 4609, 7226, 20760, 1114, 16745, 7311, 1322, 18616, 6313, 20726, 2073, 17230, 12037, 8836, 14545, 6854, 3540, 19047, 11847, 21087, 5926, 19835, 18302, 17733, 4535, 4969, 4774, 1198, 19496, 497, 14644, 13621, 12663, 3374, 22320, 9463, 13624, 18539, 3356, 13099, 3378, 4052, 15889, 21873, 21053, 822, 19097, 14202, 17567, 2346, 4631, 20488, 6191, 10353, 15390, 20925, 8601, 5521, 8973, 19965, 10293, 14429, 1979, 398, 17611, 2480, 17978, 15868, 486, 5761, 17181, 12504, 13452, 20334, 14708, 5889, 20644, 2591, 8471, 1432, 14872, 14165, 8089, 1112, 20762, 13005, 2681, 17098, 21695, 6211, 2284, 21246, 178, 12707, 12490, 18899, 11781, 633, 10154, 17932, 15629, 9820, 11519, 9346, 21370, 6625, 17614, 20040, 8126, 16984, 13912, 11962, 14608, 3765, 9791, 6913, 21512, 12866, 18841, 13178, 16023, 19893, 17472, 18055, 6080, 21476, 6340, 17770, 3922, 7361, 11561, 6802, 4311, 12992, 8066, 10770, 12000, 16256, 7681, 9240, 17040, 19648, 1104, 1442, 10918, 12428, 12828, 3959, 16709, 19536, 9876, 11889, 14967, 8281, 20868, 15439, 2015, 11792, 17363, 15771, 3753, 8641, 13093, 8982, 17320, 8833, 7006, 12706, 254, 21247, 17402, 19947, 21486, 14451, 2227, 14621, 14840, 19060, 12068, 17671, 13707, 15702, 19782, 17278, 13074, 9937, 2395, 993, 4850, 6747, 18925, 14686, 3806, 8103, 21354, 1643, 6012, 4691, 18584, 20705, 19458, 11041, 17538, 6466, 795, 4959, 9344, 11521, 2616, 18276, 11777, 5181, 2863, 5938, 2223, 3618, 11804, 12421, 20100, 3022, 15406, 1265, 13472, 19639, 18691, 13249, 17688, 11576, 1532, 7529, 13825, 3340, 3964, 17394, 13718, 20560, 13148, 14721, 13603, 3592, 21539, 10120, 18479, 16904, 2883, 2464, 7917, 16680, 1386, 16561, 8486, 1192, 9150, 17281, 17963, 17665, 3020, 20102, 17502, 6510, 6850, 15728, 12950, 9012, 12164, 19873, 1985, 13493, 6980, 16205, 3285, 9381, 19018, 22081, 12931, 9917, 650, 14160, 10361, 11875, 7235, 2450, 6043, 2529, 16886, 4106, 760, 15057, 6679, 12396, 18728, 7050, 7183, 20239, 11416, 4927, 10968, 10730, 2383, 12170, 12938, 17812, 13019, 9064, 18023, 17354, 4594, 10018, 18761, 21770, 19833, 5928, 1358, 4899, 5057, 8211, 7722, 2400, 14099, 18086, 9853, 21459, 1948, 13232, 18127, 12316, 20035, 21148, 11855, 9797, 16421, 4799, 13780, 20526, 4072, 2240, 19904, 19593, 9597, 18660, 4479, 16794, 14928, 11196, 22391]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c3575eae12645e2bb58660e7639a35ff4af57b1 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 22391, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l6-s4/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-sum-permutation-l3-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l3-s3/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a7010d9a33393a05d5d1d9787c9b5019b076f9d --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 80, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s3/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..eb1dbe03da349a026209c011d1b990358299cd12 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [80, 1, 78, 3, 76, 5, 74, 7, 72, 9, 70, 11, 68, 13, 66, 15, 64, 17, 62, 19, 60, 21, 58, 23, 56, 25, 54, 27, 52, 29, 50, 31, 48, 33, 46, 35, 44, 37, 42, 39, 40, 41, 38, 43, 36, 45, 34, 47, 32, 49, 30, 51, 28, 53, 26, 55, 24, 57, 22, 59, 20, 61, 18, 63, 16, 65, 14, 67, 12, 69, 10, 71, 8, 73, 6, 75, 4, 77, 2, 79]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a7010d9a33393a05d5d1d9787c9b5019b076f9d --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 80, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l3-s3/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l3-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s4/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..09307b8083f935e396bf0e3d057bda2d06542d45 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 282, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s4/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a479d4c052323f583a174f88be46cf4d445d1702 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [282, 1, 280, 3, 278, 5, 276, 7, 274, 9, 272, 11, 270, 13, 268, 15, 266, 17, 264, 19, 262, 21, 260, 23, 258, 25, 256, 27, 254, 29, 252, 31, 250, 33, 248, 35, 246, 37, 244, 39, 242, 41, 240, 43, 238, 45, 236, 47, 234, 49, 232, 51, 230, 53, 228, 55, 226, 57, 224, 59, 222, 61, 220, 63, 218, 65, 216, 67, 214, 69, 212, 71, 210, 73, 208, 75, 206, 77, 204, 79, 202, 81, 200, 83, 198, 85, 196, 87, 194, 89, 192, 91, 190, 93, 188, 95, 186, 97, 184, 99, 182, 101, 180, 103, 178, 105, 176, 107, 174, 109, 172, 111, 170, 113, 168, 115, 166, 117, 164, 119, 162, 121, 160, 123, 158, 125, 156, 127, 154, 129, 152, 131, 150, 133, 148, 135, 146, 137, 144, 139, 142, 141, 140, 143, 138, 145, 136, 147, 134, 149, 132, 151, 130, 153, 128, 155, 126, 157, 124, 159, 122, 161, 120, 163, 118, 165, 116, 167, 114, 169, 112, 171, 110, 173, 108, 175, 106, 177, 104, 179, 102, 181, 100, 183, 98, 185, 96, 187, 94, 189, 92, 191, 90, 193, 88, 195, 86, 197, 84, 199, 82, 201, 80, 203, 78, 205, 76, 207, 74, 209, 72, 211, 70, 213, 68, 215, 66, 217, 64, 219, 62, 221, 60, 223, 58, 225, 56, 227, 54, 229, 52, 231, 50, 233, 48, 235, 46, 237, 44, 239, 42, 241, 40, 243, 38, 245, 36, 247, 34, 249, 32, 251, 30, 253, 28, 255, 26, 257, 24, 259, 22, 261, 20, 263, 18, 265, 16, 267, 14, 269, 12, 271, 10, 273, 8, 275, 6, 277, 4, 279, 2, 281]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..09307b8083f935e396bf0e3d057bda2d06542d45 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 282, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s2/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l2-s2/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23e579ec87084f4a9be8e3a43bf1cd17f4c631ef --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s2/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24a7efb57c34db028474656fca84a7fed20de014 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23e579ec87084f4a9be8e3a43bf1cd17f4c631ef --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l2-s2/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-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-prime-graph-coloring-l2-s5/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s5/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bce0ba3f979f40c7891ece24aaf25e842a3747e8 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s5/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ae3ac5c121cc5b8a44bd953a8b894a7ea445d88 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bce0ba3f979f40c7891ece24aaf25e842a3747e8 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1943bcaf2d1c859f03d46ed54d8c4f39adf41f98 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"F0": 31, "A": 1, "B": 3523, "S": 204520, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..16eb8363c71f7eac4a46ae0ed657fe62b4966426 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [2, 4, 7, 11, 14, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1943bcaf2d1c859f03d46ed54d8c4f39adf41f98 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"F0": 31, "A": 1, "B": 3523, "S": 204520, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s7/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l4-s7/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2daba70af127c25d64fea315ad523c1553313f2f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"F0": 9, "A": 7, "B": 3633, "S": 57181065149912192853, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s7/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8a7fa9a221254fae2dfb20a6c05d26ab6b357d4b --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 5, 12, 13, 14, 17, 18, 19, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-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-l4-s7/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2daba70af127c25d64fea315ad523c1553313f2f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"F0": 9, "A": 7, "B": 3633, "S": 57181065149912192853, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l4-s7/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l4-s9/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s9/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15a8ce7db16bea1e3aaa61ea6e751ffd101504b0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"F0": 10, "A": 4, "B": 2254, "S": 1116125671820130, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s9/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..905ef10e755c34d06f2c4d89f409b859affe0cd8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/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-l4-s9/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15a8ce7db16bea1e3aaa61ea6e751ffd101504b0 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"F0": 10, "A": 4, "B": 2254, "S": 1116125671820130, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l3-s8/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l3-s8/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef3f79b80214f358cbfe08c19fb8a87379484ac4 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"K": 97002, "n_max": 105, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l3-s8/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2ee015dec23d3718eef69dea52538c070887777 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 51, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l3-s8/tests/check.py b/tasks/construct-rlve-shortest-path-count-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s8/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l3-s8/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef3f79b80214f358cbfe08c19fb8a87379484ac4 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"K": 97002, "n_max": 105, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l3-s8/tests/run.py b/tasks/construct-rlve-shortest-path-count-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l3-s8/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-subgraph-isomorphism-l4-s0/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s0/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b2c035d2bd344796e52436acf588f1ac0dc93bca --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n1": 9, "n2": 18, "edges1": [[3, 7], [1, 4], [0, 6], [0, 3], [5, 6], [6, 7], [0, 1], [0, 7], [1, 2], [1, 3], [2, 4], [1, 5], [4, 7], [1, 7], [0, 4], [2, 6], [0, 8]], "edges2": [[12, 16], [4, 10], [3, 7], [5, 8], [3, 5], [0, 16], [7, 12], [8, 16], [7, 9], [2, 3], [8, 13], [0, 14], [10, 15], [2, 12], [5, 12], [5, 9], [12, 13], [12, 17], [9, 15], [0, 7], [7, 13], [0, 8], [3, 9], [11, 14], [0, 10], [11, 13], [5, 14], [15, 17], [8, 11], [14, 15], [4, 13], [2, 13], [8, 10], [6, 11], [1, 14], [2, 7], [1, 10], [6, 7], [13, 14], [4, 6], [16, 17], [6, 16], [9, 16], [1, 9], [6, 14], [10, 11], [4, 17], [4, 11], [3, 8], [10, 13], [6, 17], [5, 15], [6, 13]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s0/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b949cfb6af421f1467d433d8cd604745ca1be05c --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [13, 10, 0, 4, 8, 15, 14, 11, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/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-l4-s0/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b2c035d2bd344796e52436acf588f1ac0dc93bca --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n1": 9, "n2": 18, "edges1": [[3, 7], [1, 4], [0, 6], [0, 3], [5, 6], [6, 7], [0, 1], [0, 7], [1, 2], [1, 3], [2, 4], [1, 5], [4, 7], [1, 7], [0, 4], [2, 6], [0, 8]], "edges2": [[12, 16], [4, 10], [3, 7], [5, 8], [3, 5], [0, 16], [7, 12], [8, 16], [7, 9], [2, 3], [8, 13], [0, 14], [10, 15], [2, 12], [5, 12], [5, 9], [12, 13], [12, 17], [9, 15], [0, 7], [7, 13], [0, 8], [3, 9], [11, 14], [0, 10], [11, 13], [5, 14], [15, 17], [8, 11], [14, 15], [4, 13], [2, 13], [8, 10], [6, 11], [1, 14], [2, 7], [1, 10], [6, 7], [13, 14], [4, 6], [16, 17], [6, 16], [9, 16], [1, 9], [6, 14], [10, 11], [4, 17], [4, 11], [3, 8], [10, 13], [6, 17], [5, 15], [6, 13]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s7/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l4-s7/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..687fe2a728ac980709bbc9513233c83ae8d69fc3 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n1": 15, "n2": 18, "edges1": [[6, 7], [3, 4], [2, 4], [6, 8], [0, 11], [2, 14], [4, 13], [8, 9], [2, 3], [0, 9], [10, 14], [1, 12], [8, 11], [1, 9], [3, 10], [5, 13], [3, 7], [8, 13], [0, 1], [1, 7], [1, 3], [4, 9], [10, 11], [1, 5], [5, 8], [2, 12], [3, 9], [1, 6], [5, 12], [2, 5], [4, 10], [12, 13]], "edges2": [[7, 13], [5, 14], [2, 16], [5, 13], [14, 15], [10, 13], [5, 16], [1, 9], [3, 12], [4, 14], [11, 16], [8, 11], [0, 13], [1, 5], [4, 15], [1, 7], [13, 17], [10, 17], [5, 11], [4, 11], [3, 11], [0, 7], [2, 15], [10, 14], [0, 4], [7, 10], [1, 11], [9, 16], [0, 1], [8, 12], [2, 10], [4, 7], [11, 14], [3, 6], [4, 6], [3, 4], [6, 10], [4, 17]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s7/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..41ba8b36536a07bba3ab7aae5f50eacc4b04c28d --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [15, 4, 1, 11, 5, 7, 6, 3, 10, 14, 16, 2, 0, 13, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..687fe2a728ac980709bbc9513233c83ae8d69fc3 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n1": 15, "n2": 18, "edges1": [[6, 7], [3, 4], [2, 4], [6, 8], [0, 11], [2, 14], [4, 13], [8, 9], [2, 3], [0, 9], [10, 14], [1, 12], [8, 11], [1, 9], [3, 10], [5, 13], [3, 7], [8, 13], [0, 1], [1, 7], [1, 3], [4, 9], [10, 11], [1, 5], [5, 8], [2, 12], [3, 9], [1, 6], [5, 12], [2, 5], [4, 10], [12, 13]], "edges2": [[7, 13], [5, 14], [2, 16], [5, 13], [14, 15], [10, 13], [5, 16], [1, 9], [3, 12], [4, 14], [11, 16], [8, 11], [0, 13], [1, 5], [4, 15], [1, 7], [13, 17], [10, 17], [5, 11], [4, 11], [3, 11], [0, 7], [2, 15], [10, 14], [0, 4], [7, 10], [1, 11], [9, 16], [0, 1], [8, 12], [2, 10], [4, 7], [11, 14], [3, 6], [4, 6], [3, 4], [6, 10], [4, 17]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l4-s7/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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/optimize-ea-circles-rectangle-n21/environment/Dockerfile b/tasks/optimize-ea-circles-rectangle-n21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-circles-rectangle-n21/environment/instance.json b/tasks/optimize-ea-circles-rectangle-n21/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26c6f9e3f2c7448f2165854f1979a97fdcb145cb --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/environment/instance.json @@ -0,0 +1 @@ +{"n": 21, "direction": "maximize", "family": "ea_circles_rectangle_21", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-circles-rectangle-n21/solution/solve.sh b/tasks/optimize-ea-circles-rectangle-n21/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..50be8e8adb6e3153669f9d0588f9cace570ae91a --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"circles": [[0.12396161, 0.12396161, 0.12396159760383901], [0.0747415, 0.31647214, 0.07474149252585001], [0.12740019, 0.51163445, 0.127400177259981], [0.0747415, 0.70679675, 0.07474149252585001], [0.12396161, 0.89930729, 0.12396159760383901], [0.36284141, 0.11508312, 0.115083108491688], [0.25916864, 0.31452627, 0.10969588903041], [0.37244262, 0.51163445, 0.117642228235776], [0.25916864, 0.70874263, 0.10969588903041], [0.3628414, 0.90818577, 0.11508311849168701], [0.59083599, 0.11292169, 0.11292167870783101], [0.48083152, 0.30914434, 0.112032298796769], [0.62891008, 0.51163445, 0.138825206117478], [0.48083152, 0.71412455, 0.112032298796769], [0.59083598, 0.9103472, 0.11292168870783001], [0.67852787, 0.2919303, 0.086412051358794], [0.85766825, 0.39257159, 0.11906284809371401], [0.85766825, 0.6306973, 0.11906284809371401], [0.67852787, 0.73133859, 0.086412051358794], [0.83965981, 0.8861976, 0.13707128629287002], [0.83965981, 0.1370713, 0.13707128629287002]]} +RLMATH_EOF diff --git a/tasks/optimize-ea-circles-rectangle-n21/tests/check.py b/tasks/optimize-ea-circles-rectangle-n21/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..75f56da763151ed4490b1e352b0fa9409811ddf7 --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/tests/check.py @@ -0,0 +1,27 @@ +"""21 disjoint circles in a rectangle of perimeter 4, maximize the sum of radii +(EinsteinArena circles-rectangle, MIT). + +Upstream bug fixed: the perimeter test is exact (Fractions) upstream but the disjointness test compares +float sqrt distances; both are exact here.""" +from fractions import Fraction + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + c = float_matrix(ans.get("circles"), n, 3, "circles") + F = [tuple(Fraction(v) for v in row) for row in c] + if any(r <= 0 for _, _, r in F): + raise Invalid("radii must be positive") + w = max(x + r for x, _, r in F) - min(x - r for x, _, r in F) + h = max(y + r for _, y, r in F) - min(y - r for _, y, r in F) + if w + h > 2: + raise Invalid("bounding rectangle violates width + height <= 2") + for i in range(n): + xi, yi, ri = F[i] + for j in range(i + 1, n): + xj, yj, rj = F[j] + if (xi - xj) ** 2 + (yi - yj) ** 2 < (ri + rj) ** 2: + raise Invalid(f"circles {i} and {j} overlap") + return sum(r for _, _, r in c), {} diff --git a/tasks/optimize-ea-circles-rectangle-n21/tests/instance.json b/tasks/optimize-ea-circles-rectangle-n21/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..043fd07e65e5d8f0449348aa0085e041f7f79465 --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/tests/instance.json @@ -0,0 +1 @@ +{"n": 21, "direction": "maximize", "best_known": 2.3658323759, "baseline": 1.96875, "family": "ea_circles_rectangle_21", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-circles-rectangle-n21/tests/run.py b/tasks/optimize-ea-circles-rectangle-n21/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ea-circles-rectangle-n21/tests/test.sh b/tasks/optimize-ea-circles-rectangle-n21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-circles-rectangle-n21/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ea-uncertainty-principle/environment/Dockerfile b/tasks/optimize-ea-uncertainty-principle/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ea-uncertainty-principle/environment/instance.json b/tasks/optimize-ea-uncertainty-principle/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8aff289b37d435fc83d9e042aace96ce9ac2aaa9 --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/environment/instance.json @@ -0,0 +1 @@ +{"max_roots": 25, "max_root": 300, "direction": "minimize", "family": "ea_uncertainty_principle", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-uncertainty-principle/solution/solve.sh b/tasks/optimize-ea-uncertainty-principle/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6ea2123a2d48992dc90d2de2cd88cea3e908e419 --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"laguerre_double_roots": [3.64273649, 5.68246114, 33.00463486, 40.97185579, 50.1028231, 53.76768016]} +RLMATH_EOF diff --git a/tasks/optimize-ea-uncertainty-principle/tests/check.py b/tasks/optimize-ea-uncertainty-principle/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8333ef5642f3cf52e0eefca66545e021b9c9fb8d --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/tests/check.py @@ -0,0 +1,151 @@ +"""Uncertainty principle upper bound via Laguerre double roots (EinsteinArena uncertainty-principle, MIT). + +Given double-root positions z_1..z_m, g = sum_{j=0}^{2m+1} c_j L_{2j}^{(-1/2)} with g(0)=0, g'(0)=1, +g(z_i)=g'(z_i)=0; h = g / (x prod (x-z_i)^2) is a polynomial and the score is r/(2 pi), r = largest +positive root of h of odd multiplicity (last sign change) (minimize). + +Changes vs the upstream verifier (float64 / mpmath linear solve, 200k-point float grid scan + brentq): +* the linear system is solved in 400- and 600-digit decimal arithmetic, h is formed by exact synthetic + division, and the last sign change is found by exact real-root isolation (sympy) of h with + coefficients rounded to 60 significant digits -- no grid, so close root pairs and roots beyond the + upstream scan window (1.5 max z + 100) cannot be missed; the two precisions must agree; +* NEW validity check (upstream omission): the test function -g(2 pi x^2) e^{-pi x^2} must be eventually + non-negative, i.e. the leading coefficient of h must be negative; otherwise the bound is not valid; +* mpmath is not used (not in the allowed runtime set).""" +import math +from decimal import Decimal, localcontext +from fractions import Fraction + +import sympy as sp + +from run import Invalid, num + +SIG = 60 + + +def _laguerre(nmax): + al = Fraction(-1, 2) + L = [[Fraction(1)], [1 + al, Fraction(-1)]] + for k in range(1, nmax): + a, b = L[k], L[k - 1] + nxt = [Fraction(0)] * (k + 2) + for i, c in enumerate(a): + nxt[i] += (2 * k + 1 + al) * c + nxt[i + 1] -= c + for i, c in enumerate(b): + nxt[i] -= (k + al) * c + L.append([c / (k + 1) for c in nxt]) + return L + + +def _h_coeffs(zs, prec): + """Coefficients (high -> low) of h, as exact rationals rounded to SIG significant digits.""" + m = len(zs) + degs = list(range(0, 4 * m + 4, 2)) + L = _laguerre(degs[-1]) + with localcontext() as ctx: + ctx.prec = prec + + def D(q): + return Decimal(q.numerator) / Decimal(q.denominator) + + P = [[D(c) for c in L[d]] for d in degs] + Pd = [[i * c for i, c in enumerate(p)][1:] for p in P] + Pd[0] = [Decimal(0)] + + def ev(p, x): + r = Decimal(0) + for c in reversed(p): + r = r * x + c + return r + + zd = [D(z) for z in zs] + A = [[ev(p, Decimal(0)) for p in P] + [Decimal(0)], [ev(p, Decimal(0)) for p in Pd] + [Decimal(1)]] + for z in zd: + A.append([ev(p, z) for p in P] + [Decimal(0)]) + A.append([ev(p, z) for p in Pd] + [Decimal(0)]) + n = len(A) + for col in range(n): + piv = max(range(col, n), key=lambda r: abs(A[r][col])) + if A[piv][col] == 0: + raise Invalid("singular interpolation system") + A[col], A[piv] = A[piv], A[col] + pv = A[col][col] + for r in range(col + 1, n): + f = A[r][col] / pv + if f: + A[r] = [x - f * y for x, y in zip(A[r], A[col])] + c = [Decimal(0)] * n + for r in range(n - 1, -1, -1): + c[r] = (A[r][n] - sum(A[r][k] * c[k] for k in range(r + 1, n))) / A[r][r] + g = [Decimal(0)] * (degs[-1] + 1) + for cj, p in zip(c, P): + for i, v in enumerate(p): + g[i] += cj * v + poly = list(reversed(g)) + rems = [] + + def synth(pl, z): + out = [pl[0]] + for co in pl[1:]: + out.append(co + out[-1] * z) + return out[:-1], out[-1] + + poly, rm = synth(poly, Decimal(0)) + rems.append(rm) + for z in zd: + for _ in range(2): + poly, rm = synth(poly, z) + rems.append(rm) + scale = max(abs(x) for x in poly) + if scale == 0 or max(abs(r) for r in rems) > scale * Decimal(10) ** (-(prec // 3)): + raise Invalid("numerically unstable root configuration") + out = [] + for x in poly: + if x == 0: + out.append(sp.Integer(0)) + continue + q = x.adjusted() - SIG + out.append(sp.Integer(int(x.scaleb(-q).to_integral_value())) * sp.Rational(10) ** q) + return out + + +def _last_sign_change(coeffs): + x = sp.Symbol("x") + h = sp.Poly(coeffs, x, domain="QQ") + if not h.LC() < 0: + raise Invalid("the test function is not eventually of the right sign (leading coefficient of h >= 0)") + best = None + for fac, mult in h.sqf_list()[1]: + if mult % 2 == 0: + continue + for (lo, hi), _ in fac.intervals(): + if best is None or hi > best[2]: + best = (fac, lo, hi) + if best is None: + raise Invalid("no sign change") + fac, lo, hi = best + lo, hi = fac.refine_root(lo, hi, eps=sp.Rational(1, 10 ** 16)) + r = (lo + hi) / 2 + if not r > 0: + raise Invalid("no positive sign change") + return float(r) + + +def check(inst, ans): + zs = ans.get("laguerre_double_roots") + if not isinstance(zs, list) or not 1 <= len(zs) <= inst["max_roots"]: + raise Invalid(f"laguerre_double_roots must be a list of 1..{inst['max_roots']} numbers") + Z = [] + for z in zs: + v = num(z, "root") + if not 0 < v <= inst["max_root"]: + raise Invalid(f"roots must lie in (0, {inst['max_root']}]") + Z.append(Fraction(repr(v))) + if len(set(Z)) != len(Z): + raise Invalid("duplicate roots") + r1 = _last_sign_change(_h_coeffs(Z, 400)) + r2 = _last_sign_change(_h_coeffs(Z, 600)) + if abs(r1 - r2) > 1e-12 * max(1.0, abs(r2)): + raise Invalid("numerically unstable root configuration") + return r2 / (2 * math.pi), {"r": r2} diff --git a/tasks/optimize-ea-uncertainty-principle/tests/instance.json b/tasks/optimize-ea-uncertainty-principle/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d97d564504d7019f5283c494869fb92aba6d897e --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/tests/instance.json @@ -0,0 +1 @@ +{"max_roots": 25, "max_root": 300, "direction": "minimize", "best_known": 0.31885, "baseline": 0.6132901966611566, "family": "ea_uncertainty_principle", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-uncertainty-principle/tests/run.py b/tasks/optimize-ea-uncertainty-principle/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ea-uncertainty-principle/tests/test.sh b/tasks/optimize-ea-uncertainty-principle/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-uncertainty-principle/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt